diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-05-26 05:28:59 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-26 05:28:59 +0000 |
commit | 7aed9239088b582a065da3fb63796ff66cd357c8 (patch) | |
tree | 8be9bc4faec21b20cbcc060ad5e9ca128465d09e /modules | |
parent | 2966289b147ceae2fed79b9534840607bf38e0d8 (diff) |
Restructure the module lifecycle.
Install: <module>_installer::install() is called, any necessary tables
are created.
Activate: <module>_installer::activate() is called. Module
controllers are routable, helpers are accessible, etc. The module is
in use.
Deactivate: <module>_installer::deactivate() is called. Module code
is not accessible or routable. Module is *not* in use, but its tables
are still around.
Uninstall: <module>_installer::uninstall() is called. Module is
completely removed from the database.
Admin > Modules will install and activate modules, but will only
deactivate (will NOT uninstall modules).
Diffstat (limited to 'modules')
20 files changed, 47 insertions, 55 deletions
diff --git a/modules/akismet/helpers/akismet_installer.php b/modules/akismet/helpers/akismet_installer.php index 3bb8aff1..920c58b7 100644 --- a/modules/akismet/helpers/akismet_installer.php +++ b/modules/akismet/helpers/akismet_installer.php @@ -23,12 +23,13 @@ class akismet_installer { if ($version == 0) { module::set_version("akismet", 1); } + } + static function activate() { akismet::check_config(); } - static function uninstall() { + static function deactivate() { site_status::clear("akismet_config"); - module::delete("akismet"); } } diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php index 695aa298..b1cfcdc0 100644 --- a/modules/comment/helpers/comment_installer.php +++ b/modules/comment/helpers/comment_installer.php @@ -61,6 +61,5 @@ class comment_installer { module::event("item_related_update_batch", $sql); $db->query("DROP TABLE IF EXISTS {comments};"); - module::delete("comment"); } } diff --git a/modules/exif/helpers/exif_installer.php b/modules/exif/helpers/exif_installer.php index 5f37996a..77cf3f3d 100644 --- a/modules/exif/helpers/exif_installer.php +++ b/modules/exif/helpers/exif_installer.php @@ -33,14 +33,18 @@ class exif_installer { KEY(`item_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); module::set_version("exif", 1); + } + } + + static function activate() { exif::check_index(); } + + static function deactivate() { + site_status::clear("exif_index_out_of_date"); } static function uninstall() { - $db = Database::instance(); - $db->query("DROP TABLE IF EXISTS {exif_records};"); - site_status::clear("exif_index_out_of_date"); - module::delete("exif"); + Database::instance()->query("DROP TABLE IF EXISTS {exif_records};"); } } diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index d035e004..37efcad0 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -111,13 +111,13 @@ class g2_import_Core { $stats["photos"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryPhotoItem")); $stats["movies"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryMovieItem")); - if (g2_import::g2_module_active("comment") && module::is_installed("comment")) { + if (g2_import::g2_module_active("comment") && module::is_active("comment")) { list (, $stats["comments"]) = g2(GalleryCommentHelper::fetchAllComments($root_album_id, 1)); } else { $stats["comments"] = 0; } - if (g2_import::g2_module_active("tags") && module::is_installed("tag")) { + if (g2_import::g2_module_active("tags") && module::is_active("tag")) { $result = g2($gallery->search("SELECT COUNT(DISTINCT([TagItemMap::itemId])) FROM [TagItemMap]")) ->nextResult(); @@ -441,7 +441,7 @@ class g2_import_Core { } static function import_keywords_as_tags($keywords, $item) { - if (!module::is_installed("tag")) { + if (!module::is_active("tag")) { return; } @@ -466,7 +466,8 @@ class g2_import_Core { // Precaution: if the Gallery2 item was watermarked, or we have the Gallery3 watermark module // active then we'd have to do something a lot more sophisticated here. For now, just skip // this step in those cases. - if (module::is_installed("watermark") && module::get_var("watermark", "name")) { + // @todo we should probably use an API here, eventually. + if (module::is_active("watermark") && module::get_var("watermark", "name")) { return; } diff --git a/modules/g2_import/helpers/g2_import_installer.php b/modules/g2_import/helpers/g2_import_installer.php index 1e60a83d..2bfb7f8c 100644 --- a/modules/g2_import/helpers/g2_import_installer.php +++ b/modules/g2_import/helpers/g2_import_installer.php @@ -33,8 +33,4 @@ class g2_import_installer { module::set_version("g2_import", 1); } } - - static function uninstall() { - module::delete("g2_import"); - } } diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 1195dc3d..5206f9fb 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -90,8 +90,8 @@ class Gallery_Unit_Test_Controller extends Controller { @mkdir('test/var/logs', 0777, true); // Reset our caches - module::$module_names = array(); module::$modules = array(); + module::$active = array(); module::$var_cache = array(); $db->clear_cache(); @@ -100,6 +100,7 @@ class Gallery_Unit_Test_Controller extends Controller { core_installer::install(true); module::load_modules(); module::install("user"); + module::activate("user"); $modules = array(); foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) { $module_name = basename(dirname(dirname($file))); @@ -107,6 +108,7 @@ class Gallery_Unit_Test_Controller extends Controller { continue; } module::install($module_name); + module::activate($module_name); } $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null; diff --git a/modules/image_block/helpers/image_block_installer.php b/modules/image_block/helpers/image_block_installer.php index b9ee4d5f..57279d05 100644 --- a/modules/image_block/helpers/image_block_installer.php +++ b/modules/image_block/helpers/image_block_installer.php @@ -23,8 +23,4 @@ class image_block_installer { module::set_version("image_block", 1); } } - - static function uninstall() { - module::delete("image_block"); - } } diff --git a/modules/info/helpers/info_installer.php b/modules/info/helpers/info_installer.php index f291b508..94fc22d0 100644 --- a/modules/info/helpers/info_installer.php +++ b/modules/info/helpers/info_installer.php @@ -24,8 +24,4 @@ class info_installer { module::set_version("info", 1); } } - - static function uninstall() { - module::delete("info"); - } } diff --git a/modules/notification/helpers/notification_installer.php b/modules/notification/helpers/notification_installer.php index 71f33640..ad10184b 100644 --- a/modules/notification/helpers/notification_installer.php +++ b/modules/notification/helpers/notification_installer.php @@ -47,7 +47,5 @@ class notification_installer { $db = Database::instance(); $db->query("DROP TABLE IF EXISTS {subscriptions};"); $db->query("DROP TABLE IF EXISTS {pending_notifications};"); - - module::delete("notification"); } } diff --git a/modules/organize/helpers/organize_installer.php b/modules/organize/helpers/organize_installer.php index f739709c..ea0f4e3d 100644 --- a/modules/organize/helpers/organize_installer.php +++ b/modules/organize/helpers/organize_installer.php @@ -24,8 +24,4 @@ class organize_installer { module::set_version("organize", 1); } } - - static function uninstall() { - module::delete("organize"); - } } diff --git a/modules/recaptcha/helpers/recaptcha_installer.php b/modules/recaptcha/helpers/recaptcha_installer.php index ccc27aae..6269c632 100644 --- a/modules/recaptcha/helpers/recaptcha_installer.php +++ b/modules/recaptcha/helpers/recaptcha_installer.php @@ -20,16 +20,16 @@ class recaptcha_installer { static function install() { $version = module::get_version("recaptcha"); - if ($version == 0) { module::set_version("recaptcha", 1); } + } + static function activate() { recaptcha::check_config(); } static function uninstall() { site_status::clear("recaptcha_config"); - module::delete("recaptcha"); } } diff --git a/modules/rss/helpers/rss_installer.php b/modules/rss/helpers/rss_installer.php index ffd1ca75..2beafb33 100644 --- a/modules/rss/helpers/rss_installer.php +++ b/modules/rss/helpers/rss_installer.php @@ -24,8 +24,4 @@ class rss_installer { module::set_version("rss", 1); } } - - static function uninstall() { - module::delete("rss"); - } } diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 2c7be123..15efa3b2 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -67,8 +67,8 @@ class search_Core { $record->item_id = $item->id; } - foreach (module::installed() as $module_name => $module_info) { - $class_name = "{$module_name}_search"; + foreach (module::active() as $module) { + $class_name = "{$module->name}_search"; if (method_exists($class_name, "item_index_data")) { $data[] = call_user_func(array($class_name, "item_index_data"), $record->item()); } @@ -83,12 +83,16 @@ class search_Core { ->select("items.id") ->from("items") ->join("search_records", "items.id", "search_records.item_id", "left") + ->open_paren() ->where("search_records.item_id", null) ->orwhere("search_records.dirty", 1) + ->close_paren() ->get() ->count(); + $total = ORM::factory("item")->count_all(); $percent = round(100 * ($total - $remaining) / $total); + return array($remaining, $total, $percent); } } diff --git a/modules/search/helpers/search_installer.php b/modules/search/helpers/search_installer.php index a3d0f79e..5fc9b37b 100644 --- a/modules/search/helpers/search_installer.php +++ b/modules/search/helpers/search_installer.php @@ -31,18 +31,23 @@ class search_installer { KEY(`item_id`), FULLTEXT INDEX (`data`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); - - // populate the index with dirty records - $db->query("INSERT INTO {search_records} (`item_id`) SELECT `id` FROM {items}"); module::set_version("search", 1); + } + } + + static function activate() { + // Update the root item. This is a quick hack because the search module is activated as part + // of the official install, so this way we don't start off with a "your index is out of date" + // banner. + search::update(model_cache::get("item", 1)); search::check_index(); } + + static function deactivate() { + site_status::clear("search_index_out_of_date"); } static function uninstall() { - $db = Database::instance(); - $db->query("DROP TABLE {search_records}"); - site_status::clear("search_index_out_of_date"); - module::delete("search"); + Database::instance()->query("DROP TABLE {search_records}"); } } diff --git a/modules/server_add/helpers/server_add_installer.php b/modules/server_add/helpers/server_add_installer.php index 7094dfbe..b592b448 100644 --- a/modules/server_add/helpers/server_add_installer.php +++ b/modules/server_add/helpers/server_add_installer.php @@ -28,9 +28,11 @@ class server_add_installer { server_add::check_config(); } + static function deactivate() { + site_status::clear("server_add_configuration"); + } + static function uninstall() { access::delete_permission("server_add"); - module::delete("server_add"); - site_status::clear("server_add_configuration"); } } diff --git a/modules/slideshow/helpers/slideshow_event.php b/modules/slideshow/helpers/slideshow_event.php index 12765922..c6cd7dc7 100644 --- a/modules/slideshow/helpers/slideshow_event.php +++ b/modules/slideshow/helpers/slideshow_event.php @@ -19,10 +19,10 @@ */ class slideshow_event_Core { static function module_change($changes) { - if (!module::is_installed("rss") || in_array("rss", $changes->uninstall)) { + if (!module::is_active("rss") || in_array("rss", $changes->deactivate)) { site_status::warning( t("The Slideshow module requires the RSS module. " . - "<a href=\"%url\">Install the RSS module now</a>", + "<a href=\"%url\">Activate the RSS module now</a>", array("url" => url::site("admin/modules"))), "slideshow_needs_rss"); } else { diff --git a/modules/slideshow/helpers/slideshow_installer.php b/modules/slideshow/helpers/slideshow_installer.php index 959e9f55..b46f5471 100644 --- a/modules/slideshow/helpers/slideshow_installer.php +++ b/modules/slideshow/helpers/slideshow_installer.php @@ -25,8 +25,7 @@ class slideshow_installer { } } - static function uninstall() { - module::delete("slideshow"); + static function deactivate() { site_status::clear("slideshow_needs_rss"); } } diff --git a/modules/tag/helpers/tag_installer.php b/modules/tag/helpers/tag_installer.php index 74fa97a5..07544c54 100644 --- a/modules/tag/helpers/tag_installer.php +++ b/modules/tag/helpers/tag_installer.php @@ -46,6 +46,5 @@ class tag_installer { $db = Database::instance(); $db->query("DROP TABLE IF EXISTS {tags};"); $db->query("DROP TABLE IF EXISTS {items_tags};"); - module::delete("tag"); } } diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 66ac0048..68868fc1 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -99,11 +99,11 @@ class user_installer { try { Session::instance()->destroy(); } catch (Exception $e) { + // We don't care if there was a problem destroying the session. } $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::delete("user"); } }
\ No newline at end of file diff --git a/modules/watermark/helpers/watermark_installer.php b/modules/watermark/helpers/watermark_installer.php index 6b54bd33..ed4265ec 100644 --- a/modules/watermark/helpers/watermark_installer.php +++ b/modules/watermark/helpers/watermark_installer.php @@ -40,8 +40,6 @@ class watermark_installer { } static function uninstall() { - graphics::remove_rules("watermark"); - module::delete("watermark"); Database::instance()->query("DROP TABLE {watermarks}"); dir::unlink(VARPATH . "modules/watermark"); } |