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) <noreply@anthropic.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user