Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function doTask()
 {
     $config = ConfigProvider::getInstance();
     self::$logger = new Logger('BackupTask');
     self::$logger->setLogProviderFile($config->get('app.file.store.dir') . 'logs/tasks.log');
     if (!file_exists($config->get('backup.dir'))) {
         mkdir($config->get('backup.dir'));
     }
     $targetDir = $config->get('backup.dir') . date('Y-m-d') . '/';
     if (file_exists($targetDir)) {
         FileUtils::deleteDirectoryContents($targetDir);
     }
     if (!file_exists($targetDir)) {
         mkdir($targetDir);
     }
     $back = new BackupUtils();
     $back->backUpAttachmentsAndLogs($targetDir);
     $back->backUpDatabase($targetDir);
     $additionalDirectories = explode(',', $config->get('backup.include.dirs'));
     if (count($additionalDirectories) > 0) {
         foreach ($additionalDirectories as $additionalDirectory) {
             FileUtils::copy($additionalDirectory, $targetDir . basename($additionalDirectory));
         }
     }
     if ($config->get('backup.compress')) {
         FileUtils::zip($targetDir, $config->get('backup.dir') . date('Y-m-d') . '.zip');
         // we can safely remove the uncompressed files now to save space...
         FileUtils::deleteDirectoryContents($targetDir . 'logs');
         rmdir($targetDir . 'logs');
         FileUtils::deleteDirectoryContents($targetDir . 'attachments');
         rmdir($targetDir . 'attachments');
         unlink($targetDir . $config->get('db.name') . '_' . date('Y-m-d') . '.sql');
         if (count($additionalDirectories) > 0) {
             foreach ($additionalDirectories as $additionalDirectory) {
                 FileUtils::deleteDirectoryContents($targetDir . basename($additionalDirectory));
                 rmdir($targetDir . basename($additionalDirectory));
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @since 1.0
  */
 public function __construct()
 {
     $config = ConfigProvider::getInstance();
     self::$logger = new Logger('CronManager');
     self::$logger->setLogProviderFile($config->get('app.file.store.dir') . 'logs/tasks.log');
     self::$logger->debug('>>__construct()');
     self::$logger->info('New CronManager invoked');
     $taskList = self::getTaskClassNames();
     self::$logger->info('Found [' . count($taskList) . '] tasks in the directory [' . $config->get('app.root') . 'tasks]');
     foreach ($taskList as $taskClass) {
         $taskClass = 'Alpha\\Task\\' . $taskClass;
         self::$logger->info('Loading task [' . $taskClass . ']');
         $task = new $taskClass();
         $startTime = microtime(true);
         $maxAllowedTime = $startTime + $task->getMaxRunTime();
         self::$logger->info('Start time is [' . $startTime . '], maximum task run time is [' . $task->getMaxRunTime() . ']');
         // only continue to execute for the task max time
         set_time_limit($task->getMaxRunTime());
         $task->doTask();
         self::$logger->info('Done in [' . round(microtime(true) - $startTime, 5) . '] seconds');
     }
     self::$logger->info('Finished processing all cron tasks');
     self::$logger->debug('<<__construct');
 }