diff --git a/src/script.php b/src/script.php index d78ceb6..c48027e 100644 --- a/src/script.php +++ b/src/script.php @@ -93,6 +93,7 @@ class Tpl_MokoonyxInstallerScript implements InstallerScriptInterface $this->replaceCassiopeiaReferences(); $this->clearFaviconStamp(); $this->cleanMediaFolder(); + $this->removeDeletedFiles(); $this->lockExtension(); } @@ -483,6 +484,68 @@ class Tpl_MokoonyxInstallerScript implements InstallerScriptInterface } } + /** + * Remove files and directories that were shipped in previous versions + * but have since been deleted from the package. + * + * Joomla's installer never deletes files on upgrade — it only + * adds/overwrites. This method fills that gap so stale overrides + * and deprecated assets don't linger on disk. + * + * Maintain this list: when you delete a file from the repo, add its + * path here (relative to the template root) so existing installs + * get cleaned up on the next update. + */ + private function removeDeletedFiles(): void + { + $templateRoot = JPATH_ROOT . '/templates/' . self::NEW_NAME; + + // Paths relative to templates/mokoonyx/ + $deletedFiles = [ + // JoomGallery template overrides — removed in 02.19.00 + 'html/com_joomgallery/category/default.php', + 'html/com_joomgallery/category/default_cat.php', + 'html/com_joomgallery/category/index.html', + 'html/com_joomgallery/gallery/default.php', + 'html/com_joomgallery/gallery/index.html', + 'html/com_joomgallery/image/default.php', + 'html/com_joomgallery/image/index.html', + ]; + + // Directories to remove (only if empty after file deletion) + $deletedDirs = [ + 'html/com_joomgallery/image', + 'html/com_joomgallery/gallery', + 'html/com_joomgallery/category', + 'html/com_joomgallery', + ]; + + $removed = 0; + + foreach ($deletedFiles as $relPath) { + $file = $templateRoot . '/' . $relPath; + if (is_file($file)) { + @unlink($file); + $removed++; + } + } + + foreach ($deletedDirs as $relPath) { + $dir = $templateRoot . '/' . $relPath; + if (is_dir($dir)) { + // Only remove if empty + $entries = @scandir($dir); + if ($entries && count($entries) <= 2) { // . and .. only + @rmdir($dir); + } + } + } + + if ($removed > 0) { + $this->logMessage("Removed {$removed} deprecated file(s) from previous versions."); + } + } + private function logMessage(string $message, string $priority = 'info'): void { $priorities = [