/** * Constructor. * @param $args array */ function ScheduledTask($args = array()) { $this->_args = $args; $this->_processId = uniqid(); // Check the scheduled task execution log folder. import('lib.pkp.classes.file.PrivateFileManager'); $fileMgr = new PrivateFileManager(); $scheduledTaskFilesPath = realpath($fileMgr->getBasePath()) . DIRECTORY_SEPARATOR . SCHEDULED_TASK_EXECUTION_LOG_DIR; $this->_executionLogFile = $scheduledTaskFilesPath . DIRECTORY_SEPARATOR . str_replace(' ', '', $this->getName()) . '-' . $this->getProcessId() . '-' . date('Ymd') . '.log'; if (!$fileMgr->fileExists($scheduledTaskFilesPath, 'dir')) { $success = $fileMgr->mkdirtree($scheduledTaskFilesPath); if (!$success) { // files directory wrong configuration? assert(false); $this->_executionLogFile = null; } } AppLocale::requireComponents(LOCALE_COMPONENT_PKP_ADMIN, LOCALE_COMPONENT_PKP_COMMON); }
/** * Get the base path for file storage. * @return string */ function getBasePath() { return parent::getBasePath() . '/contexts/' . $this->contextId . '/library/'; }
/** * @param $usageEvent array */ private function _writeUsageEventInLogFile($usageEvent) { $desiredParams = array($usageEvent['ip']); if (isset($usageEvent['classification'])) { $desiredParams[] = $usageEvent['classification']; } else { $desiredParams[] = '-'; } if (isset($usageEvent['user'])) { $desiredParams[] = $usageEvent['user']->getId(); } else { $desiredParams[] = '-'; } $desiredParams = array_merge($desiredParams, array('"' . $usageEvent['time'] . '"', $usageEvent['canonicalUrl'], '"' . $usageEvent['userAgent'] . '"')); $usageLogEntry = implode(' ', $desiredParams) . PHP_EOL; import('lib.pkp.classes.file.PrivateFileManager'); $fileMgr = new PrivateFileManager(); // Get the current day filename. $filename = 'usage_events_' . date("Ymd") . '.log'; // Check the plugin file directory. $usageEventFilesPath = realpath($fileMgr->getBasePath()) . DIRECTORY_SEPARATOR . 'usageStats' . DIRECTORY_SEPARATOR . 'usageEventLogs'; if (!$fileMgr->fileExists($usageEventFilesPath, 'dir')) { $success = $fileMgr->mkdirtree($usageEventFilesPath); if (!$success) { // Files directory wrong configuration? assert(false); return false; } } $filePath = $usageEventFilesPath . DIRECTORY_SEPARATOR . $filename; $fp = fopen($filePath, 'ab'); if (flock($fp, LOCK_EX)) { fwrite($fp, $usageLogEntry); flock($fp, LOCK_UN); } else { // Couldn't lock the file. assert(false); } fclose($fp); }
/** * Download execution log file. * @param $file string */ function downloadExecutionLog($file) { import('lib.pkp.classes.file.PrivateFileManager'); $fileMgr = new PrivateFileManager(); $fileMgr->downloadFile($fileMgr->getBasePath() . DIRECTORY_SEPARATOR . SCHEDULED_TASK_EXECUTION_LOG_DIR . DIRECTORY_SEPARATOR . $file); }
/** * Get the base path for temporary file storage. * @return string */ function getBasePath() { return parent::getBasePath() . '/temp/'; }
/** * Get the plugin's files path. * @return string */ function getFilesPath() { import('lib.pkp.classes.file.PrivateFileManager'); $fileMgr = new PrivateFileManager(); return realpath($fileMgr->getBasePath()) . DIRECTORY_SEPARATOR . 'usageStats'; }
/** * Get the base path for file storage * @return string */ function getBasePath() { $dirNames = Application::getFileDirectories(); return parent::getBasePath() . $dirNames['context'] . $this->contextId . '/'; }