updated dependencies to the latest versions also took a swing at rendering performance, which was pretty basic. it was fine for sites with not that many pages, but it gets a bit stick above 50 as of right now, performance has been improved slighthy by forcing some garbage collection, rendering 65 pages in under 30 seconds with 256MB available. the issue seems to the speed of initial page collections from the directories and then converting them to objects that the system can use. going to explore some options to optimize that particular script also removed page load from PageRepository instantion because when the app loads, it was calling that class as part of the start of process and loading pages everytime no matter what page was being looked at. removing that made non page sections snappier
116 lines
4.1 KiB
PHP
116 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Assets;
|
|
|
|
use App\Services\Data\ThemeService;
|
|
|
|
class AssetService
|
|
{
|
|
protected $themeTestImagePath;
|
|
protected $themeTestCSSPath;
|
|
protected $themeTestScriptsPath;
|
|
protected $themeCSSPath;
|
|
protected $themeImagePath;
|
|
protected $themeScriptsPath;
|
|
protected $themes;
|
|
protected $currentTheme;
|
|
|
|
public function __construct(ThemeService $themeService)
|
|
{
|
|
$this->themeImagePath = '../public/assets/images/global/';
|
|
$this->themeTestImagePath = '../public/theme/images/global/';
|
|
$this->themeCSSPath = '../public/assets/css/theme/';
|
|
$this->themeTestCSSPath = '../public/theme/css/theme/';
|
|
$this->themeScriptsPath = '../public/assets/scripts/theme/';
|
|
$this->themeTestScriptsPath = '../public/theme/scripts/theme/';
|
|
$this->themes = $themeService;
|
|
$this->currentTheme = $this->themes->getCurrentTheme();
|
|
}
|
|
|
|
public function getCurrentTheme()
|
|
{
|
|
return $this->currentTheme;
|
|
}
|
|
|
|
public function moveToTheme($live = false)
|
|
{
|
|
$imagePath = '';
|
|
$cssPath = '';
|
|
$scriptPath = '';
|
|
($live) ? $imagePath = $this->themeImagePath : $imagePath = $this->themeTestImagePath;
|
|
($live) ? $cssPath = $this->themeCSSPath : $cssPath = $this->themeTestCSSPath;
|
|
($live) ? $scriptPath = $this->themeScriptsPath : $scriptPath = $this->themeTestScriptsPath;
|
|
//get current theme
|
|
foreach (
|
|
new \DirectoryIterator('../content/themes/' . $this->currentTheme . '/assets/images/global/') as $file
|
|
) {
|
|
if ($file->isDot()) {
|
|
continue;
|
|
}
|
|
//make theme directory if not present
|
|
if (!is_dir($imagePath)) {
|
|
mkdir($imagePath, 0755, true);
|
|
}
|
|
|
|
if (!is_file($imagePath . $file->getFileName())) {
|
|
copy(
|
|
'../content/themes/' .
|
|
$this->currentTheme .
|
|
'/assets/images/global/' .
|
|
$file->getFileName(),
|
|
$imagePath . $file->getFileName()
|
|
);
|
|
} else {
|
|
//image is already there, so chill
|
|
}
|
|
}
|
|
//clear test theme css and script directories
|
|
$styles = glob($cssPath . '*'); // get all file names
|
|
foreach ($styles as $file) { // iterate files
|
|
if (is_file($file)) {
|
|
unlink($file); // delete file
|
|
}
|
|
}
|
|
$scripts = glob($scriptPath . '*'); // get all file names
|
|
foreach ($scripts as $file) { // iterate files
|
|
if (is_file($file)) {
|
|
unlink($file); // delete file
|
|
}
|
|
}
|
|
|
|
//copy theme assets to public
|
|
$newcss = glob('../content/themes/' . $this->currentTheme . '/assets/css/*');
|
|
if (!is_dir($cssPath)) {
|
|
mkdir($cssPath, 0755, true);
|
|
}
|
|
foreach ($newcss as $file) { // iterate files
|
|
if (is_file($file)) {
|
|
$path = explode('/', $file);
|
|
copy($file, $cssPath . $path[6]);
|
|
} else {
|
|
// if there is a type/font folder, move it
|
|
|
|
$typePath = explode('/', $file);
|
|
$src = '../content/themes/' . $this->currentTheme . '/assets/css/' . $typePath[6];
|
|
$dst = $cssPath . $typePath[6];
|
|
if (is_dir($dst)) {
|
|
delete_directory($dst);
|
|
copy_directory($src, $dst);
|
|
} else {
|
|
copy_directory($src, $dst);
|
|
}
|
|
//rename($file, $cssPath . $typePath[6]);
|
|
}
|
|
}
|
|
$newjs = glob('../content/themes/' . $this->currentTheme . '/assets/scripts/*');
|
|
if (!is_dir($scriptPath)) {
|
|
mkdir($scriptPath, 0755, true);
|
|
}
|
|
foreach ($newjs as $file) { // iterate files
|
|
if (is_file($file)) {
|
|
$path = explode('/', $file);
|
|
copy($file, $scriptPath . $path[6]);
|
|
}
|
|
}
|
|
}
|
|
}
|