/** * this logs to the sytem log the application load time * NOTE: this code runs once at boot time so it is the ideal place to implecate * things that need a run-once at startup * * @return array that will be encoded to JSON */ public function logloadingtimeJsonAction() { RM_Log::toLog('Admin end loading time: ' . $this->_getParam('time'), RM_Log::INFO); // update load status $model = new RM_System(); $data = $model->setRunStatus(1); // check for new modules or plugins $extensions = RM_Environment::getInstance()->getOutOfDateExtensions(); // make a string of modules that have updates available $moduleNames = false; if (!empty($extensions['modules'])) { foreach ($extensions['modules'] as $module) { $moduleNames[] = $module; } $moduleNames = implode(",", $moduleNames); } // make a string of plugins that have updates available $pluginNames = false; if (!empty($extensions['plugins'])) { foreach ($extensions['plugins'] as $plugins) { $pluginsNames[] = $plugins; } $pluginsNames = implode(",", $pluginsNames); } $config = new RM_Config(); $licenceKey = false; if ($config->getValue('rm_config_licensekey') !== "") { $licenceKey = true; } return array('data' => array('success' => true, 'moduleupdates' => $moduleNames, 'pluginupdates' => $pluginNames, 'licensekey' => $licenceKey)); }
/** * Execute every sql query in the file * * @param string $sqlFilepath path to file with SQL queries * @return bool */ public static function executeSQLFile($sqlFilepath) { if (is_file($sqlFilepath) == false) { return true; } $sqlString = file_get_contents($sqlFilepath); if ($sqlString === false || $sqlString == "") { return true; } $sqlString = trim($sqlString); $system = new RM_System(); $result = $system->parseSQL($sqlString); //$result = self::executeSQLCode($sqlString); return $result; }
/** * Returns the run status * * @return string */ public function getRunStatus() { $model = new RM_System(); $data = $model->getRunStatus()->toArray(); return (int) $data[0]['runstatus']; }
/** This performs the DB Upgrade * step 3 * This process will apply the upgrade sql files in sequence. So that all * updates are applied from one version to the next. * * @return json */ public function upgradedatabaseJsonAction() { // get the current db version $system = new RM_System(); $dbVersion = $system->getDBVersion()->current()->db_version; // get the latest version $version = RM_Environment::getInstance()->getLatestVersion(); if ($dbVersion == $version) { RM_Log::toLog('Upgrade - DB upgrade not required as DB is at latest revision: ' . $dbVersion, RM_Log::INFO); return array('data' => array('success' => 1, 'error' => "No DB Upgrade Action Required as DB Version is at Latest Revision")); } // Remove all dots from version so we will get the integer of the version. ie: 1211630 $dbCurrentVersionNumber = (int) str_replace(".", "", $dbVersion); $sqlPath = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'temp', 'upgrade', 'system', 'sql')); // if this is the stable release switch to the upgrades folder... if (version_compare($dbVersion, "1.0.0", '>=')) { $sqlPath = $sqlPath . DIRECTORY_SEPARATOR . "upgrades"; } $filesContent = array(); $files = RM_Filesystem::getFiles($sqlPath, array('sql')); $numbers = array(); foreach ($files as $file) { $chunks = explode('.', $file); if (count($chunks) == 3 && $chunks[1] == 'upgrade') { $numbers[] = $chunks[0]; } } sort($numbers); foreach ($numbers as $number) { if ($number > $dbCurrentVersionNumber) { $sqlFile = $sqlPath . DIRECTORY_SEPARATOR . $number . ".upgrade.sql"; RM_Log::toLog('Upgrade - Applying DB upgrade file: ' . $sqlFile, RM_Log::INFO); if (file_exists($sqlFile)) { $filesContent[] = file_get_contents($sqlFile); } } } foreach ($filesContent as $fileContent) { try { $result = $system->parseSQL($fileContent); } catch (Exception $e) { $result = false; } if (!$result) { RM_Log::toLog('Upgrade - DB Upgrade has failed!', RM_Log::ERR); $msg = 'The database query for installation/upgrade has failed! More Information about the exception thrown will be in the systemlog'; return array('data' => array('success' => false, 'msg' => $msg)); } } return array('data' => array('success' => true)); }