示例#1
0
 /**
  * Flushes all application cache data
  */
 public function actionFlush()
 {
     Yii::app()->cache->flush();
     ModuleManager::flushCache();
     if (Yii::app()->cache instanceof CApcCache) {
         print "Warning: Could not flush APC Cache! - Restart Webserver!\n";
     }
     print "All application caches flushed!\n";
 }
示例#2
0
 /**
  * Installs latest compatible module version
  *
  * @param type $moduleId
  */
 public function install($moduleId)
 {
     $modulePath = Yii::app()->getModulePath();
     if (!is_writable($modulePath)) {
         throw new CHttpException(500, Yii::t('AdminModule.libs_OnlineModuleManager', 'Module directory %modulePath% is not writeable!', array('%modulePath%' => $modulePath)));
     }
     $moduleInfo = $this->getModuleInfo($moduleId);
     if (!isset($moduleInfo['latestCompatibleVersion'])) {
         throw new CException(Yii::t('AdminModule.libs_OnlineModuleManager', "No compatible module version found!"));
     }
     if (is_dir($modulePath . DIRECTORY_SEPARATOR . $moduleId)) {
         throw new CHttpException(500, Yii::t('AdminModule.libs_OnlineModuleManager', 'Module directory for module %moduleId% already exists!', array('%moduleId%' => $moduleId)));
     }
     // Check Module Folder exists
     $moduleDownloadFolder = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . 'module_downloads';
     if (!is_dir($moduleDownloadFolder)) {
         if (!@mkdir($moduleDownloadFolder)) {
             throw new CException("Could not create module download folder!");
         }
     }
     $version = $moduleInfo['latestCompatibleVersion'];
     // Download
     $downloadUrl = $version['downloadUrl'];
     $downloadTargetFileName = $moduleDownloadFolder . DIRECTORY_SEPARATOR . basename($downloadUrl);
     try {
         $http = new Zend_Http_Client($downloadUrl, array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'curloptions' => $this->getCurlOptions(), 'timeout' => 30));
         $response = $http->request();
         file_put_contents($downloadTargetFileName, $response->getBody());
     } catch (Exception $ex) {
         throw new CHttpException('500', Yii::t('AdminModule.libs_OnlineModuleManager', 'Module download failed! (%error%)', array('%error%' => $ex->getMessage())));
     }
     // Extract Package
     if (file_exists($downloadTargetFileName)) {
         // Unzip
         $zip = new ZipArchive();
         $res = $zip->open($downloadTargetFileName);
         if ($res === TRUE) {
             $zip->extractTo($modulePath);
             $zip->close();
         } else {
             throw new CHttpException('500', Yii::t('AdminModule.libs_OnlineModuleManager', 'Could not extract module!'));
         }
     } else {
         throw new CHttpException('500', Yii::t('AdminModule.libs_OnlineModuleManager', 'Download of module failed!'));
     }
     ModuleManager::flushCache();
     // Call Modules autostart
     $autostartFilename = $modulePath . DIRECTORY_SEPARATOR . $moduleId . DIRECTORY_SEPARATOR . 'autostart.php';
     if (file_exists($autostartFilename)) {
         require_once $autostartFilename;
         $module = Yii::app()->moduleManager->getModule($moduleId);
         $module->install();
     }
 }
 public function actionRun()
 {
     $this->forcePostRequest();
     $updatePackage = OnlineUpdateAPI::getAvailableUpdate();
     if ($updatePackage === null) {
         return $this->redirect($this->createUrl('index'));
     }
     $warnings = $updatePackage->install();
     $migration = "";
     Yii::import('application.commands.shell.HUpdateCommand');
     if (class_exists('HUpdateCommand') && method_exists('HUpdateCommand', 'AutoUpdate')) {
         $migration = HUpdateCommand::AutoUpdate();
     } else {
         // Old way
         Yii::import('application.commands.shell.ZMigrateCommand');
         $migration = ZMigrateCommand::AutoMigrate();
     }
     Yii::app()->cache->flush();
     ModuleManager::flushCache();
     $this->render('run', array('updatePackage' => $updatePackage, 'warnings' => $warnings, 'migration' => $migration));
 }
