Mwalker has submitted this change and it was merged.

Change subject: (FR #894) Crazy sql to rebuild corrupt logs
......................................................................


(FR #894) Crazy sql to rebuild corrupt logs

Change-Id: I51146a7392a05ca6227c3dae1afdb869ce7e80e4
---
A patches/patch-rebuild-templatelog.sql
1 file changed, 73 insertions(+), 0 deletions(-)

Approvals:
  Mwalker: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/patches/patch-rebuild-templatelog.sql 
b/patches/patch-rebuild-templatelog.sql
new file mode 100644
index 0000000..1198cc0
--- /dev/null
+++ b/patches/patch-rebuild-templatelog.sql
@@ -0,0 +1,73 @@
+-- Fix corrupted logs, where the "created" entry null values for all banner 
settings.
+-- See https://mingle.corp.wikimedia.org/projects/fundraiser_2012/cards/894
+--
+-- There is no DatabaseUpdater condition to run this script, it's meant to be 
done
+-- manually, and is definitely an optional fixup.  The primary use case for 
this
+-- data is Allocation History.
+
+-- Get all bad log entries which are followed by a "modified" entry
+-- which can be used to repopulate missing data.
+UPDATE cn_template_log target_log
+       JOIN
+       (
+               SELECT
+                       bad_log.tmplog_id AS bad_log_id,
+                       data_log.*
+               FROM /*_*/cn_template_log bad_log
+               JOIN /*_*/cn_template_log data_log
+               WHERE
+                       bad_log.tmplog_action = 'created'
+                       AND bad_log.tmplog_end_anon IS NULL
+                       AND
+                       (
+                               SELECT MIN( tmplog_id ) FROM 
/*_*/cn_template_log
+                               WHERE
+                                       tmplog_template_id = 
bad_log.tmplog_template_id
+                                       AND tmplog_id > bad_log.tmplog_id
+                                       AND tmplog_action = 'modified'
+                       ) = data_log.tmplog_id
+       ) AS next_data
+       SET 
+               target_log.tmplog_end_anon = next_data.tmplog_begin_anon,
+               target_log.tmplog_end_account = next_data.tmplog_begin_account,
+               target_log.tmplog_end_fundraising = 
next_data.tmplog_begin_fundraising,
+               target_log.tmplog_end_autolink = 
next_data.tmplog_begin_autolink,
+               target_log.tmplog_end_landingpages = 
next_data.tmplog_begin_landingpages,
+               target_log.tmplog_end_prioritylangs = 
next_data.tmplog_begin_prioritylangs,
+               target_log.tmplog_end_archived = 
next_data.tmplog_begin_archived,
+               target_log.tmplog_end_category = 
next_data.tmplog_begin_category,
+               target_log.tmplog_end_preview_sandbox = 
next_data.tmplog_begin_preview_sandbox,
+               target_log.tmplog_end_mixins = next_data.tmplog_begin_mixins
+       WHERE
+               bad_log_id = target_log.tmplog_id
+;
+
+-- Populate the remaining bad log entries with values from the current banner 
settings
+UPDATE cn_template_log target_log
+       JOIN
+       (
+               SELECT
+                       bad_log.tmplog_id AS bad_log_id,
+                       settings.*
+               FROM /*_*/cn_template_log bad_log
+               JOIN cn_templates settings
+               WHERE
+                       bad_log.tmplog_action = 'created'
+                       AND bad_log.tmplog_end_anon IS NULL
+       ) AS next_data
+       SET 
+               target_log.tmplog_end_anon = next_data.tmp_display_anon,
+               target_log.tmplog_end_account = next_data.tmp_display_account,
+               target_log.tmplog_end_fundraising = next_data.tmp_fundraising,
+               target_log.tmplog_end_autolink = next_data.tmp_autolink,
+               target_log.tmplog_end_landingpages = 
next_data.tmp_landing_pages,
+               target_log.tmplog_end_archived = next_data.tmp_archived,
+               target_log.tmplog_end_category = next_data.tmp_category,
+               target_log.tmplog_end_preview_sandbox = 
next_data.tmp_preview_sandbox
+
+               -- These properties didn't exist during the afflicted time 
window:
+               -- target_log.tmplog_end_prioritylangs = 
next_data.tmplog_begin_prioritylangs,
+               -- target_log.tmplog_end_mixins = next_data.tmplog_begin_mixins
+       WHERE
+               bad_log_id = target_log.tmplog_id
+;

-- 
To view, visit https://gerrit.wikimedia.org/r/58651
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I51146a7392a05ca6227c3dae1afdb869ce7e80e4
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to