1: <?php
2: /*****************************************************************************************
3: * X2Engine Open Source Edition is a customer relationship management program developed by
4: * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
5: *
6: * This program is free software; you can redistribute it and/or modify it under
7: * the terms of the GNU Affero General Public License version 3 as published by the
8: * Free Software Foundation with the addition of the following permission added
9: * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10: * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
11: * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12: *
13: * This program is distributed in the hope that it will be useful, but WITHOUT
14: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16: * details.
17: *
18: * You should have received a copy of the GNU Affero General Public License along with
19: * this program; if not, see http://www.gnu.org/licenses or write to the Free
20: * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21: * 02110-1301 USA.
22: *
23: * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
24: * California 95067, USA. or at email address contact@x2engine.com.
25: *
26: * The interactive user interfaces in modified source and object code versions
27: * of this program must display Appropriate Legal Notices, as required under
28: * Section 5 of the GNU Affero General Public License version 3.
29: *
30: * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31: * these Appropriate Legal Notices must retain the display of the "Powered by
32: * X2Engine" logo. If the display of the logo is not reasonably feasible for
33: * technical reasons, the Appropriate Legal Notices must display the words
34: * "Powered by X2Engine".
35: *****************************************************************************************/
36:
37: Yii::import('application.components.webupdater.*');
38:
39: /**
40: * Generic action class for performing a stage of an update/upgrade via AJAX.
41: *
42: * @package application.components.webupdater
43: * @author Demitri Morgan <demitri@x2engine.com>
44: */
45: class UpdateStageAction extends WebUpdaterAction {
46:
47: public function behaviors() {
48: return array(
49: 'UpdaterBehavior' => array(
50: 'class' => 'application.components.UpdaterBehavior',
51: 'errorCode' => 200, // Simple UI-based error reporting
52: 'handleErrors' => true,
53: 'handleExceptions' => true
54: )
55: );
56: }
57:
58: public function run($stage,$scenario,$version,$uniqueId,$autoRestore=0){
59: $this->scenario = $scenario;
60: if(Yii::app()->request->isAjaxRequest){
61: switch($stage) {
62: case 'download':
63: // Download the update/upgrade package
64: $this->downloadPackage($version,$uniqueId,$this->edition);
65: $this->respond(Yii::t('admin','Successfully downloaded package.'));
66: break;
67: case 'enact':
68: // The final and most critical part of the update, where
69: // files are copied and database commands are run.
70: $autoRestore = ($autoRestore === 'true') ? true : false;
71: $this->uniqueId = $uniqueId;
72: $this->enactChanges($autoRestore);
73: $this->finalizeUpdate($scenario, $uniqueId, $this->version, $this->edition);
74: $this->respond(Yii::t('admin', 'All done.'));
75: break;
76: case 'check':
77: // Retrive the manifest of changes pre-emptively, or load
78: // the existing manifest, for review. Check the installation
79: // and server environment for compatibility.
80: if(!$this->checkIf('manifestAvail',false)) {
81: // No package has yet been downloaded; if the package
82: // were present, but the manifest not ready for use,
83: // UpdaterBehavior would have thrown an exception by now
84: // (the 'verify' stage, which performs the necessary
85: // checks, should have been run first).
86: $data = $this->getUpdateData($version,$uniqueId,$this->edition);
87: if(array_key_exists('errors',$data)) {
88: // The update server doesn't like us.
89: $this->respond($data['errors'],1);
90: break;
91: }
92: $this->manifest = $data;
93: }
94:
95: $cStatus = $this->getCompatibilityStatus();
96: $this->response['allClear'] = $cStatus['allClear'];
97: $this->response['manifest'] = $this->manifest;
98: $this->response['compatibilityStatus'] = $cStatus;
99: $this->respond($this->renderCompatibilityMessages('strong',array('style'=>'text-decoration:underline;')));
100: break;
101: case 'unpack':
102: // Unpack the zip file
103: $this->unpack();
104: $this->respond(Yii::t('admin','Successfully extracted package.'));
105: break;
106: case 'verify':
107: try{
108: // Check package contents.
109: $this->checkIf('packageApplies');
110: // The JSON returned by this action should include all the
111: // necessary data to render warning messages concerning files.
112: $this->response['statusCodes'] = array(
113: 'present' => UpdaterBehavior::FILE_PRESENT,
114: 'corrupt' => UpdaterBehavior::FILE_CORRUPT,
115: 'missing' => UpdaterBehavior::FILE_MISSING
116: );
117: $this->response['filesStatus'] = $this->filesStatus;
118: $this->response['filesByStatus'] = $this->filesByStatus;
119: $this->respond(Yii::t('admin', 'Files checked.'), !((bool) $this->files) || $this->filesStatus[UpdaterBehavior::FILE_CORRUPT] > 0 || $this->filesStatus[UpdaterBehavior::FILE_MISSING] > 0);
120: }catch(Exception $e){
121: $this->respond($e->getMessage(), true);
122: }
123: break;
124: }
125: }else{
126: $this->respond('Update requests must be made via AJAX.',true);
127: }
128: }
129: }
130:
131: ?>
132: