5 * This module installs a chosen module using the data model definitions of the module. At the moment it is assumed that
6 * all dependencies is installed when trying to install a module.
7 * @author Sebastian Skejø
10 class Installer
extends AOOSModule
{
11 public function show() {
12 $url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
15 if (isset($_POST["module"])) {
16 if ($this->installModule($_POST["module"])) {
17 $str .= '<p style="color: green;">'.$_POST["module"].' installed successfully!</p>';
21 $str .= "<h1>Installed modules:</h1>";
22 foreach ($this->getInstalledModules() as $module) {
23 $str .= "<p>".$module."</p>";
25 $str .= "<h1>Uninstalled modules:</h1>";
26 foreach ($this->getUninstalledModules() as $module) {
27 $str .= '<form method="post" action="'.$url.'">
29 <input name="module" type="hidden" value="'.$module.'" />
30 <input type="submit" value="Install!" />
37 public function dataModelDefinition() {
38 $m = $this->core()->modules();
39 /* $m = new AOOSModel($this->core());
40 $m->setColumnIndex(array("NAME", "DEPS"));
42 $m->setProperty("NAME", AOOSMODEL_TYPE_STRING,
43 AOOSMODEL_PROP_FROM_DATABASE);*/
48 public function postInitialization() {
49 $m = $this->dataModel();
50 $m->setTable($this->core()->getSetting("module_table"));
55 * Returns an array with names of all uninstalled modules
58 public function getUninstalledModules() {
59 $all = $this->getAllModules();
60 $installed = $this->getInstalledModules();
61 $uninstalled = array();
63 foreach ($all as $module) {
64 if (!in_array($module, $installed)) {
65 $uninstalled[] = $module;
72 * Returns an array with names of all installed modules.
75 public function getInstalledModules() {
76 $modules = $this->getAllModules();
78 foreach ($modules as $module) {
79 if ($this->dataModel()->find(array("NAME" => $module)) !== false) {
80 $installed[] = $module;
87 * Returns an array containing names of both installed and uninstalled modules
90 public function getAllModules() {
91 $this->dataModel()->populate();
92 $d = dir($this->core()->getSetting("module_dir"));
94 while (false !== ($entry = $d->read())) {
95 $path = $this->core()->getSetting("module_dir").$entry;
96 if (is_dir($path) && $entry != "." && $entry != "..") {
104 * Tries to install $module. If install is successfull true is returned, otherwise an AOOSException is thrown and
106 * @param $module A string representing the module name
109 public function installModule($module) {
110 $path = $this->core()->getSetting("module_dir").$module."/".$module.$this->core()->getSetting("extension");
113 $deps = call_user_func(array($module,"dependencies"));
114 $this->dataModel()->insert(array("NAME" => $module,
115 "DEPS" => implode(",",$deps)));
116 $this->dataModel()->save();
117 print_r($this->core()->modules()->getColumn("NAME"));
119 $m = $this->core()->loadModule($module);
120 $m->dataModel()->create();
126 * Removes a module from the database. If the module is successfully removed true is returned. Otherwise false is
127 * returned. If $module isn't a module in the database an AOOSException is thrown.
128 * @param $module A string representing the module name
131 public function uninstallModule($module) {