Skip to content

Commit

Permalink
Replace default admin user (= 1) to first admin user.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Oct 14, 2016
1 parent 54ef79d commit b9291e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/Migrations/Schema/V110/Version20150603181728.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function up(Schema $schema)
$this->addSql("DELETE FROM c_item_property WHERE to_user_id IS NOT NULL AND to_user_id <> 0 AND to_user_id NOT IN (SELECT id FROM user)");

// Sometimes the user was deleted but we need to keep the document.
// Assuming user.id = 1 (admin)
$this->addSql("UPDATE c_item_property SET insert_user_id = 1 WHERE insert_user_id IS NOT NULL AND insert_user_id <> 0 AND insert_user_id NOT IN (SELECT id FROM user)");
// Taking first admin
$this->addSql("UPDATE c_item_property SET insert_user_id = (SELECT user_id FROM admin LIMIT 1) WHERE insert_user_id IS NOT NULL AND insert_user_id <> 0 AND insert_user_id NOT IN (SELECT id FROM user)");

// Remove inconsistencies about non-existing users
$this->addSql("DELETE FROM c_item_property WHERE c_id NOT IN (SELECT id FROM course)");
Expand Down

3 comments on commit b9291e1

@ywarnier
Copy link
Member

@ywarnier ywarnier commented on b9291e1 Oct 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but this could be further improved by checking if this user is active (user.active = 1), otherwise you could end up assigning it to a user that is disabled (unlikely, but possible).

@jmontoyaa
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@jmontoyaa
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.