diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/scaffold.php | 11 | ||||
-rw-r--r-- | core/helpers/MY_url.php | 8 | ||||
-rw-r--r-- | core/helpers/album.php | 27 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 1 | ||||
-rw-r--r-- | core/helpers/photo.php | 33 | ||||
-rw-r--r-- | core/models/item.php | 4 | ||||
-rw-r--r-- | core/tests/Album_Helper_Test.php | 1 | ||||
-rw-r--r-- | core/tests/Photo_Helper_Test.php | 12 |
8 files changed, 27 insertions, 70 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php index 395e032d..8266ba8f 100644 --- a/core/controllers/scaffold.php +++ b/core/controllers/scaffold.php @@ -112,11 +112,8 @@ class Scaffold_Controller extends Template_Controller { // Since we're in a state of flux, it's possible that other stuff went wrong with the // uninstall, so back off and nuke it from orbit. It's the only way to be sure. $db = Database::instance(); - $tables = $db->list_tables(); - if (!empty($tables)) { - foreach ($db->list_tables() as $table) { - $db->query("DROP TABLE `$table`"); - } + foreach ($db->list_tables() as $table) { + $db->query("DROP TABLE `$table`"); } set_error_handler($old_handler); } else { @@ -426,9 +423,7 @@ class Scaffold_Controller extends Template_Controller { function _create_directories() { foreach (array("logs", "uploads") as $dir) { - if (!file_exists(VARPATH . "$dir")) { - @mkdir(VARPATH . "$dir"); - } + @mkdir(VARPATH . "$dir"); } } diff --git a/core/helpers/MY_url.php b/core/helpers/MY_url.php index c5f2d16c..dd3682df 100644 --- a/core/helpers/MY_url.php +++ b/core/helpers/MY_url.php @@ -19,9 +19,9 @@ */ class url extends url_Core { static function site($uri, $protocol=false) { - $parts = explode("/", $uri, 3); - if ($parts[0] == "albums" || $parts[0] == "photos") { - $uri = ORM::factory("item", empty($parts[1]) ? 1 : $parts[1])->relative_path(); + list($controller, $arg1, $args) = explode("/", $uri, 3); + if ($controller == "albums" || $controller == "photos") { + $uri = ORM::factory("item", $arg1)->relative_path(); } return parent::site($uri, $protocol); } @@ -33,7 +33,7 @@ class url extends url_Core { $count = count(Router::$segments); foreach (ORM::factory("item") - ->where("path", Router::$segments[$count - 1]) + ->where("name", Router::$segments[$count - 1]) ->where("level", $count + 1) ->find_all() as $match) { if ($match->relative_path() == Router::$current_uri) { diff --git a/core/helpers/album.php b/core/helpers/album.php index b19a003d..c45b9bd8 100644 --- a/core/helpers/album.php +++ b/core/helpers/album.php @@ -30,41 +30,28 @@ class album_Core { * @param string $name the name of this new album (it will become the directory name on disk) * @param integer $title the title of the new album * @param string $description (optional) the longer description of this album - * @param string $path (optional) the name to use as the filesystem path component - * @param integer $owner_id(optional) explicitly set the owner of this album * @return Item_Model */ - static function create($parent, $name, $title, $description=null, $path=null, $owner_id=null) { + static function create($parent, $name, $title, $description=null, $owner_id=null) { if (!$parent->loaded || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } - // Randomize the name if there's a conflict - $name_count = ORM::factory("item") - ->where("parent_id", $parent->id) - ->where("name", $name) - ->count_all(); - $name = $name_count == 0 ? $name : sprintf("%s_%03d", $name, $name_count); - - $path = !empty($path) ? $path : preg_replace("/[^A-Za-z0-9\.\-_]/", "_", $name); - - // Randomize the path if there's a conflict - $path_count = ORM::factory("item") - ->where("parent_id", $parent->id) - ->where("path", $path) - ->count_all(); - $path = $path_count == 0 ? $path : sprintf("%s_%03d", $path, $path_count); - $album = ORM::factory("item"); $album->type = "album"; $album->title = $title; $album->description = $description; $album->name = $name; - $album->path = $path; $album->owner_id = $owner_id; $album->thumb_dirty = 1; $album->resize_dirty = 1; + while (ORM::factory("item") + ->where("parent_id", $parent->id) + ->where("name", $album->name) + ->find()->id) { + $album->name = "{$name}-" . rand(); + } $album = $album->add_to_parent($parent); mkdir($album->file_path()); diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index eacb08eb..24b9e993 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -63,7 +63,6 @@ class core_installer { `level` int(9) NOT NULL, `mime_type` varchar(64) default NULL, `name` varchar(255) default NULL, - `path` varchar(255) default NULL, `owner_id` int(9) default NULL, `parent_id` int(9) NOT NULL, `resize_height` int(9) default NULL, diff --git a/core/helpers/photo.php b/core/helpers/photo.php index 1b087bd1..349e8760 100644 --- a/core/helpers/photo.php +++ b/core/helpers/photo.php @@ -31,12 +31,10 @@ class photo_Core { * @param string $name the filename to use for this photo in the album * @param integer $title the title of the new photo * @param string $description (optional) the longer description of this photo - * @param string $path (optional) the name to use as the file system path component - * @param integer $owner_id(optional) explicitly set the owner of this photo * @return Item_Model */ - static function create($parent, $filename, $name, $title, $description=null, $path=null, - $owner_id=null) { + static function create($parent, $filename, $name, $title, + $description=null, $owner_id=null) { if (!$parent->loaded || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } @@ -56,29 +54,11 @@ class photo_Core { $name .= "." . $pi["extension"]; } - // Randomize the name if there's a conflict - $name_count = ORM::factory("item") - ->where("parent_id", $parent->id) - ->where("name", $name) - ->count_all(); - $name = $name_count == 0 ? $name : - sprintf("%s_%03d.%s", $pi["filename"], $name_count, $pi["extension"]); - - $path = !empty($path) ? $path : preg_replace("/[^A-Za-z0-9\.\-_]/", "_", $name); - - // Randomize the path if there's a conflict - $path_count = ORM::factory("item") - ->where("parent_id", $parent->id) - ->where("path", $path) - ->count_all(); - $path = $path_count == 0 ? $path : sprintf("%s_%03d", $path, $path_count); - $photo = ORM::factory("item"); $photo->type = "photo"; $photo->title = $title; $photo->description = $description; $photo->name = $name; - $photo->path = $path; $photo->owner_id = $owner_id; $photo->width = $image_info[0]; $photo->height = $image_info[1]; @@ -86,6 +66,15 @@ class photo_Core { $photo->thumb_dirty = 1; $photo->resize_dirty = 1; + // Randomize the name if there's a conflict + while (ORM::Factory("item") + ->where("parent_id", $parent->id) + ->where("name", $photo->name) + ->find()->id) { + // @todo Improve this. Random numbers are not user friendly + $photo->name = rand() . "." . $pi["extension"]; + } + // This saves the photo $photo->add_to_parent($parent); copy($filename, $photo->file_path()); diff --git a/core/models/item.php b/core/models/item.php index 7086625f..e29f3245 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -215,10 +215,10 @@ class Item_Model extends ORM_MPTT { if (empty($this->relative_path)) { foreach ($this->parents() as $parent) { if ($parent->id > 1) { - $paths[] = $parent->path; + $paths[] = $parent->name; } } - $paths[] = $this->path; + $paths[] = $this->name; $this->relative_path = implode($paths, "/"); } return $this->relative_path; diff --git a/core/tests/Album_Helper_Test.php b/core/tests/Album_Helper_Test.php index 75981265..d085ca88 100644 --- a/core/tests/Album_Helper_Test.php +++ b/core/tests/Album_Helper_Test.php @@ -43,7 +43,6 @@ class Album_Helper_Test extends Unit_Test_Case { $album1 = album::create($root, $rand, $rand, $rand); $album2 = album::create($root, $rand, $rand, $rand); $this->assert_true($album1->name != $album2->name); - $this->assert_true($album1->path != $album2->path); } public function thumb_url_test() { diff --git a/core/tests/Photo_Helper_Test.php b/core/tests/Photo_Helper_Test.php index 5db63e49..2219a846 100644 --- a/core/tests/Photo_Helper_Test.php +++ b/core/tests/Photo_Helper_Test.php @@ -53,18 +53,6 @@ class Photo_Helper_Test extends Unit_Test_Case { $photo1 = photo::create($root, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand); $photo2 = photo::create($root, DOCROOT . "core/tests/test.jpg", "$rand.jpg", $rand, $rand); $this->assert_true($photo1->name != $photo2->name); - $this->assert_true($photo1->path != $photo2->path); - } - - public function create_special_characters_in_name_test() { - $rand = rand(); - $rand2 = rand(); - $name = "$rand & $rand's.jpg"; - $path = !empty($path) ? $path : preg_replace("/[^A-Za-z0-9\.\-_]/", "_", $name); - $root = ORM::factory("item", 1); - $photo = photo::create($root, DOCROOT . "core/tests/test.jpg", $name, $rand, $rand); - $this->assert_equal($name, $photo->name); - $this->assert_equal($path, $photo->path); } public function create_photo_with_no_extension_test() { |