/**
  * 修改一个每日任务
  */
 public function actionUpdate()
 {
     $cronForm = new CronForm('update');
     if (Yii::app()->request->getIsPostRequest()) {
         $post = Yii::app()->request->getPost('CronForm');
         $cronForm->setAttributes($post, false);
         if ($cronForm->validate()) {
             $minuteTime = date('H:i');
             if ($post['runtime'] < $minuteTime) {
                 $post['last_run_date'] = date('Y-m-d');
             } else {
                 $post['last_run_date'] = '0000-00-00';
             }
             $id = $post['id'];
             unset($post['id']);
             $post['update_time'] = time();
             if (CronModel::instance()->update($id, $post)) {
                 $this->redirect(array('/cron'));
             }
         }
     } else {
         $id = Yii::app()->request->getQuery('id');
         $cron = CronModel::instance()->getById($id);
         $cronForm->setAttributes($cron, false);
         $this->setTitle('修改每日任务');
     }
     $this->render('update', array('cronForm' => $cronForm));
 }
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new CronForm();
     }
     return self::$instance;
 }
Example #3
0
 /**
  * Control settings for the updater
  *
  * This method controls the update interval setting for the application.
  */
 public function actionUpdaterSettings()
 {
     $admin =& Yii::app()->settings;
     // Save new updater cron settings in crontab
     $cf = new CronForm();
     $cf->jobs = array('app_update' => array('cmd' => Yii::app()->basePath . DIRECTORY_SEPARATOR . 'yiic update app --lock=1 &>/dev/null', 'desc' => Yii::t('admin', 'Automatic software updates cron job')));
     if (isset($_POST['Admin'])) {
         $admin->setAttributes($_POST['Admin']);
         foreach (array('unique_id', 'edition') as $var) {
             if (isset($_POST['unique_id'])) {
                 $admin->{$var} = $_POST[$var];
             }
         }
         if ($admin->save()) {
             if (isset($_POST['cron'])) {
                 // Save new updater cron settings in crontab
                 $cf->save($_POST);
             } else {
                 // Delete remaining jobs
                 $cf->save(array());
             }
             $this->redirect('updaterSettings');
         }
     }
     foreach ($cf->jobs as $tag => $attributes) {
         $commands[$tag] = $attributes['cmd'];
     }
     if (isset($_POST['cron'])) {
         // Save new updater cron settings in crontab
         $cf->save($_POST);
     }
     $this->render('updaterSettings', array('model' => $admin, 'displayCmds' => $commands));
 }
 public function save_schedule_event()
 {
     if (!$this->isAjax || $this->method != 'POST') {
         $this->app->abort(404, $this->setLocalization('Page not found'));
     }
     if ($no_auth = $this->checkAuth()) {
         return $no_auth;
     }
     $data = array();
     $data['action'] = 'addEvent';
     $error = $this->setlocalization($this->setlocalization('Not enough data'));
     $from_db = array_flip($this->getFieldFromArray($this->db->getTableFields('schedule_events'), 'Field'));
     $form_post = $this->postData;
     $recipient_func = "getRecipientBy" . ucfirst(strtolower(str_replace(array('by_', 'to_'), '', $form_post['user_list_type'])));
     $form_post['recipient'] = $this->{$recipient_func}($form_post);
     $form_post['periodic'] = (int) str_replace('schedule_type_', '', $form_post['type']) - 1;
     $form_post['state'] = 1;
     $form_post['reboot_after_ok'] = (int) (!empty($form_post['need_reboot']) && (string) $form_post['need_reboot'] != 'false' && (string) $form_post['need_reboot'] != 'off' && (string) $form_post['need_reboot'] != 'false' && (string) $form_post['need_reboot'] != '0');
     if (array_key_exists('month', $form_post)) {
         $form_post['month'] = (int) $form_post['month'];
     }
     if (array_key_exists('every_month', $form_post)) {
         $form_post['every_month'] = (int) $form_post['every_month'];
     }
     if (array_key_exists('every_day', $form_post)) {
         $form_post['every_day'] = (int) $form_post['every_day'];
     }
     if (array_key_exists('every_hour', $form_post)) {
         $form_post['every_hour'] = (int) $form_post['every_hour'];
     }
     if (array_key_exists('every_minute', $form_post)) {
         $form_post['every_minute'] = (int) $form_post['every_minute'];
     }
     if (array_key_exists('date_begin', $form_post)) {
         $date = \DateTime::createFromFormat('d/m/Y', $form_post['date_begin']);
         $form_post['date_begin'] = $date ? $date->format('Y-m-d G:i:s') : 'NOW()';
     }
     if (array_key_exists('date_end', $form_post)) {
         $date = \DateTime::createFromFormat('d/m/Y', $form_post['date_end']);
         $form_post['date_end'] = $date ? $date->format('Y-m-d G:i:s') : '';
     }
     $form_post['schedule'] = \CronForm::getInstance()->setFormData($form_post)->getExpression();
     $params = array();
     $from_db = array_combine(array_keys($from_db), array_fill(0, count($from_db), NULL));
     if (!empty($form_post['id'])) {
         $id = $form_post['id'];
         $operation = 'update';
         $params[] = array_replace($from_db, array_intersect_key($form_post, $from_db));
         $params[] = $id;
     } else {
         $operation = 'insert';
         $params[] = array_replace($from_db, array_intersect_key($form_post, $from_db));
     }
     unset($params[0]['id']);
     $result = call_user_func_array(array($this->db, $operation . "ScheduleEvents"), $params);
     if (is_numeric($result)) {
         $error = '';
         if ($result === 0) {
             $data['nothing_to_do'] = TRUE;
             $data['msg'] = $this->setlocalization($this->setlocalization('Nothing to do'));
         }
     }
     $response = $this->generateAjaxResponse($data, $error);
     return new Response(json_encode($response), empty($error) ? 200 : 500);
 }