public function action_init()
 {
     spl_autoload_register(array(__CLASS__, '_autoload'));
     // @todo move this to activation hook
     if (!CronTab::get_cronjob(self::CHECK_LINKS_CRON)) {
         CronTab::add_weekly_cron(self::CHECK_LINKS_CRON, 'check_links_cron', _t('Check links in posts for errors', self::TEXT_DOMAIN));
     }
 }
예제 #2
0
파일: test_cron.php 프로젝트: habari/tests
 public function test_delete_on_fail()
 {
     $job = CronTab::add_single_cron('test_delete_fail', 'this_cron_hook_doesnt_exist', DateTime::create(), 'Test Cron');
     for ($z = 0; $z < 10; $z++) {
         $job = CronTab::get_cronjob('test_delete_fail');
         Options::set('next_cron', 0);
         Options::delete('cron_running');
         $job->execute();
     }
     $this->assert_false($job->active, 'The cron is still active after failing more than the allowed number of times.');
     CronTab::delete_cronjob('test_delete_fail');
 }
예제 #3
0
파일: crontab.php 프로젝트: habari/system
 /**
  * Add a new cron job to the DB.
  *
  * @see CronJob
  * @param array $paramarray A paramarray of cron job feilds.
  * @return \Habari\CronJob
  */
 static function add_cron($paramarray)
 {
     // Delete any existing job with this same name
     if ($job = CronTab::get_cronjob($paramarray['name'])) {
         $job->delete();
     }
     $cron = new CronJob($paramarray);
     $result = $cron->insert();
     //If the new cron should run earlier than the others, rest next_cron to its strat time.
     $next_cron = DB::get_value('SELECT next_run FROM {crontab} ORDER BY next_run ASC LIMIT 1', array());
     if (intval(Options::get('next_cron')) > intval($next_cron)) {
         Options::set('next_cron', $next_cron);
     }
     return $result ? $cron : false;
 }
예제 #4
0
 /**
  * Run activation routines, and setup default options.
  */
 public function action_plugin_activation()
 {
     if (!CronTab::get_cronjob('blogroll:update')) {
         CronTab::add_hourly_cron('blogroll:update', 'blogroll_update_cron', 'Updates the blog updated timestamp from weblogs.com');
     }
     Options::set('blogroll__api_version', self::API_VERSION);
     Options::set('blogroll__use_updated', true);
     Options::set('blogroll__max_links', '10');
     Options::set('blogroll__sort_by', 'id');
     Options::set('blogroll__direction', 'ASC');
     Options::set('blogroll__list_title', 'Blogroll');
     Post::add_new_type(self::CONTENT_TYPE);
     // Give anonymous users access, if the group exists
     $group = UserGroup::get_by_name('anonymous');
     if ($group) {
         $group->grant(self::CONTENT_TYPE, 'read');
     }
 }
예제 #5
0
 private function upgrade_db_post_5116()
 {
     // make sure the update cronjob has not failed too many times during our server move
     $cron = CronTab::get_cronjob('update_check');
     $cron->active = true;
     $cron->failures = 0;
     $cron->update();
 }
예제 #6
0
 private function upgrade_db_post_1310()
 {
     // Auto-truncate the log table
     if (!CronTab::get_cronjob('truncate_log')) {
         CronTab::add_daily_cron('truncate_log', array('Utils', 'truncate_log'), _t('Truncate the log table'));
     }
     return true;
 }
 public function formui_submit(FormUI $form)
 {
     if (isset($form->cron_id)) {
         $cron = CronTab::get_cronjob((int) $form->cron_id->value);
     } else {
         $required = array('cron_name', 'callback', 'description');
         foreach ($required as $req) {
             if (!$form->{$req}->value) {
                 Session::error(_t('%s is a required feild.', array(ucwords($req)), 'crontabmanager'));
                 return;
             }
         }
         $cron = new CronJob();
         //$cron->insert();
     }
     $cron->name = $form->cron_name->value;
     $cron->callback = strpos($form->callback->value, 'a:') === 0 || strpos($form->callback->value, 'O:') === 0 ? unserialize($form->callback->value) : $form->callback->value;
     $cron->increment = $form->increment->value ? $form->increment->value : 86400;
     $cron->next_run = HabariDateTime::date_create(isset($form->next_run) && $form->next_run->value ? $form->next_run->value : HabariDateTime::date_create());
     $cron->start_time = HabariDateTime::date_create($form->start_time->value ? $form->start_time->value : HabariDateTime::date_create());
     $cron->end_time = $form->end_time->value ? HabariDateTime::date_create($form->end_time->value) : null;
     $cron->description = $form->description->value;
     $cron->cron_class = $form->cron_class->value;
     if (intval(Options::get('next_cron')) > $cron->next_run->int) {
         Options::set('next_cron', $cron->next_run->int);
     }
     if ($cron->update()) {
         Session::notice(_t('Cron Job saved.', 'crontabmanager'));
     } else {
         Session::error(_t('Could not save Cron Job.', 'crontabmanager'));
     }
 }