mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-18 20:58:39 +00:00
Usage of InfoManager
This commit is contained in:
parent
1b0837af1e
commit
b4fae9cb67
|
|
@ -42,7 +42,7 @@ class InstallerAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
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');
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class UninstallAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function uninstall(Pool $dbPool, array $info)
|
||||
public static function uninstall(Pool $dbPool, InfoManager $info)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user