00001 <?php
00002
00003
00004
00005
00006 class DAOScheduler extends DataObjectBase implements IStatusHolder, ISelfDescribing {
00007 public $id;
00008 public $scheduledate;
00009 public $reschedule_error;
00010 public $reschedule_success;
00011 public $runs_error;
00012 public $runs_success;
00013 public $action;
00014 public $name;
00015 public $error_message;
00016 public $status;
00017
00018
00019
00020
00021
00022
00023 protected function create_table_object() {
00024 return new DBTable(
00025 'scheduler',
00026 array(
00027 new DBFieldInt('id', null, DBFieldInt::AUTOINCREMENT | DBFieldInt::NOT_NULL | DBFieldInt::UNSIGNED),
00028 new DBFieldDateTime('scheduledate', DBFieldDateTime::NOW, DBFieldDateTime::NOT_NULL),
00029 new DBFieldEnum('reschedule_error', array_keys(Scheduler::get_reschedule_policies()), Scheduler::RESCHEDULE_TERMINATOR_1, DBFieldEnum::NOT_NULL),
00030 new DBFieldEnum('reschedule_success', array_keys(Scheduler::get_reschedule_policies()), Scheduler::RESCHEDULE_TERMINATOR_1, DBFieldEnum::NOT_NULL),
00031 new DBFieldInt('runs_error', 0, DBFieldInt::UNSIGNED | DBFieldInt::NOT_NULL),
00032 new DBFieldInt('runs_success', 0, DBFieldInt::UNSIGNED | DBFieldInt::NOT_NULL),
00033 new DBFieldText('action', 255, null, DBFieldText::NOT_NULL ),
00034 new DBFieldText('name', 255, null, DBFieldText::NOT_NULL ),
00035 new DBFieldText('error_message', DBFieldText::BLOB_LENGTH_SMALL, null, DBFieldText::NONE),
00036 new DBFieldEnum('status', array_keys(Scheduler::get_statuses()), Scheduler::STATUS_ACTIVE, DBFieldEnum::NOT_NULL )
00037 ),
00038 'id'
00039 );
00040 }
00041
00042
00043
00044
00045
00046
00047 public function validate() {
00048 if (empty($this->name)) {
00049 $this->name = $this->action;
00050 }
00051 return parent::validate();
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061 public function set_status($status) {
00062 $this->status = $status;
00063 }
00064
00065
00066
00067
00068 public function get_status() {
00069 return $this->status;
00070 }
00071
00072
00073
00074
00075 public function is_active() {
00076 return
00077 $this->status == Scheduler::STATUS_ACTIVE
00078 ||
00079 $this->status == Scheduler::STATUS_RESCHEDULED;
00080 }
00081
00082
00083
00084
00085 public function is_disabled() {
00086 return $this->status == Scheduler::STATUS_DISABLED;
00087 }
00088
00089
00090
00091
00092
00093
00094 public function is_unconfirmed() {
00095 return false;
00096 }
00097
00098
00099
00100
00101
00102
00103 public function is_deleted() {
00104 return false;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 public function get_title() {
00117 return $this->name;
00118 }
00119
00120
00121
00122
00123
00124
00125 public function get_description() {
00126 return '';
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 protected function get_actions_for_context($context, $user, $params){
00142 $ret = array();
00143 if ($context == 'list') {
00144 foreach(Scheduler::get_statuses() as $key => $descr) {
00145 if ($key === Scheduler::STATUS_ACTIVE || $key === Scheduler::STATUS_DISABLED) {
00146 $cmd = 'status['. $key .']';
00147 $descr = tr('Set'. $descr, 'scheduler');
00148 $ret[$cmd] = $descr;
00149 }
00150 }
00151 }
00152 return $ret;
00153 }
00154
00155
00156
00157
00158 public function get_filters() {
00159 $arr_stat = array();
00160 foreach(Scheduler::get_statuses() as $k => $d) {
00161 $arr_stat[strtolower($k)] = new DBFilterColumn(
00162 'scheduler.status', $k, $d
00163 );
00164 }
00165 return array(
00166 new DBFilterGroup(
00167 'status',
00168 tr('Status'),
00169 $arr_stat
00170 ),
00171 );
00172 }
00173
00174
00175
00176
00177 public function get_sortable_columns() {
00178 return array(
00179 'scheduledate' => new DBSortColumn('scheduledate', tr('Execution time', 'scheduler'), DBSortColumn::TYPE_DATE, DBSortColumn::ORDER_FORWARD, true),
00180 );
00181 }
00182
00183
00184
00185
00186 public function get_sort_default_column() {
00187 return 'scheduledate';
00188 }
00189
00190 }