Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
cron_job_remove_soap_response_files.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/system/cron/cron_job/cron_job.inc';
19 require_once SQ_FUDGE_PATH.'/general/datetime.inc';
20 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
21 
35 {
36 
37 
44  function __construct($assetid=0)
45  {
46  parent::__construct($assetid);
47 
48  }//end constructor
49 
50 
62  public function create(Array &$link)
63  {
64  require_once SQ_CORE_PACKAGE_PATH.'/system/system_asset_fns.inc';
65  if (!system_asset_fns_create_pre_check($this)) {
66  return FALSE;
67  }
68  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
69  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
70 
71  if ($linkid = parent::create($link)) {
72  if (!system_asset_fns_create_cleanup($this)) {
73  $linkid = FALSE;
74  }
75  }
76 
77  if ($linkid) {
78  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
79  } else {
80  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
81  }
82 
83  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
84  return $linkid;
85 
86  }//end create()
87 
88 
98  protected function _getName($short_name=FALSE)
99  {
100  return 'Remove SOAP Response Files Cron Job';
101 
102  }//end _getName()
103 
104 
111  public function canClone()
112  {
113  return FALSE;
114 
115  }//end canClone()
116 
117 
126  public function canDelete()
127  {
128  return FALSE;
129 
130  }//end canDelete()
131 
132 
144  protected function _exec(&$msg)
145  {
146  $dir_to_check = SQ_DATA_PATH.'/private/soap_action_file_responses/';
147  // no dir found...nothing to do
148  if (!is_dir($dir_to_check)) return SQ_CRON_JOB_COMPLETED;
149 
150  $session_dirs = list_dirs($dir_to_check, TRUE);
151  // no sessions dirs found safely bail out
152  // as we got nothing to delete here
153  if (empty($session_dirs)) return SQ_CRON_JOB_COMPLETED;
154 
155  if (!self::remove_temp_files($session_dirs)) return SQ_CRON_JOB_ERROR;
156 
157  return SQ_CRON_JOB_COMPLETED;
158 
159  }//end _exec()
160 
161 
171  public function run()
172  {
173  $res = parent::run();
174  if ($res & SQ_CRON_JOB_REMOVE) {
175  $res = $res - SQ_CRON_JOB_REMOVE;
176  }
177  return $res;
178 
179  }//end run()
180 
181 
192  public static function remove_temp_files($dirs=Array())
193  {
194  $success = TRUE;
195  foreach ($dirs as $dir) {
196  // delete all(1) files under this dir
197  if (!clear_directory($dir)) {
198  $success = FALSE;
199  } else {
200  // if the file deletion was super awesome
201  // go ahead and remove the dir itself too
202  if (!delete_directory($dir)) $success = FALSE;
203  }
204  }// end foreach
205 
206  return $success;
207 
208  }// end remove_temp_files()
209 
210 
211 }//end class
212 
213 
214 
215 ?>