From 1712291df1ac2bc68e12d4668d1287eb78489e94 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Thu, 30 Apr 2026 10:21:18 -0500 Subject: [PATCH] feat: add production-ready site reset maintenance actions Add 8 new one-shot maintenance toggles for resetting a site after development: reset votes, normalize publish dates, clear action logs, clear redirect logs, clear user notes, flush mail queue, flush sessions, and set robots to index/follow. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Extension/MokoWaaS.php | 318 +++++++++++++++++++++ src/language/en-GB/plg_system_mokowaas.ini | 16 ++ src/language/en-US/plg_system_mokowaas.ini | 16 ++ src/mokowaas.xml | 88 ++++++ 4 files changed, 438 insertions(+) diff --git a/src/Extension/MokoWaaS.php b/src/Extension/MokoWaaS.php index 1a5a9b0b..a7875cab 100644 --- a/src/Extension/MokoWaaS.php +++ b/src/Extension/MokoWaaS.php @@ -749,6 +749,150 @@ class MokoWaaS extends CMSPlugin ); } + if ((int) $params->get('reset_votes', 0) === 1) + { + $count = $this->resetAllVotes(); + $params->set('reset_votes', '0'); + $changed = true; + + $app->enqueueMessage( + sprintf('Deleted %d article rating records.', $count), + 'message' + ); + + Log::add( + sprintf('All article ratings/votes purged (%d rows) by MokoWaaS', $count), + Log::WARNING, + 'mokowaas' + ); + } + + if ((int) $params->get('normalize_publish_dates', 0) === 1) + { + $count = $this->normalizePublishDates(); + $params->set('normalize_publish_dates', '0'); + $changed = true; + + $app->enqueueMessage( + sprintf('Normalized publish dates on %d published articles.', $count), + 'message' + ); + + Log::add( + sprintf('Publish dates normalized to today on %d articles by MokoWaaS', $count), + Log::WARNING, + 'mokowaas' + ); + } + + if ((int) $params->get('clear_action_logs', 0) === 1) + { + $count = $this->clearActionLogs(); + $params->set('clear_action_logs', '0'); + $changed = true; + + $app->enqueueMessage( + sprintf('Cleared %d action log entries.', $count), + 'message' + ); + + Log::add( + sprintf('All action logs cleared (%d rows) by MokoWaaS', $count), + Log::WARNING, + 'mokowaas' + ); + } + + if ((int) $params->get('clear_redirects', 0) === 1) + { + $count = $this->clearRedirects(); + $params->set('clear_redirects', '0'); + $changed = true; + + $app->enqueueMessage( + sprintf('Cleared %d redirect entries.', $count), + 'message' + ); + + Log::add( + sprintf('All redirect links cleared (%d rows) by MokoWaaS', $count), + Log::WARNING, + 'mokowaas' + ); + } + + if ((int) $params->get('clear_user_notes', 0) === 1) + { + $count = $this->clearUserNotes(); + $params->set('clear_user_notes', '0'); + $changed = true; + + $app->enqueueMessage( + sprintf('Cleared %d user notes.', $count), + 'message' + ); + + Log::add( + sprintf('All user notes cleared (%d rows) by MokoWaaS', $count), + Log::WARNING, + 'mokowaas' + ); + } + + if ((int) $params->get('flush_mail_queue', 0) === 1) + { + $count = $this->flushMailQueue(); + $params->set('flush_mail_queue', '0'); + $changed = true; + + $app->enqueueMessage( + sprintf('Flushed %d queued mail messages.', $count), + 'message' + ); + + Log::add( + sprintf('Mail queue flushed (%d rows) by MokoWaaS', $count), + Log::WARNING, + 'mokowaas' + ); + } + + if ((int) $params->get('flush_sessions', 0) === 1) + { + $count = $this->flushSessions(); + $params->set('flush_sessions', '0'); + $changed = true; + + $app->enqueueMessage( + sprintf('Flushed %d sessions. All users will need to log in again.', $count), + 'message' + ); + + Log::add( + sprintf('All sessions flushed (%d rows) by MokoWaaS', $count), + Log::WARNING, + 'mokowaas' + ); + } + + if ((int) $params->get('set_robots_index_follow', 0) === 1) + { + $this->setRobotsIndexFollow(); + $params->set('set_robots_index_follow', '0'); + $changed = true; + + $app->enqueueMessage( + 'Global robots meta tag set to "index, follow".', + 'message' + ); + + Log::add( + 'Robots meta set to index,follow by MokoWaaS', + Log::WARNING, + 'mokowaas' + ); + } + if ($changed) { $db = Factory::getDbo(); @@ -806,6 +950,180 @@ class MokoWaaS extends CMSPlugin return $db->getAffectedRows(); } + /** + * Delete all article rating/vote records. + * + * @return int Number of rows deleted + * + * @since 02.01.22 + */ + protected function resetAllVotes() + { + $db = Factory::getDbo(); + + $db->setQuery( + $db->getQuery(true) + ->delete($db->quoteName('#__content_rating')) + ); + $db->execute(); + + return $db->getAffectedRows(); + } + + /** + * Normalize publish dates on all published articles. + * + * Sets publish_up to today and clears publish_down so articles + * appear freshly published with no expiry. Only affects articles + * with state = 1 (published). + * + * @return int Number of rows affected + * + * @since 02.01.22 + */ + protected function normalizePublishDates() + { + $db = Factory::getDbo(); + $now = Factory::getDate()->toSql(); + + $db->setQuery( + $db->getQuery(true) + ->update($db->quoteName('#__content')) + ->set($db->quoteName('publish_up') . ' = ' . $db->quote($now)) + ->set($db->quoteName('publish_down') . ' = NULL') + ->where($db->quoteName('state') . ' = 1') + ); + $db->execute(); + + return $db->getAffectedRows(); + } + + /** + * Clear all action log entries. + * + * @return int Number of rows deleted + * + * @since 02.01.22 + */ + protected function clearActionLogs() + { + $db = Factory::getDbo(); + + $db->setQuery( + $db->getQuery(true) + ->delete($db->quoteName('#__action_logs')) + ); + $db->execute(); + + return $db->getAffectedRows(); + } + + /** + * Clear all redirect link entries. + * + * @return int Number of rows deleted + * + * @since 02.01.22 + */ + protected function clearRedirects() + { + $db = Factory::getDbo(); + + $db->setQuery( + $db->getQuery(true) + ->delete($db->quoteName('#__redirect_links')) + ); + $db->execute(); + + return $db->getAffectedRows(); + } + + /** + * Clear all user notes. + * + * @return int Number of rows deleted + * + * @since 02.01.22 + */ + protected function clearUserNotes() + { + $db = Factory::getDbo(); + + $db->setQuery( + $db->getQuery(true) + ->delete($db->quoteName('#__user_notes')) + ); + $db->execute(); + + return $db->getAffectedRows(); + } + + /** + * Flush all queued mail messages. + * + * @return int Number of rows deleted + * + * @since 02.01.22 + */ + protected function flushMailQueue() + { + $db = Factory::getDbo(); + + $db->setQuery( + $db->getQuery(true) + ->delete($db->quoteName('#__mail_queue')) + ); + $db->execute(); + + return $db->getAffectedRows(); + } + + /** + * Flush all sessions, forcing all users to log in again. + * + * @return int Number of rows deleted + * + * @since 02.01.22 + */ + protected function flushSessions() + { + $db = Factory::getDbo(); + + $db->setQuery( + $db->getQuery(true) + ->delete($db->quoteName('#__session')) + ); + $db->execute(); + + return $db->getAffectedRows(); + } + + /** + * Set the global robots meta tag to "index, follow" in Joomla + * global configuration. + * + * @return void + * + * @since 02.01.22 + */ + protected function setRobotsIndexFollow() + { + $config = Factory::getApplication()->getConfig(); + $configFile = JPATH_CONFIGURATION . '/configuration.php'; + + $config->set('robots', 'index, follow'); + + $contents = file_get_contents($configFile); + + $contents = preg_replace( + '/public\s+\$robots\s*=\s*[\'"].*?[\'"]\s*;/', + "public \$robots = 'index, follow';", + $contents + ); + + file_put_contents($configFile, $contents); + } + /** * Event triggered after the route has been determined. * diff --git a/src/language/en-GB/plg_system_mokowaas.ini b/src/language/en-GB/plg_system_mokowaas.ini index 8ba246f9..5b90d1c1 100644 --- a/src/language/en-GB/plg_system_mokowaas.ini +++ b/src/language/en-GB/plg_system_mokowaas.ini @@ -62,6 +62,22 @@ PLG_SYSTEM_MOKOWAAS_RESET_HITS_LABEL="Reset All Hits" PLG_SYSTEM_MOKOWAAS_RESET_HITS_DESC="Set all article hit counters to zero across the site. This action executes on save and resets to No." PLG_SYSTEM_MOKOWAAS_DELETE_VERSIONS_LABEL="Delete All Versions" PLG_SYSTEM_MOKOWAAS_DELETE_VERSIONS_DESC="Purge all content version history from the database. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_RESET_VOTES_LABEL="Reset All Votes" +PLG_SYSTEM_MOKOWAAS_RESET_VOTES_DESC="Delete all article ratings and votes. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_NORMALIZE_DATES_LABEL="Normalize Publish Dates" +PLG_SYSTEM_MOKOWAAS_NORMALIZE_DATES_DESC="Set publish_up to today and clear publish_down on all published articles. Makes articles appear freshly published with no expiry. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_CLEAR_ACTION_LOGS_LABEL="Clear Action Logs" +PLG_SYSTEM_MOKOWAAS_CLEAR_ACTION_LOGS_DESC="Delete all admin action log entries. Removes the development activity trail. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_CLEAR_REDIRECTS_LABEL="Clear Redirect Logs" +PLG_SYSTEM_MOKOWAAS_CLEAR_REDIRECTS_DESC="Delete all redirect link entries. Removes 404 tracking from development. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_CLEAR_USER_NOTES_LABEL="Clear User Notes" +PLG_SYSTEM_MOKOWAAS_CLEAR_USER_NOTES_DESC="Delete all user notes. Removes development notes attached to user accounts. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_FLUSH_MAIL_QUEUE_LABEL="Flush Mail Queue" +PLG_SYSTEM_MOKOWAAS_FLUSH_MAIL_QUEUE_DESC="Delete all queued outbound emails. Prevents unsent test emails from being delivered. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_FLUSH_SESSIONS_LABEL="Flush All Sessions" +PLG_SYSTEM_MOKOWAAS_FLUSH_SESSIONS_DESC="Delete all active sessions. Forces every user to log in again. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_SET_ROBOTS_LABEL="Set Robots to Index, Follow" +PLG_SYSTEM_MOKOWAAS_SET_ROBOTS_DESC="Update the global configuration robots meta tag to 'index, follow'. Enables search engine indexing for production. This action executes on save and resets to No." ; ===== Visual Branding fieldset ===== PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_LABEL="Visual Branding" diff --git a/src/language/en-US/plg_system_mokowaas.ini b/src/language/en-US/plg_system_mokowaas.ini index 8ba246f9..5b90d1c1 100644 --- a/src/language/en-US/plg_system_mokowaas.ini +++ b/src/language/en-US/plg_system_mokowaas.ini @@ -62,6 +62,22 @@ PLG_SYSTEM_MOKOWAAS_RESET_HITS_LABEL="Reset All Hits" PLG_SYSTEM_MOKOWAAS_RESET_HITS_DESC="Set all article hit counters to zero across the site. This action executes on save and resets to No." PLG_SYSTEM_MOKOWAAS_DELETE_VERSIONS_LABEL="Delete All Versions" PLG_SYSTEM_MOKOWAAS_DELETE_VERSIONS_DESC="Purge all content version history from the database. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_RESET_VOTES_LABEL="Reset All Votes" +PLG_SYSTEM_MOKOWAAS_RESET_VOTES_DESC="Delete all article ratings and votes. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_NORMALIZE_DATES_LABEL="Normalize Publish Dates" +PLG_SYSTEM_MOKOWAAS_NORMALIZE_DATES_DESC="Set publish_up to today and clear publish_down on all published articles. Makes articles appear freshly published with no expiry. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_CLEAR_ACTION_LOGS_LABEL="Clear Action Logs" +PLG_SYSTEM_MOKOWAAS_CLEAR_ACTION_LOGS_DESC="Delete all admin action log entries. Removes the development activity trail. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_CLEAR_REDIRECTS_LABEL="Clear Redirect Logs" +PLG_SYSTEM_MOKOWAAS_CLEAR_REDIRECTS_DESC="Delete all redirect link entries. Removes 404 tracking from development. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_CLEAR_USER_NOTES_LABEL="Clear User Notes" +PLG_SYSTEM_MOKOWAAS_CLEAR_USER_NOTES_DESC="Delete all user notes. Removes development notes attached to user accounts. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_FLUSH_MAIL_QUEUE_LABEL="Flush Mail Queue" +PLG_SYSTEM_MOKOWAAS_FLUSH_MAIL_QUEUE_DESC="Delete all queued outbound emails. Prevents unsent test emails from being delivered. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_FLUSH_SESSIONS_LABEL="Flush All Sessions" +PLG_SYSTEM_MOKOWAAS_FLUSH_SESSIONS_DESC="Delete all active sessions. Forces every user to log in again. This action executes on save and resets to No." +PLG_SYSTEM_MOKOWAAS_SET_ROBOTS_LABEL="Set Robots to Index, Follow" +PLG_SYSTEM_MOKOWAAS_SET_ROBOTS_DESC="Update the global configuration robots meta tag to 'index, follow'. Enables search engine indexing for production. This action executes on save and resets to No." ; ===== Visual Branding fieldset ===== PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_LABEL="Visual Branding" diff --git a/src/mokowaas.xml b/src/mokowaas.xml index fa11a19b..a7e51afc 100644 --- a/src/mokowaas.xml +++ b/src/mokowaas.xml @@ -190,6 +190,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +