00001 <?php
00002
00003
00004
00005 class CreateSchedulerBaseCommand extends CommandChain {
00006 protected function do_execute() {
00007 $ret = new Status();
00008 $params = $this->validate_params($this->get_params());
00009
00010
00011 $created = false;
00012 $ret->merge($this->create_scheduler($params, $created));
00013 if ($ret->is_ok()) {
00014 $ret->merge($this->check_exclusive($params, $created));
00015 }
00016 return $ret;
00017 }
00018
00019
00020
00021
00022 protected function validate_params($params) {
00023 $action = Arr::get_item($params, 'action', '');
00024 if (strpos($action, '://') !== false) {
00025 $url = Url::create($action);
00026 if ($url->is_valid()) {
00027 $params['action'] = $url->get_path();
00028 }
00029 }
00030 return $params;
00031 }
00032
00033
00034
00035
00036
00037
00038 protected function create_scheduler($params, &$created) {
00039 Load::commands('generics/create');
00040 $cmd = new CreateCommand('scheduler', $params);
00041 $ret = $cmd->execute();
00042 if ($ret->is_ok()) {
00043 $created = $cmd->get_result();
00044 $this->set_result($created);
00045 }
00046 return $ret;
00047 }
00048
00049
00050
00051
00052
00053
00054 protected function check_exclusive($params, $created) {
00055 $ret = new Status();
00056 if (Arr::get_item($params, 'exclusive', false)) {
00057 $scheduler = new DAOScheduler();
00058 $scheduler->add_where('action', '=', $created->action);
00059 $scheduler->add_where('scheduledate', '<', $created->scheduledate);
00060 $scheduler->add_where('status', '!=', Scheduler::STATUS_PROCESSING);
00061 $ret->merge($scheduler->delete(DAOScheduler::WHERE_ONLY));
00062 }
00063 return $ret;
00064 }
00065 }