private function loadInit() { \GO\Base\Observable::cacheListeners(); //when GO initializes modules need to perform their first run actions. unset(\GO::session()->values['firstRunDone']); if (\GO::user()) { $this->fireEvent('loadapplication', array(&$this)); } }
protected function actionUpgrade($params) { if (!$this->isCli()) { echo '<pre>'; } if (!version_compare(phpversion(), "5.3", ">=")) { exit("You are running a PHP version older than 5.3. PHP 5.3 or greater is required to run Group-Office " . \GO::config()->version); } $this->lockAction(); GO::setIgnoreAclPermissions(true); GO::session()->runAsRoot(); \GO::clearCache(); \GO\Base\Db\Columns::$forceLoad = true; //don't be strict in upgrade process \GO::getDbConnection()->query("SET sql_mode=''"); $v3 = $this->_checkV3(); $logDir = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'log/upgrade/'); $logDir->create(); global $logFile; $logFile = $logDir->path() . '/' . date('Ymd_Gi') . '.log'; touch($logFile); if (!is_writable($logFile)) { die('Fatal error: Could not write to log file'); } ob_start("GO\\Core\\Controller\\MaintenanceController::ob_upgrade_log"); echo "Updating " . \GO::config()->product_name . " database\n"; //build an array of all update files. The queries are indexed by timestamp //so they will all be executed in the right order. $u = array(); require \GO::config()->root_path . 'install/updates.php'; //put the updates in an extra array dimension so we know to which module //they belong too. foreach ($updates as $timestamp => $updatequeries) { $u["{$timestamp}"]['core'] = $updatequeries; } $modules = \GO::modules()->getAllModules(); while ($module = array_shift($modules)) { if ($module->isAvailable()) { $updatesFile = $module->path . 'install/updates.php'; if (!file_exists($updatesFile)) { $updatesFile = $module->path . 'install/updates.inc.php'; } if (file_exists($updatesFile)) { $updates = array(); require $updatesFile; //put the updates in an extra array dimension so we know to which module //they belong too. foreach ($updates as $timestamp => $updatequeries) { $u["{$timestamp}"][$module->id] = $updatequeries; } } } } //sort the array by timestamp ksort($u); // // var_dump($u); // exit(); $currentCoreVersion = \GO::config()->get_setting('version'); if (!$currentCoreVersion) { $currentCoreVersion = 0; } $counts = array(); foreach ($u as $timestamp => $updateQuerySet) { foreach ($updateQuerySet as $module => $queries) { //echo "Getting updates for ".$module."\n"; if (!is_array($queries)) { exit("Invalid queries in module: " . $module); } if ($module == 'core') { $currentVersion = $currentCoreVersion; } else { $currentVersion = \GO::modules()->{$module}->version; } if (!isset($counts[$module])) { $counts[$module] = 0; } foreach ($queries as $query) { $counts[$module]++; if ($counts[$module] > $currentVersion) { if (substr($query, 0, 7) == 'script:') { if ($module == 'core') { $updateScript = \GO::config()->root_path . 'install/updatescripts/' . substr($query, 7); } else { $updateScript = \GO::modules()->{$module}->path . 'install/updatescripts/' . substr($query, 7); } if (!file_exists($updateScript)) { die($updateScript . ' not found!'); } //if(!$quiet) echo 'Running ' . $updateScript . "\n"; flush(); if (empty($params['test'])) { require_once $updateScript; } } else { echo 'Excuting query: ' . $query . "\n"; flush(); if (empty($params['test'])) { try { if (!empty($query)) { \GO::getDbConnection()->query($query); } } catch (PDOException $e) { //var_dump($e); echo $e->getMessage() . "\n"; echo "Query: " . $query; // if ($e->getCode() == 1091 || $e->getCode() == 1060) { // //duplicate and drop errors. Ignore those on updates // } else { // die(); // } } } } if (empty($params['test'])) { if ($module == 'core') { \GO::config()->save_setting('version', $counts[$module]); } else { //echo $module.' updated to '.$counts[$module]."\n"; $moduleModel = \GO::modules()->{$module}; $moduleModel->version = $counts[$module]; $moduleModel->save(); } ob_flush(); } } } } } if (empty($params['test'])) { echo "Database updated to version " . \GO::config()->mtime, "\n"; ob_flush(); \GO::config()->save_setting('upgrade_mtime', \GO::config()->mtime); } else { echo "Ran in test mode\n"; } echo "Removing cached javascripts...\n\n"; //in some exceptions alowed deletes is still on false here. \GO\Base\Fs\File::setAllowDeletes(true); \GO::clearCache(); //rebuild listeners \GO\Base\Observable::cacheListeners(); if ($v3) { // if(\GO::modules()->isInstalled('projects') && \GO::modules()->isInstalled('files')){ // echo "Renaming projects folder temporarily for new project paths\n"; // $folder = \GO\Files\Model\Folder::model()->findByPath('projects'); // if($folder){ // $folder->name='oldprojects'; // $folder->systemSave=true; // $folder->save(); // } // } // echo "Checking database after version 3.7 upgrade.\n"; // $this->actionCheckDatabase($params); // echo "Done\n\n"; // ob_flush(); $versioningFolder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'versioning'); if ($versioningFolder->exists()) { $versioningFolder->rename("versioning_backup_3_7"); } if (!$this->isCli()) { echo '</pre>'; } echo "Building search cache after version 3.7 upgrade.\n"; ob_flush(); $this->run("buildsearchcache", $params); ob_flush(); if (!$this->isCli()) { echo '<pre>'; } } echo "All Done!\n"; if (!$this->isCli() && basename($_SERVER['PHP_SELF']) != 'upgrade.php') { echo '</pre><br /><br />'; echo '<a href="' . \GO::config()->host . '">' . \GO::t('cmdContinue') . '</a>'; } ob_end_flush(); \GO\Base\Db\Columns::$forceLoad = false; //return $response; }