Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
ReleaseController.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  *
11  */
13 {
14 
15 
16  /**
17  * Sets access filters
18  *
19  * @return array
20  */
21  public function filters()
22  {
23  return array(
24  'accessControl'
25  );
26  }
27 
28  /**
29  * Sets access rules
30  *
31  * @return array
32  */
33  public function accessRules()
34  {
35  return array(
36  array('allow',
37  'actions' => array('create', 'updateStep1', 'updateStep2', 'updateStep3'),
38  'roles' => array('Admin'),
39  ),
40  array('deny',
41  'users' => array('*'),
42  ),
43  );
44  }
45 
46  /**
47  * Creates a release
48  *
49  * @return array
50  */
51  public function actionCreate()
52  {
53  $model = new CreateReleaseForm();
54  $model->invitationMessage = UpdatesModule::t('With this archive you can update Gentics Portal.Node PHP to version {version}', array('{version}' => Yii::app()->getModule('updates')->currentVersion));
55  $model->invitationMessage .= "\nNOTE: Before run update check if application directory is writable!";
56  $model->finishMessage = 'Successfully updated';
57  if (!empty($_POST['CreateReleaseForm'])) {
58  $model->attributes = $_POST['CreateReleaseForm'];
59  if ($model->validate()) {
60  $release = Release::make(
61  Yii::getPathOfAlias('site'),
62  array('.git', '.idea', '.gitignore', 'custom', 'frontend/runtime', 'frontend/www/assets', 'common/runtime', 'DCR', 'FSCR'),
63  $model->invitationMessage,
64  $model->finishMessage
65  );
66  Yii::app()->request->sendFile(pathinfo($release->getZipLocation(), PATHINFO_BASENAME), file_get_contents($release->getZipLocation()), null, false);
67  exit(0);
68  }
69  }
70 
71  $this->render('create', array('model' => $model));
72  }
73 
74  /**
75  * Update action, step 1
76  *
77  * @throws Exception
78  * @return void
79  */
80  public function actionUpdateStep1()
81  {
82  Yii::app()->user->setState('releaseFile', null);
83  $model = new UpdateForm();
84  if (!empty($_POST['UpdateForm'])) {
85  $model->attributes = $_POST['UpdateForm'];
86  $model->validate();
87 
88  $file = CUploadedFile::getInstance($model, 'file');
89  if ($file && !$file->getHasError()) {
90  $fileName = Yii::getPathOfAlias('site.custom.runtime') . '/' . $file->getName();
91  $file->saveAs($fileName);
92  Yii::app()->user->setState('releaseFile', $fileName);
93  $this->redirect('updateStep2');
94  } else {
95  throw new Exception('Upload file error.' . ($file ? 'Code: ' . $file->getError() : ''));
96  }
97  }
98  $this->render('updateStep1', array('model' => $model));
99  }
100 
101  /**
102  * Update action, step 2
103  *
104  * @return void
105  */
106  public function actionUpdateStep2()
107  {
108  if ($releaseFile = Yii::app()->user->getState('releaseFile')) {
109  $release = new Release($releaseFile);
110  $this->render('updateStep2', array('release' => $release));
111  } else {
112  $this->redirect('updateStep1');
113  }
114  }
115 
116  /**
117  * Update action, step 1
118  *
119  * @return void
120  */
121  public function actionUpdateStep3()
122  {
123  if (isset($_POST['Update']) && ($releaseFile = Yii::app()->user->getState('releaseFile'))) {
124  try {
125  $backupPath = Release::backupProject(Yii::getPathOfAlias('site.custom.runtime'));
126  $release = new Release($releaseFile);
127  $release->update(Yii::getPathOfAlias('site'));
128  //Release::migrate();
129  Yii::app()->user->setState('releaseFile', null);
130  $this->render('updateStep3', array('release' => $release, 'backupPath' => $backupPath));
131  } catch (Exception $e) {
132  Yii::app()->user->setFlash('error', UpdatesModule::t('Update process fails') . ' ' . $e->getMessage());
133  $this->render('updateStep3');
134  }
135  } else {
136  $this->redirect('updateStep1');
137  }
138 
139  }
140 
141 }