Skip to content

Commit

Permalink
Maintenance: add some protections around various tasks. Drop separate…
Browse files Browse the repository at this point in the history
… font regen.
  • Loading branch information
dasgarner committed Aug 1, 2023
1 parent 49d81d9 commit 94cd6b9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 80 deletions.
17 changes: 0 additions & 17 deletions db/migrations/20220915100902_add_fonts_table_migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,5 @@ public function change()
if (file_exists($libraryLocation . 'fonts.css')) {
@unlink($libraryLocation . 'fonts.css');
}

// add a task that will re-generate fonts.css for the player
$this->table('task')
->insert([
[
'name' => 'Generate Player font css',
'class' => '\Xibo\XTR\GeneratePlayerCssTask',
'options' => '[]',
'schedule' => '*/5 * * * * *',
'isActive' => '1',
'configFile' => '/tasks/player-css.task',
'pid' => 0,
'lastRunDt' => 0,
'lastRunDuration' => 0,
'lastRunExitCode' => 0
],
])->save();
}
}
39 changes: 0 additions & 39 deletions lib/XTR/GeneratePlayerCssTask.php

This file was deleted.

43 changes: 25 additions & 18 deletions lib/XTR/MaintenanceDailyTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

use Carbon\Carbon;
use Xibo\Controller\Module;
use Xibo\Entity\Font;
use Xibo\Event\MaintenanceDailyEvent;
use Xibo\Factory\DataSetFactory;
use Xibo\Factory\FontFactory;
Expand Down Expand Up @@ -97,19 +96,33 @@ public function run()
set_time_limit(0);

// Make sure our library structure is as it should be
$this->libraryLocation = $this->getConfig()->getSetting('LIBRARY_LOCATION');
MediaService::ensureLibraryExists($this->libraryLocation);
try {
$this->libraryLocation = $this->getConfig()->getSetting('LIBRARY_LOCATION');
MediaService::ensureLibraryExists($this->libraryLocation);
} catch (\Exception $exception) {
$this->getLogger()->error('Library structure invalid, e = ' . $exception->getMessage());
$this->appendRunMessage(__('Library structure invalid'));
}

// TODO: should we remove all bundle/asset cache before we start?
// Import layouts
$this->importLayouts();

// Player bundle
$this->cachePlayerBundle();
try {
$this->appendRunMessage(__('## Build caches'));

// Cache Assets
$this->cacheAssets();
// TODO: should we remove all bundle/asset cache before we start?
// Player bundle
$this->cachePlayerBundle();

// Import layouts
$this->importLayouts();
// Cache Assets
$this->cacheAssets();

// Fonts
$this->mediaService->setUser($this->userFactory->getSystemUser())->updateFontsCss();
} catch (\Exception $exception) {
$this->getLogger()->error('Failure to build caches, e = ' . $exception->getMessage());
$this->appendRunMessage(__('Failure to build caches'));
}

// Tidy logs
$this->tidyLogs();
Expand Down Expand Up @@ -211,10 +224,11 @@ private function importLayouts()
}
}

// Fonts
// -----
// install fonts from the theme folder
$libraryLocation = $this->config->getSetting('LIBRARY_LOCATION');
$fontFolder = $this->config->uri('fonts', true);
$fontsAdded = false;
foreach (array_diff(scandir($fontFolder), array('..', '.')) as $file) {
// check if we already have this font file
if (count($this->fontFactory->getByFileName($file)) <= 0) {
Expand All @@ -231,7 +245,6 @@ private function importLayouts()
continue;
}

/** @var Font $font */
$font = $this->fontFactory->createEmpty();
$font->modifiedBy = $this->userFactory->getSystemUser()->userName;
$font->name = $fontLib->getFontName() . ' ' . $fontLib->getFontSubfamily();
Expand All @@ -241,19 +254,13 @@ private function importLayouts()
$font->md5 = md5_file($filePath);
$font->save();

$fontsAdded = true;
$copied = copy($filePath, $libraryLocation . 'fonts/' . $file);
if (!$copied) {
$this->getLogger()->error('importLayouts: Unable to copy fonts to ' . $libraryLocation);
}
}
}

if ($fontsAdded) {
// if we added any fonts here fonts.css file
$this->mediaService->setUser($this->userFactory->getSystemUser())->updateFontsCss();
}

$this->config->changeSetting('DEFAULTS_IMPORTED', 1);

$this->runMessage .= ' - ' . __('Done.') . PHP_EOL . PHP_EOL;
Expand Down
5 changes: 0 additions & 5 deletions tasks/player-css.task

This file was deleted.

2 changes: 1 addition & 1 deletion tests/http-client.env.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dev": {
"url": "http://localhost",
"serverKey": "test",
"serverKey": "6v4RduQhaw5Q",
"hardwareKey": "phpstorm",
"displayName": "PHPStorm",
"clientType": "windows",
Expand Down

0 comments on commit 94cd6b9

Please sign in to comment.