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/search | |
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/search')
-rw-r--r-- | modules/search/helpers/search.php | 8 | ||||
-rw-r--r-- | modules/search/helpers/search_installer.php | 19 |
2 files changed, 18 insertions, 9 deletions
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}"); } } |