diff options
-rw-r--r-- | modules/comment/helpers/comment_event.php | 18 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 32 | ||||
-rw-r--r-- | modules/user/helpers/user_installer.php | 24 | ||||
-rw-r--r-- | modules/user/module.info | 2 |
4 files changed, 38 insertions, 38 deletions
diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index 43a30d70..bd336cda 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -27,14 +27,16 @@ class comment_event_Core { static function user_deleted($user) { $guest = identity::guest(); - db::build() - ->update("comments") - ->set("author_id", $guest->id) - ->set("guest_email", null) - ->set("guest_name", "guest") - ->set("guest_url", null) - ->where("author_id", "=", $user->id) - ->execute(); + if (!empty($guest)) { // could be empty if there is not identity provider + db::build() + ->update("comments") + ->set("author_id", $guest->id) + ->set("guest_email", null) + ->set("guest_name", "guest") + ->set("guest_url", null) + ->where("author_id", "=", $user->id) + ->execute(); + } } static function identity_provider_changed($old_provider, $new_provider) { diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 679d65c2..1d8e3581 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -30,21 +30,23 @@ class gallery_event_Core { static function user_deleted($user) { $admin = identity::admin_user(); - db::build() - ->update("tasks") - ->set("owner_id", $admin->id) - ->where("owner_id", "=", $user->id) - ->execute(); - db::build() - ->update("items") - ->set("owner_id", $admin->id) - ->where("owner_id", "=", $user->id) - ->execute(); - db::build() - ->update("logs") - ->set("user_id", $admin->id) - ->where("user_id", "=", $user->id) - ->execute(); + if (!empty($admin)) { // could be empty if there is not identity provider + db::build() + ->update("tasks") + ->set("owner_id", $admin->id) + ->where("owner_id", "=", $user->id) + ->execute(); + db::build() + ->update("items") + ->set("owner_id", $admin->id) + ->where("owner_id", "=", $user->id) + ->execute(); + db::build() + ->update("logs") + ->set("user_id", $admin->id) + ->where("user_id", "=", $user->id) + ->execute(); + } } static function identity_provider_changed($old_provider, $new_provider) { diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 0cba502f..dd21c93c 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -20,6 +20,13 @@ class user_installer { static function install() { $db = Database::instance(); + $current_provider = module::get_var("gallery", "identity_provider"); + if (!empty($current_provider)) { + module::uninstall($current_provider); + } + IdentityProvider::reset(); + module::set_var("gallery", "identity_provider", "user"); + $db->query("CREATE TABLE IF NOT EXISTS {users} ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, @@ -70,19 +77,6 @@ class user_installer { $admin->admin = true; $admin->save(); - $current_provider = module::get_var("gallery", "identity_provider"); - if (empty($current_provider)) { - // If there is no provider defined then we are doing an initial install - // so we need to set the provider and make the administrator own everything - // If the installer is called and there is an identity provider, then we - // are switching identity providers and and the event handlers will do the - // right things - module::set_var("gallery", "identity_provider", "user"); - - // Let the admin own everything - $db->query("update {items} set owner_id = {$admin->id}"); - } - $root = ORM::factory("item", 1); access::allow($everybody, "view", $root); access::allow($everybody, "view_full", $root); @@ -93,6 +87,10 @@ class user_installer { module::set_var("user", "mininum_password_length", 5); module::set_version("user", 2); + module::event("identity_provider_changed", $current_provider, "user"); + + auth::login(IdentityProvider::instance()->admin_user()); + Session::instance()->regenerate(); } static function upgrade($version) { diff --git a/modules/user/module.info b/modules/user/module.info index 7178f108..d1e02382 100644 --- a/modules/user/module.info +++ b/modules/user/module.info @@ -2,5 +2,3 @@ name = "Users and Groups" description = "Gallery 3 user and group management" version = 2 -; Don't show this module on the module administration screen -no_module_admin = 1 |