From 8a9a28a71e6cb12236a5af29a5cb97cd5d3b6415 Mon Sep 17 00:00:00 2001 From: stefan Date: Thu, 15 Aug 2024 20:37:13 +0200 Subject: [PATCH 1/2] module migration bugfixes --- .../action/packagemgr/modules/base.php | 4 +- inc/module/module.php | 84 +++++++++++-------- version.txt | 2 +- 3 files changed, 53 insertions(+), 37 deletions(-) diff --git a/inc/controller/action/packagemgr/modules/base.php b/inc/controller/action/packagemgr/modules/base.php index 0e43aa26d..4b908516d 100644 --- a/inc/controller/action/packagemgr/modules/base.php +++ b/inc/controller/action/packagemgr/modules/base.php @@ -104,8 +104,8 @@ public function process() { $updater = (new \fpcm\model\updater\modules())->getDataCachedByKey($this->key); $this->steps['pkgKey'] = $this->key; - $this->steps['pkgurl'] = $updater['packageUrl']; - $this->steps['pkgname'] = basename($updater['packageUrl']); + $this->steps['pkgurl'] = $updater['packageUrl'] ?? ''; + $this->steps['pkgname'] = $updater['packageUrl'] ? basename($updater['packageUrl']) : ''; $this->steps['pkgsize'] = isset($updater->size) && $updater->size ? '(' . \fpcm\classes\tools::calcSize($updater->size) . ')' : ''; $this->view->setViewVars($this->steps); diff --git a/inc/module/module.php b/inc/module/module.php index 69f08edd4..82e5ce3b6 100644 --- a/inc/module/module.php +++ b/inc/module/module.php @@ -9,7 +9,7 @@ /** * Module base model - * + * * @author Stefan Seehafer * @copyright (c) 2011-2022, Stefan Seehafer * @license http://www.gnu.org/licenses/gpl.txt GPLv3 @@ -232,7 +232,7 @@ final public function getOptions() : array } /** - * + * * @return paths * @since 5.0.0-b1 */ @@ -259,7 +259,7 @@ public function getConfigViewVars() : array * Fetch system config options * @return array */ - + /** * Updates module options * @param array $options @@ -271,11 +271,11 @@ final public function setOptions(array $options) : bool $this->systemConfig->setNewConfig($options); $res = $this->systemConfig->update(); - + if (!$res) { return false; } - + $this->systemConfig->init(); $this->cache->cleanup(); @@ -356,10 +356,10 @@ public function isInstallable() : bool if (defined('FPCM_MODULE_IGNORE_DEPENDENCIES') && FPCM_MODULE_IGNORE_DEPENDENCIES) { return true; } - + $phpVersion = ''; $sysVersion = ''; - + $this->getVersionStrings($phpVersion, $sysVersion); if (version_compare(PHP_VERSION, $phpVersion, '<')) { return false; @@ -382,7 +382,7 @@ public function hasUpdates() : bool if ($data === false) { return false; } - + $phpVersion = ''; $sysVersion = ''; @@ -411,9 +411,9 @@ public function hasLocalUpdates() : bool return version_compare((new config($this->mkey, null))->version, $this->config->version, '=') ? false : true; } - + /** - * + * * Check if configure action should be displayed * @return bool */ @@ -463,7 +463,7 @@ final public function hasMigrations() : bool */ final public function getMigrations() : array { - $files = glob( $this->getConfigPathFromCurrent('migrations' . DIRECTORY_SEPARATOR . 'v*.php') ); + $files = glob( $this->config->basePath . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR . 'v*.php' ); if (!is_array($files) && !count($files)) { return []; } @@ -498,18 +498,34 @@ protected function init() : bool * @param string $key * @return string */ - public function getFullPrefix($key = '') : string + final public function getFullPrefix($key = '') : string { return 'module_' . $this->prefix . '_' . $key; } + /** + * + * @param string $tableName + * @return null|\fpcm\model\system\yatdl + * @since 5.2.1-rc2 + */ + final public function getTableObject(string $tableName) : null|\fpcm\model\system\yatdl + { + $filePath = $this->getConfigPathFromCurrent('tables' . DIRECTORY_SEPARATOR . $tableName . '.yml'); + if (!file_exists($t)) { + return null; + } + + return $this->getYaTdlObject($filePath); + } + /** * Return path for "config/" folder in current module base path * @param string $dest * @return string * @since 4.5-rc3 */ - private function getConfigPathFromCurrent(string $dest) : string + final public function getConfigPathFromCurrent(string $dest) : string { return rtrim($this->config->basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $dest; } @@ -587,7 +603,7 @@ private function getAllConfigOptions() : array $configOptions = $this->config->configOptions; return is_array($configOptions) && count($configOptions) ? $configOptions : []; } - + $configOptions = array_unique(array_merge($addcfg, $delcfg)); if (!count($configOptions)) { return []; @@ -662,7 +678,7 @@ final public function install($fromDir = false) : bool return false; } - $this->cache->cleanup(); + $this->cache->cleanup(); return true; } @@ -726,9 +742,9 @@ private function installConfig() : bool if (!count($configOptions)) { return true; } - + fpcmLogSystem('Add modules config options for ' . $this->mkey); - + $sysConfig = new \fpcm\model\system\config(false); foreach ($configOptions as $key => $value) { $key = $this->getFullPrefix($key); @@ -748,12 +764,12 @@ private function installConfig() : bool private function installUpdateCronjobs() : bool { fpcmLogSystem('Add modules cronjobs for ' . $this->mkey); - + $crons = $this->config->crons; if (!is_array($crons) || !count($crons)) { return true; } - + $cronjobs = $this->db->selectFetch( (new \fpcm\model\dbal\selectParams(\fpcm\classes\database::tableCronjobs)) ->setItem('id, cjname') @@ -762,15 +778,15 @@ private function installUpdateCronjobs() : bool ->setFetchStyle(\PDO::FETCH_KEY_PAIR) ->setFetchAll(true) ); - + if (!is_array($cronjobs)) { $cronjobs = []; } $failed = []; foreach ($crons as $name => $interval) { - - + + $className = self::getCronNamespace($this->mkey, $name); if (!class_exists($className)) { trigger_error("Unable to add cronjob, class {$className} does not exists!"); @@ -801,9 +817,9 @@ private function installUpdateCronjobs() : bool return true; } - + /** - * + * * Uninstall module * @param bool $delete * @param bool $keepFiles @@ -920,7 +936,7 @@ private function removeConfig() : bool private function removeCronjobs() : bool { fpcmLogSystem('Remove modules cronjobs for ' . $this->mkey); - + $crons = $this->config->crons; if (!is_array($crons) || !count($crons)) { fpcmLogSystem('No cronjobs for ' . $this->mkey); @@ -998,9 +1014,9 @@ final public function createDataFolder() : bool fpcmLogSystem('Module data path folder aready exists: ' . $this->getDataPath()); return true; } - + fpcmLogSystem('Create module data path ' . $this->mkey . ' : ' . $this->getDataPath()); - + if (mkdir($this->getDataPath())) { return true; } @@ -1025,9 +1041,9 @@ final public function removeDataFolder() : bool fpcmLogSystem('No data folder for ' . $this->mkey); return true; } - + fpcmLogSystem('Remove module data path ' . $this->mkey . ' : ' . $this->getDataPath()); - + if (\fpcm\model\files\ops::deleteRecursive($this->getDataPath())) { fpcmLogSystem('Data folder removed for ' . $this->mkey); return true; @@ -1161,7 +1177,7 @@ private function runMigrations() : bool $migrations = $this->getMigrations(); if (!count($migrations)) { return true; - } + } fpcmLogSystem("Processing module migrations for {$this->mkey}..."); @@ -1199,7 +1215,7 @@ private function runMigrations() : bool $this->output('Processing of migration '. get_class($migration).' failed!.'); return false; } - + return true; } @@ -1222,7 +1238,7 @@ private function getVersionStrings(string &$phpVersion, string &$sysVersion, arr } $phpRelease = \fpcm\classes\tools::getMajorMinorReleaseFromString(PHP_VERSION); - $phpVersion = is_array($data['php']) && + $phpVersion = is_array($data['php']) && $data['php'][$phpRelease] ? $data['php'][$phpRelease] @@ -1264,7 +1280,7 @@ public static function getKeyFromFilename($filename) : string return $filename; } - list($vendor, $key) = explode('_', $raw, 2); + list($vendor, $key) = explode('_', $raw, 2); return $vendor . '/' . $key; } @@ -1431,7 +1447,7 @@ public static function validateKey(string $key) : bool return false; } - return isset($match[0]); + return isset($match[0]); } } diff --git a/version.txt b/version.txt index 0a3de2323..e61ce6099 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -5.2.1-rc1 \ No newline at end of file +5.2.1-rc2 \ No newline at end of file From b8c2e9d434e5dd4a3e5d3f7bf3d83e8608932f4f Mon Sep 17 00:00:00 2001 From: stefan Date: Fri, 16 Aug 2024 11:07:38 +0200 Subject: [PATCH 2/2] module migration bugfixes --- inc/module/module.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/inc/module/module.php b/inc/module/module.php index 82e5ce3b6..46a8c091b 100644 --- a/inc/module/module.php +++ b/inc/module/module.php @@ -1186,7 +1186,18 @@ private function runMigrations() : bool }); $migrations = array_filter($migrations, function ($class) { - return class_exists($class) && is_subclass_of($class, '\\fpcm\\module\\migration'); + + if (!class_exists($class)) { + trigger_error(sprintf('Class not found %s', $class), E_USER_ERROR); + return false; + } + + if (!is_subclass_of($class, '\\fpcm\\module\\migration')) { + trigger_error(sprintf('Class %s must be an instance of \\fpcm\\module\\migration', $class), E_USER_ERROR); + return false; + } + + return true; }); if (!count($migrations)) { @@ -1341,6 +1352,10 @@ public static function getCronNamespace(string $key, string $cron) : string */ public static function getMigrationNamespace(string $key, string $migration) : string { + if (str_ends_with($migration, '.php')) { + $migration = basename($migration, '.php'); + } + return "\\fpcm\\modules\\" . str_replace('/', '\\', $key) . "\\migrations\\{$migration}"; }