Permalink
Browse files

Merge branch 'master' into talmdal_dev

  • Loading branch information...
talmdal committed Feb 26, 2010
2 parents 9f81015 + b4922f4 commit f28b80fcf43e02ca65f419eb6774321dc30a2a37
View
@@ -42,6 +42,7 @@ CREATE TABLE {caches} (
`expiration` int(9) NOT NULL,
`cache` longblob,
PRIMARY KEY (`id`),
+ KEY `key` (`key`),
KEY `tags` (`tags`)
) DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
@@ -239,7 +240,7 @@ CREATE TABLE {modules} (
UNIQUE KEY `name` (`name`)
) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
-INSERT INTO {modules} VALUES (1,1,'gallery',29);
+INSERT INTO {modules} VALUES (1,1,'gallery',30);
INSERT INTO {modules} VALUES (2,1,'user',3);
INSERT INTO {modules} VALUES (3,1,'comment',2);
INSERT INTO {modules} VALUES (4,1,'organize',1);
@@ -57,7 +57,7 @@
Password
</td>
<td>
- <input name="dbpass" value=""/>
+ <input name="dbpass" value="" type="password" />
</td>
</tr>
<tr>
@@ -18,6 +18,9 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Comment_Model_Test extends Gallery_Unit_Test_Case {
+ public function teardown() {
+ identity::set_active_user(identity::admin_user());
+ }
public function cant_view_comments_for_unviewable_items_test() {
$album = test::random_album();
@@ -304,20 +304,27 @@ static function import_user(&$queue) {
if ($user) {
$message = t("Loaded existing user: '%name'.", array("name" => $user->name));
} else {
+ $email = $g2_user->getEmail();
+ if (empty($email) || !valid::email($email)) {
+ $email = "unknown@unknown.com";
+ }
$user = identity::create_user($g2_user->getUsername(), $g2_user->getfullname(),
// Note: The API expects a password in cleartext.
// Just use the hashed password as an unpredictable
// value here. The user will have to reset the password.
- $g2_user->getHashedPassword(), $g2_user->getEmail());
+ $g2_user->getHashedPassword(), $email);
if (class_exists("User_Model") && $user instanceof User_Model) {
// This will work if G2's password is a PasswordHash password as well.
$user->hashed_password = $g2_user->getHashedPassword();
}
$message = t("Created user: '%name'.", array("name" => $user->name));
+ if ($email == "unknown@unknown.com") {
+ $message .= t("\n\tFixed invalid email (was '%invalid_email')",
+ array("invalid_email" => $g2_user->getEmail()));
+ }
}
$user->hashed_password = $g2_user->getHashedPassword();
- $user->email = $g2_user->getEmail() ? $g2_user->getEmail() : "unknown@unknown.com";
$user->locale = $g2_user->getLanguage();
foreach ($g2_groups as $g2_group_id => $g2_group_name) {
if ($g2_group_id == $g2_admin_group_id) {
@@ -47,7 +47,7 @@
<? if ($g2_sizes["resize"]["size"] && $resize_size != $g2_sizes["resize"]["size"]): ?>
<li class="g-warning">
- <?= t("Your most common intermediate size in Gallery 2 is %g2_pixels pixels, but your Gallery 3 thumbnail size is set to %g3_pixels pixels. <a href=\"%url\">Using the same value</a> will speed up your import.",
+ <?= t("Your most common intermediate size in Gallery 2 is %g2_pixels pixels, but your Gallery 3 intermediate size is set to %g3_pixels pixels. <a href=\"%url\">Using the same value</a> will speed up your import.",
array("g2_pixels" => $g2_sizes["resize"]["size"],
"g3_pixels" => $resize_size,
"url" => html::mark_clean(url::site("admin/theme_options")))) ?>
@@ -209,17 +209,18 @@ public function run($task_id) {
message::success(t("Task failed"));
break;
}
+ // Using sprintf("%F") to avoid comma as decimal separator.
print json_encode(array("result" => "success",
"task" => array(
- "percent_complete" => $task->percent_complete,
+ "percent_complete" => sprintf("%F", $task->percent_complete),
"status" => (string) $task->status,
"done" => (bool) $task->done),
"location" => url::site("admin/maintenance")));
} else {
print json_encode(array("result" => "in_progress",
"task" => array(
- "percent_complete" => $task->percent_complete,
+ "percent_complete" => sprintf("%F", $task->percent_complete),
"status" => (string) $task->status,
"done" => (bool) $task->done)));
}
@@ -80,6 +80,8 @@ public function save() {
$entry->save();
+ Gallery_I18n::clear_cache($locale);
+
print json_encode(new stdClass());
}
@@ -82,6 +82,7 @@ private function _dump_database() {
module::set_var("gallery", "blocks_{$key}", serialize($blocks));
}
+ Database::instance()->query("TRUNCATE {caches}");
Database::instance()->query("TRUNCATE {sessions}");
Database::instance()->query("TRUNCATE {logs}");
db::build()
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class gallery_Core {
- const VERSION = "3.0 git (pre-RC1)";
+ const VERSION = "3.0 RC1 (Santa Fe)";
/**
* If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is
@@ -32,13 +32,18 @@ static function install() {
PRIMARY KEY (`id`))
DEFAULT CHARSET=utf8;");
+ // Using a simple index instead of a unique key for the
+ // key column to avoid handling of concurrency issues
+ // on insert. Thus allowing concurrent inserts on the
+ // same cache key, as does Memcache / xcache.
$db->query("CREATE TABLE {caches} (
`id` int(9) NOT NULL auto_increment,
`key` varchar(255) NOT NULL,
`tags` varchar(255),
`expiration` int(9) NOT NULL,
`cache` longblob,
PRIMARY KEY (`id`),
+ KEY (`key`),
KEY (`tags`))
DEFAULT CHARSET=utf8;");
@@ -290,7 +295,7 @@ static function install() {
module::set_var("gallery", "credits", (string) $powered_by_string);
module::set_var("gallery", "simultaneous_upload_limit", 5);
module::set_var("gallery", "admin_area_timeout", 90 * 60);
- module::set_version("gallery", 29);
+ module::set_version("gallery", 30);
}
static function upgrade($version) {
@@ -545,6 +550,11 @@ static function upgrade($version) {
module::set_var("gallery", "credits", "Powered by <a href=\"%url\">%gallery_version</a>");
module::set_version("gallery", $version = 29);
}
+
+ if ($version == 29) {
+ $db->query("ALTER TABLE {caches} ADD KEY (`key`);");
+ module::set_version("gallery", $version = 30);
+ }
}
static function uninstall() {
@@ -201,6 +201,8 @@ static function update_l10n($task) {
$total = $num_fetched + $num_remaining;
$task->percent_complete = 70 + 30 * ((float) $num_fetched / $total);
} else {
+ Gallery_I18n::clear_cache();
+
$task->done = true;
$task->state = "success";
$task->status = t("Translations installed/updated");
@@ -81,6 +81,7 @@ private static function _init_language_data() {
$l["eu_ES"] = "Euskara"; // Basque
$l["fa_IR"] = "فارس"; // Farsi
$l["fi_FI"] = "Suomi"; // Finnish
+ $l["fo_FO"] = "Føroyskt"; // Faroese
$l["fr_FR"] = "Français"; // French
$l["ga_IE"] = "Gaeilge"; // Irish
$l["he_IL"] = "עברית"; // Hebrew
@@ -150,33 +150,44 @@ public function translate($message, $options=array()) {
private function lookup($locale, $message) {
if (!isset($this->_cache[$locale])) {
- $this->_cache[$locale] = array();
- // TODO: Load data from locale file instead of the DB.
+ $this->_cache[$locale] = self::load_translations($locale);
+ }
+
+ $key = self::get_message_key($message);
+
+ if (isset($this->_cache[$locale][$key])) {
+ return $this->_cache[$locale][$key];
+ } else {
+ return null;
+ }
+ }
+
+ private static function load_translations($locale) {
+ $cache_key = "translation|" . $locale;
+ $cache = Cache::instance();
+ $translations = $cache->get($cache_key);
+ if (!isset($translations) || !is_array($translations)) {
+ $translations = array();
foreach (db::build()
->select("key", "translation")
->from("incoming_translations")
->where("locale", "=", $locale)
->execute() as $row) {
- $this->_cache[$locale][$row->key] = unserialize($row->translation);
+ $translations[$row->key] = unserialize($row->translation);
}
-
+
// Override incoming with outgoing...
foreach (db::build()
->select("key", "translation")
->from("outgoing_translations")
->where("locale", "=", $locale)
->execute() as $row) {
- $this->_cache[$locale][$row->key] = unserialize($row->translation);
+ $translations[$row->key] = unserialize($row->translation);
}
+
+ $cache->set($cache_key, $translations, array("translation"), 0);
}
-
- $key = self::get_message_key($message);
-
- if (isset($this->_cache[$locale][$key])) {
- return $this->_cache[$locale][$key];
- } else {
- return null;
- }
+ return $translations;
}
public function has_translation($message, $options=null) {
@@ -256,6 +267,15 @@ public function call_log() {
return $this->_call_log;
}
+ public static function clear_cache($locale=null) {
+ $cache = Cache::instance();
+ if ($locale) {
+ $cache->delete("translation|" . $locale);
+ } else {
+ $cache->delete_tag("translation");
+ }
+ }
+
private static function get_plural_key($locale, $count) {
$parts = explode('_', $locale);
$language = $parts[0];
@@ -184,7 +184,7 @@ public function append($menu_element) {
}
/**
- * Add a new element to this menu
+ * Add a new element to this menu, after the specific element
*/
public function add_after($target_id, $new_menu_element) {
$copy = array();
@@ -198,6 +198,21 @@ public function add_after($target_id, $new_menu_element) {
return $this;
}
+ /**
+ * Add a new element to this menu, before the specific element
+ */
+ public function add_before($target_id, $new_menu_element) {
+ $copy = array();
+ foreach ($this->elements as $id => $menu_element) {
+ if ($id == $target_id) {
+ $copy[$new_menu_element->id] = $new_menu_element;
+ }
+ $copy[$id] = $menu_element;
+ }
+ $this->elements = $copy;
+ return $this;
+ }
+
/**
* Remove an element from the menu
*/
@@ -130,7 +130,7 @@ public function get($keys, $single=false) {
// Make sure the expiration is valid and that the hash matches
if ($cache->expiration != 0 && $cache->expiration <= time()) {
// Cache is not valid, delete it now
- $this->delete($cache->id);
+ $this->delete(array($cache->id));
} else {
// Disable notices for unserializing
$ER = error_reporting(~E_NOTICE);
@@ -153,15 +153,17 @@ public function get($keys, $single=false) {
* @param bool delete a tag
* @return bool
*/
- public function delete($id, $tag=false) {
+ public function delete($keys, $is_tag=false) {
$db = db::build()
->delete("caches");
- if ($id === true) {
+ if ($keys === true) {
// Delete all caches
- } else if ($tag === true) {
- $db->where("tags", "LIKE", "%<$id>%");
+ } else if ($is_tag === true) {
+ foreach ($keys as $tag) {
+ $db->where("tags", "LIKE", "%<$tag>%");
+ }
} else {
- $db->where("key", "=", $id);
+ $db->where("key", "IN", $keys);
}
$status = $db->execute();
@@ -1,3 +1,3 @@
name = "Gallery 3"
description = "Gallery core application"
-version = 29
+version = 30
@@ -20,6 +20,10 @@
class Access_Helper_Test extends Gallery_Unit_Test_Case {
private $_group;
+ public function setup() {
+ identity::set_active_user(identity::guest());
+ }
+
public function teardown() {
try {
$group = identity::lookup_group_by_name("access_test");
@@ -41,10 +45,7 @@ public function teardown() {
// Reset some permissions that we mangle below
access::allow(identity::everybody(), "view", item::root());
- }
-
- public function setup() {
- identity::set_active_user(identity::guest());
+ identity::set_active_user(identity::admin_user());
}
public function groups_and_permissions_are_bound_to_columns_test() {
@@ -118,7 +118,7 @@ public function cache_delete_id_test() {
$value3 = array("field5" => "value5", "field6" => "value6");
$this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600);
- $this->_driver->delete($id1);
+ $this->_driver->delete(array($id1));
$this->assert_false($this->_driver->exists($id1), "$id1 should have been deleted");
$this->assert_true($this->_driver->exists($id2), "$id2 should not have been deleted");
@@ -138,7 +138,7 @@ public function cache_delete_tag_test() {
$value3 = array("field5" => "value5", "field6" => "value6");
$this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600);
- $data = $this->_driver->delete("tag3", true);
+ $data = $this->_driver->delete_tag(array("tag3"));
$this->assert_true($this->_driver->exists($id1), "$id1 should not have been deleted");
$this->assert_false($this->_driver->exists($id2), "$id2 should have been deleted");
@@ -18,8 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Item_Helper_Test extends Gallery_Unit_Test_Case {
-
- public function setup() {
+ public function teardown() {
identity::set_active_user(identity::admin_user());
}
@@ -18,6 +18,10 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
+ public function teardown() {
+ identity::set_active_user(identity::admin_user());
+ }
+
public function resolve_test() {
$album = test::random_album();
$resolved = rest::resolve(rest::url("item", $album));
Oops, something went wrong.

0 comments on commit f28b80f

Please sign in to comment.