17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
64 public static function paintConfig(&$o, $class, $write_access)
67 $o->openField(translate(
'clear_cache_threshold'));
70 text_box($class.
'[SQ_HIPO_CLEAR_CACHE_THRESHOLD]', SQ_HIPO_CLEAR_CACHE_THRESHOLD, 5);
71 echo
' '.translate(
'assets');
73 echo SQ_HIPO_CLEAR_CACHE_THRESHOLD;
74 echo
' '.translate(
'assets');
91 'SQ_HIPO_CLEAR_CACHE_THRESHOLD' => Array(
'editable' => 1,
'default' => 100),
105 if (isset($this->_running_vars[
'linkid'])) {
106 return parent::getCodeName().$this->_running_vars[
'linkid'];
108 if ($this->_running_vars[
'delete_all'] ==
'yes') {
110 return parent::getCodeName().
'delete_all';
112 return parent::getCodeName().$this->_running_vars[
'assetid'];
127 return translate(
'hipo_name_clear_cache');
143 'name' =>
'Clear Cache Table',
144 'function_call' => Array(
145 'process_function' =>
'processClearCacheTable',
147 'running_mode' =>
'server',
149 'allow_cancel' => TRUE,
155 'name' => translate(
'hipo_clearing_cache'),
156 'function_call' => Array(
157 'process_function' =>
'processClearCacheFile',
159 'running_mode' =>
'server',
161 'allow_cancel' => TRUE,
167 'name' =>
'Repopulating Cache',
168 'function_call' => Array(
169 'process_function' =>
'processRepopulate',
171 'running_mode' =>
'server',
173 'allow_cancel' => TRUE,
193 if (SQ_HIPO_CLEAR_CACHE_THRESHOLD == 0)
return 0;
194 if (!isset($this->_running_vars[
'total']))
return 0;
195 return (($this->_running_vars[
'total'] + 1) / SQ_HIPO_CLEAR_CACHE_THRESHOLD) * 100;
208 if ($this->_running_vars[
'delete_all'] ==
'yes') {
212 while (!empty($this->_running_vars[
'todo_assetids'])) {
220 while (!empty($this->_running_vars[
'todo_filepaths'])) {
227 while (!empty($this->_running_vars[
'todo_repopulate'])) {
246 if (empty($this->_running_vars[
'assetid']) && $this->_running_vars[
'delete_all'] ==
'no') {
247 trigger_localised_error(
'HIPO0033', E_USER_WARNING);
251 if (isset($this->_running_vars[
'delete_all']) && $this->_running_vars[
'delete_all'] ==
'no') {
253 $assetids = $this->_running_vars[
'assetid'];
255 if (!is_array($assetids)) {
256 $assetids = Array ($assetids);
258 if (empty($assetids)) {
259 trigger_localised_error(
'HIPO0032', E_USER_WARNING, $this->_running_vars[
'assetid']);
263 $child_assets = Array();
264 $this->_running_vars[
'todo_assetids'] = Array();
265 foreach ($assetids as $assetid) {
266 switch ($this->_running_vars[
'level']) {
268 $this->_running_vars[
'todo_assetids'][] = $assetid;
271 $child_assets += $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid, $this->_running_vars[
'type_codes']);
272 $this->_running_vars[
'todo_assetids'][] = $assetid;
275 $child_assets += $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid, $this->_running_vars[
'type_codes']);
276 $this->_running_vars[
'todo_assetids'][] = $assetid;
282 if (!empty($child_assets)) {
283 $child_assets = array_keys($child_assets);
284 $this->_running_vars[
'todo_assetids'] = array_merge($this->_running_vars[
'todo_assetids'], $child_assets);
287 $this->_running_vars[
'delete_all'] = FALSE;
288 $this->_running_vars[
'total'] = count($this->_running_vars[
'todo_assetids']);
290 }
else if (isset($this->_running_vars[
'delete_all']) && $this->_running_vars[
'delete_all'] ==
'yes') {
292 $this->_running_vars[
'todo_assetids'] = Array();
293 $this->_running_vars[
'delete_all'] = TRUE;
294 $this->_running_vars[
'total'] = 1;
297 $this->_running_vars[
'done_assetids'] = Array();
298 $this->_running_vars[
'todo_filepaths'] = Array();
299 $this->_running_vars[
'done_filepaths'] = Array();
303 $this->_running_vars[
'todo_repopulate'] = Array();
304 $this->_running_vars[
'done_repopulate'] = Array();
305 if (isset($this->_running_vars[
'repopulate']) && $this->_running_vars[
'repopulate']) {
306 $this->_running_vars[
'todo_repopulate'] = $this->_running_vars[
'todo_assetids'];
309 return parent::prepare();
325 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
327 if ($this->_running_vars[
'delete_all'] ===
'yes' || $this->_running_vars[
'delete_all'] === TRUE) {
329 $this->_running_vars[
'todo_filepaths'] = $cm->getAllFilePaths();
330 $cm->clearAllCache();
334 $current_assetid = array_pop($this->_running_vars[
'todo_assetids']);
335 $file_paths = $cm->getFilePaths(Array($current_assetid));
336 $cm->clearCache(Array($current_assetid));
337 $this->_running_vars[
'todo_filepaths'] = array_merge($this->_running_vars[
'todo_filepaths'], $file_paths);
338 $this->_running_vars[
'done_assetids'][] = $current_assetid;
341 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cm);
343 if (empty($this->_running_vars[
'todo_assetids'])) {
344 $step_data[
'percent_done'] = 100;
345 $step_data[
'complete'] = TRUE;
347 $done = count($this->_running_vars[
'done_assetids']);
348 $total = count($this->_running_vars[
'todo_assetids']) + $done;
349 $step_data[
'percent_done'] = ($done / $total) * 100;
350 $step_data[
'complete'] = FALSE;
368 if (!empty($this->_running_vars[
'todo_filepaths'])) {
369 $paths = array_splice($this->_running_vars[
'todo_filepaths'], 0, SQ_HIPO_CLEAR_CACHE_THRESHOLD);
370 foreach ($paths as $path) {
371 $path_name = SQ_CACHE_PATH.
'/'.$path[
'path'];
372 if (is_file($path_name)) {
373 if (!unlink($path_name)) {
374 $this->
_addError(
'Failed to delete cache file, '.$path_name, TRUE);
381 $this->_running_vars[
'done_filepaths'] = array_merge($this->_running_vars[
'done_filepaths'], $paths);
384 if (empty($this->_running_vars[
'todo_filepaths'])) {
385 $step_data[
'percent_done'] = 100;
386 $step_data[
'complete'] = TRUE;
388 $done = count($this->_running_vars[
'done_filepaths']);
389 $total = count($this->_running_vars[
'todo_filepaths']) + $done;
390 $step_data[
'percent_done'] = ($done / $total) * 100;
391 $step_data[
'complete'] = FALSE;
409 if (!empty($this->_running_vars[
'todo_repopulate'])) {
410 $current_assetid = array_pop($this->_running_vars[
'todo_repopulate']);
411 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($current_assetid);
412 $urls_info = $asset->getURLs();
414 if (!empty($urls_info)) {
415 foreach ($urls_info as $url_info) {
416 if ($url_info[
'http'] ==
'1') {
417 $urls[] =
'http://'.$url_info[
'url'];
419 if ($url_info[
'https'] ==
'1') {
420 $urls[] =
'https://'.$url_info[
'url'];
427 'Cache-Control: public',
430 foreach ($urls as $url) {
431 fetch_url($url, array(
'RETURNTRANSFER' => 1), $headers, array(), FALSE);
434 $this->_running_vars[
'done_repopulate'][] = $current_assetid;
437 if (empty($this->_running_vars[
'todo_repopulate'])) {
438 $step_data[
'percent_done'] = 100;
439 $step_data[
'complete'] = TRUE;
441 $done = count($this->_running_vars[
'done_repopulate']);
442 $total = count($this->_running_vars[
'todo_repopulate']) + $done;
443 $step_data[
'percent_done'] = ($done / $total) * 100;
444 $step_data[
'complete'] = FALSE;