From dff1a536961cd401b8e133e260fcc3cca7c13dc6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 25 Oct 2010 21:04:48 -0700 Subject: All modules should be named Xxx_Core for extensibility. Fixes #1458. --- modules/gallery/models/access_cache.php | 2 +- modules/gallery/models/access_intent.php | 2 +- modules/gallery/models/cache.php | 2 +- modules/gallery/models/failed_auth.php | 2 +- modules/gallery/models/graphics_rule.php | 2 +- modules/gallery/models/incoming_translation.php | 2 +- modules/gallery/models/log.php | 2 +- modules/gallery/models/message.php | 2 +- modules/gallery/models/module.php | 2 +- modules/gallery/models/outgoing_translation.php | 2 +- modules/gallery/models/permission.php | 2 +- modules/gallery/models/task.php | 2 +- modules/gallery/models/theme.php | 2 +- modules/gallery/models/var.php | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/access_cache.php b/modules/gallery/models/access_cache.php index af1b5c6c..e730f25c 100644 --- a/modules/gallery/models/access_cache.php +++ b/modules/gallery/models/access_cache.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Access_Cache_Model extends ORM { +class Access_Cache_Model_Core extends ORM { } diff --git a/modules/gallery/models/access_intent.php b/modules/gallery/models/access_intent.php index e71f8c46..31711014 100644 --- a/modules/gallery/models/access_intent.php +++ b/modules/gallery/models/access_intent.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Access_Intent_Model extends ORM { +class Access_Intent_Model_Core extends ORM { } diff --git a/modules/gallery/models/cache.php b/modules/gallery/models/cache.php index 4a7e37f6..1c464d51 100644 --- a/modules/gallery/models/cache.php +++ b/modules/gallery/models/cache.php @@ -17,4 +17,4 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Cache_Model extends ORM {} +class Cache_Model_Core extends ORM {} diff --git a/modules/gallery/models/failed_auth.php b/modules/gallery/models/failed_auth.php index a541f435..649e4bc9 100644 --- a/modules/gallery/models/failed_auth.php +++ b/modules/gallery/models/failed_auth.php @@ -17,4 +17,4 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Failed_Auth_Model extends ORM {} +class Failed_Auth_Model_Core extends ORM {} diff --git a/modules/gallery/models/graphics_rule.php b/modules/gallery/models/graphics_rule.php index 49036b9c..09410af0 100644 --- a/modules/gallery/models/graphics_rule.php +++ b/modules/gallery/models/graphics_rule.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Graphics_Rule_Model extends ORM { +class Graphics_Rule_Model_Core extends ORM { } diff --git a/modules/gallery/models/incoming_translation.php b/modules/gallery/models/incoming_translation.php index 45340c30..ff6a7160 100644 --- a/modules/gallery/models/incoming_translation.php +++ b/modules/gallery/models/incoming_translation.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Incoming_Translation_Model extends ORM { +class Incoming_Translation_Model_Core extends ORM { } diff --git a/modules/gallery/models/log.php b/modules/gallery/models/log.php index aa1a37ed..5d065313 100644 --- a/modules/gallery/models/log.php +++ b/modules/gallery/models/log.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Log_Model extends ORM { +class Log_Model_Core extends ORM { /** * @see ORM::__get() */ diff --git a/modules/gallery/models/message.php b/modules/gallery/models/message.php index 994d0cdb..3f84efd0 100644 --- a/modules/gallery/models/message.php +++ b/modules/gallery/models/message.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Message_Model extends ORM { +class Message_Model_Core extends ORM { } diff --git a/modules/gallery/models/module.php b/modules/gallery/models/module.php index dc181849..e54613d1 100644 --- a/modules/gallery/models/module.php +++ b/modules/gallery/models/module.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Module_Model extends ORM { +class Module_Model_Core extends ORM { } diff --git a/modules/gallery/models/outgoing_translation.php b/modules/gallery/models/outgoing_translation.php index 43f56dce..cd580bed 100644 --- a/modules/gallery/models/outgoing_translation.php +++ b/modules/gallery/models/outgoing_translation.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Outgoing_Translation_Model extends ORM { +class Outgoing_Translation_Model_Core extends ORM { } diff --git a/modules/gallery/models/permission.php b/modules/gallery/models/permission.php index b6b544d5..51bd95e7 100644 --- a/modules/gallery/models/permission.php +++ b/modules/gallery/models/permission.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Permission_Model extends ORM { +class Permission_Model_Core extends ORM { } diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index 4888a734..4d435101 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Task_Model extends ORM { +class Task_Model_Core extends ORM { public function get($key, $default=null) { $context = unserialize($this->context); if (array_key_exists($key, $context)) { diff --git a/modules/gallery/models/theme.php b/modules/gallery/models/theme.php index 523542f9..50fd04fd 100644 --- a/modules/gallery/models/theme.php +++ b/modules/gallery/models/theme.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Theme_Model extends ORM { +class Theme_Model_Core extends ORM { } \ No newline at end of file diff --git a/modules/gallery/models/var.php b/modules/gallery/models/var.php index a79d0048..f21486ee 100644 --- a/modules/gallery/models/var.php +++ b/modules/gallery/models/var.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Var_Model extends ORM { +class Var_Model_Core extends ORM { } -- cgit v1.2.3 From f01fad1cd0661a7fee42d701b0c17dd8f4def576 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 31 Oct 2010 12:21:06 -0700 Subject: Deal in integers when doing aspect ratio operations. Fixes #1470. --- modules/gallery/models/item.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 07f781d1..d16a5dc4 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -628,7 +628,7 @@ class Item_Model_Core extends ORM_MPTT { list ($height, $width) = $this->scale_dimensions($max); if ($center_vertically && $max) { // The constant is divide by 2 to calculate the file and 10 to convert to em - $margin_top = ($max - $height) / 20; + $margin_top = (int)(($max - $height) / 20); $extra_attrs["style"] = "margin-top: {$margin_top}em"; $extra_attrs["title"] = $this->title; } @@ -656,10 +656,10 @@ class Item_Model_Core extends ORM_MPTT { if ($height) { if (isset($max)) { if ($width > $height) { - $height = (int)($max * ($height / $width)); + $height = (int)($max * $height / $width); $width = $max; } else { - $width = (int)($max * ($width / $height)); + $width = (int)($max * $width / $height); $height = $max; } } @@ -700,10 +700,10 @@ class Item_Model_Core extends ORM_MPTT { $height = $this->height; if ($width > $max_size || $height > $max_size) { if ($width > $height) { - $height *= $max_size / $width; + $height = (int)($height * $max_size / $width); $width = $max_size; } else { - $width *= $max_size / $height; + $width = (int)($width * $max_size / $height); $height = $max_size; } } -- cgit v1.2.3 From d503513eca13c9c212d2772e9791744725127a8e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 6 Nov 2010 21:54:28 -0700 Subject: Create item_before_create and item_before_update events, and make Item_Model::data_file public. This allows us to intercept and tweak data files before saving the model which enables the max_size module. --- modules/gallery/models/item.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index d16a5dc4..eaf09c9c 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -20,7 +20,7 @@ class Item_Model_Core extends ORM_MPTT { protected $children = "items"; protected $sorting = array(); - protected $data_file = null; + public $data_file = null; public function __construct($id=null) { parent::__construct($id); @@ -320,6 +320,7 @@ class Item_Model_Core extends ORM_MPTT { $this->updated = time(); if (!$this->loaded()) { // Create a new item. + module::event("item_before_create", $this); // Set a weight if it's missing. We don't do this in the constructor because it's not a // simple assignment. @@ -398,6 +399,7 @@ class Item_Model_Core extends ORM_MPTT { module::event("item_created", $this); } else { // Update an existing item + module::event("item_before_update", $item); // If any significant fields have changed, load up a copy of the original item and // keep it around. -- cgit v1.2.3 From e87c502eded374e927c531ad10a78dac8ee70e64 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 9 Nov 2010 12:48:07 -0800 Subject: Tie the image cachebuster to the file mtime instead of Item_Model::$updated since we want the url to be stable whenever possible. Fixes #1482. --- modules/gallery/models/item.php | 13 +++++++++---- modules/gallery/tests/Item_Model_Test.php | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index eaf09c9c..891153d1 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -166,8 +166,9 @@ class Item_Model_Core extends ORM_MPTT { */ public function file_url($full_uri=false) { $relative_path = "var/albums/" . $this->relative_path(); + $cache_buster = $this->_cache_buster($this->file_path()); return ($full_uri ? url::abs_file($relative_path) : url::file($relative_path)) - . "?m={$this->updated}"; + . $cache_buster; } /** @@ -198,7 +199,7 @@ class Item_Model_Core extends ORM_MPTT { * photo: http://example.com/gallery3/var/albums/album1/photo.thumb.jpg */ public function thumb_url($full_uri=false) { - $cache_buster = "?m={$this->updated}"; + $cache_buster = $this->_cache_buster($this->thumb_path()); $relative_path = "var/thumbs/" . $this->relative_path(); $base = ($full_uri ? url::abs_file($relative_path) : url::file($relative_path)); if ($this->is_photo()) { @@ -227,9 +228,9 @@ class Item_Model_Core extends ORM_MPTT { */ public function resize_url($full_uri=false) { $relative_path = "var/resizes/" . $this->relative_path(); + $cache_buster = $this->_cache_buster($this->resize_path()); return ($full_uri ? url::abs_file($relative_path) : url::file($relative_path)) . - ($this->is_album() ? "/.album.jpg" : "") - . "?m={$this->updated}"; + ($this->is_album() ? "/.album.jpg" : "") . $cache_buster; } /** @@ -1024,4 +1025,8 @@ class Item_Model_Core extends ORM_MPTT { } return $data; } + + private function _cache_buster($path) { + return "?m=" . (string)(file_exists($path) ? filemtime($path) : 0); + } } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 90c54e3c..264a2128 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -406,6 +406,29 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { return; // pass } $this->assert_true(false, "Shouldn't get here"); + } + + public function urls_test() { + $photo = test::random_photo(); + $this->assert_true( + preg_match("|http://./var/resizes/name_\d+\.jpg\?m=\d+|", $photo->resize_url()), + $photo->resize_url() . " is malformed"); + $this->assert_true( + preg_match("|http://./var/thumbs/name_\d+\.jpg\?m=\d+|", $photo->thumb_url()), + $photo->thumb_url() . " is malformed"); + $this->assert_true( + preg_match("|http://./var/albums/name_\d+\.jpg\?m=\d+|", $photo->file_url()), + $photo->file_url() . " is malformed"); + // Albums have special thumbnails. Empty album has cachebuster of 0 since it has no thumbnail + $album = test::random_album(); + $this->assert_true( + preg_match("|http://./var/thumbs/name_\d+/\.album\.jpg\?m=0|", $album->thumb_url()), + $album->thumb_url() . " is malformed"); + + $photo = test::random_photo($album); + $this->assert_true( + preg_match("|http://./var/thumbs/name_\d+/\.album\.jpg\?m=\d+|", $album->thumb_url()), + $album->thumb_url() . " is malformed"); } } -- cgit v1.2.3 From 8d030cea64c0e5934e4dbf5fc56fab87c7e253bb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 18 Nov 2010 09:52:40 -0800 Subject: Fix a bug where simultaneous deletes of the same item can result in it deleting the first item row in the database. The root issue is a bug in Kohana that's addressed in dca9b5f3fc8e80ee0667cac88d688e2287b1e7f4 but in this change we deal with the fact that reloading an item can result in an instance of the item that's unloaded. In those cases, we should just ignore it and move on. Fixes #1489. --- modules/gallery/libraries/ORM_MPTT.php | 8 ++++++-- modules/gallery/models/item.php | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index d8d88e4e..f20fafa0 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -96,12 +96,16 @@ class ORM_MPTT_Core extends ORM { $item->reload()->delete(); } - // Deleting children has affected this item - $this->reload(); + // Deleting children has affected this item, but we'll reload it below. } $this->lock(); $this->reload(); // Assume that the prior lock holder may have changed this entry + if (!$this->loaded()) { + // Concurrent deletes may result in this item already being gone. Ignore it. + return; + } + try { db::build() ->update($this->table_name) diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 891153d1..9016a04a 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -71,6 +71,11 @@ class Item_Model_Core extends ORM_MPTT { } public function delete($ignored_id=null) { + if (!$this->loaded()) { + // Concurrent deletes may result in this item already being gone. Ignore it. + return; + } + if ($this->id == 1) { $v = new Validation(array("id")); $v->add_error("id", "cant_delete_root_album"); -- cgit v1.2.3