From 1a207dfa7ff89e7a4d49e47f7ff4e9d2aed34f86 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Wed, 16 Apr 2025 21:16:00 +0200 Subject: [PATCH 1/3] Moving media generation to base class instead of separate class --- src/Tasks/Build/Base.php | 45 ++++++++++++++ src/Tasks/Build/Component.php | 6 +- src/Tasks/Build/File.php | 5 +- src/Tasks/Build/Library.php | 6 +- src/Tasks/Build/Media.php | 109 ---------------------------------- src/Tasks/Build/Module.php | 6 +- src/Tasks/Build/Plugin.php | 6 +- src/Tasks/Build/Tasks.php | 15 ----- src/Tasks/Build/Template.php | 6 +- 9 files changed, 51 insertions(+), 153 deletions(-) delete mode 100644 src/Tasks/Build/Media.php diff --git a/src/Tasks/Build/Base.php b/src/Tasks/Build/Base.php index 38f9a26..d7d67e3 100644 --- a/src/Tasks/Build/Base.php +++ b/src/Tasks/Build/Base.php @@ -314,6 +314,51 @@ public function getDate() return date('Y-m-d'); } + /** + * Copy the media files for an extension to the build folder + * + * @param string $name The name of the extension to copy media files for + * + * @return bool + * + * @since 1.0 + */ + public function buildMediaFiles($name) + { + $verbosity = $this->verbosityThreshold(); + $this->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE); + $type = substr($name, 0, 3); + $source = $this->getSourceFolder() . '/media/' . $name; + $target = $this->getBuildFolder() . '/media/' . $name; + + if ($type == 'lib') { + $source = $this->getSourceFolder() . '/media/' . substr($name, 3); + $target = $this->getBuildFolder() . '/media/' . substr($name, 3); + } + + $this->printTaskInfo("Building media folder " . $source . " for " . $name); + + if (!file_exists($source)) { + $this->printTaskInfo("Folder " . $source . " does not exist!"); + + return false; + } + + $this->taskFilesystemStack() + ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERY_VERBOSE) + ->mkdir($target) + ->run(); + + $map = $this->copyTarget($source, $target); + + $this->addFiles('media', $map); + + $this->printTaskSuccess("Finished building media folder " . $source . " for " . $name); + $this->setVerbosityThreshold($verbosity); + + return true; + } + /** * Generate a list of files * diff --git a/src/Tasks/Build/Component.php b/src/Tasks/Build/Component.php index 49a092f..d428b86 100644 --- a/src/Tasks/Build/Component.php +++ b/src/Tasks/Build/Component.php @@ -100,11 +100,7 @@ public function run() // Build media (relative path) if ($this->hasMedia) { $this->logger->log(LogLevel::INFO, 'Copy media files', $this->getTaskContext()); - $media = $this->buildMedia("media/com_" . $this->getExtensionName(), 'com_' . $this->getExtensionName(), $this->params); - $media->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) - ->run(); - - $this->addFiles('media', $media->getResultFiles()); + $this->buildMediaFiles('com_' . $this->getExtensionName()); } // Build language files for the component diff --git a/src/Tasks/Build/File.php b/src/Tasks/Build/File.php index 59fc7ff..5e1475e 100644 --- a/src/Tasks/Build/File.php +++ b/src/Tasks/Build/File.php @@ -91,10 +91,7 @@ public function run() } // Build media (relative path) - $media = $this->buildMedia("media/com_" . $this->getExtensionName(), 'com_' . $this->getExtensionName()); - $media->run(); - - $this->addFiles('media', $media->getResultFiles()); + $this->buildMediaFiles('fil_' . $this->getExtensionName()); // Build language files for the component $language = $this->buildLanguage("com_" . $this->getExtensionName()); diff --git a/src/Tasks/Build/Library.php b/src/Tasks/Build/Library.php index 4043c42..fa0526b 100644 --- a/src/Tasks/Build/Library.php +++ b/src/Tasks/Build/Library.php @@ -88,11 +88,7 @@ public function run() } // Build media (relative path) - $media = $this->buildMedia("media/" . $lib, $lib); - $media->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) - ->run(); - - $this->addFiles('media', $media->getResultFiles()); + $this->buildMediaFiles($this->libName); // Build language files for the component $language = $this->buildLanguage($lib) diff --git a/src/Tasks/Build/Media.php b/src/Tasks/Build/Media.php deleted file mode 100644 index a12e41b..0000000 --- a/src/Tasks/Build/Media.php +++ /dev/null @@ -1,109 +0,0 @@ -source = $this->getSourceFolder() . "/" . $folder; - $this->extName = $extName; - - $this->type = substr($extName, 0, 3); - - $target = $this->getBuildFolder() . "/" . $folder; - - if ($this->type == 'mod') { - $target = $this->getBuildFolder() . "/modules/" . $extName . "/" . $folder; - } elseif ($this->type == 'plg') { - $a = explode("_", $this->extName); - - $target = $this->getBuildFolder() . "/plugins/" . $a[1] . "/" . $a[2] . "/" . $folder; - } elseif ($this->type == 'lib') { - // Remove lib before - ugly hack - $ex = str_replace("lib_", "", $this->extName); - - $target = $this->getBuildFolder() . "/libraries/" . $ex . "/" . $folder; - } - - $this->target = $target; - } - - /** - * Runs the media build task - * - * @return Result - * - * @since 1.0 - */ - public function run() - { - $this->printTaskInfo("Building media folder " . $this->source . " for " . $this->extName); - - if (!file_exists($this->source)) { - $this->printTaskInfo("Folder " . $this->source . " does not exist!"); - - return Result::success($this); - } - - $this->prepareDirectory(); - - $map = $this->copyTarget($this->source, $this->target); - - $this->setResultFiles($map); - - $this->printTaskSuccess("Finished building media folder " . $this->source . " for " . $this->extName); - - return Result::success($this); - } - - /** - * Prepare the directory structure - * - * @return void - * - * @since 1.0 - */ - private function prepareDirectory() - { - $this->taskFilesystemStack() - ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERY_VERBOSE) - ->mkdir($this->target) - ->run(); - } -} diff --git a/src/Tasks/Build/Module.php b/src/Tasks/Build/Module.php index 119a73d..ecc6f43 100644 --- a/src/Tasks/Build/Module.php +++ b/src/Tasks/Build/Module.php @@ -67,11 +67,7 @@ public function run() $files = $this->copyTarget($this->source, $this->target); // Build media (relative path) - $media = $this->buildMedia("media/" . $this->modName, $this->modName); - $media->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) - ->run(); - - $this->addFiles('media', $media->getResultFiles()); + $this->buildMediaFiles($this->modName); // Build language files for the module if (is_dir($this->getSourceFolder() . '/language')) { diff --git a/src/Tasks/Build/Plugin.php b/src/Tasks/Build/Plugin.php index 794b7d6..682a273 100644 --- a/src/Tasks/Build/Plugin.php +++ b/src/Tasks/Build/Plugin.php @@ -71,11 +71,7 @@ public function run() $files = $this->copyTarget($this->source, $this->target); // Build media (relative path) - $media = $this->buildMedia("media/plg_" . $this->plgType . "_" . $this->plgName, 'plg_' . $this->plgType . "_" . $this->plgName); - $media->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) - ->run(); - - $this->addFiles('media', $media->getResultFiles()); + $this->buildMediaFiles('plg_' . $this->plgType . '_' . $this->plgName); // Build language files if (is_dir($this->getSourceFolder() . '/administrator/language')) { diff --git a/src/Tasks/Build/Tasks.php b/src/Tasks/Build/Tasks.php index d9d9720..088a968 100644 --- a/src/Tasks/Build/Tasks.php +++ b/src/Tasks/Build/Tasks.php @@ -41,21 +41,6 @@ protected function buildComponent($name, $params = []) return $this->task(Component::class, $name, $params); } - /** - * Build media folder - * - * @param string $source The media folder (an extension could have multiple) - * @param string $extName The extension name (e.g. mod_xy) - * - * @return CollectionBuilder - * - * @since 1.0 - */ - protected function buildMedia($source, $extName, $params = []) - { - return $this->task(Media::class, $source, $extName, $params); - } - /** * Build language folder * diff --git a/src/Tasks/Build/Template.php b/src/Tasks/Build/Template.php index f1765e1..8ccb0cd 100644 --- a/src/Tasks/Build/Template.php +++ b/src/Tasks/Build/Template.php @@ -67,11 +67,7 @@ public function run() $files = $this->copyTarget($this->source, $this->target); // Build media (relative path) - $media = $this->buildMedia("media/" . $this->templateName, $this->templateName); - $media->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) - ->run(); - - $this->addFiles('media', $media->getResultFiles()); + $this->buildMediaFiles('tpl_' . $this->templateName); // Build language files for the component if (is_dir($this->getSourceFolder() . '/language')) { From 19a7f75478a2ab40928b6ac027748f91f95585fb Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Wed, 16 Apr 2025 21:19:56 +0200 Subject: [PATCH 2/3] Codestyle --- src/Tasks/Build/Base.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Tasks/Build/Base.php b/src/Tasks/Build/Base.php index d7d67e3..b58139b 100644 --- a/src/Tasks/Build/Base.php +++ b/src/Tasks/Build/Base.php @@ -327,13 +327,13 @@ public function buildMediaFiles($name) { $verbosity = $this->verbosityThreshold(); $this->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE); - $type = substr($name, 0, 3); - $source = $this->getSourceFolder() . '/media/' . $name; - $target = $this->getBuildFolder() . '/media/' . $name; + $type = substr($name, 0, 3); + $source = $this->getSourceFolder() . '/media/' . $name; + $target = $this->getBuildFolder() . '/media/' . $name; if ($type == 'lib') { - $source = $this->getSourceFolder() . '/media/' . substr($name, 3); - $target = $this->getBuildFolder() . '/media/' . substr($name, 3); + $source = $this->getSourceFolder() . '/media/' . substr($name, 3); + $target = $this->getBuildFolder() . '/media/' . substr($name, 3); } $this->printTaskInfo("Building media folder " . $source . " for " . $name); From 308c8de49145da2e983bb41853de0e1d997c775c Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Thu, 17 Apr 2025 15:35:16 +0200 Subject: [PATCH 3/3] Removed Media files from File extension --- src/Tasks/Build/File.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Tasks/Build/File.php b/src/Tasks/Build/File.php index 5e1475e..80272e0 100644 --- a/src/Tasks/Build/File.php +++ b/src/Tasks/Build/File.php @@ -90,9 +90,6 @@ public function run() $this->addFiles('frontend', $frontendFiles); } - // Build media (relative path) - $this->buildMediaFiles('fil_' . $this->getExtensionName()); - // Build language files for the component $language = $this->buildLanguage("com_" . $this->getExtensionName()); $language->run();