From 5faf3acc30fb9ac3863a9feac7e51b88ed4bc104 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Mon, 10 Dec 2018 09:24:05 +1300 Subject: [PATCH] fix: Fix issues in 20140904004900_move_post_users_to_post migration --- migrations/20140904004900_move_post_users_to_post.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/migrations/20140904004900_move_post_users_to_post.php b/migrations/20140904004900_move_post_users_to_post.php index 8bf0aa750c..b5c620a74b 100644 --- a/migrations/20140904004900_move_post_users_to_post.php +++ b/migrations/20140904004900_move_post_users_to_post.php @@ -53,18 +53,19 @@ public function down() { // Get post author info $rows = $this->fetchAll( - "SELECT author_email, author_realname, id + "SELECT DISTINCT author_email, author_realname FROM posts WHERE user_id IS NULL AND - (author_email IS NOT NULL OR author_email IS NOT NULL)" + author_email IS NOT NULL AND + author_email <> ''" ); $pdo = $this->getAdapter()->getConnection(); $insert_users = $pdo->prepare("INSERT INTO users (email, realname, role) VALUES (:email, :realname, :role)"); - $update_posts = $pdo->prepare("UPDATE posts SET user_id = :user_id WHERE id = :id"); + $update_posts = $pdo->prepare("UPDATE posts SET user_id = :user_id WHERE author_email = :email"); foreach ($rows as $row) { // Create unregistered users for posts @@ -82,7 +83,7 @@ public function down() $update_posts->execute( [ ':user_id' => $user_id, - ':id' => $row['id'] + ':email' => $row['author_email'] ] ); }