/** * Default action for database updating. * * @access public * @return View * @since 2014-08-17 * @version 1.2.0-dev */ public function actionDefault() { $this->addToTitle('Database updating module'); // create update form $oForm = new Form('db_update'); $oForm->setSubmitValue(__('make update')); // check if update button has been clicked if ($oForm->isSubmittedAndValid()) { $sUpdateOutput = static::makeUpdateNoExec(); Cache::set($sUpdateOutput, 'output', 'dbupdate'); Session::flash(Router::getCurrentUrl(), __('Database updated successfully.')); } // return View return View::factory('db_update/backend/default')->bind('oForm', $oForm); }
/** * Main action to run cron jobs. * * @access public * @since 2.33.0-dev, 2015-06-07 * @version 2.39.0-dev */ public function actionDefault() { if (!class_exists('\\Cron\\CronExpression')) { throw new Exception\Fatal('Cannot run Cron jobs without proper Cron library.'); } $sTokenFromURL = Router::getParam('token'); $sTokenFromConfig = Config::get('base.cron_token'); $iCronJobsCompleted = 0; // check Cron token if ($sTokenFromURL !== $sTokenFromConfig) { throw new Exception\Code404(); } // get all Cron jobs $aAllJobs = CronJobsHelper::getCronJobs(); // count amount of all CRON jobs $iCronJobs = count($aAllJobs); // run a single CRON job foreach ($aAllJobs as $aJobData) { $sModule = $aJobData['module']; $sJobKey = base64_encode($aJobData[1] . '.' . $aJobData[2]); $aCache = Cache::get($sModule . '.' . $sJobKey, 'cron'); $iRunDate = isset($aCache['time']) ? $aCache['time'] : NULL; $oCron = CronExpression::factory($aJobData[0]); if ($iRunDate === NULL || $iRunDate < time()) { switch ($aJobData[1]) { case 'route': $sURL = Route::factory($aJobData[2])->url(); file_get_contents($sURL); break; case 'file': case 'url': file_get_contents($aJobData[2]); break; case 'function': call_user_func($aJobData[2]); break; } $iNextRun = $oCron->getNextRunDate()->format('U'); $aCacheToSave = ['time' => $iNextRun, 'last_execution_time' => time(), 'type' => $aJobData[1], 'param' => $aJobData[2]]; Cache::set($aCacheToSave, $sModule . '.' . $sJobKey, 'cron', 0); } } // log that cron jobs turning on action was completed Log::insert('Cron jobs (in amount of ' . $iCronJobs . ') were checked and ' . $iCronJobsCompleted . ' of them were turned on.'); // end of functionality exit; }
/** * Get Cron jobs from all modules of particular web application. * * @static * @access public * @return array * @since 1.1.0-dev * @version 1.1.0-dev */ public static function getCronJobs() { $aAllJobs = []; foreach (Config::get('modules') as $sGroupName => $aGroup) { foreach (array_keys($aGroup) as $module) { $sDir = PATH_MODULES . $sGroupName . DS . $module . DS . 'config'; $sFilePath = $sDir . DS . 'cron.php'; if (file_exists($sDir) && file_exists($sFilePath)) { $aCronData = Config::get($module . '.cron', NULL); foreach ($aCronData as &$data) { $jobKey = base64_encode($data[1] . '.' . $data[2]); $aCache = Cache::get($module . '.' . $jobKey, 'cron'); $data['job_key'] = $jobKey; $data['module'] = $module; $data['time'] = isset($aCache['time']) ? $aCache['time'] : NULL; $data['last_exe'] = isset($aCache['last_execution_time']) ? $aCache['last_execution_time'] : NULL; } $aAllJobs = array_merge($aAllJobs, $aCronData); } } } return $aAllJobs; }
/** * Set new data about failed login for particular IP address. * * @access private * @param integer $data * @param string $ip * @return boolean * @since 2.1.2-dev * @version 2.1.2-dev */ private static function setCachedData($data, $ip) { return Cache::set($data, $ip, static::$cacheName, 60 * 15); }
/** * Clear all I18n module cache. * * @static * @access public * @return boolean Returns information whether the language cache has been cleared. * @since 1.0.5-dev * @version 1.2.0-dev */ public static function clearCache() { static::$cachedData = NULL; $output = Cache::clearGroupCache('i18n'); return $output; }
/** * ACTION - Index action. * * @access public * @return View * @since 1.2.0-dev * @version 1.2.0-dev */ public function actionIndex() { $this->setTitle(__('Interface translations')); $info = Cache::get('info', 'i18n'); return View::factory('i18n/backend/index')->bind('info', $info); }
use Plethora\Form; ?> <?php /* @var $oForm Form */ ?> <?php $sUpdateOutput = Cache::get('output', 'dbupdate'); ?> <?php echo __('Click the button below to update database.'); echo $oForm->render(); ?> <?php if (!empty($sUpdateOutput)) { ?> <h2><?php echo __('Output data'); ?> :</h2> <pre><?php echo $sUpdateOutput; ?> </pre> <?php Cache::clearCache('output', 'dbupdate'); }