/** * Display dashboard * * @return array */ public function indexAction() { $data = array(); $data['version'] = Version::VERSION; $data['versionIsLatest'] = Version::isLatest(); $data['versionLatest'] = Version::getLatest(); $documents = new Collection(); $contentStats = array(); $contentStats['online_documents'] = array('count' => count($documents->getAvailableDocuments()), 'label' => 'Online documents', 'route' => 'content'); $contentStats['total_documents'] = array('count' => count($documents->select()->toArray()), 'label' => 'Total documents', 'route' => 'content'); $data['contentStats'] = $contentStats; $visitorModel = new Visitor(); $data['userStats'] = array('total_visitors' => array('count' => $visitorModel->getTotalVisitors(), 'label' => 'Total visitors', 'route' => 'statistics'), 'total_visits' => array('count' => $visitorModel->getTotalPageViews(), 'label' => 'Total page views', 'route' => 'statistics')); $coreConfig = $this->getServiceLocator()->get('CoreConfig'); $widgets = @unserialize($coreConfig->getValue('dashboard_widgets')); $data['dashboardSortable'] = !empty($widgets['sortable']) ? Json::encode($widgets['sortable']) : '{}'; $data['dashboardWelcome'] = !empty($widgets['welcome']); $data['customeWidgets'] = array(); $this->events()->trigger(__CLASS__, 'dashboard', $this, array('widgets' => &$data['customeWidgets'])); return $data; }
/** * 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); }