Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
cron_job_squid_cache_purge.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/system/cron/cron_job/cron_job.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
57  protected function _getName($short_name=FALSE)
58  {
59  // the ownerid must be set at the creation of this cron job
60  return translate('squid_cron_name', $this->attr('ownerid'));
61 
62  }//end _getName()
63 
64 
72  public function _getAllowedLinks()
73  {
74  $links = parent::_getAllowedLinks();
75 
76  // make sure that we can link to every asset
77  if (empty($links[SQ_LINK_NOTICE]['asset'])) {
78  $links[SQ_LINK_NOTICE]['asset'] = Array('card' => 1);
79  }
80 
81  return $links;
82 
83  }//end _getAllowedLinks()
84 
85 
95  public function canDelete()
96  {
97  if (parent::canDelete()) return TRUE;
98 
99  // read-only?
100  if ($this->attr('read_only')) return FALSE;
101 
102  // if we have admin access to the asset owning this job
103  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->attr('ownerid'));
104  if (!is_null($asset)) return $asset->adminAccess('');
105  return FALSE;
106 
107  }//end canDelete()
108 
109 
121  protected function _exec(&$msg)
122  {
123  // based on the options in the tool interface and settings in the global prefs
124  $assetid = $this->attr('ownerid');
125  $vars = Array(
126  'assetid' => $assetid,
127  'cascade' => $this->attr('cascade'),
128  'repopulate' => $this->attr('repopulate'),
129  );
130 
131  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
132  $status_errors = $hh->freestyleHipo('hipo_job_tool_clear_squid_cache', $vars, SQ_PACKAGES_PATH.'/squid/hipo_jobs');
133 
134  if (empty($status_errors)) {
135  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
136  $msg = translate('squid_cron_done_msg', $asset->name, $assetid);
137  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
138 
139  if ($this->attr('type') == 'one_off') {
140  // all OK, and we can be removed because we have done our one off task
141  return SQ_CRON_JOB_COMPLETED | SQ_CRON_JOB_REMOVE;
142  } else if ($this->attr('type') == 'repeating') {
143  // repeating time interval job, do not remove
144  return SQ_CRON_JOB_COMPLETED;
145  }
146  } else {
147  // process failed
148  trigger_localised_error('SQUID0002', E_USER_WARNING);
149  }
150 
151  // we can be removed because the error is beyound our control
152  return SQ_CRON_JOB_ERROR | SQ_CRON_JOB_REMOVE;
153 
154  }//end _exec()
155 
156 
164  public static function getActiveJobs()
165  {
166  $cm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
167  return $cm->getJobs('cron_job_squid_cache_purge');
168 
169  }//end getActiveJobs()
170 
171 
172 }//end class
173 
174 ?>