diff --git a/Application/InstallerAbstract.php b/Application/InstallerAbstract.php index 4fe8ea7fa..1b4ef602f 100644 --- a/Application/InstallerAbstract.php +++ b/Application/InstallerAbstract.php @@ -19,6 +19,7 @@ use phpOMS\Config\SettingsInterface; use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder; +use phpOMS\System\File\Local\Directory; /** * Installer abstract class. @@ -44,28 +45,9 @@ abstract class InstallerAbstract public static function install(DatabasePool $dbPool, ApplicationInfo $info, SettingsInterface $cfgHandler) : void { self::createTables($dbPool, $info); - self::registerInDatabase($dbPool, $info); self::installSettings($dbPool, $info, $cfgHandler); self::activate($dbPool, $info); - } - - /** - * Register app in database. - * - * @param DatabasePool $dbPool Database instance - * @param ApplicationInfo $info App info - * - * @return void - * - * @since 1.0.0 - */ - public static function registerInDatabase(DatabasePool $dbPool, ApplicationInfo $info) : void - { - $queryApp = new Builder($dbPool->get('insert')); - $queryApp->insert('app_name', 'app_theme', 'app_status') - ->into('app') - ->values($info->getInternalName(), 'Default', ApplicationStatus::NORMAL) - ->execute(); + self::installTheme(__DIR__ . '/../../Web/' . $info->getInternalName(), 'Default'); } /** @@ -184,7 +166,7 @@ abstract class InstallerAbstract public static function reInit(ApplicationInfo $info) : void { $class = '\\Web\\' . $info->getInternalName() . '\\Admin\\Status'; - $class::activateRoutes($appInfo); - $class::activateHooks($appInfo); + $class::activateRoutes($info); + $class::activateHooks($info); } } diff --git a/Application/StatusAbstract.php b/Application/StatusAbstract.php index c82533b71..cfa9414f3 100644 --- a/Application/StatusAbstract.php +++ b/Application/StatusAbstract.php @@ -16,6 +16,10 @@ namespace phpOMS\Application; use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\Utils\Parser\Php\ArrayParser; +use phpOMS\System\File\PermissionException; +use phpOMS\System\File\PathException; +use phpOMS\Utils\ArrayUtils; /** * Status abstract class. @@ -43,7 +47,6 @@ abstract class StatusAbstract { self::activateRoutes($info); self::activateHooks($info); - self::activateInDatabase($dbPool, $info); } /** @@ -267,25 +270,6 @@ abstract class StatusAbstract \file_put_contents($destHookPath, 'get('update')); - $query->update('app') - ->sets('app.app_status', ApplicationStatus::NORMAL) - ->where('app.app_name', '=', $info->getInternalName()) - ->execute(); - } - /** * Deactivate app. * @@ -300,25 +284,5 @@ abstract class StatusAbstract { self::deactivateRoutes($info); self::deactivateHooks($info); - self::deactivateInDatabase($dbPool, $info); - } - - /** - * Deactivate app in database. - * - * @param DatabasePool $dbPool Database instance - * @param ApplicationInfo $info Module info - * - * @return void - * - * @since 1.0.0 - */ - public static function deactivateInDatabase(DatabasePool $dbPool, ApplicationInfo $info) : void - { - $query = new Builder($dbPool->get('update')); - $query->update('app') - ->sets('app.app_status', ApplicationStatus::DISABLED) - ->where('app.app_name', '=', $info->getInternalName()) - ->execute(); } } diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index f125b9688..805056a07 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -638,7 +638,7 @@ class DataMapperAbstract implements DataMapperInterface return -1; } - $objId = self::$db->con->lastInsertId(); + $objId = empty($id = self::getObjectId($obj, $refClass)) ? self::$db->con->lastInsertId() : $id; \settype($objId, static::$columns[static::$primaryField]['type']); return $objId; diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index be2adb756..a2dcf439c 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -30,46 +30,6 @@ use phpOMS\DataStorage\Database\Schema\Builder as SchemaBuilder; */ abstract class InstallerAbstract { - /** - * Register module in database. - * - * @param DatabasePool $dbPool Database instance - * @param ModuleInfo $info Module info - * - * @return void - * - * @since 1.0.0 - */ - public static function registerInDatabase(DatabasePool $dbPool, ModuleInfo $info) : void - { - $queryModule = new Builder($dbPool->get('insert')); - $queryModule->insert('module_id', 'module_theme', 'module_path', 'module_active', 'module_version') - ->into('module') - ->values($info->getInternalName(), 'Default', $info->getDirectory(), 0, $info->getVersion()) - ->execute(); - - $queryLoad = new Builder($dbPool->get('insert')); - $queryLoad->insert('module_load_pid', 'module_load_type', 'module_load_from', 'module_load_for', 'module_load_file') - ->into('module_load'); - - $load = $info->getLoad(); - foreach ($load as $val) { - foreach ($val['pid'] as $pid) { - $queryLoad->values( - \sha1(\str_replace('/', '', $pid)), - (int) $val['type'], - $val['from'], - $val['for'], - $val['file'] - ); - } - } - - if (!empty($queryLoad->getValues())) { - $queryLoad->execute(); - } - } - /** * Install module. * @@ -84,7 +44,6 @@ abstract class InstallerAbstract public static function install(DatabasePool $dbPool, ModuleInfo $info, SettingsInterface $cfgHandler) : void { self::createTables($dbPool, $info); - self::registerInDatabase($dbPool, $info); self::installSettings($dbPool, $info, $cfgHandler); self::activate($dbPool, $info); } @@ -99,6 +58,7 @@ abstract class InstallerAbstract * @return void * * @since 1.0.0 + * @todo move to admin module as providing option (like media providing `Admin.install.php` instead of Settings.install.php) */ public static function installSettings(DatabasePool $dbPool, ModuleInfo $info, SettingsInterface $cfgHandler) : void { diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index 03b335450..d1d3cbbbb 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -163,7 +163,7 @@ final class ModuleManager ->from('module_load') ->innerJoin('module')->on('module_load.module_load_from', '=', 'module.module_id')->orOn('module_load.module_load_for', '=', 'module.module_id') ->whereIn('module_load.module_load_pid', $uriHash) - ->andWhere('module.module_active', '=', 1) + ->andWhere('module.module_status', '=', ModuleStatus::ACTIVE) ->execute(); $this->uriLoad = $sth->fetchAll(\PDO::FETCH_GROUP); @@ -187,7 +187,7 @@ final class ModuleManager $query = new Builder($this->app->dbPool->get('select')); $sth = $query->select('module.module_path') ->from('module') - ->where('module.module_active', '=', 1) + ->where('module.module_status', '=', ModuleStatus::ACTIVE) ->execute(); $active = $sth->fetchAll(\PDO::FETCH_COLUMN); @@ -209,6 +209,20 @@ final class ModuleManager return $this->active; } + /** + * Is module installed + * + * @param string $module Module name + * + * @return bool + * + * @since 1.0.0 + */ + public function isInstalled(string $module) : bool + { + return isset($this->getInstalledModules(false)[$module]); + } + /** * Is module active * @@ -296,6 +310,7 @@ final class ModuleManager $query = new Builder($this->app->dbPool->get('select')); $sth = $query->select('module.module_path') ->from('module') + ->where('module_status', '!=', ModuleStatus::AVAILABLE) ->execute(); $installed = $sth->fetchAll(\PDO::FETCH_COLUMN); @@ -495,7 +510,6 @@ final class ModuleManager } $this->installed[$module] = $info; - $this->installDependencies($info->getDependencies()); $this->installModule($info); /* Install providing but only if receiving module is already installed */ @@ -575,22 +589,6 @@ final class ModuleManager } } - /** - * Install module dependencies. - * - * @param array $dependencies Module dependencies - * - * @return void - * - * @since 1.0.0 - */ - private function installDependencies(array $dependencies) : void - { - foreach ($dependencies as $key => $version) { - $this->install($key); - } - } - /** * Install module itself. * diff --git a/Module/StatusAbstract.php b/Module/StatusAbstract.php index e2d3d3052..79356870d 100644 --- a/Module/StatusAbstract.php +++ b/Module/StatusAbstract.php @@ -50,7 +50,6 @@ abstract class StatusAbstract { self::activateRoutes($info); self::activateHooks($info); - self::activateInDatabase($dbPool, $info); } /** @@ -214,25 +213,6 @@ abstract class StatusAbstract \file_put_contents($destHookPath, 'get('update')); - $query->update('module') - ->sets('module.module_active', ModuleStatus::ACTIVE) - ->where('module.module_id', '=', $info->getInternalName()) - ->execute(); - } - /** * Deactivate module. * @@ -247,7 +227,6 @@ abstract class StatusAbstract { self::deactivateRoutes($info); self::deactivateHooks($info); - self::deactivateInDatabase($dbPool, $info); } /** @@ -401,23 +380,4 @@ abstract class StatusAbstract \file_put_contents($destHookPath, 'get('update')); - $query->update('module') - ->sets('module.module_active', ModuleStatus::INACTIVE) - ->where('module.module_id', '=', $info->getInternalName()) - ->execute(); - } } diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index 33ab83793..6e9c04e55 100644 --- a/Utils/IO/Zip/Zip.php +++ b/Utils/IO/Zip/Zip.php @@ -46,7 +46,7 @@ class Zip implements ArchiveInterface } if (\is_string($sources)) { - $sources = [$sources]; + $sources = [$sources => '']; } /** @@ -57,7 +57,7 @@ class Zip implements ArchiveInterface $source = $relative; } - $source = \str_replace('\\', '/', $source); + $source = FileUtils::absolute(\str_replace('\\', '/', $source)); $relative = \str_replace('\\', '/', $relative); if (\is_dir($source)) { @@ -78,7 +78,7 @@ class Zip implements ArchiveInterface $absolute = \realpath($file); $absolute = \str_replace('\\', '/', (string) $absolute); - $dir = \rtrim($relative, '/\\') . '/' . \ltrim(\str_replace($source . '/', '', $absolute), '/\\'); + $dir = \ltrim(\rtrim($relative, '/\\') . '/' . \ltrim(\str_replace($source . '/', '', $absolute), '/\\'), '/\\'); if (\is_dir($absolute)) { $zip->addEmptyDir($dir . '/'); @@ -101,7 +101,7 @@ class Zip implements ArchiveInterface */ public static function unpack(string $source, string $destination) : bool { - if (!\is_file($source)) { + if (!\is_file($source) || \is_dir($destination)) { return false; }