/** * Update cms * * @return \Zend\View\Model\ViewModel|array */ public function updateAction() { $versionIsLatest = Version::isLatest(); $latestVersion = Version::getLatest(); $session = $this->getSession(); if ($this->getRequest()->isPost()) { $updater = new Updater(); $versionIsLatest = false; if (!$updater->load($this->getRequest()->getPost()->get('adapter')) or $versionIsLatest) { $this->flashMessenger()->addErrorMessage('Can\'t set adapter'); return $this->redirect()->toRoute('config/cms-update'); } $currentVersion = Version::VERSION; //Fetch content if ($updater->update()) { //Upgrade cms if ($updater->upgrade()) { //Update modules $modules = $this->getServiceLocator()->get('CustomModules')->getLoadedModules(); foreach ($modules as $module) { if (method_exists($module, 'update')) { try { $module->update($latestVersion); } catch (Exception $e) { //don't care } } } //Update database $configuration = $this->getServiceLocator()->get('Config'); $dbAdapter = GlobalAdapterFeature::getStaticAdapter(); if (!$updater->updateDatabase($configuration, $dbAdapter)) { //Rollback cms $updater->rollback($currentVersion); } else { $updater->executeScripts(); $session['updateOutput'] = $updater->getMessages(); $this->flashMessenger()->addSuccessMessage(sprintf('Cms update to %s', $latestVersion)); return $this->redirect()->toRoute('config/cms-update'); } } } foreach ($updater->getMessages() as $message) { $this->flashMessenger()->addErrorMessage($message); } return $this->redirect()->toRoute('config/cms-update'); } if (!empty($session['updateOutput'])) { $updateOutput = $session['updateOutput']; unset($session['updateOutput']); } //Check modules and datatypes $datatypesErrors = array(); $this->checkVersion($this->getServiceLocator()->get('DatatypesList'), 'datatype', $datatypesErrors); $modulesErrors = array(); $this->checkVersion($this->getServiceLocator()->get('ModulesList'), 'module', $modulesErrors); return array('gitProject' => file_exists(GC_APPLICATION_PATH . '/.git'), 'isLatest' => $versionIsLatest, 'latestVersion' => $latestVersion, 'datatypesErrors' => $datatypesErrors, 'modulesErrors' => $modulesErrors, 'updateOutput' => empty($updateOutput) ? '' : $updateOutput); }
/** * Test * * @return void */ public function testGetMessages() { $this->object->load('git'); $this->assertInternalType('array', $this->object->getMessages()); }