summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/gallery/libraries/IdentityProvider.php29
-rw-r--r--modules/user/helpers/user_installer.php68
2 files changed, 61 insertions, 36 deletions
diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php
index bcb3056a..f7be33e3 100644
--- a/modules/gallery/libraries/IdentityProvider.php
+++ b/modules/gallery/libraries/IdentityProvider.php
@@ -58,6 +58,35 @@ class IdentityProvider_Core {
}
/**
+ * Return a commen confirmation message
+ */
+ static function confirmation_message() {
+ return t("Are you sure you want to change your Identity Provider? " .
+ "Continuing will delete all existing users.");
+ }
+
+ static function change_provider($new_provider) {
+ $current_provider = module::get_var("gallery", "identity_provider");
+ if (!empty($current_provider)) {
+ module::uninstall($current_provider);
+ }
+
+ IdentityProvider::reset();
+ $provider = new IdentityProvider($new_provider);
+
+ module::set_var("gallery", "identity_provider", $new_provider);
+
+ if (method_exists("{$new_provider}_installer", "initialize")) {
+ call_user_func("{$new_provider}_installer::initialize");
+ }
+
+ module::event("identity_provider_changed", $current_provider, $new_provider);
+
+ auth::login($provider->admin_user());
+ Session::instance()->regenerate();
+ }
+
+ /**
* Loads the configured driver and validates it.
*
* @return void
diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php
index dd21c93c..3882f5f2 100644
--- a/modules/user/helpers/user_installer.php
+++ b/modules/user/helpers/user_installer.php
@@ -18,15 +18,40 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_installer {
+ static function check_environment() {
+ return array("warn" => array(IdentityProvider::confirmation_message()));
+ }
+
static function install() {
- $db = Database::instance();
- $current_provider = module::get_var("gallery", "identity_provider");
- if (!empty($current_provider)) {
- module::uninstall($current_provider);
+ IdentityProvider::change_provider("user");
+ }
+
+ static function upgrade($version) {
+ if ($version == 1) {
+ module::set_var("user", "mininum_password_length", 5);
+
+ module::set_version("user", $version = 2);
+ }
+ }
+
+ static function uninstall() {
+ // Delete all users and groups so that we give other modules an opportunity to clean up
+ foreach (ORM::factory("user")->find_all() as $user) {
+ $user->delete();
+ }
+
+ foreach (ORM::factory("group")->find_all() as $group) {
+ $group->delete();
}
- IdentityProvider::reset();
- module::set_var("gallery", "identity_provider", "user");
+ $db = Database::instance();
+ $db->query("DROP TABLE IF EXISTS {users};");
+ $db->query("DROP TABLE IF EXISTS {groups};");
+ $db->query("DROP TABLE IF EXISTS {groups_users};");
+ }
+
+ static function initialize() {
+ $db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {users} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
@@ -84,36 +109,7 @@ class user_installer {
access::allow($registered, "view", $root);
access::allow($registered, "view_full", $root);
- 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) {
- if ($version == 1) {
- module::set_var("user", "mininum_password_length", 5);
-
- module::set_version("user", $version = 2);
- }
- }
-
- static function uninstall() {
- // Delete all users and groups so that we give other modules an opportunity to clean up
- foreach (ORM::factory("user")->find_all() as $user) {
- $user->delete();
- }
-
- foreach (ORM::factory("group")->find_all() as $group) {
- $group->delete();
- }
-
- $db = Database::instance();
- $db->query("DROP TABLE IF EXISTS {users};");
- $db->query("DROP TABLE IF EXISTS {groups};");
- $db->query("DROP TABLE IF EXISTS {groups_users};");
+ module::set_var("user", "mininum_password_length", 5);
}
} \ No newline at end of file