diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-03-16 08:49:55 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-03-16 08:49:55 +0000 |
commit | 1055fe6be3c3161f79767214cf662ae8cdea7cc8 (patch) | |
tree | b323e79dc096369d890d47e5e6719da9f55e144c | |
parent | 6f0ddb40576fe04b7d91e6fd993fe8d54ec27c1c (diff) |
Revive the install() and uninstall() functions in Scaffold_Controller
because we need those to make a package.
Fix the packaging code to ignore whatever prefix is being used by the
developer who is doing the packaging.
Update the install.sql file (there were a variety of small
inconsistencies, probably from hand-editing. Don't hand-edit this
file!)
-rw-r--r-- | core/controllers/scaffold.php | 80 | ||||
-rw-r--r-- | installer/install.sql | 10 |
2 files changed, 73 insertions, 17 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php index beba7f3c..1c2ce896 100644 --- a/core/controllers/scaffold.php +++ b/core/controllers/scaffold.php @@ -20,13 +20,6 @@ class Scaffold_Controller extends Template_Controller { public $template = "scaffold.html"; - public function __construct($theme=null) { - if (!(user::active()->admin)) { - throw new Exception("@todo UNAUTHORIZED", 401); - } - parent::__construct(); - } - function index() { $session = Session::instance(); @@ -256,6 +249,66 @@ class Scaffold_Controller extends Template_Controller { } } + function install($module_name, $redirect=true) { + $to_install = array(); + if ($module_name == "*") { + foreach (module::available() as $module_name => $info) { + if (empty($info->installed)) { + $to_install[] = $module_name; + } + } + } else { + $to_install[] = $module_name; + } + + foreach ($to_install as $module_name) { + if ($module_name != "core") { + require_once(DOCROOT . "modules/${module_name}/helpers/${module_name}_installer.php"); + } + module::install($module_name); + } + + if ($redirect) { + url::redirect("scaffold"); + } + } + + function uninstall($module_name, $redirect=true) { + $clean = true; + if ($module_name == "core") { + // We have to uninstall all other modules first, else their tables, etc don't + // get cleaned up. + $old_handler = set_error_handler(array("scaffold_Controller", "_error_handler")); + try { + foreach (ORM::factory("module")->find_all() as $module) { + if ($module->name != "core" && $module->version) { + try { + call_user_func(array("{$module->name}_installer", "uninstall")); + } catch (Exception $e) { + print $e; + } + } + } + core_installer::uninstall(); + } catch (Exception $e) { + print $e; + } + + + // 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 IF EXISTS `$table`"); + } + set_error_handler($old_handler); + } else { + module::uninstall($module_name); + } + if ($redirect) { + url::redirect("scaffold"); + } + } public function package() { $this->auto_render = false; @@ -286,15 +339,15 @@ class Scaffold_Controller extends Template_Controller { $db->update("users", array("password" => ""), array("id" => 2)); $dbconfig = Kohana::config('database.default'); - $dbconfig = $dbconfig["connection"]; - $pass = $dbconfig["pass"] ? "-p{$dbconfig['pass']}" : ""; + $conn = $dbconfig["connection"]; + $pass = $conn["pass"] ? "-p{$conn['pass']}" : ""; $sql_file = DOCROOT . "installer/install.sql"; if (!is_writable($sql_file)) { print "$sql_file is not writeable"; return; } - $command = "mysqldump --compact --add-drop-table -h{$dbconfig['host']} " . - "-u{$dbconfig['user']} $pass {$dbconfig['database']} > $sql_file"; + $command = "mysqldump --compact --add-drop-table -h{$conn['host']} " . + "-u{$conn['user']} $pass {$conn['database']} > $sql_file"; exec($command, $output, $status); if ($status) { print "<pre>"; @@ -305,8 +358,11 @@ class Scaffold_Controller extends Template_Controller { } // Post-process the sql file to support prefixes + $buf = ""; foreach (file($sql_file) as $line) { - $buf .= preg_replace("/(CREATE TABLE|IF EXISTS|INSERT INTO) `(\w+)`/", "\\1 {\\2}", $line); + $buf .= preg_replace( + "/(CREATE TABLE|IF EXISTS|INSERT INTO) `{$dbconfig['table_prefix']}(\w+)`/", "\\1 {\\2}", + $line); } $fd = fopen($sql_file, "wb"); fwrite($fd, $buf); diff --git a/installer/install.sql b/installer/install.sql index 48434b08..f157df78 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -11,7 +11,7 @@ CREATE TABLE {access_caches} ( PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {access_caches} VALUES (1,1,1,0,1,1); +INSERT INTO {access_caches} VALUES (1,1,1,0,1,0); DROP TABLE IF EXISTS {access_intents}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -27,7 +27,7 @@ CREATE TABLE {access_intents} ( PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {access_intents} VALUES (1,1,1,1,0,1,1,1); +INSERT INTO {access_intents} VALUES (1,1,1,1,0,1,1,0); DROP TABLE IF EXISTS {comments}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -147,7 +147,7 @@ CREATE TABLE {items} ( KEY `random` (`rand_key`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {items} VALUES (NULL,1236569573,'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1236569573,0,NULL,NULL,'id','ASC',1,1); +INSERT INTO {items} VALUES (NULL,1237193225,'',NULL,1,1,1,NULL,NULL,NULL,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1237193225,0,NULL,NULL,'id','ASC',1,1); DROP TABLE IF EXISTS {items_tags}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -312,7 +312,7 @@ CREATE TABLE {users} ( UNIQUE KEY `hash` (`hash`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {users} VALUES (1,'guest','Guest User','5aLTa63b51ea433382249bc5e16d0ecbe6c5',0,0,NULL,0,1,NULL,NULL,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL,NULL,NULL); +INSERT INTO {users} VALUES (1,'guest','Guest User','jZstacc6b8aca100c7d53663c65ef1e3428c',0,0,NULL,0,1,NULL,NULL,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL,NULL,NULL); DROP TABLE IF EXISTS {vars}; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -325,4 +325,4 @@ CREATE TABLE {vars} ( UNIQUE KEY `module_name` (`module_name`,`name`) ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO {vars} VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','default_locale','en_US'),(7,'core','graphics_toolkit','imagemagick'),(8,'core','graphics_toolkit_path','/usr/bin'),(9,'core','blocks_dashboard_sidebar','a:1:{i:1796642454;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(10,'core','blocks_dashboard_center','a:1:{i:666854679;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(11,'core','version','3.0'),(12,'comment','spam_caught','0'); +INSERT INTO {vars} VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','default_locale','en_US'),(7,'core','graphics_toolkit','imagemagick'),(8,'core','graphics_toolkit_path','/usr/bin'),(9,'core','blocks_dashboard_sidebar','a:4:{i:757340436;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:454213168;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:1443307249;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:997696381;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(10,'core','blocks_dashboard_center','a:4:{i:1396928874;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:454790507;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:902866042;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:276132468;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(11,'core','version','3.0'),(12,'comment','spam_caught','0'); |