From 68469d958bc7d5369e269269e34d32c835461fcd Mon Sep 17 00:00:00 2001 From: ro Date: Sun, 30 Jun 2024 19:50:27 -0600 Subject: [PATCH] Fix for #115, theme css subdir deleted on publish Patch for a bug that was deleteting the subdirectories of the theme css folder holding additional theme assets when being published and tested in the theme kit. also removed an unneccessary helper script and organized directory actions in their own helper file to keep it all tidy --- app/Helpers/DirectoryHelpers.php | 38 ++++++++++++++++++++++++++++ app/Helpers/PageSorter.php | 10 -------- app/Helpers/StringHelpers.php | 19 -------------- app/Services/Assets/AssetService.php | 12 ++++++--- 4 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 app/Helpers/DirectoryHelpers.php delete mode 100644 app/Helpers/PageSorter.php diff --git a/app/Helpers/DirectoryHelpers.php b/app/Helpers/DirectoryHelpers.php new file mode 100644 index 0000000..b9bcb24 --- /dev/null +++ b/app/Helpers/DirectoryHelpers.php @@ -0,0 +1,38 @@ +isDot()) { + if ($object->isDir()) { + delete_directory($object->getPathname()); + } else { + unlink($object->getPathname()); + } + } + } + rmdir($dirPath); + } else { + throw new Exception(__FUNCTION__ . '(dirPath): dirPath is not a directory!'); + } +} + +function copy_directory($src, $dst) +{ + if (file_exists($dst)) { + rrmdir($dst); + } + if (is_dir($src)) { + mkdir($dst); + $files = scandir($src); + foreach ($files as $file) { + if ($file != "." && $file != "..") { + copy_directory("$src/$file", "$dst/$file"); + } + } + } elseif (file_exists($src)) { + copy($src, $dst); + } +} diff --git a/app/Helpers/PageSorter.php b/app/Helpers/PageSorter.php deleted file mode 100644 index d439057..0000000 --- a/app/Helpers/PageSorter.php +++ /dev/null @@ -1,10 +0,0 @@ -loadAllPages(); - echo(count($pages)); -} diff --git a/app/Helpers/StringHelpers.php b/app/Helpers/StringHelpers.php index 7019655..df23c51 100644 --- a/app/Helpers/StringHelpers.php +++ b/app/Helpers/StringHelpers.php @@ -62,22 +62,3 @@ function createAppKey() { return 'base64:' . base64_encode(Encrypter::generateKey(config('app.cipher'))); } - -function delete_directory($dirPath) -{ - if (is_dir($dirPath)) { - $objects = new DirectoryIterator($dirPath); - foreach ($objects as $object) { - if (!$object->isDot()) { - if ($object->isDir()) { - delete_directory($object->getPathname()); - } else { - unlink($object->getPathname()); - } - } - } - rmdir($dirPath); - } else { - throw new Exception(__FUNCTION__ . '(dirPath): dirPath is not a directory!'); - } -} diff --git a/app/Services/Assets/AssetService.php b/app/Services/Assets/AssetService.php index e230678..f1ac0e8 100644 --- a/app/Services/Assets/AssetService.php +++ b/app/Services/Assets/AssetService.php @@ -86,11 +86,17 @@ class AssetService copy($file, $cssPath . $path[6]); } else { // if there is a type/font folder, move it + $typePath = explode('/', $file); - if (is_dir($cssPath . $typePath[6])) { - delete_directory($cssPath . $typePath[6]); + $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]); + //rename($file, $cssPath . $typePath[6]); } } $newjs = glob('../content/themes/' . $this->currentTheme . '/assets/scripts/*');