芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/public_html/mctv/lib/XTR/MaintenanceDailyTask.php
. */ namespace Xibo\XTR; use Carbon\Carbon; use Xibo\Controller\Library; use Xibo\Factory\LayoutFactory; use Xibo\Factory\UserFactory; use Xibo\Helper\DatabaseLogHandler; use Xibo\Helper\DateFormatHelper; use Xibo\Support\Exception\GeneralException; use Xibo\Support\Exception\NotFoundException; /** * Class MaintenanceDailyTask * @package Xibo\XTR */ class MaintenanceDailyTask implements TaskInterface { use TaskTrait; /** @var LayoutFactory */ private $layoutFactory; /** @var UserFactory */ private $userFactory; /** @var Library */ private $libraryController; /** @inheritdoc */ public function setFactories($container) { $this->libraryController = $container->get('\Xibo\Controller\Library'); $this->layoutFactory = $container->get('layoutFactory'); $this->userFactory = $container->get('userFactory'); return $this; } /** @inheritdoc */ public function run() { $this->runMessage = '# ' . __('Daily Maintenance') . PHP_EOL . PHP_EOL; // Long running task set_time_limit(0); // Import layouts $this->importLayouts(); // Install module files $this->installModuleFiles(); // Tidy logs $this->tidyLogs(); // Tidy Cache $this->tidyCache(); } /** * Tidy the DB logs */ private function tidyLogs() { $this->runMessage .= '## ' . __('Tidy Logs') . PHP_EOL; $maxage = $this->config->getSetting('MAINTENANCE_LOG_MAXAGE'); if ($maxage != 0) { // Run this in the log handler so that we share the same connection and don't deadlock. DatabaseLogHandler::tidyLogs( Carbon::now() ->subDays(intval($maxage)) ->format(DateFormatHelper::getSystemFormat()) ); $this->runMessage .= ' - ' . __('Done') . PHP_EOL . PHP_EOL; } else { $this->runMessage .= ' - ' . __('Disabled') . PHP_EOL . PHP_EOL; } } /** * Tidy Cache */ private function tidyCache() { $this->runMessage .= '## ' . __('Tidy Cache') . PHP_EOL; $this->pool->purge(); $this->runMessage .= ' - ' . __('Done.') . PHP_EOL . PHP_EOL; } /** * Import Layouts * @throws GeneralException */ private function importLayouts() { $this->runMessage .= '## ' . __('Import Layouts') . PHP_EOL; if ($this->config->getSetting('DEFAULTS_IMPORTED') == 0) { $folder = $this->config->uri('layouts', true); foreach (array_diff(scandir($folder), array('..', '.')) as $file) { if (stripos($file, '.zip')) { try { $layout = $this->layoutFactory->createFromZip( $folder . '/' . $file, null, $this->userFactory->getSystemUser()->getId(), false, false, true, false, true, $this->libraryController, null, null ); $layout->save([ 'audit' => false, 'import' => true ]); try { $this->layoutFactory->getById($this->config->getSetting('DEFAULT_LAYOUT')); } catch (NotFoundException $exception) { $this->config->changeSetting('DEFAULT_LAYOUT', $layout->layoutId); } } catch (\Exception $exception) { $this->log->error('Unable to import layout: ' . $file . '. E = ' . $exception->getMessage()); $this->log->debug($exception->getTraceAsString()); } } } $this->config->changeSetting('DEFAULTS_IMPORTED', 1); $this->runMessage .= ' - ' . __('Done.') . PHP_EOL . PHP_EOL; } else { $this->runMessage .= ' - ' . __('Not Required.') . PHP_EOL . PHP_EOL; } } /** * Install Module Files */ private function installModuleFiles() { $this->libraryController->installAllModuleFiles(); } }