From 71db2ca32a5393efcedcd3a5e4a541174de71c40 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 16 Jan 2009 23:58:48 +0000 Subject: Add a scaffolding tab that allows packaging up the installation for installation. At the moment, it just creates an *.sql table for each defined table. I still need to zip this and put some install code around it so it is self installing. The ajax call will build the tables, but it doesn't return the resilt correctly. What it does is return my json response(expected) and the entire welcome.html page as well (unexpected) and i'm havinf trouble figuring out why. Something stupid i bet --- core/controllers/welcome.php | 69 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'core/controllers') diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php index 019bb609..28981c74 100644 --- a/core/controllers/welcome.php +++ b/core/controllers/welcome.php @@ -53,7 +53,7 @@ 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(); @@ -465,6 +465,73 @@ class Welcome_Controller extends Template_Controller { } } + private function _load_table_info() { + //$db = Database::instance(); + //$tables = $db->list_tables(); + //foreach ($tables as $table) { + //$this->template->tables[$table] = $table == "logs" || $table == "sessions"; + //} + //foreach (array_merge(glob(APPPATH . "models/*.php"), glob(MODPATH . "*/models/*.php")) as $file) { + // print $file . "
"; + //} + $this->template->package = new View("welcome_package.html"); + 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"; + } + } + + public function package() { + try { + $tables = array("sessions"); // The sessions table doesn't have a module so include it + $modules = array_fill_keys($_POST["include"], 1); + $modules["user"] = 1; + + foreach (glob(APPPATH . "models/*.php") as $file) { + if (preg_match("#/models/(.*)\.php$#", $file, $matches)) { + $tables[] = "{$matches[1]}s"; + } + } + foreach (glob(MODPATH . "*/models/*.php") as $file) { + if (preg_match("#/modules/(.*)/models/(.*)\.php$#", $file, $matches)) { + if (!empty($modules[$matches[1]])) { + $tables[] = "{$matches[2]}s"; + } + } + } + + $temp_dir = VARPATH; + foreach (array("packaging", "sql") as $dir) { + $temp_dir .= "$dir/"; + if (!file_exists($temp_dir)) { + mkdir($temp_dir); + chmod($temp_dir, 0777); + } + } + + $dbconfig = Kohana::config('database.default'); + $dbconfig = $dbconfig["connection"]; + foreach ($tables as $table) { + $backupfile = "$temp_dir$table.sql"; + $no_data = ($table == "sessions" || $table == "logs") ? " -d" : ""; + $command = "mysqldump --compact --add-drop-table -h{$dbconfig['host']} " . + "-u{$dbconfig['user']} -p{$dbconfig['pass']} $no_data {$dbconfig['database']} " . + "$table > \"$backupfile\""; + system($command); + } + + print json_encode( + array("result" => "success", + "message" => "Gallery3 packaged to var/packaging/gallery3.tar.gz")); + } catch(Exception $e) { + print json_encode( + array("result" => "error", + "message" => $e->getMessage())); + } + } + public function add_user() { $name = $this->input->post("user_name"); $isAdmin = (bool)$this->input->post("admin"); -- cgit v1.2.3