diff options
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/helpers/graphics.php | 10 | ||||
-rw-r--r-- | modules/gallery/models/item.php | 7 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Model_Test.php | 23 |
3 files changed, 30 insertions, 10 deletions
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 39c87fbd..3548faa1 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -170,14 +170,8 @@ class graphics_Core { foreach (self::_get_rules($target) as $rule) { $args = array($working_file, $output_file, unserialize($rule->args), $item); - try { - call_user_func_array($rule->operation, $args); - $working_file = $output_file; - } catch (Exception $e) { - // Ignore this rule and move on. - Kohana_Log::add("error", "Caught exception processing image: {$item->title}\n" . - $e->getMessage() . "\n" . $e->getTraceAsString()); - } + call_user_func_array($rule->operation, $args); + $working_file = $output_file; } } diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index cccb7074..93e97af6 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -420,6 +420,13 @@ class Item_Model_Core extends ORM_MPTT { if (!empty($extension) && strcmp($this->name, $new_name)) { $this->name = $new_name; } + if ($this->is_photo()) { + list ($this->width, $this->height, $this->mime_type, $extension) = + photo::get_file_metadata($this->data_file); + } else if ($this->is_movie()) { + list ($this->width, $this->height, $this->mime_type, $extension) = + movie::get_file_metadata($this->data_file); + } } if (array_intersect($this->changed, array("parent_id", "name", "slug"))) { diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 968d7510..19ab8ec4 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -394,15 +394,34 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $this->assert_equal(20337, filesize($photo->file_path())); } - public function replacement_data_file_must_be_same_mime_type_test() { + public function replace_data_file_type_test() { // Random photo is modules/gallery/tests/test.jpg $photo = test::random_photo(); + $this->assert_equal(1024, $photo->width); + $this->assert_equal(768, $photo->height); + $this->assert_equal(6232, filesize($photo->file_path())); + $this->assert_equal("image/jpeg", $photo->mime_type); + $orig_name = $photo->name; + + // Random photo is gallery/images/graphicsmagick.png is 104x76 and 1486 bytes $photo->set_data_file(MODPATH . "gallery/images/graphicsmagick.png"); + $photo->save(); + + $this->assert_equal(104, $photo->width); + $this->assert_equal(76, $photo->height); + $this->assert_equal(1486, filesize($photo->file_path())); + $this->assert_equal("image/png", $photo->mime_type); + $this->assert_equal("png", pathinfo($photo->name, PATHINFO_EXTENSION)); + $this->assert_equal(pathinfo($orig_name, PATHINFO_FILENAME), pathinfo($photo->name, PATHINFO_FILENAME)); + } + public function unsafe_data_file_replacement_test() { try { + $photo = test::random_photo(); + $photo->set_data_file(MODPATH . "gallery/tests/Item_Model_Test.php"); $photo->save(); } catch (ORM_Validation_Exception $e) { - $this->assert_same(array("name" => "cant_change_mime_type"), $e->validation->errors()); + $this->assert_same(array("mime_type" => "invalid"), $e->validation->errors()); return; // pass } $this->assert_true(false, "Shouldn't get here"); |