Skip to content

Commit

Permalink
Merge pull request #3449 from ushahidi/refactor/fix-migration-so-it-c…
Browse files Browse the repository at this point in the history
…an-be-reverted

fix: Fix issues in 20140904004900_move_post_users_to_post migration
  • Loading branch information
rjmackay committed Dec 9, 2018
2 parents 48b6893 + 5faf3ac commit 7876c10
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions migrations/20140904004900_move_post_users_to_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,7 +83,7 @@ public function down()
$update_posts->execute(
[
':user_id' => $user_id,
':id' => $row['id']
':email' => $row['author_email']
]
);
}
Expand Down

0 comments on commit 7876c10

Please sign in to comment.