Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • AutomaticTranslationCommand
  • ConsoleFormatterUtil
  • CronCommand
  • CryptSetupCommand
  • DummyCommand
  • ExportFixtureCommand
  • MigrateCustomCommand
  • SampleDataCommand
  • UpdateCommand
  • UpdaterPackageCommand
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /*****************************************************************************************
  4:  * X2Engine Open Source Edition is a customer relationship management program developed by
  5:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  6:  * 
  7:  * This program is free software; you can redistribute it and/or modify it under
  8:  * the terms of the GNU Affero General Public License version 3 as published by the
  9:  * Free Software Foundation with the addition of the following permission added
 10:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 11:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 12:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 13:  * 
 14:  * This program is distributed in the hope that it will be useful, but WITHOUT
 15:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 16:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 17:  * details.
 18:  * 
 19:  * You should have received a copy of the GNU Affero General Public License along with
 20:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 21:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 22:  * 02110-1301 USA.
 23:  * 
 24:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 25:  * California 95067, USA. or at email address contact@x2engine.com.
 26:  * 
 27:  * The interactive user interfaces in modified source and object code versions
 28:  * of this program must display Appropriate Legal Notices, as required under
 29:  * Section 5 of the GNU Affero General Public License version 3.
 30:  * 
 31:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 32:  * these Appropriate Legal Notices must retain the display of the "Powered by
 33:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 34:  * technical reasons, the Appropriate Legal Notices must display the words
 35:  * "Powered by X2Engine".
 36:  *****************************************************************************************/
 37: 
 38: Yii::import('application.components.util.*');
 39: 
 40: /**
 41:  * X2Engine command line updater.
 42:  * 
 43:  * @package application.commands
 44:  * @author Demitri Morgan <demitri@x2engine.com>
 45:  */
 46: class UpdateCommand extends CConsoleCommand {
 47: 
 48:     public function beforeAction($action, $params){
 49:         $this->attachBehaviors(array(
 50:             'UpdaterBehavior' => array(
 51:                 'class' => 'application.components.UpdaterBehavior',
 52:                 'isConsole' => true,
 53:                 'scenario' => 'update',
 54:             )
 55:         ));
 56:         $this->requireDependencies();
 57:         return parent::beforeAction($action, $params);
 58:     }
 59: 
 60:     public function actionIndex(){
 61:         echo $this->help;
 62:     }
 63: 
 64:     /**
 65:      * Update the application.
 66:      * @param int $force "force" parameter sent to {@link runOperation}
 67:      * @param int $backup "backup" parameter sent to {@link runOperation}
 68:      */
 69:     public function actionApp($force = 0,$backup = 1, $lock=0) {
 70:         // Check updater version, update updater itself, etc.
 71:         $this->runOperation('update',(bool) $force, (bool) $backup, (bool) $lock);
 72:         return 0;
 73:     }
 74: 
 75:     /**
 76:      * Performs registration and upgrades the application to a different edition.
 77:      *
 78:      * @param type $key Product key
 79:      * @param type $firstName First name
 80:      * @param type $lastName Last name
 81:      * @param type $email Email address
 82:      * @param bool $force Same as the $force argument of {@link actionApp()}
 83:      */
 84:     public function actionUpgrade($key,$firstName,$lastName,$email,$force=0,$backup=1) {
 85:         $this->uniqueId = $key;
 86:         // Check for curl:
 87:         if(!$this->requirements['requirements']['extensions']['curl'])
 88:             $this->output(Yii::t('admin','Cannot proceed; cURL extension is required for registration.'),1,1);
 89:         // Let's see if we're clear to proceed first:
 90:         $ch = curl_init($this->updateServer.'/installs/registry/register');
 91:         curl_setopt_array($ch, array(
 92:             CURLOPT_POST => 1,
 93:             CURLOPT_RETURNTRANSFER => 1,
 94:             CURLOPT_POSTFIELDS => array(
 95:                 'firstName' => $firstName,
 96:                 'lastName' => $lastName,
 97:                 'email' => $email,
 98:                 'unique_id' => $key
 99:             ),
100:         ));
101:         $cr = json_decode(curl_exec($ch));
102: 
103: 
104:         // Now proceed:
105:         $this->runOperation('upgrade',(bool) $force, (bool) $backup);
106:     }
107: 
108:     /**
109:      * Runs the actual update/upgrade.
110:      * 
111:      * @param string $scenario The scenario (update or upgrade)
112:      * @param bool $force False to halt on encountering any
113:      *  compatibility issues; true to continue through issues
114:      * @param bool $backup If enabled: create database backup before running
115:      *  operations, and restore to the backup if operations fail.
116:      */
117:     public function runOperation($scenario,$force=false,$backup=true,$lock=false) {
118:         $this->scenario = $scenario;
119:         $unpacked = $this->checkIf('packageExists',false);
120:         if($this->checkIf('packageApplies',false)) {
121:             // All the data is here and ready to go
122:             
123:         } else if($unpacked) {
124:             // A package is present but cannot be used.
125:             // 
126:             // Re-invoke the check method to throw the necessary exception, so
127:             // that its output can be captured/displayed/logged.
128:             $this->checkIf('packageApplies');
129:         } else {
130:             // No existing package waiting is present.
131:             // 
132:             // Prepare for update from square one by first doing an updater
133:             // version check:
134:             $this->runUpdateUpdater();
135:             // Check version:
136:             $latestVersion = $this->checkUpdates(true);
137:             if(version_compare($this->configVars['version'], $latestVersion) >= 0) {
138:                 if($scenario != 'upgrade') {
139:                     $this->output(Yii::t('admin', 'X2Engine is at the latest version!'));
140:                     Yii::app()->end();
141:                 }
142:             } else if($scenario == 'upgrade') {
143:                 $this->output(Yii::t('admin',"Before upgrading, you must update to the latest version ({latestver}). ",array('{latestver}'=>$latestVersion)),1,1);
144:             }
145:             $data = $this->getUpdateData();
146:             if(array_key_exists('errors', $data)){
147:                 // The update server doesn't like us.
148:                 $this->output($data['errors'], 1,1);
149:                 Yii::app()->end();
150:             }
151:             $this->manifest = $data;
152:         }
153: 
154:         // Check compatibility status:
155:         $this->output($this->renderCompatibilityMessages());
156:         if(!$this->compatibilityStatus['allClear'] && !$force) {
157:             Yii::app()->end();
158:         }
159: 
160:         // Download and unpack the package:
161:         if(!$unpacked) {
162:             $this->downloadPackage();
163:             $this->unpack();
164:             $this->checkIf('packageApplies');
165:             if(!((bool) $this->files) || $this->filesStatus[UpdaterBehavior::FILE_CORRUPT] > 0 || $this->filesStatus[UpdaterBehavior::FILE_MISSING] > 0) {
166:                 $this->output(Yii::t('admin','Could not apply package. {n_mis} files are missing, {n_cor} are corrupt', array(
167:                             '{n_mis}' => $this->filesStatus[UpdaterBehavior::FILE_MISSING],
168:                             '{n_cor}' => $this->filesStatus[UpdaterBehavior::FILE_CORRUPT]
169:                         )), 1, 1);
170:             }
171:         }
172: 
173:         // Lock (if specified)
174:         if($lock) {
175:             $this->output(Yii::t('admin','Locking the app to prevent data entry during update.'));
176:             Yii::app()->locked = time();
177:         }
178: 
179:         try{
180:             // Backup
181:             if($backup)
182:                 $this->makeDatabaseBackup();
183: 
184:             // Run
185:             $this->enactChanges($backup);
186:             
187:         }catch(Exception $e){
188: 
189:             if($lock){
190:                 $this->output(Yii::t('admin', 'Unlocking the app.'));
191:                 Yii::app()->setLocked(false);
192:             }
193:             throw $e;
194:         }
195: 
196:         if($lock) {
197:             $this->output(Yii::t('admin','Unlocking the app.'));
198:             Yii::app()->setLocked(false);
199:         }
200:         $this->finalizeUpdate($scenario, $this->uniqueId, $this->version, $this->edition);
201:         $this->output(Yii::t('admin','All done.'));
202:     }
203: 
204: 
205:     /**
206:      *
207:      * @return int 1 to indicate that a self-update was performed; 0 to indicate
208:      *  that the updater utility is already the latest version.
209:      */
210:     public function runUpdateUpdater() {
211:         $config = $this->configVars;
212:         extract($config);
213:         $status = 0;
214:         $latestUpdaterVersion = $this->getLatestUpdaterVersion();
215:         if($latestUpdaterVersion){
216:             $backCompat = $this->backCompatHooks($latestUpdaterVersion);
217:             $refreshCriteria = version_compare($updaterVersion,$latestUpdaterVersion) < 0
218:                     || $backCompat;
219:             if($refreshCriteria){
220:                 $classes = $this->updateUpdater($latestUpdaterVersion);
221:                 if(empty($classes)){
222:                     if($backCompat) {
223:                         $this->output(Yii::t('admin', 'Re-run the command to proceed.'));
224:                     } else {
225:                         $this->output(Yii::t('admin', 'The updater is now up-to-date and compliant with the updates server. Re-run the command to proceed.'));
226:                     }
227:                 } else {
228:                     $this->output(Yii::t('admin', 'One or more dependencies of AdminController are missing and could not be automatically retrieved. They are {classes}', array('{classes}' => implode(', ', $classes))),1,1);
229:                 }
230:                 Yii::app()->end();
231:             } else {
232:                 $this->output(Yii::t('admin','The updater is up-to-date and safe to use.'));
233:                 return;
234:             }
235:         }else{
236:             if(!$this->requirements['requirements']['environment']['updates_connection']) {
237:                 $this->output(Yii::t('admin','Could not connect to the updates server, or an error occurred on the updates server.').' '.(
238:                         $this->requirements['requirements']['extensions']['curl'] || $this->requirements['requirements']['environment']['allow_url_fopen']
239:                         ? ''
240:                         : Yii::t('admin','Note, outbound HTTP requests are not permitted in this PHP runtime environment, because all methods of doing so have been disabled.')
241:                         ),1,1);
242:             }
243:         }
244:     }
245: 
246: }
247: 
248: ?>
249: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0