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

This commit is contained in:
Tim Almdal
2009-01-16 23:58:48 +00:00
parent a7b6409b74
commit 71db2ca32a
3 changed files with 124 additions and 2 deletions
+68 -1
View File
@@ -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 . "<br/>";
//}
$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");
+6 -1
View File
@@ -9,7 +9,7 @@
}
div.outer {
width: 600px;
width: 650px;
background: white;
border: 1px solid black;
margin: 0 auto;
@@ -206,6 +206,7 @@
<li><a href="javascript:show('info')">Info</a></li>
<li><a href="javascript:show('benchmarks')">Benchmarks</a></li>
<li><a href="javascript:show('docs')">Docs</a></li>
<li><a href="javascript:show('package')">Packaging</a></li>
<? endif ?>
</ul>
@@ -484,6 +485,10 @@
</li>
</ul>
</div>
<div id="package" class="activity">
<?= $package ?>
</div>
</div>
</div>
</div>
+50
View File
@@ -0,0 +1,50 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<script>
$("#package").ready(function() {
ajaxify_package_form();
});
function ajaxify_package_form() {
$("#package form").ajaxForm({
dataType: "json",
success: function(data) {
if (data.result == "success") {
$("#package .success").html(data.message);
$("#package .success").removeClass("gHide");
$("#package .error").addClass("gHide");
} else {
$("#package .error").html(data.message);
$("#package .error").removeClass("gHide");
$("#package .success").addClass("gHide");
}
}
});
};
</script>
<p>Press the button to package this the modules as an installation package.</p>
<form action="<?= url::site("welcome/package") ?>" method="POST">
<table style="width: 400px">
<tr>
<th align="left">Include</th>
<th align="left">Module</th>
</tr>
<? foreach ($installed as $module_name => $required): ?>
<tr>
<td>
<input type="checkbox" name="include[]" value="<?= $module_name ?>" checked
<? if (!empty($required)): ?> disabled="disabled"<? endif ?>
/>
</td>
<td><?= $module_name ?></td>
</tr>
<? endforeach ?>
<tr>
<td colspan="2" align="center">
<input type="Submit" value="Package" />
</td>
</tr>
</table>
<div id="SuccessMsg" class="success gHide"></div>
<div id="FailMsg" class="error gHide"></div>
</form>