From 5acafdf1b9ba4a564d814360d762625febece4f4 Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 1 Apr 2015 16:50:09 -0700 Subject: [PATCH] Datetime migration fix: bans table wasn't taken into account --- tools/migrate_datetime.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/migrate_datetime.php b/tools/migrate_datetime.php index 25a90390..cb18452c 100644 --- a/tools/migrate_datetime.php +++ b/tools/migrate_datetime.php @@ -3,12 +3,27 @@ require dirname(__FILE__) . '/inc/cli.php'; # edited_at column was using DATETIME when time column uses INT(11). This script solves that. -$boards = listBoards(TRUE); -#$boards = array('test2'); +#$boards = listBoards(TRUE); +#$boards = array('tester'); -foreach ($boards as $i => $b) { +/*foreach ($boards as $i => $b) { + echo "Processing board $b...\n"; query(sprintf('ALTER TABLE ``posts_%s`` ADD COLUMN edited_at_temp INT(11) DEFAULT NULL AFTER edited_at', $b)); query(sprintf('UPDATE ``posts_%s`` SET edited_at_temp = IF(edited_at IS NOT NULL, UNIX_TIMESTAMP(edited_at), NULL)', $b)); query(sprintf('ALTER TABLE ``posts_%s`` DROP COLUMN edited_at', $b)); query(sprintf('ALTER TABLE ``posts_%s`` CHANGE edited_at_temp edited_at INT(11) DEFAULT NULL', $b)); +}*/ + +$bans2fix = query('SELECT * FROM ``bans`` WHERE post IS NOT NULL'); + +while ($post = $bans2fix->fetch(PDO::FETCH_ASSOC)) { + $p = json_decode($post['post'], true); + if (!isset($p['edited_at']) || !$p['edited_at']) continue; + $nea = ((string)strtotime($p['edited_at'])); + $p['edited_at'] = $nea; + $query = prepare('UPDATE ``bans`` SET post = :post WHERE id = :id'); + $query->bindValue(':post', json_encode($p)); + $query->bindValue(':id', $post['id']); + $query->execute() or error(db_error($query)); } +