From bfca0c79030d5b8a18e41e8b80f5560ebaf6f202 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 12:00:49 -0700 Subject: Refactor the install/upgrade code to be more flexible. Add xxx_installer::upgrade($version) method so that upgrade stanzas are separate from install stanzas. In the old code, to do an upgrade meant that you had to re-evolve everything from the initial install because we'd step through each version's changes. But what we really want is for the initial install to start off in the perfect initial state, and the upgrades to do the work behind the scenes. So now the install() function gets things set up properly the first time, and the upgrade() function does any work to catch you up to the latest code. See gallery_installer.php for a good example. --- modules/gallery/controllers/admin_modules.php | 6 +++++- modules/gallery/controllers/upgrader.php | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php index f7dd909d..ed1f7665 100644 --- a/modules/gallery/controllers/admin_modules.php +++ b/modules/gallery/controllers/admin_modules.php @@ -45,7 +45,11 @@ class Admin_Modules_Controller extends Admin_Controller { } else if (!$info->active && $desired && !module::is_active($module_name)) { $changes->activate[] = $module_name; $activated_names[] = $info->name; - module::install($module_name); + if (module::is_installed($module_name)) { + module::upgrade($module_name); + } else { + module::install($module_name); + } module::activate($module_name); } } diff --git a/modules/gallery/controllers/upgrader.php b/modules/gallery/controllers/upgrader.php index 5eb96fdd..91952fa9 100644 --- a/modules/gallery/controllers/upgrader.php +++ b/modules/gallery/controllers/upgrader.php @@ -50,8 +50,8 @@ class Upgrader_Controller extends Controller { } // Upgrade gallery and user first - module::install("gallery"); - module::install("user"); + module::upgrade("gallery"); + module::upgrade("user"); // Then upgrade the rest foreach (module::available() as $id => $module) { @@ -60,7 +60,7 @@ class Upgrader_Controller extends Controller { } if ($module->active && $module->code_version != $module->version) { - module::install($id); + module::upgrade($id); } } -- cgit v1.2.3 From d5ee5741f2afa0e4a2d6406828cdad01bc8c3f2e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 14:08:07 -0700 Subject: Don't allow renaming of the root album. --- modules/gallery/controllers/albums.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'modules/gallery/controllers') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 17fdec6b..22f50fb8 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -167,7 +167,8 @@ class Albums_Controller extends Items_Controller { $form = album::get_edit_form($album); if ($valid = $form->validate()) { // Make sure that there's not a conflict - if (Database::instance() + if ($album->id != 1 && + Database::instance() ->from("items") ->where("parent_id", $album->parent_id) ->where("id <>", $album->id) @@ -188,7 +189,9 @@ class Albums_Controller extends Items_Controller { $album->description = $form->edit_album->description->value; $album->sort_column = $form->edit_album->sort_order->column->value; $album->sort_order = $form->edit_album->sort_order->direction->value; - $album->rename($form->edit_album->dirname->value); + if ($album->id != 1) { + $album->rename($form->edit_album->dirname->value); + } $album->save(); module::event("item_updated", $orig, $album); -- cgit v1.2.3