summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2008-11-04 22:18:00 +0000
committerTim Almdal <tnalmdal@shaw.ca>2008-11-04 22:18:00 +0000
commitd0629584b503be10a940766d8536c8ed0bd08bbe (patch)
treeb27660ec9d3ea426fe128a158d98a60a7bcc8099
parent605d2de336eac8c8f80b916d30989b347d813e94 (diff)
Have the scaffolding code see what what modules are available and list whether they need to be installed or uninstalled.
-rw-r--r--core/controllers/welcome.php73
-rw-r--r--core/views/welcome_syscheck.html.php13
2 files changed, 79 insertions, 7 deletions
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php
index a5719cf0..e704978a 100644
--- a/core/controllers/welcome.php
+++ b/core/controllers/welcome.php
@@ -25,13 +25,82 @@ class Welcome_Controller extends Template_Controller {
$this->template->syscheck->errors = $this->_get_config_errors();
try {
- $this->template->syscheck->modules = ORM::factory("module")->find_all();
+ $this->template->syscheck->modules = $this->_readModules();
} catch (Exception $e) {
$this->template->syscheck->modules = array();
}
- $this->_create_directories();
+ $this->_create_directories();
}
+ /**
+ * Create an array of all the modules that are install or available and the version number
+ * @return array(moduleId => version)
+ */
+ private function _readModules() {
+ $modules = array();
+ try {
+ $installed = ORM::factory("module")->find_all();
+ foreach ($installed as $installedModule) {
+ $modules[$installedModule->name] = $installedModule->version;
+ }
+ } catch (Exception $e) {}
+
+ if (!empty($modules['core'])) {
+ if ($dh = opendir(MODPATH)) {
+ while (($file = readdir($dh)) !== false) {
+ if ($file[0] != '.' &&
+ file_exists(MODPATH . "$file/helpers/{$file}_installer.php")) {
+ if (empty($modules[$file])) {
+ $modules[$file] = 0;
+ }
+ }
+ }
+ }
+ closedir($dh);
+ }
+
+ return $modules;
+ }
+
+ private function _find_available_modules() {
+ $installed = ORM::factory("module")->find_all();
+ $moduleList = array();
+ foreach ($installed as $installedModule) {
+ $moduleList[$installedModule->name] = 1;
+ }
+
+ var_dump($moduleList);
+ $modules = array();
+ $paths = Kohana::config('core.modules');
+ foreach ($paths as $path) {
+ $module = substr($path, strrpos($path, "/") + 1);
+ var_dump($module, "$path/helpers/{$module}_installer.php");
+ if (file_exists("$path/helpers/{$module}_installer.php")) {
+ $modules[$module] = !empty($moduleList[$module]) ? "install" : "unintall";
+ }
+// $installer_directory = "$module_path/helpers";
+// if (is_dir($controller_directory)) {
+// if ($dh = opendir($controller_directory)) {
+// while (($controller = readdir($dh)) !== false) {
+// if ($controller[0] == ".") {
+// continue;
+// }
+// $matches = array();
+// if (preg_match("#^admin_([a-zA-Z][a-z_A-Z0-9]*)\.php$#", $controller, $matches)) {
+// $descriptor = $this->_get_descriptor("Admin_" . ucfirst($matches[1]) . '_Controller');
+// if (!empty($descriptor)) {
+// $admin_controllers["admin/$matches[1]"] = $descriptor;
+// }
+// }
+// }
+// closedir($dh);
+// }
+// }
+ }
+
+ return $modules;
+ }
+
function install($module) {
call_user_func(array("{$module}_installer", "install"));
url::redirect("welcome");
diff --git a/core/views/welcome_syscheck.html.php b/core/views/welcome_syscheck.html.php
index 5f1a1945..63919c73 100644
--- a/core/views/welcome_syscheck.html.php
+++ b/core/views/welcome_syscheck.html.php
@@ -35,13 +35,16 @@
<th align="left">Version</th>
<th align="left">Action</th>
</tr>
- <? foreach ($modules as $module): ?>
+ <? foreach ($modules as $module_name => $module_version): ?>
<tr>
- <td><?= $module->name ?></td>
- <td><?= $module->version ?></td>
+ <td><?= $module_name ?></td>
+ <td><?= empty($module_version) ? "" : $module_version ?></td>
<td>
- <?= html::anchor("welcome/install/{$module->name}", "install") ?>,
- <?= html::anchor("welcome/uninstall/{$module->name}", "uninstall") ?>
+ <? if (empty($module_version)): ?>
+ <?= html::anchor("welcome/install/{$module_name}", "install") ?>
+ <? else: ?>
+ <?= html::anchor("welcome/uninstall/{$module_name}", "uninstall") ?>
+ <? endif; ?>
</td>
</tr>
<? endforeach; ?>