Example #1
0
 /**
  * Update action method
  *
  * @param  int $id
  * @return void
  */
 public function update($id)
 {
     $module = new Model\Module();
     $module->getById($id);
     if (isset($module->id) && isset($this->sess->updates->modules[$module->name]) && version_compare($module->version, $this->sess->updates->modules[$module->name]) < 0) {
         if ($this->request->getQuery('update') == 2 && is_writable(MODULES_ABS_PATH) && is_writable(MODULES_ABS_PATH . '/' . $module->folder) && is_writable(MODULES_ABS_PATH . '/' . $module->folder . '.zip')) {
             clearstatcache();
             $updaterClass = $module->prefix . 'Updater';
             if (class_exists($updaterClass)) {
                 $updater = new $updaterClass($module->name);
                 $updater->runPost();
             }
             $mod = \Phire\Table\Modules::findById($id);
             if (isset($mod->id)) {
                 $mod->version = $this->sess->updates->modules[$module->name];
                 $mod->updated_on = date('Y-m-d H:i:s');
                 $mod->save();
             }
             $this->redirect(BASE_PATH . APP_URI . '/modules/complete/' . $id);
         } else {
             if ($this->request->getQuery('update') == 1 && is_writable(MODULES_ABS_PATH) && is_writable(MODULES_ABS_PATH . '/' . $module->folder) && is_writable(MODULES_ABS_PATH . '/' . $module->folder . '.zip')) {
                 $updater = new \Phire\Updater($module->name);
                 $updater->getUpdate($module->name, $this->sess->updates->modules[$module->name], $module->version, $id);
                 $this->redirect(BASE_PATH . APP_URI . '/modules/update/' . $id . '?update=2');
             } else {
                 $this->prepareView('phire/modules/update.phtml');
                 $this->view->title = 'Update ' . $module->name;
                 $this->view->module_id = $module->id;
                 $this->view->module_name = $module->name;
                 $this->view->module_update_version = $this->sess->updates->modules[$module->name];
                 if (is_writable(MODULES_ABS_PATH) && is_writable(MODULES_ABS_PATH . '/' . $module->folder) && is_writable(MODULES_ABS_PATH . '/' . $module->folder . '.zip')) {
                     $this->view->writable = true;
                 } else {
                     $this->view->writable = false;
                 }
                 $this->send();
             }
         }
     } else {
         $this->redirect(BASE_PATH . APP_URI . '/modules');
     }
 }
 /**
  * Update action method
  *
  * @return void
  */
 public function update()
 {
     $config = new Model\Config();
     $updates = $config->getUpdates();
     $moduleId = $this->getModuleId();
     $module = Table\Modules::findById($moduleId);
     if (isset($module->id)) {
         if (isset($updates->modules[$module->folder]) && version_compare($updates->modules[$module->folder], $module->version) < 0) {
             $this->console->append();
             $this->console->append($this->console->colorize('The \'' . $module->folder . '\' module is available for update.', Console::BOLD_YELLOW));
             $this->console->append();
             $this->console->append($this->console->colorize('Please back up all of your files and your database before proceeding.', Console::BOLD_RED));
             $this->console->append();
             $this->console->send();
             $update = null;
             while (strtolower($update) != 'y' && strtolower($update) != 'n') {
                 $update = $this->console->prompt($this->console->getIndent() . 'Update the \'' . $module->folder . '\' module? (Y/N) ');
             }
             if (strtolower($update) == 'y') {
                 if (is_writable(__DIR__ . '/../../../') && is_writable(__DIR__ . '/../../../' . $module->folder) && is_writable(__DIR__ . '/../../../' . $module->folder . '.zip')) {
                     $updater = new \Phire\Updater($module->folder);
                     $updater->getUpdate($module->folder);
                     clearstatcache();
                     $updaterClass = $module->prefix . 'Updater';
                     if (class_exists($updaterClass)) {
                         $updater = new $updaterClass($module->folder);
                         $updater->runPost();
                     } else {
                         if (file_exists(__DIR__ . '/../../../' . $module->folder . '/src/Updater.php')) {
                             include __DIR__ . '/../../../' . $module->folder . '/src/Updater.php';
                             if (class_exists($updaterClass)) {
                                 $updater = new $updaterClass($module->folder);
                                 $updater->runPost();
                             }
                         } else {
                             $module->updated_on = date('Y-m-d H:i:s');
                             $module->save();
                         }
                     }
                     $this->console->append();
                     $this->console->append($this->console->colorize('Update completed successfully!', Console::BOLD_CYAN));
                     $this->console->append($this->console->colorize('You have updated \'' . $module->folder . '\' to version ' . $updates->modules[$module->folder] . '.', Console::BOLD_CYAN));
                     $this->console->send();
                 } else {
                     $this->console->append();
                     $this->console->append($this->console->colorize('The module folders are not writable. They must be writable to update the module.', Console::BOLD_RED));
                     $this->console->send();
                 }
             }
         } else {
             $this->console->append();
             $this->console->append($this->console->colorize('The \'' . $module->folder . '\' module is up-to-date!', Console::BOLD_GREEN));
             $this->console->send();
         }
     }
 }