summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/gallery_event.php45
-rw-r--r--modules/gallery/helpers/gallery_task.php31
-rw-r--r--modules/gallery/helpers/l10n_client.php47
-rw-r--r--modules/gallery/helpers/module.php67
4 files changed, 132 insertions, 58 deletions
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 679d65c2..6175e049 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -30,21 +30,23 @@ class gallery_event_Core {
static function user_deleted($user) {
$admin = identity::admin_user();
- db::build()
- ->update("tasks")
- ->set("owner_id", $admin->id)
- ->where("owner_id", "=", $user->id)
- ->execute();
- db::build()
- ->update("items")
- ->set("owner_id", $admin->id)
- ->where("owner_id", "=", $user->id)
- ->execute();
- db::build()
- ->update("logs")
- ->set("user_id", $admin->id)
- ->where("user_id", "=", $user->id)
- ->execute();
+ if (!empty($admin)) { // could be empty if there is not identity provider
+ db::build()
+ ->update("tasks")
+ ->set("owner_id", $admin->id)
+ ->where("owner_id", "=", $user->id)
+ ->execute();
+ db::build()
+ ->update("items")
+ ->set("owner_id", $admin->id)
+ ->where("owner_id", "=", $user->id)
+ ->execute();
+ db::build()
+ ->update("logs")
+ ->set("user_id", $admin->id)
+ ->where("user_id", "=", $user->id)
+ ->execute();
+ }
}
static function identity_provider_changed($old_provider, $new_provider) {
@@ -109,12 +111,11 @@ class gallery_event_Core {
->label(t("Login")));
} else {
$csrf = access::csrf_token();
- $item = $theme->item();
$menu->append(Menu::factory("dialog")
->id("user_menu_edit_profile")
->css_id("g-user-profile-link")
->view("login_current_user.html")
- ->url(url::site("form/edit/users/{$user->id}"))
+ ->url(url::site("form/edit/user/{$user->id}"))
->label($user->display_name()));
$menu->append(Menu::factory("link")
->id("user_menu_logout")
@@ -228,11 +229,7 @@ class gallery_event_Core {
->append(Menu::factory("link")
->id("advanced")
->label(t("Advanced"))
- ->url(url::site("admin/advanced_settings")))
- ->append(Menu::factory("link")
- ->id("authentication")
- ->label(t("Authentication"))
- ->url(url::site("admin/identity"))))
+ ->url(url::site("admin/advanced_settings"))))
->append(Menu::factory("link")
->id("modules")
->label(t("Modules"))
@@ -305,7 +302,7 @@ class gallery_event_Core {
->append(
Menu::factory("ajax_link")
->id("rotate_ccw")
- ->label(t("Rotate 90° counter clockwise"))
+ ->label(t("Rotate 90° counter clockwise"))
->css_class("ui-icon-rotate-ccw")
->ajax_handler("function(data) { " .
"\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
@@ -313,7 +310,7 @@ class gallery_event_Core {
->append(
Menu::factory("ajax_link")
->id("rotate_cw")
- ->label(t("Rotate 90° clockwise"))
+ ->label(t("Rotate 90° clockwise"))
->css_class("ui-icon-rotate-cw")
->ajax_handler("function(data) { " .
"\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index 3a705027..b3b79e06 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -122,7 +122,7 @@ class gallery_task_Core {
$start = microtime(true);
$data = Cache::instance()->get("update_l10n_cache:{$task->id}");
if ($data) {
- list($dirs, $files, $cache) = unserialize($data);
+ list($dirs, $files, $cache, $num_fetched) = unserialize($data);
}
$i = 0;
@@ -130,6 +130,7 @@ class gallery_task_Core {
case "init": // 0%
$dirs = array("gallery", "modules", "themes", "installer");
$files = $cache = array();
+ $num_fetched = 0;
$task->set("mode", "find_files");
$task->status = t("Finding files");
break;
@@ -161,7 +162,7 @@ class gallery_task_Core {
}
break;
- case "scan_files": // 10% - 90%
+ case "scan_files": // 10% - 70%
while (($file = array_pop($files)) && microtime(true) - $start < 0.5) {
$file = DOCROOT . $file;
switch (pathinfo($file, PATHINFO_EXTENSION)) {
@@ -179,25 +180,31 @@ class gallery_task_Core {
$task->status = t2("Scanning files: scanned 1 file",
"Scanning files: scanned %count files", $total_files - count($files));
- $task->percent_complete = 10 + 80 * ($total_files - count($files)) / $total_files;
+ $task->percent_complete = 10 + 60 * ($total_files - count($files)) / $total_files;
if (empty($files)) {
$task->set("mode", "fetch_updates");
$task->status = t("Fetching updates");
- $task->percent_complete = 90;
+ $task->percent_complete = 70;
}
break;
- case "fetch_updates": // 90% - 100%
- l10n_client::fetch_updates();
- $task->done = true;
- $task->state = "success";
- $task->status = t("Translations installed/updated");
- $task->percent_complete = 100;
+ case "fetch_updates": // 70% - 100%
+ // Send fetch requests in batches until we're done
+ $num_remaining = l10n_client::fetch_updates($num_fetched);
+ if ($num_remaining) {
+ $total = $num_fetched + $num_remaining;
+ $task->percent_complete = 70 + 30 * ((float) $num_fetched / $total);
+ } else {
+ $task->done = true;
+ $task->state = "success";
+ $task->status = t("Translations installed/updated");
+ $task->percent_complete = 100;
+ }
}
- if ($task->percent_complete < 100) {
+ if (!$task->done) {
Cache::instance()->set("update_l10n_cache:{$task->id}",
- serialize(array($dirs, $files, $cache)));
+ serialize(array($dirs, $files, $cache, $num_fetched)));
} else {
Cache::instance()->delete("update_l10n_cache:{$task->id}");
}
diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php
index fe70933d..086245e8 100644
--- a/modules/gallery/helpers/l10n_client.php
+++ b/modules/gallery/helpers/l10n_client.php
@@ -68,9 +68,15 @@ class l10n_client_Core {
}
/**
- * @return an array of messages that will be written to the task log
+ * Fetches translations for l10n messages. Must be called repeatedly
+ * until 0 is returned (which is a countdown indicating progress).
+ *
+ * @param $num_fetched in/out parameter to specify which batch of
+ * messages to fetch translations for.
+ * @return The number of messages for which we didn't fetch
+ * translations for.
*/
- static function fetch_updates() {
+ static function fetch_updates(&$num_fetched) {
$request->locales = array();
$request->messages = new stdClass();
@@ -79,23 +85,42 @@ class l10n_client_Core {
$request->locales[] = $locale;
}
- // @todo Batch requests (max request size)
- foreach (db::build()
- ->select("key", "locale", "revision", "translation")
- ->from("incoming_translations")
- ->execute() as $row) {
+ // See the server side code for how we arrive at this
+ // number as a good limit for #locales * #messages.
+ $max_messages = 2000 / count($locales);
+ $num_messages = 0;
+ $rows = db::build()
+ ->select("key", "locale", "revision", "translation")
+ ->from("incoming_translations")
+ ->order_by("key")
+ ->limit(1000000) // ignore, just there to satisfy SQL syntax
+ ->offset($num_fetched)
+ ->execute();
+ $num_remaining = $rows->count();
+ foreach ($rows as $row) {
if (!isset($request->messages->{$row->key})) {
+ if ($num_messages >= $max_messages) {
+ break;
+ }
$request->messages->{$row->key} = 1;
+ $num_messages++;
}
- if (!empty($row->revision) && !empty($row->translation)) {
+ if (!empty($row->revision) && !empty($row->translation) &&
+ isset($locales[$row->locale])) {
if (!is_object($request->messages->{$row->key})) {
$request->messages->{$row->key} = new stdClass();
}
- $request->messages->{$row->key}->{$row->locale} = $row->revision;
+ $request->messages->{$row->key}->{$row->locale} = (int) $row->revision;
}
+ $num_fetched++;
+ $num_remaining--;
}
// @todo Include messages from outgoing_translations?
+ if (!$num_messages) {
+ return $num_remaining;
+ }
+
$request_data = json_encode($request);
$url = self::_server_url() . "?q=translations/fetch";
list ($response_data, $response_status) = remote::post($url, array("data" => $request_data));
@@ -103,7 +128,7 @@ class l10n_client_Core {
throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED " . $response_status);
}
if (empty($response_data)) {
- return array(t("Translations fetch request resulted in an empty response"));
+ return $num_remaining;
}
$response = json_decode($response_data);
@@ -150,6 +175,8 @@ class l10n_client_Core {
$entry->translation = $translation;
$entry->save();
}
+
+ return $num_remaining;
}
static function submit_translations() {
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 6c7078a3..f680ff6a 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -120,19 +120,46 @@ class module_Core {
}
/**
+ * Check that the module can be activated. (i.e. all the prerequistes exist)
+ * @param string $module_name
+ * @return array an array of warning or error messages to be displayed
+ */
+ static function can_activate($module_name) {
+ module::_add_to_path($module_name);
+ $messages = array();
+
+ $installer_class = "{$module_name}_installer";
+ if (method_exists($installer_class, "can_activate")) {
+ $messages = call_user_func(array($installer_class, "can_activate"));
+ }
+
+ // Remove it from the active path
+ module::_remove_from_path($module_name);
+ return $messages;
+ }
+
+ /**
+ * Allow modules to indicate the impact of deactivating the specifeid module
+ * @param string $module_name
+ * @return array an array of warning or error messages to be displayed
+ */
+ static function can_deactivate($module_name) {
+ $data = (object)array("module" => $module_name, "messages" => array());
+
+ module::event("pre_deactivate", $data);
+
+ return $data->messages;
+ }
+
+ /**
* Install a module. This will call <module>_installer::install(), which is responsible for
* creating database tables, setting module variables and calling module::set_version().
* Note that after installing, the module must be activated before it is available for use.
* @param string $module_name
*/
static function install($module_name) {
- $config = Kohana_Config::instance();
- $kohana_modules = $config->get("core.modules");
- array_unshift($kohana_modules, MODPATH . $module_name);
- $config->set("core.modules", $kohana_modules);
+ module::_add_to_path($module_name);
- // 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());
@@ -142,13 +169,32 @@ class module_Core {
module::load_modules();
// Now the module is installed but inactive, so don't leave it in the active path
- array_shift($kohana_modules);
- $config->set("core.modules", $kohana_modules);
+ module::_remove_from_path($module_name);
log::success(
"module", t("Installed module %module_name", array("module_name" => $module_name)));
}
+ private static function _add_to_path($module_name) {
+ $config = Kohana_Config::instance();
+ $kohana_modules = $config->get("core.modules");
+ array_unshift($kohana_modules, MODPATH . $module_name);
+ $config->set("core.modules", $kohana_modules);
+ // Rebuild the include path so the module installer can benefit from auto loading
+ Kohana::include_paths(true);
+ }
+
+ private static function _remove_from_path($module_name) {
+ $config = Kohana_Config::instance();
+ $kohana_modules = $config->get("core.modules");
+ if (($key = array_search(MODPATH . $module_name, $kohana_modules)) !== false) {
+ unset($kohana_modules[$key]);
+ $kohana_modules = array_values($kohana_modules); // reindex
+ }
+ $config->set("core.modules", $kohana_modules);
+ Kohana::include_paths(true);
+ }
+
/**
* Upgrade a module. This will call <module>_installer::upgrade(), which is responsible for
* modifying database tables, changing module variables and calling module::set_version().
@@ -194,10 +240,7 @@ class module_Core {
* @param string $module_name
*/
static function activate($module_name) {
- $config = Kohana_Config::instance();
- $kohana_modules = $config->get("core.modules");
- array_unshift($kohana_modules, MODPATH . $module_name);
- $config->set("core.modules", $kohana_modules);
+ module::_add_to_path($module_name);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "activate")) {