summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-10-22 22:29:56 -0700
committerTim Almdal <tnalmdal@shaw.ca>2009-10-22 22:30:25 -0700
commitb74b131e25ca0ddb42d2545a5d0ea2d796452f1d (patch)
tree68dda2e42827b7c92b947ed6b56816c429682249
parent89ca1590e4435da56fc15c74fcff74b467bb8717 (diff)
Change Identity adminstration to use the uninstall/install methods when changing providers.
-rw-r--r--modules/gallery/controllers/admin_identity.php19
-rw-r--r--modules/gallery/helpers/identity.php34
-rw-r--r--modules/gallery/helpers/module.php4
-rw-r--r--modules/gallery/libraries/IdentityProvider.php26
-rw-r--r--modules/gallery/libraries/drivers/IdentityProvider.php10
-rw-r--r--modules/gallery/views/admin_identity.html.php4
-rw-r--r--modules/gallery/views/admin_identity_confirm.html.php2
-rw-r--r--modules/user/helpers/user.php85
-rw-r--r--modules/user/helpers/user_installer.php76
-rw-r--r--modules/user/libraries/drivers/IdentityProvider/Gallery.php16
10 files changed, 110 insertions, 166 deletions
diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php
index d06132ff..0521a0f8 100644
--- a/modules/gallery/controllers/admin_identity.php
+++ b/modules/gallery/controllers/admin_identity.php
@@ -47,23 +47,26 @@ class Admin_Identity_Controller extends Admin_Controller {
module::event("pre_identity_change", $active_provider, $new_provider);
- identity::deactivate();
+ module::deactivate($active_provider);
+ module::uninstall($active_provider);
+
+ try {
+ Session::instance()->destroy();
+ } catch (Exception $e) {
+ // We don't care if there was a problem destroying the session.
+ }
// Switch authentication
- module::set_var("gallery", "identity_provider", $new_provider);
identity::reset();
+ module::set_var("gallery", "identity_provider", $new_provider);
- identity::activate();
+ module::install($new_provider);
+ module::activate($new_provider);
// @todo this type of collation is questionable from an i18n perspective
message::success(t("Changed to %description",
array("description" => $providers->$new_provider)));
- try {
- Session::instance()->destroy();
- } catch (Exception $e) {
- // We don't care if there was a problem destroying the session.
- }
url::redirect(item::root()->abs_url());
}
diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php
index cf84c8a9..d0cba8e7 100644
--- a/modules/gallery/helpers/identity.php
+++ b/modules/gallery/helpers/identity.php
@@ -40,6 +40,16 @@ class identity_Core {
}
/**
+ * Frees the current instance of the identity provider so the next call to instance will reload
+ *
+ * @param string configuration
+ * @return Identity_Core
+ */
+ static function reset() {
+ IdentityProvider::reset();
+ }
+
+ /**
* Make sure that we have a session and group_ids cached in the session.
*/
static function load_user() {
@@ -71,12 +81,12 @@ class identity_Core {
$session->set("group_ids", $ids);
}
//} catch (Exception $e) {
- //try {
- //Session::instance()->destroy();
- //} catch (Exception $e) {
+ // try {
+ // Session::instance()->destroy();
+ // } catch (Exception $e) {
// We don't care if there was a problem destroying the session.
- //}
- //url::redirect(item::root()->abs_url());
+ // }
+ // url::redirect(item::root()->abs_url());
//}
}
@@ -126,20 +136,6 @@ class identity_Core {
}
/**
- * @see IdentityProvider_Driver::activate.
- */
- static function activate() {
- IdentityProvider::instance()->activate();
- }
-
- /**
- * @see IdentityProvider_Driver::deactivate.
- */
- static function deactivate() {
- IdentityProvider::instance()->deactivate();
- }
-
- /**
* @see IdentityProvider_Driver::guest.
*/
static function guest() {
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 1d77e63d..9d41cd51 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -130,6 +130,8 @@ class module_Core {
array_unshift($kohana_modules, MODPATH . $module_name);
Kohana::config_set("core.modules", $kohana_modules);
+ // Rebuild the include path so the module installer can benefit from auto loading
+ Kohana::include_paths(true);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "install")) {
call_user_func_array(array($installer_class, "install"), array());
@@ -154,7 +156,7 @@ class module_Core {
*/
static function upgrade($module_name) {
$kohana_modules = Kohana::config("core.modules");
- array_unshift($kohana_modules, MODPATH . $module_name);
+ $kohana_modules = array_unshift($kohana_modules, MODPATH . $module_name);
Kohana::config_set("core.modules", $kohana_modules);
$version_before = module::get_version($module_name);
diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php
index 512f28eb..38718d4b 100644
--- a/modules/gallery/libraries/IdentityProvider.php
+++ b/modules/gallery/libraries/IdentityProvider.php
@@ -38,7 +38,7 @@ class IdentityProvider_Core {
* @return Identity_Core
*/
static function & instance() {
- if (!isset(self::$instance)) {
+ if (empty(self::$instance)) {
// Create a new instance
self::$instance = new IdentityProvider();
}
@@ -47,14 +47,14 @@ class IdentityProvider_Core {
}
/**
- * Returns a singleton instance of Identity.
- * There can only be one Identity driver configured at a given point
+ * Frees the current instance of the identity provider so the next call to instance will reload
*
* @param string configuration
* @return Identity_Core
*/
static function reset() {
- self::$instance = new IdentityProvider();
+ self::$instance = null;
+ Kohana::config_clear("identity");
}
/**
@@ -66,12 +66,12 @@ class IdentityProvider_Core {
$config = module::get_var("gallery", "identity_provider", "user");
// Test the config group name
- if (($this->config = Kohana::config("identity.".$config)) === NULL) {
+ if (($this->config = Kohana::config("identity." . $config)) === NULL) {
throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $config");
}
// Set driver name
- $driver = "IdentityProvider_".ucfirst($this->config["driver"])."_Driver";
+ $driver = "IdentityProvider_" . ucfirst($this->config["driver"]) ."_Driver";
// Load the driver
if ( ! Kohana::auto_load($driver)) {
@@ -101,20 +101,6 @@ class IdentityProvider_Core {
}
/**
- * @see IdentityProvider_Driver::activate.
- */
- public function activate() {
- $this->driver->activate();
- }
-
- /**
- * @see IdentityProvider_Driver::deactivate.
- */
- public function deactivate() {
- $this->driver->deactivate();
- }
-
- /**
* @see IdentityProvider_Driver::guest.
*/
public function guest() {
diff --git a/modules/gallery/libraries/drivers/IdentityProvider.php b/modules/gallery/libraries/drivers/IdentityProvider.php
index 8a578d1b..5bb41dcc 100644
--- a/modules/gallery/libraries/drivers/IdentityProvider.php
+++ b/modules/gallery/libraries/drivers/IdentityProvider.php
@@ -19,16 +19,6 @@
*/
interface IdentityProvider_Driver {
/**
- * Initialize the provider so it is ready to use
- */
- public function activate();
-
- /**
- * Cleanup up this provider so it is unavailable for use and won't conflict with the current driver
- */
- public function deactivate();
-
- /**
* Return the guest user.
*
* @return User_Definition the user object
diff --git a/modules/gallery/views/admin_identity.html.php b/modules/gallery/views/admin_identity.html.php
index 1405cacb..358860cf 100644
--- a/modules/gallery/views/admin_identity.html.php
+++ b/modules/gallery/views/admin_identity.html.php
@@ -10,7 +10,7 @@
$("#g-dialog").html(data);
$("#g-dialog").dialog({
bgiframe: true,
- title: "<?= t("Confirm Change Identity Provider") ?>",
+ title: <?= t("Confirm identity provider change")->for_js() ?>,
resizable: false,
height:165,
modal: true,
@@ -34,7 +34,7 @@
</script>
<div id="g-modules">
- <h1> <?= t("Gallery Identity Management") ?> </h1>
+ <h1> <?= t("Manage Identity Providers") ?> </h1>
<p>
<?= t("Choose a different user/group management provider.") ?>
</p>
diff --git a/modules/gallery/views/admin_identity_confirm.html.php b/modules/gallery/views/admin_identity_confirm.html.php
index e14525b5..54aae9c8 100644
--- a/modules/gallery/views/admin_identity_confirm.html.php
+++ b/modules/gallery/views/admin_identity_confirm.html.php
@@ -4,7 +4,7 @@
<?= form::hidden("provider", $new_provider) ?>
<p><span class="ui-icon ui-icon-alert" style="float: left; margin:0 7px 20px 0;"></span>
- <?= t("Do you really want to switch Identity providers? Continuing will delete all existing users.") ?>
+ <?= t("Are you sure you want to change your Identity Provider? Continuing will delete all existing users.") ?>
</p>
</form>
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index 5f154313..5ef2b726 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -25,91 +25,6 @@
*/
class user_Core {
/**
- * Initialize the provider so it is ready to use
- */
- static function activate() {
- $db = Database::instance();
- $db->query("CREATE TABLE IF NOT EXISTS {users} (
- `id` int(9) NOT NULL auto_increment,
- `name` varchar(32) NOT NULL,
- `full_name` varchar(255) NOT NULL,
- `password` varchar(64) NOT NULL,
- `login_count` int(10) unsigned NOT NULL DEFAULT 0,
- `last_login` int(10) unsigned NOT NULL DEFAULT 0,
- `email` varchar(64) default NULL,
- `admin` BOOLEAN default 0,
- `guest` BOOLEAN default 0,
- `hash` char(32) default NULL,
- `url` varchar(255) default NULL,
- `locale` char(10) default NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY(`hash`),
- UNIQUE KEY(`name`))
- DEFAULT CHARSET=utf8;");
-
- $db->query("CREATE TABLE IF NOT EXISTS {groups} (
- `id` int(9) NOT NULL auto_increment,
- `name` char(64) default NULL,
- `special` BOOLEAN default 0,
- PRIMARY KEY (`id`),
- UNIQUE KEY(`name`))
- DEFAULT CHARSET=utf8;");
-
- $db->query("CREATE TABLE IF NOT EXISTS {groups_users} (
- `group_id` int(9) NOT NULL,
- `user_id` int(9) NOT NULL,
- PRIMARY KEY (`group_id`, `user_id`),
- UNIQUE KEY(`user_id`, `group_id`))
- DEFAULT CHARSET=utf8;");
-
- $everybody = group::create("Everybody");
- $everybody->special = true;
- $everybody->save();
-
- $registered = group::create("Registered Users");
- $registered->special = true;
- $registered->save();
-
- $guest = user::create("guest", "Guest User", "");
- $guest->guest = true;
- $guest->remove($registered);
- $guest->save();
-
- $admin = user::create("admin", "Gallery Administrator", "admin");
- $admin->admin = true;
- $admin->save();
-
- // 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);
-
- access::allow($registered, "view", $root);
- access::allow($registered, "view_full", $root);
- }
-
- /**
- * Cleanup up this provider so it is unavailable for use and won't conflict with the current driver
- */
- static function deactivate() {
- // 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};");
- }
-
- /**
* Return the guest user.
*
* @return User_Model the user object
diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php
index 1410f1ef..36c617a8 100644
--- a/modules/user/helpers/user_installer.php
+++ b/modules/user/helpers/user_installer.php
@@ -19,18 +19,84 @@
*/
class user_installer {
static function install() {
+ $db = Database::instance();
+ $db->query("CREATE TABLE IF NOT EXISTS {users} (
+ `id` int(9) NOT NULL auto_increment,
+ `name` varchar(32) NOT NULL,
+ `full_name` varchar(255) NOT NULL,
+ `password` varchar(64) NOT NULL,
+ `login_count` int(10) unsigned NOT NULL DEFAULT 0,
+ `last_login` int(10) unsigned NOT NULL DEFAULT 0,
+ `email` varchar(64) default NULL,
+ `admin` BOOLEAN default 0,
+ `guest` BOOLEAN default 0,
+ `hash` char(32) default NULL,
+ `url` varchar(255) default NULL,
+ `locale` char(10) default NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`hash`),
+ UNIQUE KEY(`name`))
+ DEFAULT CHARSET=utf8;");
+
+ $db->query("CREATE TABLE IF NOT EXISTS {groups} (
+ `id` int(9) NOT NULL auto_increment,
+ `name` char(64) default NULL,
+ `special` BOOLEAN default 0,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`name`))
+ DEFAULT CHARSET=utf8;");
+
+ $db->query("CREATE TABLE IF NOT EXISTS {groups_users} (
+ `group_id` int(9) NOT NULL,
+ `user_id` int(9) NOT NULL,
+ PRIMARY KEY (`group_id`, `user_id`),
+ UNIQUE KEY(`user_id`, `group_id`))
+ DEFAULT CHARSET=utf8;");
+
+ $everybody = group::create("Everybody");
+ $everybody->special = true;
+ $everybody->save();
+
+ $registered = group::create("Registered Users");
+ $registered->special = true;
+ $registered->save();
+
+ $guest = user::create("guest", "Guest User", "");
+ $guest->guest = true;
+ $guest->remove($registered);
+ $guest->save();
+
+ $admin = user::create("admin", "Gallery Administrator", "admin");
+ $admin->admin = true;
+ $admin->save();
+
+ // 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);
+
+ access::allow($registered, "view", $root);
+ access::allow($registered, "view_full", $root);
user::activate();
module::set_var("gallery", "identity_provider", "user");
module::set_version("user", 1);
}
static function uninstall() {
- user::deactivate();
+ // 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();
+ }
- try {
- Session::instance()->destroy();
- } catch (Exception $e) {
- // We don't care if there was a problem destroying the session.
+ 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};");
}
} \ No newline at end of file
diff --git a/modules/user/libraries/drivers/IdentityProvider/Gallery.php b/modules/user/libraries/drivers/IdentityProvider/Gallery.php
index 5941abb7..026f04e9 100644
--- a/modules/user/libraries/drivers/IdentityProvider/Gallery.php
+++ b/modules/user/libraries/drivers/IdentityProvider/Gallery.php
@@ -20,21 +20,7 @@
/*
* Based on the Cache_Sqlite_Driver developed by the Kohana Team
*/
-class Identity_Gallery_Driver implements IdentityProvider_Driver {
- /**
- * @see IdentityProvider_Driver::activate.
- */
- public function activate() {
- user::activate();
- }
-
- /**
- * @see IdentityProvider_Driver::deactivate.
- */
- public function deactivate() {
- user::deactivate();
- }
-
+class IdentityProvider_Gallery_Driver implements IdentityProvider_Driver {
/**
* @see IdentityProvider_Driver::guest.
*/