17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
45 $this->uses_trans = FALSE;
46 parent::__construct($code_name);
47 $GLOBALS[
'SQ_SYSTEM']->lm->includePackageStrings(
'squid');
63 return parent::getCodeName().
'-'.$this->_running_vars[
'assetid'];
76 return translate(
'squid_hipo_name_clear_squid_cache');
92 'name' => translate(
'squid_hipo_clearing_squid_cache'),
93 'function_call' => Array(
94 'process_function' =>
'processClearCache',
96 'running_mode' =>
'server',
101 'allow_cancel' => TRUE,
116 while (!empty($this->_running_vars[
'todo_urls'])) {
135 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
138 $this->_running_vars[
'hostnames'] = explode(
"\n", trim(SQ_TOOL_SQUID_CACHE_HOSTNAMES));
139 $this->_running_vars[
'path'] = SQ_TOOL_SQUID_CACHE_PATH;
140 if ($this->_running_vars[
'path'] ==
'') {
141 $this->_running_vars[
'path'] =
'/usr/bin/squidclient';
143 $this->_running_vars[
'port'] = SQ_TOOL_SQUID_CACHE_PORT;
144 if ($this->_running_vars[
'port'] !=
'') {
145 $this->_running_vars[
'port'] =
'-p '.$this->_running_vars[
'port'];
147 $this->_running_vars[
'option'] = SQ_TOOL_SQUID_CACHE_OPTION;
148 $this->_running_vars[
'slash'] = SQ_TOOL_SQUID_CACHE_SLASH;
149 $this->_running_vars[
'url_port'] = SQ_TOOL_SQUID_URL_PORT;
152 $assetids = Array($this->_running_vars[
'assetid']);
153 if ($this->_running_vars[
'cascade']) {
154 $children = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($this->_running_vars[
'assetid']));
155 $assetids = array_merge($assetids, $children);
158 $this->_running_vars[
'todo_urls'] = Array();
159 foreach ($assetids as $assetid) {
160 $result = $GLOBALS[
'SQ_SYSTEM']->am->getURLs($assetid);
161 $this->_running_vars[
'todo_urls'] = array_merge($result, $this->_running_vars[
'todo_urls']);
163 $this->_running_vars[
'done_urls'] = Array();
164 return parent::prepare();
180 if (!empty($this->_running_vars[
'todo_urls'])) {
182 $hostnames = $this->_running_vars[
'hostnames'];
183 $path = $this->_running_vars[
'path'];
184 $port = $this->_running_vars[
'port'];
185 $options = $this->_running_vars[
'option'];
186 $cascade = $this->_running_vars[
'cascade'];
187 $index = array_shift(array_keys($this->_running_vars[
'todo_urls']));
188 $urls = Array($this->_running_vars[
'todo_urls'][$index][
'url']);
191 if ($this->_running_vars[
'slash'] || strpos($this->_running_vars[
'todo_urls'][$index][
'url'],
'/') === FALSE) {
193 $urls[] = $this->_running_vars[
'todo_urls'][$index][
'url'].
'/';
195 $protocols = Array();
196 if ($this->_running_vars[
'todo_urls'][$index][
'http']) {
197 $protocols[] =
'http';
199 if ($this->_running_vars[
'todo_urls'][$index][
'https']) {
200 $protocols[] =
'https';
203 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
205 foreach ($hostnames as $hostname) {
207 $hostname = trim($hostname);
208 foreach ($urls as $url) {
209 foreach ($protocols as $protocol) {
212 if ($this->_running_vars[
'url_port'] <>
'') {
216 $path_parts = explode(
'/', $url, 2);
219 $path_parts[0] .=
':'.$this->_running_vars[
'url_port'];
222 $url = implode(
'/', $path_parts);
226 $system_log_command =
"$path -h $hostname $port $options -m PURGE $protocol://$url";
227 error_log(
'Running: '.$system_log_command);
228 exec(escapeshellcmd($system_log_command), $output, $status);
231 if (empty($output)) {
232 trigger_localised_error(
'SQUID0002', E_USER_WARNING);
235 $msg = $ms->newMessage();
236 $msg->type =
'purge.squid.cache';
239 $command_str = $system_log_command;
240 $repopulate = ($this->_running_vars[
'repopulate']) ? translate(
'yes') : translate(
'no');
241 $command_str .=
"\nRepopulate Cache: ".$repopulate;
242 $cascade = ($this->_running_vars[
'cascade']) ? translate(
'yes') : translate(
'no');
243 $command_str .=
', Cascade: '.$cascade;
244 $system_log_output =
"Output : \n";
245 foreach ($output as $key=>$line) {
246 $system_log_output .=
"$line\n";
249 'command' => $command_str,
250 'result' => $system_log_output,
253 $msg->replacements = $msg_reps;
254 $ms->send(Array($msg));
263 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($ms);
266 if ($this->_running_vars[
'repopulate']) {
267 foreach ($urls as $url) {
268 $this->
requestPage(
"$protocol://$url", $hostname, $port);
273 $step_data[
'message'] = translate(
'squid_clearing_squid_cache', $url);
274 $this->_running_vars[
'done_urls'][] = $url;
277 unset($this->_running_vars[
'todo_urls'][$index]);
282 if (empty($this->_running_vars[
'todo_urls'])) {
283 $step_data[
'percent_done'] = 100;
284 $step_data[
'complete'] = TRUE;
286 $total = count($this->_running_vars[
'todo_urls']) + count($this->_running_vars[
'done_urls']);
287 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_urls']) / $total) * 100;
288 $step_data[
'complete'] = FALSE;
310 $port =
':'.trim(str_replace(
'-p',
'', $port));
315 'Cache-Control: public',
320 'PROXY' => $host.$port,
324 $response = fetch_url($url, $options, $headers, FALSE);