示例#4
0
 /**
  * Uninstalls a module
  *
  * You may overwrite this method to add more cleanup stuff.
  *
  * This method shall:
  *      - Delete all module files
  *      - Delete all modules tables, database changes
  */
 public function uninstall()
 {
     if ($this->isCoreModule) {
         throw new CException("Could not uninstall core modules!");
         return;
     }
     if ($this->isEnabled()) {
         $this->disable();
     }
     // Use uninstall migration, when found
     $uninstallMigration = $this->getPath() . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR . 'uninstall.php';
     if (file_exists($uninstallMigration)) {
         Yii::import("application.commands.shell.*");
         ob_start();
         require_once $uninstallMigration;
         $migration = new uninstall();
         $migration->setDbConnection(Yii::app()->db);
         try {
             $migration->up();
         } catch (Exception $ex) {
         }
         ob_get_clean();
     }
     // Delete all executed migration by module
     $command = Yii::app()->db->createCommand('DELETE FROM migration WHERE module = :moduleId');
     $command->execute(array(':moduleId' => $this->getId()));
     Yii::app()->moduleManager->removeModuleFolder($this->getId());
     ModuleManager::flushCache();
 }
示例#5
0
 public function actionList()
 {
     $installedModules = Yii::app()->moduleManager->getInstalledModules();
     ModuleManager::flushCache();
     $this->render('list', array('installedModules' => $installedModules));
 }
 /**
  * Caching Options
  */
 public function actionCaching()
 {
     Yii::import('admin.forms.*');
     $form = new CacheSettingsForm();
     $form->type = HSetting::Get('type', 'cache');
     $form->expireTime = HSetting::Get('expireTime', 'cache');
     // uncomment the following code to enable ajax-based validation
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'cache-settings-form') {
         echo CActiveForm::validate($form);
         Yii::app()->end();
     }
     if (isset($_POST['CacheSettingsForm'])) {
         Yii::app()->cache->flush();
         ModuleManager::flushCache();
         // Delete also published assets
         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Yii::app()->getAssetManager()->getBasePath(), FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
             // Do not remove .gitignore in assets folder
             if ($path->getPathname() == Yii::app()->getAssetManager()->getBasePath() . DIRECTORY_SEPARATOR . '.gitignore') {
                 continue;
             }
             if ($path->isDir()) {
                 rmdir($path->getPathname());
             } else {
                 unlink($path->getPathname());
             }
         }
         $_POST['CacheSettingsForm'] = Yii::app()->input->stripClean($_POST['CacheSettingsForm']);
         $form->attributes = $_POST['CacheSettingsForm'];
         if ($form->validate()) {
             HSetting::Set('type', $form->type, 'cache');
             HSetting::Set('expireTime', $form->expireTime, 'cache');
             // set flash message
             Yii::app()->user->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved and flushed cache'));
             $this->redirect(Yii::app()->createUrl('//admin/setting/caching'));
         }
     }
     $cacheTypes = array('CDummyCache' => Yii::t('AdminModule.controllers_SettingController', 'No caching (Testing only!)'), 'CFileCache' => Yii::t('AdminModule.controllers_SettingController', 'File'), 'CDbCache' => Yii::t('AdminModule.controllers_SettingController', 'Database'), 'CApcCache' => Yii::t('AdminModule.controllers_SettingController', 'APC'));
     $this->render('caching', array('model' => $form, 'cacheTypes' => $cacheTypes));
 }
 /**
  * Lists all installed modules.
  *
  * @param array $args
  */
 public function actionIndex($args)
 {
     print "Checking for new updates...";
     $updatePackage = OnlineUpdateAPI::getAvailableUpdate();
     print "OK\n\n";
     if ($updatePackage == null) {
         print "No new update available!\n\n";
         return;
     }
     print "Update to " . $updatePackage->versionTo . " found!\n";
     print "\n";
     echo Yii::t('UpdaterModule.base', 'Please note:') . "\n";
     echo "\t - " . Yii::t('UpdaterModule.base', 'Backup all your files & database before proceed') . "\n";
     echo "\t - " . Yii::t('UpdaterModule.base', 'Make sure all files are writable by application') . "\n";
     echo "\t - " . Yii::t('UpdaterModule.base', 'Please update installed marketplace modules before and after the update') . "\n";
     echo "\t - " . Yii::t('UpdaterModule.base', 'Make sure custom modules or themes are compatible with version %version%', array('%version%' => $updatePackage->versionTo)) . "\n";
     echo "\t - " . Yii::t('UpdaterModule.base', 'Do not use this updater in combination with Git!') . "\n";
     echo "\n";
     if (!$this->confirm("Proceed?", true)) {
         print "Aborted!\n";
         return;
     }
     print "\n";
     print "Downloading update package...";
     $updatePackage->download();
     print "OK!\n";
     print "Extracting update package...";
     $updatePackage->extract();
     print "OK!\n";
     print "Validating package...";
     $validationResults = $updatePackage->validate();
     print "OK!\n";
     print "\n";
     if (count($validationResults['notWritable']) != 0) {
         print "ERROR!\n";
         print "Following files are not writable: \n";
         foreach ($validationResults['notWritable'] as $file) {
             print "\t - " . $file . "\n";
         }
         print "\n";
         print "Please make this files writable and restart.\n\n";
         return;
     }
     if (count($validationResults['modified']) != 0) {
         echo Yii::t('UpdaterModule.base', 'The following files seems to be not original (%version%) and will be overwritten or deleted during update process.', array('%version%' => $updatePackage->versionFrom)) . "\n";
         foreach ($validationResults['modified'] as $file) {
             print "\t - " . $file . "\n";
         }
         if (!$this->confirm("These file(s) will be overwritten during update. OK?", true)) {
             print "Aborted!\n";
             return;
         }
         print "\n";
     }
     print "\n";
     print "RELEASE NOTES:\n\n";
     print $updatePackage->getReleaseNotes();
     print "\n\n";
     if (!$this->confirm("Proceed?", true)) {
         print "Aborted!\n";
         return;
     }
     print "\n";
     print "Installing...";
     $warnings = $updatePackage->install();
     print "OK!\n";
     if (count($warnings) != 0) {
         print "\n";
         print "WARNINGS:\n";
         foreach ($warnings as $warning) {
             print "\t - " . $warning . "\n";
         }
     }
     print "Migrating DB...";
     $migration = "";
     Yii::import('application.commands.shell.HUpdateCommand');
     if (class_exists('HUpdateCommand') && method_exists('HUpdateCommand', 'AutoUpdate')) {
         $migration = HUpdateCommand::AutoUpdate();
     } else {
         // Old way
         Yii::import('application.commands.shell.ZMigrateCommand');
         $migration = ZMigrateCommand::AutoMigrate();
     }
     print "OK!\n";
     if ($this->confirm("Show migration results?", false)) {
         print $migration . "\n";
     }
     Yii::app()->cache->flush();
     ModuleManager::flushCache();
     print "\n\n*** Updater successfully finished! ***\n\n";
     if ($this->confirm("Check for new/next available update?", true)) {
         print "\n\n------------------------------- \n\n\n";
         return $this->actionIndex($args);
     }
 }
示例#8
0
 public function actionUpdateAll($args)
 {
     $installedModules = Yii::app()->moduleManager->getInstalledModules(false, true);
     ModuleManager::flushCache();
     print "Updating modules: \n\n";
     foreach ($installedModules as $moduleId => $moduleClass) {
         $this->actionUpdate(array($moduleId), true);
     }
 }
示例#9
0
 public function run($args)
 {
     $exitCode = parent::run($args);
     Yii::app()->cache->flush();
     ModuleManager::flushCache();
 }