/** * 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; }
/** * 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); }
/** * This method creates INFO file with basic information about * cached translations. * * @static * @param string $translations * @param Import $importSystem * @since 1.2.0-dev * @version 1.2.0-dev */ private static function cacheInfo($translations, Import $importSystem) { $date = new \DateTime(); $langs = array_keys($translations); $info = []; $info['date'] = $date->format('Y-m-d H:i:s'); $info['langs'] = $langs; $info['amount'] = []; $info['amount_per_part'] = $importSystem->getCountedValues(); foreach ($langs as $lang) { $info['amount'][$lang] = count($translations[$lang]); } Cache::set($info, 'info', 'i18n', 0); }