Skip to content

Commit

Permalink
Merge pull request #31 from sea75300/dev
Browse files Browse the repository at this point in the history
Merge v5.2.1-rc2 dev into master
  • Loading branch information
sea75300 authored Aug 16, 2024
2 parents ae44506 + b8c2e9d commit 0cba31b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 38 deletions.
4 changes: 2 additions & 2 deletions inc/controller/action/packagemgr/modules/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
101 changes: 66 additions & 35 deletions inc/module/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Module base model
*
*
* @author Stefan Seehafer <[email protected]>
* @copyright (c) 2011-2022, Stefan Seehafer
* @license http://www.gnu.org/licenses/gpl.txt GPLv3
Expand Down Expand Up @@ -232,7 +232,7 @@ final public function getOptions() : array
}

/**
*
*
* @return paths
* @since 5.0.0-b1
*/
Expand All @@ -259,7 +259,7 @@ public function getConfigViewVars() : array
* Fetch system config options
* @return array
*/

/**
* Updates module options
* @param array $options
Expand All @@ -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();

Expand Down Expand Up @@ -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;
Expand All @@ -382,7 +382,7 @@ public function hasUpdates() : bool
if ($data === false) {
return false;
}

$phpVersion = '';
$sysVersion = '';

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 [];
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 [];
Expand Down Expand Up @@ -662,7 +678,7 @@ final public function install($fromDir = false) : bool
return false;
}

$this->cache->cleanup();
$this->cache->cleanup();
return true;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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')
Expand All @@ -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!");
Expand Down Expand Up @@ -801,9 +817,9 @@ private function installUpdateCronjobs() : bool

return true;
}

/**
*
*
* Uninstall module
* @param bool $delete
* @param bool $keepFiles
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -1161,7 +1177,7 @@ private function runMigrations() : bool
$migrations = $this->getMigrations();
if (!count($migrations)) {
return true;
}
}

fpcmLogSystem("Processing module migrations for {$this->mkey}...");

Expand All @@ -1170,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)) {
Expand Down Expand Up @@ -1199,7 +1226,7 @@ private function runMigrations() : bool
$this->output('Processing of migration '. get_class($migration).' failed!.');
return false;
}

return true;
}

Expand All @@ -1222,7 +1249,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]
Expand Down Expand Up @@ -1264,7 +1291,7 @@ public static function getKeyFromFilename($filename) : string
return $filename;
}

list($vendor, $key) = explode('_', $raw, 2);
list($vendor, $key) = explode('_', $raw, 2);
return $vendor . '/' . $key;
}

Expand Down Expand Up @@ -1325,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}";
}

Expand Down Expand Up @@ -1431,7 +1462,7 @@ public static function validateKey(string $key) : bool
return false;
}

return isset($match[0]);
return isset($match[0]);
}

}
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.1-rc1
5.2.1-rc2

0 comments on commit 0cba31b

Please sign in to comment.