Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
cron_job_refresh_cache_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/system/cron/cron_job/cron_job_edit_fns.inc';
19 
38 {
39 
40 
46  function __construct()
47  {
48  parent::__construct();
49 
50  }//end constructor
51 
52 
63  public function paintInLineBackend(Cron_Job_Refresh_Cache $asset, Backend_Outputter $o, $prefix)
64  {
65  if ($asset->writeAccess('')) {
66 
67  ?>
68  <table class="sq-backend-table">
69  <tr>
70  <!-- Asset to Refresh -->
71  <th class="sq-backend-table-header">Asset</th>
72  <td class="sq-backend-table-cell"><?php asset_finder($prefix.'_assetid', 0, Array('asset' => 'D')); ?></td>
73  </tr>
74  <tr>
75  <!-- Cron Job Schedule -->
76  <th class="sq-backend-table-header">Schedule</th>
77  <td class="sq-backend-table-cell">
78  <?php
79  // paint the start time using a one off job's edit fns
80  $cron_job = new Cron_Job();
81  $edit_fns = $cron_job->getEditFns();
82  echo translate('cron_job_refresh_cache_at');
83  $edit_fns->_paintWhenBox($cron_job, $o, $prefix);
84 
85  // paint the repeat frequency using repeating time interval job's edit fns
86  echo '<br />'.translate('cron_job_regenerate_report_repeat');
87  $this->_paintWhenBox($asset, $o, $prefix);
88  ?>
89  </td>
90  </tr>
91  </table>
92  <?php
93 
94  echo '<br />';
95 
96  }//end if
97 
98  return TRUE;
99 
100  }//end paintInLineBackend()
101 
102 
113  public function processInLineBackend(Cron_Job_Refresh_Cache $asset, Backend_Outputter $o, $prefix)
114  {
115  $cron_job = new Cron_Job();
116  $edit_fns = $cron_job->getEditFns();
117  $when_oo = $edit_fns->_processWhenBox($cron_job, $o, $prefix);
118 
119  if (empty($_REQUEST[$prefix.'_assetid']['assetid'])) {
120  // No asset chosen, do not add a job
121  return FALSE;
122  } else {
123  $assetid = $_REQUEST[$prefix.'_assetid']['assetid'];
124 
125  $asset->setAttrValue('asset', $assetid);
126 
127  if ( $_REQUEST[$prefix.'_when_interval_mins'] == '--'
128  && $_REQUEST[$prefix.'_when_interval_hours'] == '--'
129  && $_REQUEST[$prefix.'_when_interval_days'] == '-') {
130 
131  if (!$when_oo) {
132  // nothing has been set, do not add a job
133  return FALSE;
134  }
135 
136  // if repeat frequency is not set, this is a one off job
137  $asset->setAttrValue('type', 'one_off');
138  if (!$asset->setAttrValue('when', $when_oo)) {
139  return FALSE;
140  }
141  return TRUE;
142 
143  } else {
144 
145  // repeat frequency is set, but start time not specified, error
146  if (!$when_oo) {
147  trigger_localised_error('CRON0050', E_USER_WARNING, $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($asset->type(), 'name'));
148  return FALSE;
149  }
150 
151  // work out the period/duration start time (one off job code reuse)
152  // mute warning as we are only using this bit to working out the start time
153  if (!@$cron_job->setAttrValue('when', $when_oo)) {
154  $cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
155  trigger_localised_error('CRON0048', E_USER_WARNING, $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($asset->type(), 'name'), easy_datetime($cron_mgr->timeOfNextRun()));
156  return FALSE;
157  }
158 
159  $when_oo_str = $cron_job->attr('when');
160  $start_time = $cron_job->getNextRun($when_oo_str);
161 
162  // update the start time of this repeating time interval job
163  $when_ti = $this->_processWhenBox($asset, $o, $prefix);
164  $when_ti_arr = explode(',', $when_ti);
165  $when_ti_arr[0] = 'TI='.$start_time;
166  $when_ti_str = implode(',', $when_ti_arr);
167  $asset->setAttrValue('when', $when_ti_str);
168  $asset->setAttrValue('long', TRUE);
169  return TRUE;
170  }
171 
172  }//end else
173 
174  return FALSE;
175 
176  }//end processInLineBackend()
177 
178 
179 }//end class
180 
181 ?>