summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/welcome.php69
-rw-r--r--core/views/welcome.html.php7
-rw-r--r--core/views/welcome_package.html.php50
3 files changed, 124 insertions, 2 deletions
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 . "<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");
diff --git a/core/views/welcome.html.php b/core/views/welcome.html.php
index 4b9e8fa8..73deedb9 100644
--- a/core/views/welcome.html.php
+++ b/core/views/welcome.html.php
@@ -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>
diff --git a/core/views/welcome_package.html.php b/core/views/welcome_package.html.php
new file mode 100644
index 00000000..913e7820
--- /dev/null
+++ b/core/views/welcome_package.html.php
@@ -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>