_destroySubDirsFrom(WWW_PATH . '/' . App_Report_Obj::REPORT_ACCESS_PATH); $this->_destroySubDirsFrom(BASE_PATH . '/tmp/' . App_Report_AdminObj::REPORT_ADMIN_ACCESS_PATH); $this->_removeOldArchive(); exit; } protected function _destroySubDirsFrom($path) { foreach (scandir($path) as $dir) { if ($dir != '..' && $dir != '.' && $dir != '.htaccess' && $dir != '.htaccess_dev' && !$this->sessionExists($dir)) { $this->_destroyDir($path . '/' . $dir); } } } protected function _destroyDir($dir) { if (!is_dir($dir) || is_link($dir)) { return unlink($dir); } foreach (scandir($dir) as $file) { if ($file == '.' || $file == '..' || $file == '.htaccess') { continue; } if (!$this->_destroyDir($dir . DIRECTORY_SEPARATOR . $file)) { chmod($dir . DIRECTORY_SEPARATOR . $file, 0777); if (!$this->_destroyDir($dir . DIRECTORY_SEPARATOR . $file)) { return false; } }; } return rmdir($dir); } public function sessionExists($sessionId) { $file = $this->getSessionSavePath() . '/sess_' . $sessionId; return file_exists($file); } public function getSessionSavePath() { if (null === $this->_sessionSavePath) { $this->_sessionSavePath = session_save_path(); if (empty($this->_sessionSavePath)) { $this->_sessionSavePath = sys_get_temp_dir(); } } return $this->_sessionSavePath; } protected function _doNoop() { exit; } protected function _doOverdueNotification() { $result = array(); $from = App_Settings_Obj::getEmailForm($this->_settingsPrefix . 'From'); $subject = App_Settings_Obj::get($this->_settingsPrefix . 'Subject'); $template = App_Settings_Obj::get($this->_settingsPrefix . 'Body'); $link = Qs_SiteMap::findFirst(null, array('type' => 'Report_'), null, 'url'); $notificationDataList = array(); $notificationDataList['10'] = $this->_getDataObj()->getOverdueWithinXDayReports(10); $notificationDataList['0'] = $this->_getDataObj()->getOverdueTodayReports(); $notificationDataList['-1'] = $this->_getDataObj()->getOverdueWithinXDayReports(-1); $notificationDataList['-5'] = $this->_getDataObj()->getOverdueWithinXDayReports(-5); $notificationDataList['-10'] = $this->_getDataObj()->getOverdueWithinXDayReports(-10); $notificationDataList['-30'] = $this->_getDataObj()->getOverdueWithinXDayReports(-30); foreach ($notificationDataList as $idx => $info) { if (empty($info)) { continue; } // IMED-119#comment=92-82943 - the reminders only start on July 1st if ($idx < 0 && date('md', strtotime($info['date'])) < '0701') { continue; } foreach ($info['list'] as $school) { if (empty($school['userList'])) { continue; } $result[] = array( 'school' => $school['schoolName'], 'reportCount' => count($school['list']), ); $mailData = array( '{date}' => date('M j, Y'), '{schoolName}' => $school['schoolName'], '{count}' => count($school['list']), '{link}' => $link ? $link : constant('BASE_URL'), ); $mailData = array_map('htmlspecialchars', $mailData); $mailData['{list}'] = $this->_renderReportList($school['list']); $to = Qs_Array::fetchCol($school['userList'], 'email'); $body = str_replace(array_keys($mailData), array_values($mailData), $template); $this->_sendMail(compact('from', 'to', 'subject', 'body')); } } echo json_encode($result); exit; } protected function _renderReportList(array $list) { $item = array( 'list' => $list, 'tpl' => Qs_Sitemap::getTemplate('Report/notification-reports.tpl') ); $this->_doc->assign('item', new Qs_Doc_Item($item)); return $this->_doc->fetch($item['tpl']); } protected function _removeOldArchive() { // we need check all archive files like: archive-123.zip or archive-all.zip $pattern = sprintf(App_Report_Archive_View::REPORT_ARCHIVE_FILE_TPL, '*'); $folder = constant('WWW_PATH') . '/' . App_Report_AbstractObj::REPORT_PATH . '/'; if (false === ($files = glob($folder . $pattern, GLOB_NOSORT))) { return $this; } foreach ($files as $path) { if (file_exists($path) && ($mtime = filemtime($path)) && $mtime < time() - App_Report_Archive_Obj::ARCHIVE_TTL) { unlink($path); } } return $this; } }