mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
bug fixes
This commit is contained in:
parent
e8cae23ca9
commit
9ae2cd45ed
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, '<?php return ' . ArrayParser::serializeArray($appHooks) . ';', \LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate app in database.
|
||||
*
|
||||
* @param DatabasePool $dbPool Database instance
|
||||
* @param ApplicationInfo $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function activateInDatabase(DatabasePool $dbPool, ApplicationInfo $info) : void
|
||||
{
|
||||
$query = new Builder($dbPool->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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<string, string> $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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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, '<?php return ' . ArrayParser::serializeArray($appHooks) . ';', \LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate module in database.
|
||||
*
|
||||
* @param DatabasePool $dbPool Database instance
|
||||
* @param ModuleInfo $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function activateInDatabase(DatabasePool $dbPool, ModuleInfo $info) : void
|
||||
{
|
||||
$query = new Builder($dbPool->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, '<?php return ' . ArrayParser::serializeArray($appHooks) . ';', \LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate module in database.
|
||||
*
|
||||
* @param DatabasePool $dbPool Database instance
|
||||
* @param ModuleInfo $info Module info
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function deactivateInDatabase(DatabasePool $dbPool, ModuleInfo $info) : void
|
||||
{
|
||||
$query = new Builder($dbPool->get('update'));
|
||||
$query->update('module')
|
||||
->sets('module.module_active', ModuleStatus::INACTIVE)
|
||||
->where('module.module_id', '=', $info->getInternalName())
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user