From eee3242c4b2d94aac870958c142d7d410ca6414c Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Wed, 22 Apr 2026 02:35:24 -0500 Subject: [PATCH] feat: replace MokoCassiopeia references in content/modules on install/update Adds replaceCassiopeiaReferences() to script.php postflight so article content and custom HTML modules are updated during Joomla admin install/update, not just on frontend page load. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/script.php | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/script.php b/src/script.php index fa08acb..dcbfa07 100644 --- a/src/script.php +++ b/src/script.php @@ -91,12 +91,73 @@ class Tpl_MokoonyxInstallerScript implements InstallerScriptInterface // On install or update: migrate from MokoCassiopeia if it exists if ($type === 'install' || $type === 'update') { $this->migrateFromCassiopeia(); + $this->replaceCassiopeiaReferences(); $this->clearFaviconStamp(); } return true; } + /** + * Replace MokoCassiopeia references in article content and module content. + */ + private function replaceCassiopeiaReferences(): void + { + $db = Factory::getDbo(); + + // Replace in article content (introtext + fulltext) + foreach (['introtext', 'fulltext'] as $col) { + try { + $query = $db->getQuery(true) + ->update('#__content') + ->set( + $db->quoteName($col) . ' = REPLACE(REPLACE(' + . $db->quoteName($col) . ', ' + . $db->quote(self::OLD_DISPLAY) . ', ' + . $db->quote(self::NEW_DISPLAY) . '), ' + . $db->quote(self::OLD_NAME) . ', ' + . $db->quote(self::NEW_NAME) . ')' + ) + ->where( + '(' . $db->quoteName($col) . ' LIKE ' . $db->quote('%' . self::OLD_DISPLAY . '%') + . ' OR ' . $db->quoteName($col) . ' LIKE ' . $db->quote('%' . self::OLD_NAME . '%') . ')' + ); + $db->setQuery($query)->execute(); + $n = $db->getAffectedRows(); + if ($n > 0) { + $this->logMessage("Replaced MokoCassiopeia in {$n} content row(s) ({$col})."); + } + } catch (\Throwable $e) { + $this->logMessage('Content replacement failed (' . $col . '): ' . $e->getMessage(), 'warning'); + } + } + + // Replace in module content (custom HTML modules etc.) + try { + $query = $db->getQuery(true) + ->update('#__modules') + ->set( + $db->quoteName('content') . ' = REPLACE(REPLACE(' + . $db->quoteName('content') . ', ' + . $db->quote(self::OLD_DISPLAY) . ', ' + . $db->quote(self::NEW_DISPLAY) . '), ' + . $db->quote(self::OLD_NAME) . ', ' + . $db->quote(self::NEW_NAME) . ')' + ) + ->where( + '(' . $db->quoteName('content') . ' LIKE ' . $db->quote('%' . self::OLD_DISPLAY . '%') + . ' OR ' . $db->quoteName('content') . ' LIKE ' . $db->quote('%' . self::OLD_NAME . '%') . ')' + ); + $db->setQuery($query)->execute(); + $n = $db->getAffectedRows(); + if ($n > 0) { + $this->logMessage("Replaced MokoCassiopeia in {$n} module(s)."); + } + } catch (\Throwable $e) { + $this->logMessage('Module replacement failed: ' . $e->getMessage(), 'warning'); + } + } + /** * Delete the favicon stamp file so favicons and site.webmanifest * are regenerated on the next page load after install/update.