diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-02-06 16:39:18 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-02-06 16:39:18 +0000 |
commit | 4e107dac41f58d3ed6064809d8ee461ea8592e2c (patch) | |
tree | 06933f36bc392a6bc9623bd304581b6e690799ab | |
parent | 48acd42f9b1dfee5ba011501a1c989eb7fde0373 (diff) |
Implement fix for ticket #35. *** Requires reinstall of core ***
* Added new field in items table (path) which is sanitized version of
name.
* Added __set method on Items_module to set the path field whenever
the name field is changed.
* Made some changes to the scaffolding so missing the path column
would not kill the scaffolding.
* Changed MY_url::site so not having a 3rd parameter won't throw an error.
-rw-r--r-- | core/controllers/scaffold.php | 11 | ||||
-rw-r--r-- | core/helpers/MY_url.php | 8 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 1 | ||||
-rw-r--r-- | core/models/item.php | 14 |
4 files changed, 25 insertions, 9 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php index 8266ba8f..395e032d 100644 --- a/core/controllers/scaffold.php +++ b/core/controllers/scaffold.php @@ -112,8 +112,11 @@ 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(); - foreach ($db->list_tables() as $table) { - $db->query("DROP TABLE `$table`"); + $tables = $db->list_tables(); + if (!empty($tables)) { + foreach ($db->list_tables() as $table) { + $db->query("DROP TABLE `$table`"); + } } set_error_handler($old_handler); } else { @@ -423,7 +426,9 @@ class Scaffold_Controller extends Template_Controller { function _create_directories() { foreach (array("logs", "uploads") as $dir) { - @mkdir(VARPATH . "$dir"); + if (!file_exists(VARPATH . "$dir")) { + @mkdir(VARPATH . "$dir"); + } } } diff --git a/core/helpers/MY_url.php b/core/helpers/MY_url.php index dd3682df..c5f2d16c 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) { - list($controller, $arg1, $args) = explode("/", $uri, 3); - if ($controller == "albums" || $controller == "photos") { - $uri = ORM::factory("item", $arg1)->relative_path(); + $parts = explode("/", $uri, 3); + if ($parts[0] == "albums" || $parts[0] == "photos") { + $uri = ORM::factory("item", empty($parts[1]) ? 1 : $parts[1])->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("name", Router::$segments[$count - 1]) + ->where("path", Router::$segments[$count - 1]) ->where("level", $count + 1) ->find_all() as $match) { if ($match->relative_path() == Router::$current_uri) { diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index 24b9e993..eacb08eb 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -63,6 +63,7 @@ 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/models/item.php b/core/models/item.php index e29f3245..e188e0a3 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->name; + $paths[] = $parent->path; } } - $paths[] = $this->name; + $paths[] = $this->path; $this->relative_path = implode($paths, "/"); } return $this->relative_path; @@ -242,6 +242,16 @@ class Item_Model extends ORM_MPTT { } /** + * @see ORM::__get() + */ + public function __set($column, $value) { + if ($column == "name") { + parent::__set("path", preg_replace("/[^A-Za-z0-9\.\-_]/", "_", $value)); + } + parent::__set($column, $value); + } + + /** * @see ORM::save() */ public function save() { |