18 require_once SQ_SYSTEM_ROOT.
'/core/assets/system/tool/tool.inc';
45 $this->
Tool($assetid);
61 $tool_info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code);
64 $cache_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
65 if (!$cache_manager->attr(
'enabled')) {
66 $o->openSection($tool_info[
'name']);
67 $o->openField(
'Note');
68 $o->note(
'<span class="sq-backend-warning">Matrix caching status is currently "Off".</span><br />');
74 $o->openSection($tool_info[
'name']);
77 $o->openField(translate(
'choose_asset'));
78 asset_finder($type_code.
'_assetid');
82 $o->openField(translate(
'level'));
84 'single' => translate(
'this_asset'),
85 'dependants' => translate(
'this_asset_and_dependants'),
86 'children' => translate(
'this_asset_and_children'),
88 combo_box($type_code.
'_level', $options,
'', FALSE);
92 $o->openField(translate(
'asset_types'));
93 $type_options = Array();
94 $asset_types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
95 foreach ($asset_types as $code) {
96 $info = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($code);
97 if ($info[
'allowed_access'] !=
'system' && $info[
'instantiable']) {
98 $type_options[$code] = $info[
'name'];
101 asort($type_options);
102 $type_options = array_reverse($type_options, TRUE);
103 $type_options[
''] =
'-- '.translate(
'all_asset_types').
' --';
104 $type_options = array_reverse($type_options, TRUE);
105 combo_box($type_code.
'_type_codes', $type_options, TRUE,
'', 8);
109 $o->openField(translate(
'tool_matrix_cache_populate_question'));
110 $disabled = (function_exists(
'curl_init')) ?
'' :
'disabled';
111 check_box($type_code.
'_repopulate', TRUE, FALSE,
'', $disabled);
112 echo translate(
'tool_matrix_cache_populate_note');
115 $o->note(
'<span class="sq-backend-warning">Note: PHP libcurl package is not installed</span>');
118 $o->note(translate(
'tool_matrix_cache_note'));
122 $o->openField(translate(
'tool_matrix_cache_clear_now_field'));
123 check_box($type_code.
'_clear_now', TRUE);
130 $o->openSection(translate(
'matrix_cache_schedule_section'));
132 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
133 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'Cron_Job_Clear_Matrix_Cache');
137 if (!empty($purge_jobs)) {
138 $o->openField(translate(
'matrix_cache_scheduled_job_field'),
'new_line');
140 <table
class=
"sq-backend-table">
142 <td
class=
"sq-backend-table-header"><?php echo translate(
'asset'); ?></td>
143 <td
class=
"sq-backend-table-header"><?php echo translate(
'when'); ?></td>
144 <td align=
"center" class=
"sq-backend-table-header" style=
"text-align: center;"><?php echo translate(
'delete_question'); ?></td>
147 for ($i = 0; $i < count($purge_jobs); $i++) {
150 <td
class=
"sq-backend-table-cell">
151 <?php echo get_asset_tag_line($purge_jobs[$i]->
attr(
'ownerid')); ?>
154 <td
class=
"sq-backend-table-cell">
155 <?php echo $purge_jobs[$i]->readableWhen(); ?>
157 <td align=
"center" class=
"sq-backend-table-cell">
159 check_box($type_code.
'_remove_fs[]', $purge_jobs[$i]->id);
171 $cron_epoc = (int)$cron_mgr->attr(
'epoch');
172 $cron_refresh = (int)$cron_mgr->attr(
'refresh_time');
173 if ($cron_epoc > 0 && $cron_refresh > 0) {
176 $o->openField(translate(
'matrix_cache_one_off_field'),
'new_line');
177 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
179 $edit_fns = $new_job->getEditFns();
180 $edit_fns->paintInLineBackend($new_job, $o, $type_code.
'_one_off');
181 echo
' <br /><br />';
185 $o->openField(translate(
'matrix_cache_repeating_field'),
'new_line');
187 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
188 $new_job->setAttrValue(
'type',
'repeating');
189 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
190 $edit_fns = $new_job->getEditFns();
191 $edit_fns->paintInLineBackend($new_job, $o, $type_code.
'_repeating');
192 $o->note(translate(
'cron_manager_next_run', $cron_mgr->readableRefreshTime(), readable_datetime($cron_mgr->timeOfNextRun())));
196 $o->openField(
'Note');
197 $o->note(translate(
'cron_manager_not_configured'));
201 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cron_mgr);
202 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cache_manager);
220 $cache_manager = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
221 if (!$cache_manager->attr(
'enabled'))
return;
223 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
224 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'Cron_Job_Clear_Matrix_Cache');
227 if (!empty($_POST[$type_code.
'_remove_fs'])) {
228 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'Cron_Job_Clear_Matrix_Cache');
230 if (!empty($purge_jobs)) {
231 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($cron_mgr->id,
'links')) {
232 for ($i = 0; $i < count($purge_jobs); $i++) {
233 if (in_array($purge_jobs[$i]->
id, $_POST[$type_code.
'_remove_fs'])) {
234 $cron_mgr->removeJob($purge_jobs[$i]);
238 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($cron_mgr->id,
'links');
240 trigger_localised_error(
'SYS0232', E_USER_NOTICE);
244 if (!$_REQUEST[$type_code.
'_assetid'][
'assetid']) {
249 if (isset($_POST[$type_code.
'_assetid']) && !empty($_POST[$type_code.
'_assetid'][
'assetid'])) {
251 $assetid = $_POST[$type_code.
'_assetid'][
'assetid'];
252 $level = (isset($_POST[$type_code.
'_level'])) ? $_POST[$type_code.
'_level'] :
'single';
253 $type_codes = Array();
254 if (isset($_POST[$type_code.
'_type_codes']) && !empty($_POST[$type_code.
'_type_codes'][0])) {
255 $type_codes = $_POST[$type_code.
'_type_codes'];
258 if (isset($_POST[$type_code.
'_repopulate']) && $_POST[$type_code.
'_repopulate']) {
261 $run_now = isset($_POST[$type_code.
'_clear_now']) && $_POST[$type_code.
'_clear_now'];
262 if ($repopulate) $run_now = TRUE;
266 $edit_fns = $new_job->getEditFns();
267 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
268 $new_job->setAttrValue(
'ownerid', $assetid);
269 $new_job->setAttrValue(
'level', $level);
270 $new_job->setAttrValue(
'type_codes', $type_codes);
271 $new_job->setAttrValue(
'repopulate', $repopulate);
272 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
273 if ($edit_fns->processInLineBackend($new_job, $o, $type_code.
'_one_off')) {
274 $cron_mgr->addJob($new_job, $GLOBALS[
'SQ_SYSTEM']->user);
279 $edit_fns = $new_job->getEditFns();
280 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
281 $new_job->setAttrValue(
'type',
'repeating');
282 $new_job->setAttrValue(
'ownerid',$assetid);
283 $new_job->setAttrValue(
'level', $level);
284 $new_job->setAttrValue(
'type_codes', $type_codes);
285 $new_job->setAttrValue(
'repopulate', $repopulate);
286 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
287 if ($edit_fns->processInLineBackend($new_job, $o, $type_code.
'_repeating')) {
288 $cron_mgr->addJob($new_job, $GLOBALS[
'SQ_SYSTEM']->user);
293 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
295 'assetid' => Array ($assetid),
297 'type_codes' => $type_codes,
298 'delete_all' =>
'no',
299 'repopulate' => $repopulate,
301 $hh->queueHipo(
'hipo_job_clear_cache', $vars, $_SERVER[
'REQUEST_URI'].
'&tool_type_code=tool_clear_matrix_cache');
302 $url = $hh->runQueuedJobs();
303 if (!empty($url)) $o->setRedirect($url);