From c136a2e84aade9125b7df95607949834fc02b952 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 19 Jan 2009 05:16:55 +0000 Subject: Packager now does a clean reinstall of just the packages we want, then rebuilds the install.sql and init_var.php files accordingly. --- core/controllers/welcome.php | 162 ++++++++++++++++++------------------ core/helpers/module.php | 4 +- core/views/welcome.html.php | 5 +- core/views/welcome_package.html.php | 33 -------- installer/init_var.php | 18 ++-- installer/install.sql | 59 ++++++++++--- 6 files changed, 137 insertions(+), 144 deletions(-) delete mode 100644 core/views/welcome_package.html.php diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php index d957e335..ab23fe99 100644 --- a/core/controllers/welcome.php +++ b/core/controllers/welcome.php @@ -53,7 +53,6 @@ class Welcome_Controller extends Template_Controller { $this->_load_group_info(); $this->_load_comment_info(); $this->_load_tag_info(); - $this->_load_table_info(); restore_error_handler(); $this->_create_directories(); @@ -64,7 +63,7 @@ class Welcome_Controller extends Template_Controller { } } - function install($module_name) { + function install($module_name, $redirect=true) { $to_install = array(); if ($module_name == "*") { foreach (module::available() as $module_name => $info) { @@ -83,10 +82,12 @@ class Welcome_Controller extends Template_Controller { module::install($module_name); } - url::redirect("welcome"); + if ($redirect) { + url::redirect("welcome"); + } } - function uninstall($module_name) { + 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 @@ -118,7 +119,9 @@ class Welcome_Controller extends Template_Controller { } else { module::uninstall($module_name); } - url::redirect("welcome"); + if ($redirect) { + url::redirect("welcome"); + } } function mptt() { @@ -465,94 +468,87 @@ class Welcome_Controller extends Template_Controller { } } - private function _load_table_info() { - $this->template->package = new View("welcome_package.html"); + public function package() { + $this->auto_render = false; + + // Cleanly uninstalling and reinstalling within the same request requires us to do the "cache + // invalidation" cha-cha. It's a dance of many steps. + $this->uninstall("core", false); + module::$module_names = array(); + module::$modules = array(); + Database::instance()->clear_cache(); + $this->install("core", false); module::load_modules(); - $modules = module::installed(); - $this->template->package->installed = array(); - foreach (array_keys($modules) as $module_name) { - $this->template->package->installed[$module_name] = $module_name == "core" || $module_name == "user"; + foreach (array("core", "user", "comment", "info", + "media_rss", "search", "slideshow", "tag") as $module_name) { + $this->install($module_name, false); } + url::redirect("welcome/dump_database"); } - public function package() { + public function dump_database() { $this->auto_render = false; - try { - $tables = array("sessions"); // The sessions table doesn't have a module so include it - $modules = array_fill_keys(array_merge(array("core", "user"), $_POST["include"]), 1); - - foreach (array(APPPATH . "models/*.php", MODPATH . "*/models/*.php") as $path) { - foreach (glob($path) as $file) { - if (preg_match("#.*/(.*)/models/(.*)\.php$#", $file, $matches)) { - if (!empty($modules[$matches[1]])) { - $tables[] = "{$matches[2]}s"; - } - } - } - } - $var_dir = dir(VARPATH); - $init_g3 = array("read()) { - if ($entry == "." || $entry == "..") { - continue; - } - if (is_dir(VARPATH . $entry) & $entry != "g3_installer") { - $sub_dirs[] = "\"$entry\""; - } - } - $var_dir->close(); - - $init_g3 = array_merge($init_g3, array( - "foreach (array(" . implode(", ", $sub_dirs) . ") as \$dir) {", - " if (!@mkdir(\"var/\$dir\")) {", - " throw new Exception(\"Unable to create directory '\$dir'\");", - " }", - " chmod(\"var/\$dir\", 0777);", - "}")); - - $install_data = VARPATH . "g3_installer/"; - if (!file_exists($install_data)) { - mkdir($install_data); - chmod($install_data, 0775); - } + // We now have a clean install with just the packages that we want. Make sure that the + // database is clean too. + $db = Database::instance(); + $db->query("TRUNCATE `sessions`"); + $db->query("TRUNCATE `logs`"); + $db->query("UPDATE `users` SET `password` = '' WHERE `id` = 2"); + + $dbconfig = Kohana::config('database.default'); + $dbconfig = $dbconfig["connection"]; + $pass = $dbconfig["pass"] ? "-p{$dbconfig['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"; + exec($command, $output, $status); + if ($status) { + print "
";
+      print "$command\n";
+      print "Failed to dump database\n";
+      print implode("\n", $output);
+      return;
+    }
+    url::redirect("welcome/dump_var");
+  }
+
+  public function dump_var() {
+    $this->auto_render = false;
 
-      file_put_contents("$install_data/init_var.php", implode("\n", $init_g3));
-
-      // Dump the database tables and data.
-      $dbconfig = Kohana::config('database.default');
-      $dbconfig = $dbconfig["connection"];
-      $db_install_sql = "{$install_data}install.sql";
-      $command = "mysqldump --compact --add-drop-table -h{$dbconfig['host']} " .
-          "-u{$dbconfig['user']} -p{$dbconfig['pass']} $no_data {$dbconfig['database']} " .
-          "> \"$db_install_sql\"";
-      exec($command, $output, $status);
-      if ($status) {
-        Kohana::log("alert", implode("\n", $output));
-        throw new Exception("@TODO FAILED TO DUMP DATABASE SEE LOGS");
+    $objects = new RecursiveIteratorIterator(
+      new RecursiveDirectoryIterator(VARPATH),
+      RecursiveIteratorIterator::SELF_FIRST);
+
+    $var_file = DOCROOT . "installer/init_var.php";
+    if (!is_writable($var_file)) {
+      print "$var_file is not writeable";
+      return;
+    }
+
+    $fd = fopen($var_file, "w");
+    fwrite($fd, " $file){
+      if ($file->getBasename() == "database.php") {
+        continue;
+      } else if (basename($file->getPath()) == "logs") {
+        continue;
       }
 
-      $installer_path = DOCROOT . "installer/data";
-      print json_encode(
-        array("result" => "success",
-              "message" => "Gallery3 initial sql created. 
Copy the files from " . - "'$install_data' to
'$installer_path'.")); - } catch(Exception $e) { - Kohana::log("alert", $e->getMessage() . "\n" . $e->getTraceAsString()); - print json_encode( - array("result" => "error", - "message" => $e->getMessage())); + if ($file->isDir()) { + fwrite($fd, "mkdir(\"var/" . substr($name, strlen(VARPATH)) . "\");\n"); + } else { + // @todo: serialize non-directories + print "Unknown file: $name"; + return; + } } + fclose($fd); + url::redirect("welcome"); } public function add_user() { diff --git a/core/helpers/module.php b/core/helpers/module.php index b45f6c78..70e9bec6 100644 --- a/core/helpers/module.php +++ b/core/helpers/module.php @@ -24,8 +24,8 @@ * Note: by design, this class does not do any permission checking. */ class module_Core { - private static $module_names = array(); - private static $modules = array(); + public static $module_names = array(); + public static $modules = array(); static function get_version($module_name) { return ORM::factory("module")->where("name", $module_name)->find()->version; diff --git a/core/views/welcome.html.php b/core/views/welcome.html.php index 27aa6184..be801163 100644 --- a/core/views/welcome.html.php +++ b/core/views/welcome.html.php @@ -295,7 +295,10 @@ - +
+ Packaging + ">Make Package +
Rearrange diff --git a/core/views/welcome_package.html.php b/core/views/welcome_package.html.php deleted file mode 100644 index 6996dda6..00000000 --- a/core/views/welcome_package.html.php +++ /dev/null @@ -1,33 +0,0 @@ - - -
- Create install.sql -

Press the button to extract the initial database configuration.

-
" method="POST"> - -
-
-
-
diff --git a/installer/init_var.php b/installer/init_var.php index 42d50c0a..471de7e7 100644 --- a/installer/init_var.php +++ b/installer/init_var.php @@ -1,13 +1,7 @@ API Key','3'); DROP TABLE IF EXISTS `modules`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -183,9 +193,9 @@ CREATE TABLE `modules` ( `version` int(9) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO `modules` VALUES (1,'core',1),(2,'user',1),(3,'comment',1),(4,'akismet',1); +INSERT INTO `modules` VALUES (1,'core',1),(2,'user',1),(3,'comment',1),(4,'info',1),(5,'media_rss',1),(6,'search',1),(7,'slideshow',1),(8,'tag',1); DROP TABLE IF EXISTS `permissions`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -198,6 +208,19 @@ CREATE TABLE `permissions` ( ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; INSERT INTO `permissions` VALUES (1,'view','View'),(2,'view_full','View Full Size'),(3,'edit','Edit'); +DROP TABLE IF EXISTS `search_records`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `search_records` ( + `id` int(9) NOT NULL auto_increment, + `item_id` int(9) default NULL, + `dirty` tinyint(1) default '1', + `data` longtext, + PRIMARY KEY (`id`), + FULLTEXT KEY `data` (`data`) +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; +INSERT INTO `search_records` VALUES (1,1,0,'Welcome to your Gallery3 Gallery '); DROP TABLE IF EXISTS `sessions`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -208,7 +231,17 @@ CREATE TABLE `sessions` ( PRIMARY KEY (`session_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO `sessions` VALUES ('7d414ede0f86afc6079a90e424b51c41',1232179528,'c2Vzc2lvbl9pZHxzOjMyOiI3ZDQxNGVkZTBmODZhZmM2MDc5YTkwZTQyNGI1MWM0MSI7dG90YWxfaGl0c3xpOjc0O19rZl9mbGFzaF98YTowOnt9dXNlcl9hZ2VudHxzOjkwOiJNb3ppbGxhLzUuMCAoV2luZG93czsgVTsgV2luZG93cyBOVCA1LjE7IGVuLVVTOyBydjoxLjkuMC41KSBHZWNrby8yMDA4MTIwMTIyIEZpcmVmb3gvMy4wLjUiO2lwX2FkZHJlc3N8czoxMzoiMjQuNjkuMjExLjEzNSI7bGFzdF9hY3Rpdml0eXxpOjEyMzIxNzk1MjE7dXNlcnxPOjEwOiJVc2VyX01vZGVsIjo2OntzOjE0OiIAKgBvYmplY3RfbmFtZSI7czo0OiJ1c2VyIjtzOjk6IgAqAG9iamVjdCI7YToxMDp7czoyOiJpZCI7aToyO3M6NDoibmFtZSI7czo1OiJhZG1pbiI7czo5OiJmdWxsX25hbWUiO3M6MjE6IkdhbGxlcnkgQWRtaW5pc3RyYXRvciI7czo4OiJwYXNzd29yZCI7czozNjoiU1VdNjMzMjY3NDhiNT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ZGJhNSI7czoxMToibG9naW5fY291bnQiO2k6MDtzOjEwOiJsYXN0X2xvZ2luIjtpOjA7czo1OiJlbWFpbCI7TjtzOjU6ImFkbWluIjtpOjA7czo1OiJndWVzdCI7aToxO3M6MzoidXJsIjtOO31zOjEwOiIAKgBjaGFuZ2VkIjthOjA6e31zOjk6IgAqAGxvYWRlZCI7YjoxO3M6ODoiACoAc2F2ZWQiO2I6MTtzOjEwOiIAKgBzb3J0aW5nIjthOjE6e3M6MjoiaWQiO3M6MzoiYXNjIjt9fWdyb3VwX2lkc3xhOjE6e2k6MDtpOjE7fWNzcmZ8czozMjoiYzlhZDY2YmFjMzRhYjk5Y2NmOTRiMGEwMjhkNWI3ZWQiOw=='); +DROP TABLE IF EXISTS `tags`; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +CREATE TABLE `tags` ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(64) NOT NULL, + `count` int(10) unsigned NOT NULL default '0', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS `tasks`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -255,7 +288,7 @@ CREATE TABLE `users` ( UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; -INSERT INTO `users` VALUES (1,'guest','Guest User','mP`hf6bf25b90e2765ffe2e65737b142dba5',0,0,NULL,0,1,NULL),(2,'admin','Gallery Administrator','SU]63326748b5026b4d7b5d5c8c83a266743',1,1232172351,NULL,1,0,NULL); +INSERT INTO `users` VALUES (1,'guest','Guest User','qb9ta17514f489c7c0d46c6832c678849e47',0,0,NULL,0,1,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL); DROP TABLE IF EXISTS `vars`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; @@ -266,6 +299,6 @@ CREATE TABLE `vars` ( `value` text, PRIMARY KEY (`id`), UNIQUE KEY `module_name` (`module_name`,`name`) -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=12 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','graphics_toolkit','imagemagick'),(7,'core','graphics_toolkit_path','/usr/bin'),(8,'core','dashboard_blocks','a:2:{s:7:\"sidebar\";a:3:{i:1897057832;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:863091211;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1286303073;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}s:4:\"main\";a:4:{i:1969666309;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:353682022;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:1636721943;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:458629768;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}}'),(9,'core','version','3.0'),(10,'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','graphics_toolkit','imagemagick'),(7,'core','graphics_toolkit_path','/usr/bin'),(8,'core','blocks_dashboard_sidebar','a:4:{i:296985161;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:226504839;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:603830327;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1728549679;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(9,'core','blocks_dashboard_center','a:4:{i:1086295926;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:55717447;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:1368963415;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:2029466538;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(10,'core','version','3.0'),(11,'comment','spam_caught','0'); -- cgit v1.2.3