diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index 9e536afc7..09ff3a34b 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -42,7 +42,7 @@ class InstallerAbstract * @since 1.0.0 * @author Dennis Eichhorn */ - public static function install(Pool $dbPool, array $info) + public static function install(Pool $dbPool, InfoManager $info) { self::$installRoutes(ROOT_PATH . '/Web/Routes.php', ROOT_PATH . '/Modules/' . $info['directory'] . '/Admin/Routes/http.php'); diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index a1cebdc8b..c3c2f9543 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -296,18 +296,27 @@ class ModuleManager // todo download; } - $path = realpath($oldPath = self::MODULE_PATH . '/' . $module . '/' . 'info.json'); + $info = $this->loadInfo(); - if ($path === false || strpos($path, self::MODULE_PATH) === false) { - throw new PathException($module); + $this->registerInDatabase(); + $this->installDependencies($info->getDependencies()); + $this->installModule($module); + $this->installed[$module] = true; + + /* Install providing */ + $providing = $info->getProviding(); + foreach ($providing as $key => $version) { + $this->installProviding($module, $key); } - $info = json_decode(file_get_contents($path), true); - - if (!isset($info)) { - throw new InvalidJsonException($path); + /* Install receiving */ + foreach ($installed as $key => $value) { + $this->installProviding($key, $module); } + } + private function registerInDatabase(InfoManager $info) + { switch ($this->app->dbPool->get('core')->getType()) { case DatabaseType::MYSQL: $this->app->dbPool->get('core')->con->beginTransaction(); @@ -317,11 +326,11 @@ class ModuleManager (:internal, :theme, :path, :active, :version);' ); - $sth->bindValue(':internal', $info['name']['internal'], \PDO::PARAM_INT); + $sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT); $sth->bindValue(':theme', 'Default', \PDO::PARAM_STR); - $sth->bindValue(':path', $info['directory'], \PDO::PARAM_STR); + $sth->bindValue(':path', $info->getDirectory(), \PDO::PARAM_STR); $sth->bindValue(':active', 1, \PDO::PARAM_INT); - $sth->bindValue(':version', $info['version'], \PDO::PARAM_STR); + $sth->bindValue(':version', $info->getVersion(), \PDO::PARAM_STR); $sth->execute(); @@ -330,7 +339,8 @@ class ModuleManager (:pid, :type, :from, :for, :file);' ); - foreach ($info['load'] as $val) { + $load = $info->getLoad(); + foreach ($load as $val) { foreach ($val['pid'] as $pid) { $sth->bindValue(':pid', $pid, \PDO::PARAM_STR); $sth->bindValue(':type', $val['type'], \PDO::PARAM_INT); @@ -346,26 +356,41 @@ class ModuleManager break; } + } - foreach ($info['dependencies'] as $key => $version) { + private function installDependencies(array $dependencies) + { + foreach ($dependencies as $key => $version) { $this->install($key); } + } + + private function installModule(string $module) + { + $class = '\\Modules\\' . $module . '\\Admin\\Installer'; + + if(!Autoloader::exist($class)) { + throw new \Exception('Module installer does not exist'); + } + /** @var $class InstallerAbstract */ $class::install($this->app->dbPool, $info); + } - // TODO: change this - $this->installed[$module] = true; + private function loadInfo(string $module) : InfoManager + { + $path = realpath($oldPath = self::MODULE_PATH . '/' . $module . '/' . 'info.json'); - foreach ($info['providing'] as $key => $version) { - $this->installProviding($module, $key); + if ($path === false || strpos($path, self::MODULE_PATH) === false) { + throw new PathException($module); } - /* Install receiving */ - foreach ($installed as $key => $value) { - $this->installProviding($key, $module); - } + $info = InfoManager($module); + $info->load(); + + return $info; } /** diff --git a/Module/UninstallAbstract.php b/Module/UninstallAbstract.php index cfc9c06f6..9da0da83d 100644 --- a/Module/UninstallAbstract.php +++ b/Module/UninstallAbstract.php @@ -42,7 +42,7 @@ class UninstallAbstract * @since 1.0.0 * @author Dennis Eichhorn */ - public static function uninstall(Pool $dbPool, array $info) + public static function uninstall(Pool $dbPool, InfoManager $info) { }