From cefbe3e381ec6ab5f4053be0849b285703a70e55 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Tue, 20 Aug 2024 22:39:22 +1000 Subject: [PATCH 01/34] fix issue #564 --- external/composer.json | 6 +++--- system/Base/Installer/Components/Setup.php | 12 ------------ .../Modules/Packages/Providers/Core/package.json | 10 +++++----- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/external/composer.json b/external/composer.json index 763652bc7..69266b4d5 100644 --- a/external/composer.json +++ b/external/composer.json @@ -15,13 +15,13 @@ "extra": { "patches": { "react\/socket": { - "phpv8.3 support": "\/var\/www\/html\/sp\/system\/Base\/..\/..\/external\/patches\/react_socket_connection.patch" + "phpv8.3 support": "patches\/react_socket_connection.patch" }, "cboden\/ratchet": { - "phpv8.3 support": "\/var\/www\/html\/sp\/system\/Base\/..\/..\/external\/patches\/cboden_ratchet_ioconnection.patch" + "phpv8.3 support": "patches\/cboden_ratchet_ioconnection.patch" }, "league\/oauth2-server": { - "extract client_id": "\/var\/www\/html\/sp\/system\/Base\/..\/..\/external\/patches\/oauth2_server_bearertokenvalidator.patch" + "extract client_id": "patches\/league_oauth2_server_bearertokenvalidator.patch" } } } diff --git a/system/Base/Installer/Components/Setup.php b/system/Base/Installer/Components/Setup.php index 7b4a1db32..f1366026f 100644 --- a/system/Base/Installer/Components/Setup.php +++ b/system/Base/Installer/Components/Setup.php @@ -845,18 +845,6 @@ protected function populateComposerJsonFile() } if (isset($coreJsonFile['dependencies']['composer']['extra'])) { - if (isset($coreJsonFile['dependencies']['composer']['extra']['patches']) && - is_array($coreJsonFile['dependencies']['composer']['extra']['patches']) - ) { - foreach ($coreJsonFile['dependencies']['composer']['extra']['patches'] as $package => &$patchDetails) { - if (is_array($patchDetails)) { - foreach ($patchDetails as $description => &$location) { - $location = base_path($location); - } - } - } - } - $composerJsonFile['extra'] = $coreJsonFile['dependencies']['composer']['extra']; } diff --git a/system/Base/Installer/Packages/Setup/Register/Modules/Packages/Providers/Core/package.json b/system/Base/Installer/Packages/Setup/Register/Modules/Packages/Providers/Core/package.json index 02b80f373..f097cc9de 100644 --- a/system/Base/Installer/Packages/Setup/Register/Modules/Packages/Providers/Core/package.json +++ b/system/Base/Installer/Packages/Setup/Register/Modules/Packages/Providers/Core/package.json @@ -73,15 +73,15 @@ { "react/socket" : { - "phpv8.3 support" : "external/patches/react_socket_connection.patch" + "phpv8.3 support" : "patches/react_socket_connection.patch" }, - "cboden/ratchet" : + "cboden/ratchet" : { - "phpv8.3 support" : "external/patches/cboden_ratchet_ioconnection.patch" + "phpv8.3 support" : "patches/cboden_ratchet_ioconnection.patch" }, - "league/oauth2-server" : + "league/oauth2-server" : { - "extract client_id" : "external/patches/oauth2_server_bearertokenvalidator.patch" + "extract client_id" : "patches/league_oauth2_server_bearertokenvalidator.patch" } } } From e50194f8563bf16e62a760f19e67d59f7df4622f Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Thu, 22 Aug 2024 02:30:40 +1000 Subject: [PATCH 02/34] Update issue #34 --- .../Core/Packages/Adminltetags/Tags/Modal.php | 4 + .../Views/Default/html/modules/analyse.html | 7 + system/Base/Helpers.php | 2 + .../Packages/Providers/Core/package.json | 7 +- .../ModulesServiceProvider/Installer.php | 131 +++++++++++++++++- .../Modules/Packages/PackagesData.php | 5 + .../ModulesServiceProvider/Queues.php | 12 +- 7 files changed, 156 insertions(+), 12 deletions(-) diff --git a/apps/Core/Packages/Adminltetags/Tags/Modal.php b/apps/Core/Packages/Adminltetags/Tags/Modal.php index 7f5a64653..335ab4ea5 100644 --- a/apps/Core/Packages/Adminltetags/Tags/Modal.php +++ b/apps/Core/Packages/Adminltetags/Tags/Modal.php @@ -150,6 +150,10 @@ protected function generateContent() $this->params['modalEscClose'] : 'false'; + if ($this->modalParams['modalEscClose'] === true) { + $this->modalParams['modalEscClose'] = 'true'; + } + $this->modalParams['modalType'] = isset($this->params['modalType']) ? $this->params['modalType'] : diff --git a/apps/Core/Views/Default/html/modules/analyse.html b/apps/Core/Views/Default/html/modules/analyse.html index cc90af274..d9c7a63c6 100644 --- a/apps/Core/Views/Default/html/modules/analyse.html +++ b/apps/Core/Views/Default/html/modules/analyse.html @@ -355,6 +355,11 @@ if (object === 'analyse_logs' || object === 'precheck_logs' || object === 'result_logs') { if (logObject[object] !== '-') { + if ($(this).data()['moduletype'] !== 'external') { + logObject[object] = JSON.parse(logObject[object]); + logObject[object] = BazHelpers.createHtmlList({'obj': logObject[object]}); + } + logObject[object] = '
' + logObject[object] + '
'; } } @@ -426,6 +431,8 @@ 'modalSize' : 'xl', 'modalHeader' : true, 'modalFooter' : true, + 'modalHeaderCloseButton' : true, + 'modalEscClose' : true, 'modalTitle' : ' LOGS' ] )}} diff --git a/system/Base/Helpers.php b/system/Base/Helpers.php index 1ac4bd396..9399360ae 100644 --- a/system/Base/Helpers.php +++ b/system/Base/Helpers.php @@ -465,6 +465,8 @@ function array_get_values_recursive($keys = [], array $arr) { return count($val) > 1 ? $val : array_pop($val); } +} + if (!function_exists('arraySqueeze')) { //$task = keep - Keep the data of defined keys, remove rest diff --git a/system/Base/Installer/Packages/Setup/Register/Modules/Packages/Providers/Core/package.json b/system/Base/Installer/Packages/Setup/Register/Modules/Packages/Providers/Core/package.json index f097cc9de..83ec5c01f 100644 --- a/system/Base/Installer/Packages/Setup/Register/Modules/Packages/Providers/Core/package.json +++ b/system/Base/Installer/Packages/Setup/Register/Modules/Packages/Providers/Core/package.json @@ -58,7 +58,8 @@ "wp-cli/php-cli-tools" : "^0.11.22", "react/event-loop" : "1.5.0", "mattiasgeniar/php-percentages" : "^1.3", - "spatie/server-side-rendering" : "^0.3.2" + "spatie/server-side-rendering" : "^0.3.2", + "xobotyi/rsync" : "^1.0" }, "config" : { @@ -75,11 +76,11 @@ { "phpv8.3 support" : "patches/react_socket_connection.patch" }, - "cboden/ratchet" : + "cboden/ratchet" : { "phpv8.3 support" : "patches/cboden_ratchet_ioconnection.patch" }, - "league/oauth2-server" : + "league/oauth2-server" : { "extract client_id" : "patches/league_oauth2_server_bearertokenvalidator.patch" } diff --git a/system/Base/Providers/ModulesServiceProvider/Installer.php b/system/Base/Providers/ModulesServiceProvider/Installer.php index 3c85b72c4..3526ba4ec 100644 --- a/system/Base/Providers/ModulesServiceProvider/Installer.php +++ b/system/Base/Providers/ModulesServiceProvider/Installer.php @@ -3,13 +3,16 @@ namespace System\Base\Providers\ModulesServiceProvider; use League\Flysystem\FilesystemException; +use League\Flysystem\UnableToCheckExistence; use League\Flysystem\UnableToCopyFile; +use League\Flysystem\UnableToDeleteDirectory; use League\Flysystem\UnableToDeleteFile; use League\Flysystem\UnableToMoveFile; use League\Flysystem\UnableToReadFile; use League\Flysystem\UnableToRetrieveMetadata; use League\Flysystem\UnableToWriteFile; use System\Base\BasePackage; +use xobotyi\rsync\Rsync; use z4kn4fein\SemVer\Version; class Installer extends BasePackage @@ -58,8 +61,12 @@ public function init($process = 'precheck') $this->zip = new \ZipArchive; - if (!$this->localContent->fileExists($this->downloadLocation)) { - $this->localContent->createDirectory($this->downloadLocation); + try { + if (!$this->localContent->directoryExists($this->downloadLocation)) { + $this->localContent->createDirectory($this->downloadLocation); + } + } catch (FilesystemException | UnableToCheckExistence | \throwable $e) { + throw $e; } $this->basepackages->progress->init(null, 'modulesinstaller'); @@ -524,16 +531,15 @@ protected function extractModulesDownloadedFromRepo() return false; } - $files = $this->basepackages->utils->scanDir($this->zipFile['location'], false); if ($files && isset($files['dirs'][0])) { try { $name = str_replace('.zip', '', $this->zipFile['name']); - $files['dirs'][0]; - $this->localContent->move($files['dirs'][0], $this->downloadLocation . $name . '/' . $name); + + $this->zip->close(); } catch (FilesystemException | UnableToMoveFile $e) { $this->addResponse('Error renaming extracted directory for : ' . $this->zipFile['name'], 1); @@ -548,6 +554,100 @@ protected function extractModulesDownloadedFromRepo() return false; } + protected function dryRunRsync($args) + { + $taskName = $args[0]; + $module = $args[1]; + + $this->queue['results'][$taskName][$module['module_type']][$module['id']]['precheck'] = 'fail'; + + $preCheckQueueLogs = &$this->queue['results'][$taskName][$module['module_type']][$module['id']]['precheck_logs']; + + try { + $rsync = new Rsync([ + Rsync::CONF_CWD => base_path('var/tmp/installer/' . $this->zipFile['name'] . '/' . $this->zipFile['name']), + Rsync::CONF_OPTIONS => + [ + Rsync::OPT_DRY_RUN => true, + Rsync::OPT_VERBOSE => true, + Rsync::OPT_ARCHIVE => true, + Rsync::OPT_HUMAN_READABLE => true, + Rsync::OPT_CHECKSUM => true, + Rsync::OPT_DELETE_AFTER => true, + Rsync::OPT_INCLUDE => + [ + 'public', + 'public/index.php', + 'public/.htaccess_example', + 'public/core/***', + 'external', + 'external/patches', + 'external/patches/***', + 'apps', + 'apps/Core/***', + 'system/***' + ], + Rsync::OPT_EXCLUDE => ['*'], + ] + ]); + + $rsync->sync('.', base_path('')); + + if ($rsync->getExitCode() == 0) { + $outputArr = explode(PHP_EOL, $rsync->getStdout()); + // trace([$outputArr], false, false, true); + $modifiedFiles = []; + $deleteFiles = []; + + array_walk($outputArr, function($output) use (&$modifiedFiles, &$deleteFiles) { + if (str_starts_with($output, 'apps') || + str_starts_with($output, 'system') || + str_starts_with($output, 'public') || + str_starts_with($output, 'external') + ) { + if (!str_ends_with($output, '/') && + !str_ends_with($output, '.git') + ) { + array_push($modifiedFiles, $output); + } + } + + if (str_starts_with($output, 'deleting')) { + if (!str_ends_with($output, '/') && + !str_ends_with($output, '.git') && + !str_ends_with($output, 'keys') + ) { + $output = str_replace('deleting ', '', $output); + array_push($deleteFiles, $output); + } + } + }); + } + + $this->queue['results'][$taskName][$module['module_type']][$module['id']]['precheck'] = 'pass'; + + $preCheckQueueLogs = $this->helper->encode(['modifiedFiles' => $modifiedFiles, 'deleteFiles' => $deleteFiles]); + // trace(varsToDump : [$modifiedFiles, $deleteFiles], object: true); + + return true; + } catch (\throwable $e) { + if (str_contains($e->getMessage(), 'No such file or directory')) { + $rsyncError = 'Incorrect directory : ' . $rsync->getCWD(); + } else { + $rsyncError = $e->getMessage(); + } + } + + if (!isset($rsyncError)) { + $rsyncError = $rsync->getStderr(); + } + + return $this->preCheckHasErrors( + $rsyncError, + $preCheckQueueLogs + ); + } + protected function checkDependencies() { if (count($this->modulesToProcess) === 0) { @@ -753,7 +853,7 @@ protected function checkRegisteredDependencies($dependencies) return $found; } - protected function cleanup(array $what) + public function cleanup(array $what) { if (in_array('composer', $what)) { $files = $this->basepackages->utils->scanDir('external', false); @@ -772,6 +872,16 @@ protected function cleanup(array $what) } } } + + if (in_array('downloads', $what)) { + try { + if ($this->localContent->directoryExists($this->downloadLocation)) { + $this->localContent->deleteDirectory($this->downloadLocation); + } + } catch (FilesystemException | UnableToCheckExistence | UnableToDeleteDirectory | \throwable $e) { + throw $e; + } + } } // protected function getLatestRepositoryModulesData() @@ -1022,7 +1132,7 @@ protected function rollBack() protected function registerRunProcessPrecheckProgressMethods() { $this->runProcessPrecheckProgressMethods = []; - // trace([$this->queue['tasks']['analysed']]); + foreach ($this->queue['tasks']['analysed'] as $taskName => $modulesTypes) { if (($taskName === 'first' || $taskName === 'install' || $taskName === 'update') && count($modulesTypes) > 0 @@ -1096,6 +1206,13 @@ protected function registerRunProcessPrecheckProgressMethods() 'text' => 'Extracting downloaded module ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...' ] ); + array_push($this->runProcessPrecheckProgressMethods, + [ + 'method' => 'dryRunRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + 'text' => 'Running rsync --dry-run for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', + 'args' => [$taskName, $module], + ] + ); } } } diff --git a/system/Base/Providers/ModulesServiceProvider/Modules/Packages/PackagesData.php b/system/Base/Providers/ModulesServiceProvider/Modules/Packages/PackagesData.php index e9a78f517..353249e6d 100644 --- a/system/Base/Providers/ModulesServiceProvider/Modules/Packages/PackagesData.php +++ b/system/Base/Providers/ModulesServiceProvider/Modules/Packages/PackagesData.php @@ -36,4 +36,9 @@ public function __isset($key) { return array_key_exists($key, $this->packagesData); } + + public function reset() + { + $this->packagesData = []; + } } \ No newline at end of file diff --git a/system/Base/Providers/ModulesServiceProvider/Queues.php b/system/Base/Providers/ModulesServiceProvider/Queues.php index 6736b5649..c0e78a943 100644 --- a/system/Base/Providers/ModulesServiceProvider/Queues.php +++ b/system/Base/Providers/ModulesServiceProvider/Queues.php @@ -231,6 +231,10 @@ public function analyseQueue(&$queue = null, $reAnalyse = false) return true; } + if ($reAnalyse) { + $this->modules->installer->cleanup(['composer', 'downloads']); + } + $this->queueTasks = []; $this->results = []; $queue['tasks']['analysed'] = [];//Reset Analysed @@ -577,8 +581,12 @@ protected function checkComposerAndAddToQueue($composerPackages, $module) } if (isset($composerPackages['extra']['patches'][$composerPackage])) { - $composerJsonFile['extra']['patches'][$composerPackage][$this->helper->firstKey($composerPackages['extra']['patches'][$composerPackage])] = base_path($this->helper->first($composerPackages['extra']['patches'][$composerPackage])); - $hasPatch = true; + foreach ($composerPackages['extra']['patches'][$composerPackage] as $patchKey => $patchValue) { + if (!isset($composerJsonFile['extra']['patches'][$composerPackage][$patchKey])) { + $composerJsonFile['extra']['patches'][$composerPackage][$patchKey] = $patchValue; + $hasPatch = true; + } + } } if ($installExternal || $hasConfigChange || $hasPatch) { From b24b7e26bfa461c17e28d234dad62de6111f467f Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Fri, 23 Aug 2024 12:07:10 +1000 Subject: [PATCH 03/34] update issue #352 - Added .gitignore for apptypes - Fixed not able to add differnt version to dependency - Fixed URL for Core and non core modules - Fixed github link for apptypes --- .../Devtools/Modules/DevtoolsModules.php | 17 +++++++++++------ .../Modules/Files/ApptypesGitignore.txt | 4 ++++ .../Default/html/devtools/modules/module.html | 19 ++++++++++++------- 3 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 apps/Core/Packages/Devtools/Modules/Files/ApptypesGitignore.txt diff --git a/apps/Core/Packages/Devtools/Modules/DevtoolsModules.php b/apps/Core/Packages/Devtools/Modules/DevtoolsModules.php index af5d9f23d..52bc27ffc 100644 --- a/apps/Core/Packages/Devtools/Modules/DevtoolsModules.php +++ b/apps/Core/Packages/Devtools/Modules/DevtoolsModules.php @@ -485,6 +485,9 @@ protected function addUpdateAppTypeFiles($appType) if (!$dirExists) {//addGitkeep $this->localContent->write($path . '/.gitkeep', ''); } + + $file = $this->localContent->read('apps/Core/Packages/Devtools/Modules/Files/ApptypesGitignore.txt'); + $this->localContent->write('apps/' . ucfirst($appType['app_type']) . '/.gitignore', $file); } catch (FilesystemException | UnableToCheckExistence | UnableToWriteFile $exception) { $this->addResponse('Unable to write json content to file: .gitkeep for apptypes'); @@ -2950,13 +2953,15 @@ public function generateModuleRepoUrl($data) $name = preg_split('/(?=[A-Z])/', $name); if ($data['module_type'] !== 'bundles') { - if (isset($baseView) && isset($baseView['name'])) { - $name = strtolower($baseView['name'] . '-' . implode('', $name)); - } else { - $name = strtolower(implode('', $name)); - } + if ($name[0] !== 'core') { + if (isset($baseView) && isset($baseView['name'])) { + $name = strtolower($baseView['name'] . '-' . implode('', $name)); + } else { + $name = strtolower(implode('', $name)); + } - $url .= '/' . $data['app_type'] . '-' . $data['module_type'] . '-' . $data['category'] . '-' . $name; + $url .= '/' . $data['app_type'] . '-' . $data['module_type'] . '-' . $data['category'] . '-' . $name; + } } else { $url .= '/' . $data['app_type'] . '-' . $data['module_type'] . '-' . strtolower(implode('', $name)); } diff --git a/apps/Core/Packages/Devtools/Modules/Files/ApptypesGitignore.txt b/apps/Core/Packages/Devtools/Modules/Files/ApptypesGitignore.txt new file mode 100644 index 000000000..a61ddb138 --- /dev/null +++ b/apps/Core/Packages/Devtools/Modules/Files/ApptypesGitignore.txt @@ -0,0 +1,4 @@ +Components/* +Middlewares/* +Packages/* +Views/* \ No newline at end of file diff --git a/apps/Core/Views/Default/html/devtools/modules/module.html b/apps/Core/Views/Default/html/devtools/modules/module.html index f8b142c45..b805585c4 100644 --- a/apps/Core/Views/Default/html/devtools/modules/module.html +++ b/apps/Core/Views/Default/html/devtools/modules/module.html @@ -1295,9 +1295,14 @@ onSubmitResponse: function(response) { if (response.responseData && response.responseData.newRepo && $('#repo-details').length > 0) { $('#path').html(BazHelpers.capitalizeFirstLetter($('#{{componentId}}-{{sectionId}}-app_type').val())); + var devLink = '/src/branch/dev'; + + if (response.responseData.newRepo.html_url.includes('github')) { + devLink = '/tree/dev'; + } $('#repo_url').html(response.responseData.newRepo.clone_url); $('#repo_url_dev').html(response.responseData.newRepo.html_url); - $('#repo_url_dev_a').attr('href', response.responseData.newRepo.html_url + '/src/branch/dev'); + $('#repo_url_dev_a').attr('href', response.responseData.newRepo.html_url + devLink); $('#repo-details').attr('hidden', false); $('#module-details').attr('hidden', true); @@ -3071,14 +3076,14 @@ var found = false; if (label === 'core') { dataCollectionSectionForm['vars']['moduleDependencies'][label] = { }; - dataCollectionSectionForm['vars']['moduleDependencies'][label]['name'] = moduleData['name']; - dataCollectionSectionForm['vars']['moduleDependencies'][label]['version'] = moduleData['version']; - dataCollectionSectionForm['vars']['moduleDependencies'][label]['repo'] = moduleData['repo']; + dataCollectionSectionForm['vars']['moduleDependencies'][label]['name'] = $('#{{componentId}}-{{sectionId}}-dependencies-modulename').val(); + dataCollectionSectionForm['vars']['moduleDependencies'][label]['version'] = $('#{{componentId}}-{{sectionId}}-dependencies-moduleversion').val(); + dataCollectionSectionForm['vars']['moduleDependencies'][label]['repo'] = $('#{{componentId}}-{{sectionId}}-dependencies-modulerepo').val(); } else if (label === 'apptypes') { dataCollectionSectionForm['vars']['moduleDependencies']['apptype'] = { }; - dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['name'] = moduleData['name']; - dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['version'] = moduleData['version']; - dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['repo'] = moduleData['repo']; + dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['name'] = $('#{{componentId}}-{{sectionId}}-dependencies-modulename').val(); + dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['version'] = $('#{{componentId}}-{{sectionId}}-dependencies-moduleversion').val(); + dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['repo'] = $('#{{componentId}}-{{sectionId}}-dependencies-modulerepo').val(); } else if (label === 'external') { if (dataCollectionSectionForm['vars']['module_type'] === 'core') { if (!dataCollectionSectionForm['vars']['moduleDependencies']['composer']) { From 1267fe6c78ab4dc73c16e52b0906f965de8bee77 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Fri, 23 Aug 2024 12:09:34 +1000 Subject: [PATCH 04/34] update #34 - Added option to add query only specific repository for a module instead of the whole organization --- .../services/apis/repos/gitea/form.html | 18 +-- .../services/apis/repos/github/form.html | 20 ++-- .../ApiClientServices/Apis/Repos.php | 4 +- .../ModulesServiceProvider/Manager.php | 113 ++++++++++++++---- 4 files changed, 112 insertions(+), 43 deletions(-) diff --git a/apps/Core/Views/Default/html/system/api/client/services/apis/repos/gitea/form.html b/apps/Core/Views/Default/html/system/api/client/services/apis/repos/gitea/form.html index 6e90b0c84..b42603d05 100644 --- a/apps/Core/Views/Default/html/system/api/client/services/apis/repos/gitea/form.html +++ b/apps/Core/Views/Default/html/system/api/client/services/apis/repos/gitea/form.html @@ -118,10 +118,10 @@ 'componentId' : componentId, 'sectionId' : sectionId, 'fieldId' : 'repo_url', - 'fieldLabel' : 'API Repo Url', + 'fieldLabel' : 'Org/User/Repo Url', 'fieldType' : 'input', 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'API Repo URL', + 'fieldHelpTooltipContent' : 'Org/User/Repo Url', 'fieldRequired' : true, 'fieldBazScan' : true, 'fieldBazPostOnCreate' : true, @@ -140,10 +140,10 @@ 'componentId' : componentId, 'sectionId' : sectionId, 'fieldId' : 'branch', - 'fieldLabel' : 'API Repo Branch', + 'fieldLabel' : 'Repo Branch', 'fieldType' : 'input', 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'API Repo Branch', + 'fieldHelpTooltipContent' : 'Repo Branch', 'fieldRequired' : true, 'fieldBazScan' : true, 'fieldBazPostOnCreate' : true, @@ -350,8 +350,8 @@ '{{componentId}}-{{sectionId}}-description' : { }, '{{componentId}}-{{sectionId}}-api_url' : { }, '{{componentId}}-{{sectionId}}-org_user' : { }, - '{{componentId}}-{{sectionId}}-branch' : { }, '{{componentId}}-{{sectionId}}-repo_url' : { }, + '{{componentId}}-{{sectionId}}-branch' : { }, '{{componentId}}-{{sectionId}}-auth_type' : { afterInit : function() { $('#{{componentId}}-{{sectionId}}-auth_type').click(function() { @@ -379,8 +379,10 @@ '{{componentId}}-{{sectionId}}-name' : 'required', '{{componentId}}-{{sectionId}}-category' : 'required', '{{componentId}}-{{sectionId}}-location' : 'required', + '{{componentId}}-{{sectionId}}-api_url' : 'required', + '{{componentId}}-{{sectionId}}-org_user' : 'required', '{{componentId}}-{{sectionId}}-repo_url' : 'required', - '{{componentId}}-{{sectionId}}-site_url' : 'required', + '{{componentId}}-{{sectionId}}-branch' : 'required', '{{componentId}}-{{sectionId}}-username' : 'required', '{{componentId}}-{{sectionId}}-password' : 'required', '{{componentId}}-{{sectionId}}-access_token' : 'required', @@ -390,8 +392,10 @@ '{{componentId}}-{{sectionId}}-name' : 'Please enter api name', '{{componentId}}-{{sectionId}}-category' : 'Please enter api category', '{{componentId}}-{{sectionId}}-location' : 'Please enter api location', + '{{componentId}}-{{sectionId}}-api_url' : 'Please enter repo url', + '{{componentId}}-{{sectionId}}-org_user' : 'Please enter org name or username', '{{componentId}}-{{sectionId}}-repo_url' : 'Please enter repo url', - '{{componentId}}-{{sectionId}}-site_url' : 'Please enter site url', + '{{componentId}}-{{sectionId}}-branch' : 'Please enter branch (main/dev)', '{{componentId}}-{{sectionId}}-username' : 'Please enter username', '{{componentId}}-{{sectionId}}-password' : 'Please enter password', '{{componentId}}-{{sectionId}}-access_token' : 'Please enter api access token', diff --git a/apps/Core/Views/Default/html/system/api/client/services/apis/repos/github/form.html b/apps/Core/Views/Default/html/system/api/client/services/apis/repos/github/form.html index 6e90b0c84..0471868b2 100644 --- a/apps/Core/Views/Default/html/system/api/client/services/apis/repos/github/form.html +++ b/apps/Core/Views/Default/html/system/api/client/services/apis/repos/github/form.html @@ -97,7 +97,7 @@ 'fieldLabel' : 'Org/User', 'fieldType' : 'input', 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'Org/User name', + 'fieldHelpTooltipContent' : 'Org/User name. Note: For modules, ', 'fieldRequired' : true, 'fieldBazScan' : true, 'fieldBazPostOnCreate' : true, @@ -118,10 +118,10 @@ 'componentId' : componentId, 'sectionId' : sectionId, 'fieldId' : 'repo_url', - 'fieldLabel' : 'API Repo Url', + 'fieldLabel' : 'Org/User/Repo Url', 'fieldType' : 'input', 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'API Repo URL', + 'fieldHelpTooltipContent' : 'Org/User/Repo Url', 'fieldRequired' : true, 'fieldBazScan' : true, 'fieldBazPostOnCreate' : true, @@ -140,10 +140,10 @@ 'componentId' : componentId, 'sectionId' : sectionId, 'fieldId' : 'branch', - 'fieldLabel' : 'API Repo Branch', + 'fieldLabel' : 'Repo Branch', 'fieldType' : 'input', 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'API Repo Branch', + 'fieldHelpTooltipContent' : 'Repo Branch', 'fieldRequired' : true, 'fieldBazScan' : true, 'fieldBazPostOnCreate' : true, @@ -350,8 +350,8 @@ '{{componentId}}-{{sectionId}}-description' : { }, '{{componentId}}-{{sectionId}}-api_url' : { }, '{{componentId}}-{{sectionId}}-org_user' : { }, - '{{componentId}}-{{sectionId}}-branch' : { }, '{{componentId}}-{{sectionId}}-repo_url' : { }, + '{{componentId}}-{{sectionId}}-branch' : { }, '{{componentId}}-{{sectionId}}-auth_type' : { afterInit : function() { $('#{{componentId}}-{{sectionId}}-auth_type').click(function() { @@ -379,8 +379,10 @@ '{{componentId}}-{{sectionId}}-name' : 'required', '{{componentId}}-{{sectionId}}-category' : 'required', '{{componentId}}-{{sectionId}}-location' : 'required', + '{{componentId}}-{{sectionId}}-api_url' : 'required', + '{{componentId}}-{{sectionId}}-org_user' : 'required', '{{componentId}}-{{sectionId}}-repo_url' : 'required', - '{{componentId}}-{{sectionId}}-site_url' : 'required', + '{{componentId}}-{{sectionId}}-branch' : 'required', '{{componentId}}-{{sectionId}}-username' : 'required', '{{componentId}}-{{sectionId}}-password' : 'required', '{{componentId}}-{{sectionId}}-access_token' : 'required', @@ -390,8 +392,10 @@ '{{componentId}}-{{sectionId}}-name' : 'Please enter api name', '{{componentId}}-{{sectionId}}-category' : 'Please enter api category', '{{componentId}}-{{sectionId}}-location' : 'Please enter api location', + '{{componentId}}-{{sectionId}}-api_url' : 'Please enter repo url', + '{{componentId}}-{{sectionId}}-org_user' : 'Please enter org name or username', '{{componentId}}-{{sectionId}}-repo_url' : 'Please enter repo url', - '{{componentId}}-{{sectionId}}-site_url' : 'Please enter site url', + '{{componentId}}-{{sectionId}}-branch' : 'Please enter branch (main/dev)', '{{componentId}}-{{sectionId}}-username' : 'Please enter username', '{{componentId}}-{{sectionId}}-password' : 'Please enter password', '{{componentId}}-{{sectionId}}-access_token' : 'Please enter api access token', diff --git a/system/Base/Installer/Packages/Setup/Register/Basepackages/ApiClientServices/Apis/Repos.php b/system/Base/Installer/Packages/Setup/Register/Basepackages/ApiClientServices/Apis/Repos.php index 355976c59..30d7e50af 100644 --- a/system/Base/Installer/Packages/Setup/Register/Basepackages/ApiClientServices/Apis/Repos.php +++ b/system/Base/Installer/Packages/Setup/Register/Basepackages/ApiClientServices/Apis/Repos.php @@ -31,8 +31,8 @@ public function register($db, $ff) $modulesRepo = [ 'api_url' => 'https://api.github.com', - 'org_user' => 'sp-framework', - 'repo_url' => 'https://github.com/sp-framework/sp-modules', + 'org_user' => 'sp-modules', + 'repo_url' => 'https://github.com/sp-modules/', 'branch' => 'main', 'auth_type' => 'autho', 'authorization' => '' diff --git a/system/Base/Providers/ModulesServiceProvider/Manager.php b/system/Base/Providers/ModulesServiceProvider/Manager.php index d75811f9d..f7ea240cd 100644 --- a/system/Base/Providers/ModulesServiceProvider/Manager.php +++ b/system/Base/Providers/ModulesServiceProvider/Manager.php @@ -473,28 +473,45 @@ public function syncRemoteWithLocal($data) protected function getRemoteModules() { - if (strtolower($this->apiClientConfig['provider']) === 'gitea') { - $collection = 'OrganizationApi'; - $method = 'orgListRepos'; - $args = [$this->apiClientConfig['org_user']]; - } else if (strtolower($this->apiClientConfig['provider']) === 'github') { - $collection = 'ReposApi'; - $method = 'reposListForOrg'; - $args = [$this->apiClientConfig['org_user']]; - } + $this->apiClientConfig['repo_url'] = rtrim($this->apiClientConfig['repo_url'], '/'); + //Get one or core repo details, no need to loop through all repos in the org. + if (str_ends_with($this->apiClientConfig['repo_url'], '/core')) { + return $this->getRemoteModule('core'); + } else if (!str_ends_with($this->apiClientConfig['repo_url'], '/' . $this->apiClientConfig['org_user'])) { + $repoUrlArr = explode('/', $this->apiClientConfig['repo_url']); - try { - $modulesArr = $this->apiClient->useMethod($collection, $method, $args)->getResponse(true); - } catch (\throwable | ClientException $e) { - $this->addResponse($e->getMessage(), 1); + $remoteModule = $this->getRemoteModule($this->helper->last($repoUrlArr)); - if ($e->getCode() === 401) { - $this->addResponse('API Authentication failed.', 1); - } else if (str_contains($e->getMessage(), 'Connection timed out')) { - $this->addResponse('Error connecting to the repository.', 1); + if (!$remoteModule) { + return false; } - return false; + $modulesArr = [$remoteModule]; + } else { + //Process all repositories in the org as repourl and org name is the same + if (strtolower($this->apiClientConfig['provider']) === 'gitea') { + $collection = 'OrganizationApi'; + $method = 'orgListRepos'; + $args = [$this->apiClientConfig['org_user']]; + } else if (strtolower($this->apiClientConfig['provider']) === 'github') { + $collection = 'ReposApi'; + $method = 'reposListForOrg'; + $args = [$this->apiClientConfig['org_user']]; + } + + try { + $modulesArr = $this->apiClient->useMethod($collection, $method, $args)->getResponse(true); + } catch (\throwable | ClientException $e) { + $this->addResponse($e->getMessage(), 1); + + if ($e->getCode() === 401) { + $this->addResponse('API Authentication failed.', 1); + } else if (str_contains($e->getMessage(), 'Connection timed out')) { + $this->addResponse('Error connecting to the repository.', 1); + } + + return false; + } } if ($modulesArr) { @@ -516,13 +533,6 @@ protected function getRemoteModules() $names = explode('-', $module['name']); - if ($names && count($names) === 1 && $names[0] === 'core') { - $this->remoteModules['packages'] = []; - $this->remoteModules['packages'] = [$module]; - - return true; - } - if (strtolower($this->apiClientConfig['provider']) === 'github') {//Github does not have release_counter set $collection = 'ReposApi'; $method = 'reposListReleases'; @@ -573,6 +583,57 @@ protected function getRemoteModules() return false; } + protected function getRemoteModule($moduleName) + { + if (strtolower($this->apiClientConfig['provider']) === 'gitea') { + $collection = 'RepositoryApi'; + $method = 'repoGet'; + $args = [$this->apiClientConfig['org_user']]; + } else if (strtolower($this->apiClientConfig['provider']) === 'github') { + $collection = 'ReposApi'; + $method = 'reposGet'; + $args = [$this->apiClientConfig['org_user'], $moduleName]; + } + + try { + $module = $this->apiClient->useMethod($collection, $method, $args)->getResponse(true); + } catch (\throwable | ClientException $e) { + $this->addResponse($e->getMessage(), 1); + + if ($e->getCode() === 401) { + $this->addResponse('API Authentication failed.', 1); + } else if (str_contains($e->getMessage(), 'Connection timed out')) { + $this->addResponse('Error connecting to the repository.', 1); + } + + return false; + } + + if ($moduleName !== 'core') { + return $module; + } + + if ($this->apiClientConfig['sync'] && + isset($this->apiClientConfig['sync']['modules']['last_sync']) && + $this->apiClientConfig['sync']['modules']['last_sync'] !== '' + ) { + $lastSync = \Carbon\Carbon::parse($this->apiClientConfig['sync']['modules']['last_sync']); + } + + if (isset($lastSync) && isset($module['updated_at']) && $module['updated_at'] !== '') { + $updatedAt = \Carbon\Carbon::parse($module['updated_at']); + + if ($lastSync->greaterThan($updatedAt)) {//Only process if its updated. + return true; + } + } + + $this->remoteModules['packages'] = []; + $this->remoteModules['packages'] = [$module]; + + return true; + } + protected function getRemoteModuleJson($moduleType, $module, $onlyJson = false) { if ($moduleType === 'apptypes') { @@ -633,7 +694,7 @@ protected function getRemoteModuleJson($moduleType, $module, $onlyJson = false) $e->getMessage() ); - //We dont so anything here with respect to return. If the json file is not there, we consider the module to be unavailable + //We dont do anything here with respect to return. If the json file is not there, we consider the module to be unavailable } return true; From 038ecde09cfccf7dda66c0e1c52b1b57ba0d7898 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Sat, 24 Aug 2024 14:57:40 +1000 Subject: [PATCH 05/34] update issue #484 - Cleanup apis generic form/view. - API client services should only list apis that are available for core in core app_type. --- .../services/apis/repos/generic/form.html | 296 ------------------ .../services/apis/repos/generic/view.html | 27 -- .../html/system/api/client/services/view.html | 12 +- .../ApiClientServices/ApiClientServices.php | 10 +- 4 files changed, 10 insertions(+), 335 deletions(-) delete mode 100644 apps/Core/Views/Default/html/system/api/client/services/apis/repos/generic/form.html delete mode 100644 apps/Core/Views/Default/html/system/api/client/services/apis/repos/generic/view.html diff --git a/apps/Core/Views/Default/html/system/api/client/services/apis/repos/generic/form.html b/apps/Core/Views/Default/html/system/api/client/services/apis/repos/generic/form.html deleted file mode 100644 index 57604e56e..000000000 --- a/apps/Core/Views/Default/html/system/api/client/services/apis/repos/generic/form.html +++ /dev/null @@ -1,296 +0,0 @@ -{% if api['id'] is defined %} - {% set apiId = api['id'] %} - {% set apiSetup = api['setup'] %} - {% set apiName = api['name'] %} - {% set apiInUse = api['in_use'] %} - {% set apiUsedBy = api['used_by'] %} - {% set apiDescription = api['description'] %} - {% set apiApiUrl = api['api_url'] %} - {% set apiAuthType = api['auth_type'] %} - {% set apiUsername = api['username'] %} - {% set apiPassword = api['password'] %} - {% set apiToken = api['token'] %} - {% set apiAuthorization = api['authorization'] %} -{% else %} - {% set apiId = '' %} - {% set apiSetup = '' %} - {% set apiName = '' %} - {% set apiInUse = '0' %} - {% set apiUsedBy = '' %} - {% set apiDescription = '' %} - {% set apiApiUrl = '' %} - {% set apiAuthType = 'none' %} - {% set apiUsername = '' %} - {% set apiPassword = '' %} - {% set apiToken = '' %} - {% set apiAuthorization = '' %} -{% endif %} -{% if apiAuthType === 'auth' %} - {% set authDisabled = false %} - {% set authoDisabled = true %} - {% set tokenDisabled = true %} -{% elseif apiAuthType === 'token' %} - {% set authDisabled = true %} - {% set authoDisabled = true %} - {% set tokenDisabled = false %} -{% elseif apiAuthType === 'autho' %} - {% set authDisabled = true %} - {% set authoDisabled = false %} - {% set tokenDisabled = true %} -{% else %} - {% set authDisabled = true %} - {% set authoDisabled = true %} - {% set tokenDisabled = true %} -{% endif %} -
-
- {% include 'services/apis/common.html' %} -
-
- {{adminltetags.useTag('fields', - [ - 'component' : component, - 'componentName' : componentName, - 'componentId' : componentId, - 'sectionId' : sectionId, - 'fieldId' : 'api_url', - 'fieldLabel' : 'API Url', - 'fieldType' : 'input', - 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'API URL', - 'fieldRequired' : true, - 'fieldBazScan' : true, - 'fieldBazPostOnCreate' : true, - 'fieldBazPostOnUpdate' : true, - 'fieldDataInputMinLength' : 1, - 'fieldDataInputMaxLength' : 1024, - 'fieldValue' : apiApiUrl - ] - )}} -
-
-
-
-
- {{adminltetags.useTag('fields', - [ - 'component' : component, - 'componentName' : componentName, - 'componentId' : componentId, - 'sectionId' : sectionId, - 'fieldId' : 'auth_type', - 'fieldLabel' : 'Auth/Token/Authorization?', - 'fieldType' : 'radio', - 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'Select either basic user authentication is used or user token/authorization is used.', - 'fieldRequired' : true, - 'fieldBazPostOnCreate' : true, - 'fieldBazPostOnUpdate' : true, - 'fieldBazScan' : true, - 'fieldRadioButtons' : - [ - 'none' : - [ - 'title' : 'None', - 'type' : 'secondary', - 'dataValue' : 'none' - ], - 'auth' : - [ - 'title' : 'Auth', - 'type' : 'primary', - 'dataValue' : 'auth' - ], - 'token' : - [ - 'title' : 'Token', - 'type' : 'primary', - 'dataValue' : 'token' - ], - 'autho' : - [ - 'title' : 'Authorization', - 'type' : 'primary', - 'dataValue' : 'autho' - ] - ], - 'fieldRadioChecked' : apiAuthType - ] - )}} -
-
-
-
- {{adminltetags.useTag('fields', - [ - 'component' : component, - 'componentName' : componentName, - 'componentId' : componentId, - 'sectionId' : sectionId, - 'fieldId' : 'username', - 'fieldLabel' : 'Username', - 'fieldType' : 'input', - 'fieldRequired' : true, - 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'Username', - 'fieldBazPostOnCreate' : true, - 'fieldBazPostOnUpdate' : true, - 'fieldBazScan' : true, - 'fieldDataInputMinLength' : 1, - 'fieldDataInputMaxLength' : 50, - 'fieldDisabled' : authDisabled, - 'fieldValue' : apiUsername - ] - )}} -
-
- {{adminltetags.useTag('fields', - [ - 'component' : component, - 'componentName' : componentName, - 'componentId' : componentId, - 'sectionId' : sectionId, - 'fieldId' : 'password', - 'fieldLabel' : 'Password', - 'fieldType' : 'input', - 'fieldInputType' : 'password', - 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'Password', - 'fieldRequired' : true, - 'fieldBazScan' : true, - 'fieldBazPostOnCreate' : true, - 'fieldBazPostOnUpdate' : true, - 'fieldDisabled' : authDisabled, - 'fieldValue' : apiPassword - ] - )}} -
-
-
-
- {{adminltetags.useTag('fields', - [ - 'component' : component, - 'componentName' : componentName, - 'componentId' : componentId, - 'sectionId' : sectionId, - 'fieldId' : 'token', - 'fieldLabel' : 'Token', - 'fieldType' : 'input', - 'fieldInputType' : 'password', - 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'Token', - 'fieldRequired' : true, - 'fieldBazScan' : true, - 'fieldBazPostOnCreate' : true, - 'fieldBazPostOnUpdate' : true, - 'fieldDisabled' : tokenDisabled, - 'fieldValue' : apiToken - ] - )}} -
-
-
-
- {{adminltetags.useTag('fields', - [ - 'component' : component, - 'componentName' : componentName, - 'componentId' : componentId, - 'sectionId' : sectionId, - 'fieldId' : 'authorization', - 'fieldLabel' : 'Authorization Code', - 'fieldType' : 'textarea', - 'fieldHelp' : true, - 'fieldHelpTooltipContent' : 'Authorization Code', - 'fieldRequired' : true, - 'fieldBazScan' : true, - 'fieldBazPostOnCreate' : true, - 'fieldBazPostOnUpdate' : true, - 'fieldDisabled' : authoDisabled, - 'fieldValue' : apiAuthorization - ] - )}} -
-
-
-
-
-
- \ No newline at end of file diff --git a/apps/Core/Views/Default/html/system/api/client/services/apis/repos/generic/view.html b/apps/Core/Views/Default/html/system/api/client/services/apis/repos/generic/view.html deleted file mode 100644 index a160eb78d..000000000 --- a/apps/Core/Views/Default/html/system/api/client/services/apis/repos/generic/view.html +++ /dev/null @@ -1,27 +0,0 @@ -{{adminltetags.useTag('content', - [ - 'component' : component, - 'componentName' : componentName, - 'componentId' : componentId, - 'parentComponentId' : parent, - 'sectionId' : 'main', - 'contentType' : 'sectionWithForm', - 'cardHeader' : true, - 'cardFooter' : true, - 'cardType' : 'primary', - 'cardIcon' : 'exchange-alt', - 'cardTitle' : title, - 'cardAdditionalClass' : 'rounded-0', - 'cardBodyInclude' : 'services/apis/repo/gitea/form', - 'formButtons' : - [ - 'updateButtonId' : apiId, - 'addActionUrl' : 'system/api/client/services/add', - 'addSuccessRedirectUrl' : 'system/api/client/services', - 'updateActionUrl' : 'system/api/client/services/update', - 'updateSuccessRedirectUrl' : 'system/api/client/services', - 'cancelActionUrl' : 'system/api/client/services', - 'closeActionUrl' : 'system/api/client/services' - ] - ] -)}} \ No newline at end of file diff --git a/apps/Core/Views/Default/html/system/api/client/services/view.html b/apps/Core/Views/Default/html/system/api/client/services/view.html index cb312ac08..4509c50a1 100644 --- a/apps/Core/Views/Default/html/system/api/client/services/view.html +++ b/apps/Core/Views/Default/html/system/api/client/services/view.html @@ -3,14 +3,6 @@ {% set title = 'API:' ~ api['category'] ~ ':' ~ api['provider'] ~ ' - ' ~ api['name'] %} {% else %} {% set apiId = '' %} - {% if api['repository'] is defined and api['repository'] === true %} - {% set title = 'New API:' ~ api['category'] %} - {% else %} - {% set title = 'New API:' ~ api['category'] ~ ':' ~ api['provider'] %} - {% endif %} + {% set title = 'New API:' ~ api['category'] ~ ':' ~ api['provider'] %} {% endif %} -{% if api['repository'] is defined and api['repository'] === true %} - {{view.getPartial('../../modules/repositories/view')}} -{% else %} - {{view.getPartial('services/apis/' ~ api['category'] ~ '/' ~ api['provider']|lower ~ '/view')}} -{% endif %} \ No newline at end of file +{{view.getPartial('services/apis/' ~ api['category'] ~ '/' ~ api['provider']|lower ~ '/view')}} \ No newline at end of file diff --git a/system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/ApiClientServices.php b/system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/ApiClientServices.php index 493df07e1..5dcecb075 100644 --- a/system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/ApiClientServices.php +++ b/system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/ApiClientServices.php @@ -95,13 +95,19 @@ protected function registerApiCategories() { $this->apiCategories = []; - $basepackagesApis = $this->modules->packages->getPackagesForCategory('basepackagesApis'); $apis = $this->modules->packages->getPackagesForCategory('appsApis'); - $apis = array_merge($basepackagesApis, $apis); + if ($this->apps->getAppInfo()['app_type'] === 'core') { + $basepackagesApis = $this->modules->packages->getPackagesForCategory('basepackagesApis'); + $apis = array_merge($basepackagesApis, $apis); + } if ($apis && is_array($apis) && count($apis) > 0) { foreach ($apis as $api) { + if ($this->apps->getAppInfo()['app_type'] !== $api['app_type']) { + continue; + } + $api['class'] = explode('\\', $api['class']); $category = strtolower($api['class'][$this->helper->lastKey($api['class']) - 2]); From 3b491e0f39f80d8cffc19114f9c49eb44f75d865 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Sat, 24 Aug 2024 14:59:55 +1000 Subject: [PATCH 06/34] update issue #352 - Fix information displayed on repo create to add all instead of * as we want to include .(dot) files like .gitignore as well. --- .../Core/Views/Default/html/devtools/modules/repodetails.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/Core/Views/Default/html/devtools/modules/repodetails.html b/apps/Core/Views/Default/html/devtools/modules/repodetails.html index 564b1065a..eeb4799b0 100644 --- a/apps/Core/Views/Default/html/devtools/modules/repodetails.html +++ b/apps/Core/Views/Default/html/devtools/modules/repodetails.html @@ -16,7 +16,7 @@
New repository created at remote location

git remote add origin

git pull

git checkout dev

-

git add *

+

git add --all

git commit -m "Initial Commit"

git push -u origin dev

@@ -30,7 +30,7 @@
New repository created at remote location

git remote add origin

git pull

git checkout dev

-

git add *

+

git add --all

git commit -m "Initial Commit"

git push -u origin dev

From 5803e8783f7f9314a2b0b5300788ba081396879e Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Sat, 24 Aug 2024 15:00:46 +1000 Subject: [PATCH 07/34] update #34 - Fix not able to grab categories that are camel case. --- .../Providers/ModulesServiceProvider/Modules/Packages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Base/Providers/ModulesServiceProvider/Modules/Packages.php b/system/Base/Providers/ModulesServiceProvider/Modules/Packages.php index adc1cb4b9..e761cc839 100644 --- a/system/Base/Providers/ModulesServiceProvider/Modules/Packages.php +++ b/system/Base/Providers/ModulesServiceProvider/Modules/Packages.php @@ -164,7 +164,7 @@ public function getPackagesForCategory($category) $packages = []; foreach($this->packages as $package) { - if ($package['category'] === $category) { + if (strtolower($package['category']) === strtolower($category)) { $packages[$package['id']] = $package; } } @@ -177,7 +177,7 @@ public function getPackagesForAppType($appType) $packages = []; foreach($this->packages as $package) { - if ($package['app_type'] === $appType) { + if (strtolower($package['app_type']) === strtolower($appType)) { $packages[$package['id']] = $package; } } From 1e3d246b385c21b2bd54952abeb9831ba592420f Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Fri, 30 Aug 2024 13:02:51 +1000 Subject: [PATCH 08/34] Update #568 & #569 - Fixed exception for template for timezone component - Fixed TZ extraction from wikipedia failing. - Refactored widgets and dashboard components/packages. - Removed old widgetsserviceprovider as its moved to basepackages. --- .gitmodules | 6 +- .../Dashboards/DashboardsComponent.php | 21 ++-- .../ExtractgeodataComponent.php | 40 ++++---- .../Geo/Timezones/TimezonesComponent.php | 4 +- .../Packages/Devtools/GeoExtractData/Data | 2 +- .../GeoExtractData/DevtoolsGeoExtractData.php | 43 +++++---- .../Default/html/dashboards/dashboards.html | 32 ++++--- .../html/system/geo/timezones/form.html | 69 +++++++++---- .../html/system/geo/timezones/list.html | 4 +- .../widgets/worldclock/worldclock.html | 14 +-- public/core/default/css/plugins.css | 4 +- .../gridstack/10.3.1/gridstack-extra.min.css | 1 + .../gridstack/10.3.1/gridstack.min.css | 1 + .../gridstack/7.2.3/gridstack-extra.min.css | 1 - .../plugins/gridstack/7.2.3/gridstack.min.css | 1 - .../core/default/js/footer/jsFooterPlugins.js | 2 +- .../plugins/gridstack/10.3.1/gridstack-all.js | 2 + .../plugins/gridstack/7.2.3/gridstack-all.js | 2 - system/Base/BaseComponent.php | 62 +++--------- system/Base/Helpers.php | 14 ++- .../Register/Basepackages/Geo/Timezones.php | 3 +- .../Schema/Basepackages/Geo/Timezones.php | 10 +- system/Base/Providers.php | 1 - .../Packages/Dashboards.php | 96 +++++++++++++------ .../Packages/Geo/Data/AllCountries.json | 2 +- .../Packages/Geo/Data/TimeZones.json | 2 +- .../Packages/Widgets.php | 30 ++---- .../Base/Providers/WidgetServiceProvider.php | 25 ----- .../WidgetServiceProvider/Widget.php | 46 --------- 29 files changed, 262 insertions(+), 278 deletions(-) create mode 100644 public/core/default/css/plugins/gridstack/10.3.1/gridstack-extra.min.css create mode 100644 public/core/default/css/plugins/gridstack/10.3.1/gridstack.min.css delete mode 100644 public/core/default/css/plugins/gridstack/7.2.3/gridstack-extra.min.css delete mode 100644 public/core/default/css/plugins/gridstack/7.2.3/gridstack.min.css create mode 100644 public/core/default/js/footer/plugins/gridstack/10.3.1/gridstack-all.js delete mode 100644 public/core/default/js/footer/plugins/gridstack/7.2.3/gridstack-all.js delete mode 100644 system/Base/Providers/WidgetServiceProvider.php delete mode 100644 system/Base/Providers/WidgetServiceProvider/Widget.php diff --git a/.gitmodules b/.gitmodules index d08773eac..a262d99ef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ [submodule "phpunit"] path = phpunit url = https://github.com/sp-framework/phpunit.git -[submodule "apps/Core/Packages/Devtools/GeoExtractData/Data"] - path = apps/Core/Packages/Devtools/GeoExtractData/Data - url = https://github.com/sp-framework/geodata.git [submodule "docker"] path = docker url = https://github.com/sp-framework/docker-sp-core.git +[submodule "apps/Core/Packages/Devtools/GeoExtractData/Data"] + path = apps/Core/Packages/Devtools/GeoExtractData/Data + url = https://github.com/sp-framework/geodata.git diff --git a/apps/Core/Components/Dashboards/DashboardsComponent.php b/apps/Core/Components/Dashboards/DashboardsComponent.php index b465948f1..1d7788c0b 100644 --- a/apps/Core/Components/Dashboards/DashboardsComponent.php +++ b/apps/Core/Components/Dashboards/DashboardsComponent.php @@ -12,28 +12,27 @@ class DashboardsComponent extends BaseComponent public function viewAction() { if (isset($this->getData()['widgets'])) { + $this->getNewToken(); + if ($this->getData()['widgets'] == 'info') { - $this->getNewToken(); return $this->basepackages->widgets->getWidget($this->getData()['id'], 'info')['info']; - } else if ($this->getData()['widgets'] == 'content') { + } else if ($this->getData()['widgets'] == 'content') {//This is when we add the widget via list of widgets in dashboard. $dashboardWidget = $this->basepackages->dashboards->getDashboardWidgetById($this->getData()['id'], $this->getData()['did']); + $dashboardWidget['getWidgetData'] = true; - $this->getNewToken(); return $this->basepackages->widgets->getWidget($this->getData()['wid'], 'content', $dashboardWidget)['content']; } } else { if (isset($this->getData()['id'])) { $dashboardId = $this->getData()['id']; } else { - $app = $this->apps->getAppInfo(); - - if (is_string($app['settings'])) { - $app['settings'] = $this->helper->decode($app['settings'], true); + if (is_string($this->app['settings'])) { + $this->app['settings'] = $this->helper->decode($this->app['settings'], true); } - if (isset($app['settings']['defaultDashboard'])) { - $dashboardId = $app['settings']['defaultDashboard']; + if (isset($this->app['settings']['defaultDashboard'])) { + $dashboardId = $this->app['settings']['defaultDashboard']; } } } @@ -110,11 +109,11 @@ public function removeWidgetFromDashboardAction() ); } - public function getWidgetContentAction() + public function getDashboardWidgetsAction() { $this->requestIsPost(); - $this->basepackages->dashboards->getWidgetContent($this->postData()); + $this->basepackages->dashboards->getDashboardWidgets($this->postData()); $this->addResponse( $this->basepackages->dashboards->packagesData->responseMessage, diff --git a/apps/Core/Components/Devtools/Extractgeodata/ExtractgeodataComponent.php b/apps/Core/Components/Devtools/Extractgeodata/ExtractgeodataComponent.php index ac13d2ce5..6d8fae27b 100644 --- a/apps/Core/Components/Devtools/Extractgeodata/ExtractgeodataComponent.php +++ b/apps/Core/Components/Devtools/Extractgeodata/ExtractgeodataComponent.php @@ -38,9 +38,11 @@ public function processAction() } try { + $success = false; + if (isset($this->postData()['geo']) && $this->postData()['geo'] == 'true') { - $this->geoExtractDataPackage->downloadGeoData(); - $this->geoExtractDataPackage->processGeoData(); + $success = $this->geoExtractDataPackage->downloadGeoData(); + $success = $this->geoExtractDataPackage->processGeoData(); } if (isset($this->postData()['timezone']) && $this->postData()['timezone'] == 'true') { @@ -49,16 +51,18 @@ public function processAction() } if (isset($this->postData()['ip']) && $this->postData()['ip'] == 'true') { - $this->geoExtractDataPackage->downloadGeoIpv4Data(); - $this->geoExtractDataPackage->unzipGeoIpv4Data(); - $this->geoExtractDataPackage->processGeoIpv4Data(); - $this->geoExtractDataPackage->downloadGeoIpv6Data(); - $this->geoExtractDataPackage->unzipGeoIpv6Data(); - $this->geoExtractDataPackage->processGeoIpv6Data(); - $this->geoExtractDataPackage->mergeGeoIpData(); + $success = $this->geoExtractDataPackage->downloadGeoIpv4Data(); + $success = $this->geoExtractDataPackage->unzipGeoIpv4Data(); + $success = $this->geoExtractDataPackage->processGeoIpv4Data(); + $success = $this->geoExtractDataPackage->downloadGeoIpv6Data(); + $success = $this->geoExtractDataPackage->unzipGeoIpv6Data(); + $success = $this->geoExtractDataPackage->processGeoIpv6Data(); + $success = $this->geoExtractDataPackage->mergeGeoIpData(); } - $this->geoExtractDataPackage->zipData(); + if ($success) { + $this->geoExtractDataPackage->zipData(); + } $this->addResponse( $this->geoExtractDataPackage->packagesData->responseMessage, @@ -150,14 +154,18 @@ protected function registerProgressMethods() return false; } - $methods = array_merge($methods, - [ + if ((isset($this->postData()['geo']) && $this->postData()['geo'] == 'true') || + (isset($this->postData()['geo']) && $this->postData()['geo'] == 'true') + ) { + $methods = array_merge($methods, [ - 'method' => 'zipData', - 'text' => 'Zip Geo Location Data...', + [ + 'method' => 'zipData', + 'text' => 'Zip Geo Location Data...', + ] ] - ] - ); + ); + } $this->basepackages->progress->registerMethods($methods); diff --git a/apps/Core/Components/System/Geo/Timezones/TimezonesComponent.php b/apps/Core/Components/System/Geo/Timezones/TimezonesComponent.php index 01f1c8da2..ea5eb52b2 100644 --- a/apps/Core/Components/System/Geo/Timezones/TimezonesComponent.php +++ b/apps/Core/Components/System/Geo/Timezones/TimezonesComponent.php @@ -75,9 +75,9 @@ public function viewAction() $this->geoTimezones, 'system/geo/timezones/view', null, - ['zone_name', 'tz_name', 'gmt_offset', 'gmt_offset_name', 'gmt_offset_dst', 'gmt_offset_name_dst', 'abbreviation'], + ['zone_name', 'tz_name', 'gmt_offset', 'gmt_offset_name', 'abbreviation', 'gmt_offset_dst', 'gmt_offset_name_dst', 'abbreviation_dst'], true, - ['zone_name', 'tz_name', 'gmt_offset', 'gmt_offset_name', 'gmt_offset_dst', 'gmt_offset_name_dst', 'abbreviation'], + ['zone_name', 'tz_name', 'gmt_offset', 'gmt_offset_name', 'abbreviation', 'gmt_offset_dst', 'gmt_offset_name_dst', 'abbreviation_dst'], $controlActions, ['gmt_offset'=>'gmt offset (secs)','gmt_offset_dst'=>'gmt offset DST (secs)','tz_name'=>'time zone name'], $replaceColumns, diff --git a/apps/Core/Packages/Devtools/GeoExtractData/Data b/apps/Core/Packages/Devtools/GeoExtractData/Data index 45cf436fc..7111b2a85 160000 --- a/apps/Core/Packages/Devtools/GeoExtractData/Data +++ b/apps/Core/Packages/Devtools/GeoExtractData/Data @@ -1 +1 @@ -Subproject commit 45cf436fcec404fd4bd97f4701983e2ff8d8543b +Subproject commit 7111b2a85bb4a05efec5ea99b7bd9203d040de0d diff --git a/apps/Core/Packages/Devtools/GeoExtractData/DevtoolsGeoExtractData.php b/apps/Core/Packages/Devtools/GeoExtractData/DevtoolsGeoExtractData.php index c72509d14..2552cff64 100644 --- a/apps/Core/Packages/Devtools/GeoExtractData/DevtoolsGeoExtractData.php +++ b/apps/Core/Packages/Devtools/GeoExtractData/DevtoolsGeoExtractData.php @@ -194,33 +194,34 @@ protected function processTimezoneData() if ($table[0] && $table[0]->children) { foreach ($table[0]->children as $tr) { - if (isset($tr->children[4]) && trim($tr->children[4]->plaintext) === 'Canonical') { - $zoneName = trim($tr->children[2]->plaintext); + if (isset($tr->children[3]) && strtolower(trim($tr->children[3]->plaintext)) === 'canonical') { + $zoneName = trim($tr->children[1]->plaintext); + $zoneKey = strtolower(str_replace('/', '', $zoneName)); - $wikiTz[$zoneKey]['zoneName'] = trim($tr->children[2]->plaintext); - $wikiTz[$zoneKey]['gmtOffsetName'] = 'UTC' . trim($tr->children[5]->plaintext); - $wikiTz[$zoneKey]['gmtOffset'] = $this->getGMTOffset(trim($tr->children[5]->plaintext)); - $wikiTz[$zoneKey]['gmtOffsetNameDST'] = 'UTC' . trim($tr->children[6]->plaintext); - $wikiTz[$zoneKey]['gmtOffsetDST'] = $this->getGMTOffset(trim($tr->children[6]->plaintext)); + $wikiTz[$zoneKey]['zoneName'] = trim($tr->children[1]->plaintext); + $wikiTz[$zoneKey]['tzName'] = trim($tr->children[2]->plaintext); + if ($wikiTz[$zoneKey]['tzName'] === '') { + $wikiTz[$zoneKey]['tzName'] = $wikiTz[$zoneKey]['zoneName']; + } + $wikiTz[$zoneKey]['gmtOffsetName'] = 'UTC' . trim($tr->children[4]->plaintext); + $wikiTz[$zoneKey]['gmtOffset'] = $this->getGMTOffset(trim($tr->children[4]->plaintext)); + $wikiTz[$zoneKey]['abbreviation'] = trim($tr->children[6]->plaintext); + $wikiTz[$zoneKey]['gmtOffsetNameDST'] = 'UTC' . trim($tr->children[5]->plaintext); + $wikiTz[$zoneKey]['gmtOffsetDST'] = $this->getGMTOffset(trim($tr->children[5]->plaintext)); + if (count($tr->children) === 10) { + $wikiTz[$zoneKey]['abbreviationDST'] = trim($tr->children[7]->plaintext); + } else { + $wikiTz[$zoneKey]['abbreviationDST'] = '-'; + } } } } - $allCountries = $this->helper->decode($this->localContent->read($this->sourceDir . 'AllCountries.json'), true); - - foreach ($allCountries as $country) { - if (isset($country['timezones']) && count($country['timezones']) > 0) { - foreach ($country['timezones'] as $tzKey => $tz) { - $tzName = strtolower(str_replace('/', '', $tz['zoneName'])); + if (count($wikiTz) === 0) { + $this->addResponse('Not able to extract tz data.', 1); - if (isset($wikiTz[$tzName])) { - $wikiTz[$tzName] = array_replace($tz, $wikiTz[$tzName]); - } else { - $wikiTz[$tzName] = $tz; - } - } - } + return false; } try { @@ -229,6 +230,8 @@ protected function processTimezoneData() throw $e; } + $this->addResponse('Downloaded and extract Tz data'); + return true; } diff --git a/apps/Core/Views/Default/html/dashboards/dashboards.html b/apps/Core/Views/Default/html/dashboards/dashboards.html index 8e3df1395..0feaf8ab9 100644 --- a/apps/Core/Views/Default/html/dashboards/dashboards.html +++ b/apps/Core/Views/Default/html/dashboards/dashboards.html @@ -77,7 +77,7 @@
No widgets added to this d )}} \ No newline at end of file diff --git a/apps/Core/Views/Default/html/dashboards/dashboards/dashboard.html b/apps/Core/Views/Default/html/dashboards/dashboards/dashboard.html new file mode 100644 index 000000000..69ece22a4 --- /dev/null +++ b/apps/Core/Views/Default/html/dashboards/dashboards/dashboard.html @@ -0,0 +1,34 @@ +{% if dashboard['id'] is defined %} + {% set dashboardId = dashboard['id'] %} + {% set title = 'Dashboard (' ~ dashboard['name'] ~ ')' %} +{% else %} + {% set dashboardId = '' %} + {% set title = 'New Dashboard' %} +{% endif %} +{{adminltetags.useTag('content', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'parentComponentId' : parent, + 'sectionId' : 'main', + 'contentType' : 'sectionWithForm', + 'cardHeader' : true, + 'cardFooter' : true, + 'cardType' : 'primary', + 'cardIcon' : 'dashboard', + 'cardTitle' : title, + 'cardAdditionalClass' : 'rounded-0', + 'cardBodyInclude' : 'dashboards/dashboards/form', + 'formButtons' : + [ + 'updateButtonId' : dashboardId, + 'addActionUrl' : 'dashboards/add', + 'addSuccessRedirectUrl' : 'dashboards', + 'updateActionUrl' : 'dashboards/update', + 'updateSuccessRedirectUrl' : 'dashboards', + 'cancelActionUrl' : 'dashboards', + 'closeActionUrl' : 'dashboards' + ] + ] +)}} \ No newline at end of file diff --git a/apps/Core/Views/Default/html/dashboards/dashboards/form.html b/apps/Core/Views/Default/html/dashboards/dashboards/form.html new file mode 100644 index 000000000..f1adf40d6 --- /dev/null +++ b/apps/Core/Views/Default/html/dashboards/dashboards/form.html @@ -0,0 +1,130 @@ +{% set defaultChecked = false %} +{% if dashboard['id'] is defined %} + {% set dashboardId = dashboard['id'] %} + {% set dashboardName = dashboard['name'] %} + {% if dashboard['is_default'] is defined and dashboard['is_default'] == true %} + {% set defaultChecked = true %} + {% endif %} +{% else %} + {% set dashboardId = '' %} + {% set dashboardName = '' %} +{% endif %} +
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'id', + 'fieldLabel' : 'Dashboard ID', + 'fieldType' : 'input', + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Dashboard ID', + 'fieldRequired' : true, + 'fieldBazScan' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : true, + 'fieldHidden' : true, + 'fieldDisabled' : true, + 'fieldValue' : dashboardId + ] + )}} +
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'name', + 'fieldLabel' : 'Dashboard Name', + 'fieldType' : 'input', + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Dashboard Name', + 'fieldRequired' : true, + 'fieldBazScan' : true, + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : true, + 'fieldBazPostOnUpdate' : true, + 'fieldDataInputMinLength' : 1, + 'fieldDataInputMaxLength' : 50, + 'fieldValue' : dashboardName + ] + )}} +
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'is_default', + 'fieldLabel' : 'Dashboard is default?', + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Check to make the dashboard default dashboard.', + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'info', + 'fieldCheckboxChecked' : defaultChecked, + 'fieldCheckboxAdditionClass' : 'text-sm text-uppercase', + 'fieldBazPostOnCreate' : true, + 'fieldBazPostOnUpdate' : true, + 'fieldBazJstreeSearch' : true, + 'fieldBazScan' : true + ] + )}} +
+
+
+ \ No newline at end of file diff --git a/apps/Core/Views/Default/html/dashboards/dashboards/list.html b/apps/Core/Views/Default/html/dashboards/dashboards/list.html index da0175aa6..382bd389e 100644 --- a/apps/Core/Views/Default/html/dashboards/dashboards/list.html +++ b/apps/Core/Views/Default/html/dashboards/dashboards/list.html @@ -12,27 +12,16 @@ 'fieldGroupPreAddonIcon' : 'dashboard', 'fieldGroupPostAddonButtons' : [ - 'sync' : [ - 'title' : false, - 'type' : 'primary', - 'tooltipTitle' : 'Share', - 'icon' : 'share', - 'noMargin' : true, - 'disabled' : true, - 'buttonAdditionalClass' : 'rounded-0', - 'position' : 'right' - ], 'edit' : [ 'title' : false, 'type' : 'warning', 'icon' : 'edit', 'noMargin' : true, - 'disabled' : true, - 'url' : links.url('dashboards/q/id/0'), - 'buttonAdditionalClass' : 'rounded-0 text-white contentAjaxLink disabled', + 'url' : links.url('dashboards/q/id/'), + 'buttonAdditionalClass' : 'rounded-0 text-white contentAjaxLink', 'position' : 'right' ], - 'delete' : [ + 'remove' : [ 'title' : false, 'type' : 'danger', 'icon' : 'trash', @@ -58,10 +47,7 @@ 'fieldDataSelectOptionsKey' : 'id', 'fieldDataSelectOptionsValue' : 'name', 'fieldDataSelectOptionsSelected' : dashboard['id'], - 'fieldDataSelectOptionsZero' : true, + 'fieldDataSelectOptionsZero' : false, 'fieldDataSelectOptionsZeroTitle' : 'Select dashboard' ] -)}} - \ No newline at end of file +)}} \ No newline at end of file diff --git a/apps/Core/Views/Default/html/dashboards/dashboards/share.html b/apps/Core/Views/Default/html/dashboards/dashboards/share.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/system/Base/Installer/Packages/Setup/Register/Basepackages/Dashboard.php b/system/Base/Installer/Packages/Setup/Register/Basepackages/Dashboard.php index 38c4289db..ea23f2572 100644 --- a/system/Base/Installer/Packages/Setup/Register/Basepackages/Dashboard.php +++ b/system/Base/Installer/Packages/Setup/Register/Basepackages/Dashboard.php @@ -10,6 +10,7 @@ public function register($db, $ff, $componentFile, $helper) [ 'name' => 'Default', 'app_id' => 1, + 'app_default' => 1, 'created_by' => 1, 'settings' => $helper->encode($componentFile['settings']) ]; diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Dashboards.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Dashboards.php index ff4b07877..cdc777d43 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Dashboards.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Dashboards.php @@ -35,6 +35,13 @@ public function columns() 'notNull' => true ] ), + new Column( + 'app_default', + [ + 'type' => Column::TYPE_BOOLEAN, + 'notNull' => true + ] + ), new Column( 'created_by', [ @@ -42,6 +49,20 @@ public function columns() 'notNull' => true ] ), + new Column( + 'shared', + [ + 'type' => Column::TYPE_JSON, + 'notNull' => false + ] + ), + new Column( + 'is_default', + [ + 'type' => Column::TYPE_BOOLEAN, + 'notNull' => false + ] + ), new Column( 'settings', [ diff --git a/system/Base/Providers/BasepackagesServiceProvider/Packages/Dashboards.php b/system/Base/Providers/BasepackagesServiceProvider/Packages/Dashboards.php index 29faa7696..a14ebc9ad 100644 --- a/system/Base/Providers/BasepackagesServiceProvider/Packages/Dashboards.php +++ b/system/Base/Providers/BasepackagesServiceProvider/Packages/Dashboards.php @@ -3,6 +3,7 @@ namespace System\Base\Providers\BasepackagesServiceProvider\Packages; use System\Base\BasePackage; +use System\Base\Exceptions\IdNotFoundException; use System\Base\Providers\AccessServiceProvider\Exceptions\PermissionDeniedException; use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesDashboards; use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Dashboards\BasepackagesDashboardsWidgets; @@ -13,6 +14,8 @@ class Dashboards extends BasePackage public $dashboards; + protected $maxWidgetsPerDashboard = 10; + public function init(bool $resetCache = false) { $this->getAll($resetCache); @@ -53,6 +56,60 @@ public function getDashboardById(int $id, $getwidgets = true, $getContent = fals return false; } + public function addDashboard(array $data) + { + $data['app_id'] = $this->apps->getAppInfo()['id']; + + $data['created_by'] = 0; + if ($this->access->auth->account()) { + $data['created_by'] = $this->access->auth->account()['id']; + } + + $data['settings']['maxWidgetsPerDashboard'] = $this->maxWidgetsPerDashboard; + + if ($this->add($data)) { + $this->addResponse('Dashboard Added'); + } else { + $this->addResponse('Error Adding Dashboard', 1); + } + } + + public function updateDashboard(array $data) + { + $dashboard = $this->getDashboardById($data['dashboard_id']); + + if (!$dashboard) { + throw new IdNotFoundException; + } + + if ($this->access->auth->account() && + $this->access->auth->account()['id'] != $dashboard['created_by'] + ) { + throw new PermissionDeniedException; + } + + if ($this->update($data)) { + $this->addResponse('Dashboard Updated'); + } else { + $this->addResponse('Error Updating Dashboard', 1); + } + } + + public function removeDashboard(array $data) + { + $dashboard = $this->getById($data['id']); + + if (!$dashboard) { + throw new IdNotFoundException; + } + + if ($this->remove($data['id'])) { + $this->addResponse('Dashboard Removed'); + } else { + $this->addResponse('Error Removing Dashboard', 1); + } + } + public function getDashboardWidgetById(int $id, int $dashboardId, $getContent = false) { $dashboard = $this->getDashboardById($dashboardId, true, $getContent); @@ -78,6 +135,10 @@ public function addWidgetToDashboard(array $data) { $dashboard = $this->getDashboardById($data['dashboard_id']); + if (!$dashboard) { + throw new IdNotFoundException; + } + if ($this->access->auth->account() && $this->access->auth->account()['id'] != $dashboard['created_by'] ) { @@ -140,6 +201,10 @@ public function updateWidgetToDashboard(array $data) { $dashboard = $this->getDashboardById($data['dashboard_id']); + if (!$dashboard) { + throw new IdNotFoundException; + } + if ($this->access->auth->account() && $this->access->auth->account()['id'] != $dashboard['created_by'] ) { @@ -193,6 +258,10 @@ public function removeWidgetFromDashboard(array $data) { $dashboard = $this->getDashboardById($data['dashboard_id']); + if (!$dashboard) { + throw new IdNotFoundException; + } + if ($this->access->auth->account() && $this->access->auth->account()['id'] != $dashboard['created_by'] ) { @@ -228,6 +297,10 @@ public function getDashboardWidgets(array $data) { $dashboard = $this->getDashboardById($data['dashboard_id'], true); + if (!$dashboard) { + throw new IdNotFoundException; + } + if (isset($dashboard['widgets']) && count($dashboard['widgets']) > 0) { if (isset($data['widget_id'])) { foreach ($dashboard['widgets'] as $key => $widget) { diff --git a/system/Base/Providers/BasepackagesServiceProvider/Packages/Model/BasepackagesDashboards.php b/system/Base/Providers/BasepackagesServiceProvider/Packages/Model/BasepackagesDashboards.php index 3a26eaee6..028b3e8d1 100644 --- a/system/Base/Providers/BasepackagesServiceProvider/Packages/Model/BasepackagesDashboards.php +++ b/system/Base/Providers/BasepackagesServiceProvider/Packages/Model/BasepackagesDashboards.php @@ -15,8 +15,14 @@ class BasepackagesDashboards extends BaseModel public $app_id; + public $app_default; + public $created_by; + public $shared; + + public $is_default; + public $settings; public function initialize() From 3746c786b29c1e4323975bd99e4a5557d255c0e9 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Sun, 1 Sep 2024 14:30:28 +1000 Subject: [PATCH 12/34] update #569 --- apps/Core/Packages/Devtools/GeoExtractData/Data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/Core/Packages/Devtools/GeoExtractData/Data b/apps/Core/Packages/Devtools/GeoExtractData/Data index 7111b2a85..36833ebf0 160000 --- a/apps/Core/Packages/Devtools/GeoExtractData/Data +++ b/apps/Core/Packages/Devtools/GeoExtractData/Data @@ -1 +1 @@ -Subproject commit 7111b2a85bb4a05efec5ea99b7bd9203d040de0d +Subproject commit 36833ebf0e69c50277a21b0d8378bc9fed93a7a5 From f68b3d4b8d1693b58b2f95e11122f3d3d28737d7 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Sun, 1 Sep 2024 14:45:55 +1000 Subject: [PATCH 13/34] fix bug with timer not being stopped after we move away from dashboard worldclock widgets #569 --- .../core/default/js/header/dependencies/Baz/BazContentLoader.js | 1 + public/core/default/js/header/jsHeaderCore.js | 1 + 2 files changed, 2 insertions(+) diff --git a/public/core/default/js/header/dependencies/Baz/BazContentLoader.js b/public/core/default/js/header/dependencies/Baz/BazContentLoader.js index 6224c59b9..5f6c8f190 100644 --- a/public/core/default/js/header/dependencies/Baz/BazContentLoader.js +++ b/public/core/default/js/header/dependencies/Baz/BazContentLoader.js @@ -148,6 +148,7 @@ var BazContentLoader = function() { } function loadAjax(element, options, popped) { + BazHelpers.setTimeoutTimers.stopAll();//Stop all timers from previous component. var urlToLoad, elementId; var dataCollection = window.dataCollection; // Delete old Content Objects diff --git a/public/core/default/js/header/jsHeaderCore.js b/public/core/default/js/header/jsHeaderCore.js index fb9871c50..ca25076a4 100644 --- a/public/core/default/js/header/jsHeaderCore.js +++ b/public/core/default/js/header/jsHeaderCore.js @@ -148,6 +148,7 @@ var BazContentLoader = function() { } function loadAjax(element, options, popped) { + BazHelpers.setTimeoutTimers.stopAll();//Stop all timers from previous component. var urlToLoad, elementId; var dataCollection = window.dataCollection; // Delete old Content Objects From 0ea5ba00d79fba95933aaac384aa10c6701e6631 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Mon, 2 Sep 2024 15:19:41 +1000 Subject: [PATCH 14/34] update #570 - Added shared for dashboard. added remove for dashboard --- .../Dashboards/DashboardsComponent.php | 139 +++++++++++++++++- .../Default/html/dashboards/dashboards.html | 52 +++++-- .../html/dashboards/dashboards/form.html | 97 +++++++++++- .../html/dashboards/dashboards/list.html | 2 +- .../Packages/Dashboards.php | 71 ++++++++- .../Packages/Users/Accounts.php | 6 +- 6 files changed, 337 insertions(+), 30 deletions(-) diff --git a/apps/Core/Components/Dashboards/DashboardsComponent.php b/apps/Core/Components/Dashboards/DashboardsComponent.php index 1f4a18c15..db53ef1a3 100644 --- a/apps/Core/Components/Dashboards/DashboardsComponent.php +++ b/apps/Core/Components/Dashboards/DashboardsComponent.php @@ -24,30 +24,103 @@ public function viewAction() return $this->basepackages->widgets->getWidget($this->getData()['wid'], 'content', $dashboardWidget)['content']; } } else { + if (is_string($this->app['settings'])) { + $this->app['settings'] = $this->helper->decode($this->app['settings'], true); + } + if (isset($this->getData()['id'])) { + $this->view->sharedAccounts = []; + if ($this->getData()['id'] != 0) { $dashboardId = $this->getData()['id']; - $this->view->dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true, false); + $dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true, false); + $dashboard['is_app_default'] = false; + + if (isset($this->app['settings']['defaultDashboard'])) { + if ($this->app['settings']['defaultDashboard'] == $dashboard['id']) { + $dashboard['is_app_default'] = true; + } + + $this->view->isAppDefault = true; + } + + if (isset($dashboard['shared']) && is_string($dashboard['shared'])) { + $dashboard['shared'] = $this->helper->decode($dashboard['shared'], true); + } + + if ($dashboard['shared'] && count($dashboard['shared']) > 0) { + $sharedAccounts = []; + + foreach ($dashboard['shared'] as $accountId) { + $account = $this->basepackages->accounts->getAccountById($accountId); + + if ($account) { + $sharedAccounts[] = + ['id' => $account['id'], 'email' => $account['email']]; + } + } + + $this->view->sharedAccounts = $sharedAccounts; + } else { + $dashboard['shared'] = []; + } + + $this->view->dashboard = $dashboard; } $this->view->pick('dashboards/dashboards/dashboard'); return; } else { - if (is_string($this->app['settings'])) { - $this->app['settings'] = $this->helper->decode($this->app['settings'], true); - } - if (isset($this->app['settings']['defaultDashboard'])) { $dashboardId = $this->app['settings']['defaultDashboard']; + } - $this->view->isAppDefault = true; + $dashboards = $this->basepackages->dashboards->dashboards; + $dashboards = msort($dashboards, 'is_default'); + + if ($this->access->auth->account()) { + foreach ($dashboards as $dashboardKey => &$dashboard) { + //Check app default dashboard + if ($dashboard['id'] == $dashboardId) { + $dashboard['name'] = $dashboard['name'] . ' (App Default)'; + + continue; + } + + //Check shared + $isShared = false; + if ($dashboard['shared']) { + if (is_string($dashboard['shared'])) { + $dashboard['shared'] = $this->helper->decode($dashboard['shared'], true); + } + + if (in_array($this->access->auth->account()['id'], $dashboard['shared'])) { + $dashboard['name'] = $dashboard['name'] . ' (Shared By ' . $this->basepackages->accounts->getAccountById($dashboard['created_by'])['email'] . ')'; + $isShared = true; + } + } + + //Check Creator + if ($dashboard['created_by'] != $this->access->auth->account()['id'] && + !$isShared + ) { + unset($dashboards[$dashboardKey]); + } + + //Default + if ($dashboard['is_default'] && !$isShared) { + $dashboardId = $dashboard['id']; + + $dashboard['name'] = $dashboard['name'] . ' (User Default)'; + } + } } $this->view->dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true, false); - $this->view->dashboards = $this->basepackages->dashboards->dashboards; + $this->view->dashboards = $dashboards; $this->view->widgetsTree = $this->basepackages->widgets->getWidgetsTree(); } @@ -148,4 +221,56 @@ public function getDashboardWidgetsAction() $this->basepackages->dashboards->packagesData->responseData ); } + + public function searchAccountAction() + { + $this->requestIsPost(); + + if ($this->postData()['search']) { + $searchQuery = $this->postData()['search']; + + if (strlen($searchQuery) < 3) { + return; + } + + $searchAccounts = $this->basepackages->accounts->searchAccountInternal($searchQuery); + + if ($searchAccounts) { + $currentAccount = $this->access->auth->account(); + + if ($currentAccount) { + foreach ($searchAccounts as $accountKey => &$account) { + if ($account['id'] == $currentAccount['id']) { + unset($accounts[$accountKey]); + continue; + } + + $profile = $this->basepackages->profiles->getProfile($account['id']); + + $account['name'] = $profile['full_name']; + } + + $this->addResponse( + $this->basepackages->accounts->packagesData->responseMessage, + $this->basepackages->accounts->packagesData->responseCode, + ['accounts' => $searchAccounts] + ); + } else { + $this->addResponse( + $this->basepackages->accounts->packagesData->responseMessage, + $this->basepackages->accounts->packagesData->responseCode, + ['accounts' => $searchAccounts] + ); + } + } else { + $this->addResponse( + $this->basepackages->accounts->packagesData->responseMessage, + $this->basepackages->accounts->packagesData->responseCode, + ['accounts' => []] + ); + } + } else { + $this->addResponse('search query missing', 1); + } + } } \ No newline at end of file diff --git a/apps/Core/Views/Default/html/dashboards/dashboards.html b/apps/Core/Views/Default/html/dashboards/dashboards.html index 168bc96a0..4296b35be 100644 --- a/apps/Core/Views/Default/html/dashboards/dashboards.html +++ b/apps/Core/Views/Default/html/dashboards/dashboards.html @@ -61,7 +61,7 @@
No widgets added to this d )}} +
+ {{adminltetags.useTag('modal', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'modalId' : 'queue-settings-modal', + 'modalBodyInclude' : 'modules/settings', + 'modalSize' : 'xl', + 'modalHeader' : true, + 'modalFooter' : true, + 'modalHeaderCloseButton' : true, + 'modalEscClose' : true, + 'modalTitle' : ' QUEUE SETTINGS', + 'modalFooterButtons' : + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'parentComponentId' : parent, + 'sectionId' : sectionId, + 'buttonType' : 'button', + 'buttons' : + [ + 'modal-button-save' : [ + 'title' : 'save', + 'type' : 'primary', + 'position' : 'right', + 'icon' : 'cog fa-spin', + 'iconHidden' : true + ] + ] + ] + ] + )}} +
{{adminltetags.useTag('modal', [ @@ -437,3 +612,4 @@ ] )}}
+ \ No newline at end of file diff --git a/apps/Core/Views/Default/html/modules/settings.html b/apps/Core/Views/Default/html/modules/settings.html new file mode 100644 index 000000000..f6e6baeec --- /dev/null +++ b/apps/Core/Views/Default/html/modules/settings.html @@ -0,0 +1,391 @@ +{% set settingsBackupAppsDirChecked = false %} +{% set settingsBackupSystemsDirChecked = false %} +{% set settingsBackupPublicDirChecked = false %} +{% set settingsBackupPrivateDirChecked = false %} +{% set settingsBackupExternalDirChecked = false %} +{% set settingsBackupHTMLCompiledDirChecked = false %} +{% set settingsBackupVarDirChecked = false %} +{% set settingsBackupExternalVendorDirChecked = false %} +{% set settingsBackupOldBackupsChecked = false %} +{% set settingsBackupDatabaseChecked = false %} +{% set settingsBackupKeysChecked = false %} +{% if queue['settings']['backupSettings']['apps_dir'] == 'true' %} + {% set settingsBackupAppsDirChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['systems_dir'] == 'true' %} + {% set settingsBackupSystemsDirChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['public_dir'] == 'true' %} + {% set settingsBackupPublicDirChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['private_dir'] == 'true' %} + {% set settingsBackupPrivateDirChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['external_dir'] == 'true' %} + {% set settingsBackupExternalDirChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['html_compiled'] == 'true' %} + {% set settingsBackupHTMLCompiledDirChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['var_dir'] == 'true' %} + {% set settingsBackupVarDirChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['external_vendor_dir'] == 'true' %} + {% set settingsBackupExternalVendorDirChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['old_backups'] == 'true' %} + {% set settingsBackupOldBackupsChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['database'] == 'true' %} + {% set settingsBackupDatabaseChecked = true %} +{% endif %} +{% if queue['settings']['backupSettings']['keys'] == 'true' %} + {% set settingsBackupKeysChecked = true %} +{% endif %} +
+
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'apps_dir', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup apps directory?', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'success', + 'fieldCheckboxLabel' : 'BACKUP APPS DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupAppsDirChecked, + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'systems_dir', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup systems directory?', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'success', + 'fieldCheckboxLabel' : 'BACKUP SYSTEMS DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupSystemsDirChecked, + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'public_dir', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup public directory?', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'success', + 'fieldCheckboxLabel' : 'BACKUP PUBLIC DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupPublicDirChecked, + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'private_dir', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup private directory?', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'success', + 'fieldCheckboxLabel' : 'BACKUP PRIVATE DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupPrivateDirChecked, + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'external_dir', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup external (third party) directory? It includes only composer files. If you want to backup whole vendor folder, select Backup External Vendor Directory option as well.', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'success', + 'fieldCheckboxLabel' : 'BACKUP EXTERNAL DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupExternalDirChecked, + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'html_compiled', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Compiled Templates Directory? Note: This can be regenerated.', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'warning', + 'fieldCheckboxChecked' : settingsBackupHTMLCompiledDirChecked, + 'fieldCheckboxLabel' : 'COMPILED HTML DIRECTORY', + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'var_dir', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup var (variable) directory? This directory contains logs, cache, session information. Information that will be regenerated by the system again.', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'warning', + 'fieldCheckboxChecked' : settingsBackupVarDirChecked, + 'fieldCheckboxLabel' : 'VAR DIRECTORY', + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'external_vendor_dir', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup external (third party) vendor directory? Note: External code can be restored using composer.', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'warning', + 'fieldCheckboxLabel' : 'BACKUP EXTERNAL VENDOR DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupExternalVendorDirChecked, + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'old_backups', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Old backup files? This will increase the total size of the backup depending on how many backups you have taken before.', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'danger', + 'fieldCheckboxChecked' : settingsBackupOldBackupsChecked, + 'fieldCheckboxLabel' : 'OLD BACKUP FILES', + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'database', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup database?', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'success', + 'fieldCheckboxChecked' : settingsBackupDatabaseChecked, + 'fieldCheckboxLabel' : 'DATABASE', + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'keys', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Security and DB keys?', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'danger', + 'fieldCheckboxChecked' : settingsBackupKeysChecked, + 'fieldDisabled' : true, + 'fieldCheckboxLabel' : 'SECURITY AND DB KEYS', + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'password_protect', + 'fieldLabel' : 'Password Protect', + 'fieldType' : 'input', + 'fieldInputType' : 'password', + 'fieldInputPasswordToggleVisibility' : true, + 'fieldInputPasswordGenerate' : true, + 'fieldInputPasswordStrengthMeter' : true, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'We will password protect the zip file if password is provided. Password protection is a must in case of Security and DB keys (if not provided, a new password will be auto generated). During restore, you need to enter this password, else restore will fail. Please keep this password safe.', + 'fieldRequired' : false, + 'fieldBazScan' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldAdditionalClass' : 'mb-0', + 'fieldValue' : queue['settings']['backupSettings']['password_protect'] + ] + )}} +
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'notes', + 'fieldLabel' : 'Backup Notes', + 'fieldType' : 'textarea', + 'fieldDataMaxLength' : 2048, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Backup Notes', + 'fieldRequired' : false, + 'fieldBazScan' : true, + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldDataInputMaxLength' : 2048, + 'fieldTextareaRows' : 2, + 'fieldValue' : queue['settings']['backupSettings']['notes'] + ] + )}} +
+
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'email_report', + 'fieldLabel' : 'Email Report', + 'fieldType' : 'input', + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'Email report to the email addresses. Enter comma separated email addresses.', + 'fieldRequired' : false, + 'fieldBazScan' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldAdditionalClass' : 'mb-0', + 'fieldValue' : queue['settings']['emailReport'] + ] + )}} +
+
+
+
+
\ No newline at end of file diff --git a/apps/Core/Views/Default/html/modules/view.html b/apps/Core/Views/Default/html/modules/view.html index 79b5bcab9..ed2a1d5d5 100644 --- a/apps/Core/Views/Default/html/modules/view.html +++ b/apps/Core/Views/Default/html/modules/view.html @@ -6,6 +6,7 @@ {% if queue['status'] == 1 %} {% set precheckHidden = false %} {% set precheckTitle = 'Re-Perform Precheck' %} + {% set processHidden = false %} {% elseif queue['status'] == 2 %} {% set precheckHidden = true %} {% set analyseHidden = true %} @@ -40,8 +41,7 @@ 'type' : 'primary', 'icon' : 'cog fa-spin', 'iconHidden' : true, - 'hidden' : processHidden, - 'disabled' : true + 'hidden' : processHidden ], 'cancel' : [ 'title' : 'Cancel', diff --git a/system/Base/Installer/Packages/Setup/Schema/Modules/Queues.php b/system/Base/Installer/Packages/Setup/Schema/Modules/Queues.php index 079c19a59..3422ab5b2 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Modules/Queues.php +++ b/system/Base/Installer/Packages/Setup/Schema/Modules/Queues.php @@ -84,6 +84,13 @@ public function columns() 'type' => Column::TYPE_SMALLINTEGER, 'notNull' => false, ] + ), + new Column( + 'settings', + [ + 'type' => Column::TYPE_JSON, + 'notNull' => false, + ] ) ] ]; diff --git a/system/Base/Providers/ModulesServiceProvider/Installer.php b/system/Base/Providers/ModulesServiceProvider/Installer.php index 24799385e..a9b7ffa66 100644 --- a/system/Base/Providers/ModulesServiceProvider/Installer.php +++ b/system/Base/Providers/ModulesServiceProvider/Installer.php @@ -41,9 +41,9 @@ class Installer extends BasePackage protected $modulesToInstallOrUpdate; - protected $runProcessPrecheckProgressMethods; + protected $runPrecheckProgressMethods; - protected $installProgressMethods; + protected $runProcessProgressMethods; protected $updatedBy; @@ -76,7 +76,7 @@ public function init($process = 'precheck') } if ($process === 'runprecheck') { - $this->registerRunProcessPrecheckProgressMethods(); + $this->registerRunPrecheckProgressMethods(); } else if ($process === 'runprocess') { $this->registerRunProcessProgressMethods(); } @@ -129,7 +129,7 @@ public function runProcess(array $data) if ($this->process === 'runprecheck') { $this->basepackages->progress->preCheckComplete(); - foreach ($this->runProcessPrecheckProgressMethods as $method) { + foreach ($this->runPrecheckProgressMethods as $method) { if ($this->withProgress($method['method'], $method['args'] ?? []) === false) { $this->modules->queues->update($this->queue); @@ -143,8 +143,17 @@ public function runProcess(array $data) $this->modules->queues->update($this->queue); $this->addResponse('Precheck complete', 0, ['queue' => $this->queue]); - } else if ($process === 'runprocess') { + } else if ($this->process === 'runprocess') { $this->basepackages->progress->preCheckComplete(); + + foreach ($this->runProcessProgressMethods as $method) { + if ($this->withProgress($method['method'], $method['args'] ?? []) === false) { + $this->modules->queues->update($this->queue); + + return false; + } + // usleep(500); + } // } } @@ -684,211 +693,6 @@ protected function runRsync($args) } } - // protected function checkDependencies() - // { - // if (count($this->modulesToProcess) === 0) { - // return true; - // } - - // // var_dump($this->modulesToProcess);die(); - // foreach ($this->modulesToProcess as $moduleName => $module) { - // $this->preCheckResult[$moduleName] = []; - // $this->preCheckResult[$moduleName]['module'] = $module['module']; - // $this->preCheckResult[$moduleName]['result'] = 'success'; - // $this->preCheckResult[$moduleName]['logs'] = ''; - - // $names = explode('-', $moduleName); - - // try { - // $jsonFile = $this->helper->decode($this->localContent->read($module['location'] . 'Install/' . substr($names[1], 0, -1) . '.json'), true); - // } catch (\throwable $e) { - // $this->preCheckResult[$moduleName]['result'] = 'error'; - // $this->preCheckResult[$moduleName]['logs'] .= 'Reading module ' . $moduleName . ' install JSON file resulted in error. '; - - // continue;//move onto the next one. - // } - - // // Make sure we have an entry for all module dependencies. Even if there are no dependencies, we need to make sure we have empty array for them. - // if (!isset($jsonFile['dependencies']) || - // (isset($jsonFile['dependencies']) && - // (!isset($jsonFile['dependencies']['core']) || - // !isset($jsonFile['dependencies']['components']) || - // !isset($jsonFile['dependencies']['packages']) || - // !isset($jsonFile['dependencies']['middlewares']) || - // !isset($jsonFile['dependencies']['views']))) - // ) { - // $this->preCheckResult[$moduleName]['result'] = 'error'; - // $this->preCheckResult[$moduleName]['logs'] .= 'Reading module ' . $moduleName . ' dependencies resulted in error. '; - - // continue;//move onto the next one. - // } - - // //Check Core dependency - // if (Version::greaterThan($jsonFile['dependencies']['core']['version'], $this->core->getVersion())) { - // //Lets check for latest release on Core as required version is greater than installed version. - // $core = $this->modules->packages->getPackageByName('core'); - // $core = $this->modules->manager->updateModuleRepoDetails($core); - - // if ($core) { - // $this->preCheckResult[$moduleName]['result'] = 'warning'; - // $this->preCheckResult[$moduleName]['logs'] .= 'Module ' . $moduleName . ' needs core version : ' . $core['update_version'] . '. Installed version of core is : ' . $core['version'] . '. Adding Core to list of updates. '; - - // $this->preCheckResult['core'] = []; - // $this->preCheckResult['core']['module'] = $core; - // $this->preCheckResult['core']['result'] = 'warning'; - // $name = $module['module']['name']; - // if (isset($module['module']['display_name'])) { - // $name = $module['module']['display_name']; - // } - // $this->preCheckResult['core']['logs'] = 'Added to queue as required by module : ' . $name . '. '; - // } - // } - - // // - // } - - // var_dump($this->preCheckResult);die(); - // // $this->getLatestRepositoryModulesData(); - - // ${$this->postData()['type']} = - // $this->{$this->postData()['type']}->getById($this->postData()['id'])->getAllArr(); - - // $dependencies = - // json_decode(${$this->postData()['type']}['dependencies'], true); - - // $checkForDependencies = $this->checkRegisteredDependencies($dependencies); - - // if (is_array($checkForDependencies)) { - // $this->packagesData->responseCode = 1; - - // $this->packagesData->responseMessage = - // 'Dependency ' . $checkForDependencies['name'] . ' not found!
' . - // 'Check repository ' . $checkForDependencies['repo'] . ' for further details.'; - - // return $this->packagesData; - // } - - // return true; - // } - - // protected function checkRegisteredDependencies($dependencies) - // { - // $found = true; - - // $this->dependenciesToDownload = []; - - // foreach ($dependencies as $dependencyKey => $dependencyValue) { - // if ($dependencyKey === 'app') { - // $dependencyKey = $dependencyKey . 's'; - // } - - // if (!isset($dependencyValue['name'])) { //if dependency is an array - // foreach ($dependencyValue as $multiDependencyKey => $multiDependencyValue) { - - // $thisDependency = - // $this->{$dependencyKey}->getAll( - // [ - // 'name' => $multiDependencyValue['name'], - // 'repo' => $multiDependencyValue['repo'], - // 'version' => $multiDependencyValue['version'] - // ] - // ); - - // if (!$thisDependency) { - - // $thisDependency = - // $this->{$dependencyKey}->getAll( - // [ - // 'name' => $multiDependencyValue['name'], - // 'repo' => $multiDependencyValue['repo'], - // 'update_version' => $multiDependencyValue['version'], - // ] - // ); - - // if ($thisDependency) { - - // if ($thisDependency[0]->get('update_available') === 1) { - - // $multiDependencyValue['type'] = $dependencyKey; - // $multiDependencyValue['id'] = $thisDependency[0]->get('id'); - // array_push($this->dependenciesToDownload, $multiDependencyValue); - // } - - // $found = true; - - // } else { - // $found = $multiDependencyValue; - - // return $found; - // } - // } else { - // if ($thisDependency[0]->get('installed') === 0) { - - // $multiDependencyValue['type'] = $dependencyKey; - // $multiDependencyValue['id'] = $thisDependency[0]->get('id'); - // array_push($this->dependenciesToDownload, $multiDependencyValue); - // } - - // $found = true; - // } - // } - // } else { - - // $thisDependency = - // $this->{$dependencyKey}->getAll( - // [ - // 'name' => $dependencyValue['name'], - // 'repo' => $dependencyValue['repo'], - // 'version' => $dependencyValue['version'], - // ] - // ); - - // if (!$thisDependency) { - - // $thisDependency = - // $this->{$dependencyKey}->getAll( - // [ - // 'name' => $dependencyValue['name'], - // 'repo' => $dependencyValue['repo'], - // 'update_version' => $dependencyValue['version'], - // ] - // ); - - // if ($thisDependency) { - - // if ($thisDependency[0]->get('update_available') === 1) { - - // $dependencyValue['type'] = $dependencyKey; - // $dependencyValue['id'] = $thisDependency[0]->get('id'); - // array_push($this->dependenciesToDownload, $dependencyValue); - - // } - - // $found = true; - - // } else { - // $found = $dependencyValue; - - // return $found; - // } - - // } else { - // if ($thisDependency[0]->get('installed') === 0) { - - // $dependencyValue['type'] = $dependencyKey; - // $dependencyValue['id'] = $thisDependency[0]->get('id'); - // array_push($this->dependenciesToDownload, $dependencyValue); - - // } - - // $found = true; - // } - // } - // } - - // return $found; - // } - public function cleanup(array $what) { if (in_array('composer', $what)) { @@ -920,277 +724,50 @@ public function cleanup(array $what) } } - // protected function getLatestRepositoryModulesData() - // { - // $repositories = getAllArr($this->repositories->getAll()); - - // if (count($repositories) > 0) { - // $modules = $this->packages->use(Modules::class); - - // foreach ($repositories as $repositoryKey => $repositoryValue) { - // $sync = $modules->syncRemoteWithLocal($repositoryValue['id']); - - // if ($sync->packagesData['responseCode'] === 1) { - // $this->packagesData->responseCode = 1; - - // $this->packagesData->responseMessage = 'Error Syncing with repository ' . $repositoryValue['name']; - - // return $this->packagesData; - // } - // } - // } - // } + protected function createBackup() + { + if ((bool) $this->queue['settings']['backupSettings']['backup'] === false) { + return true; + } - // protected function createBackup() - // { - // $this->backupLocation = '.backups/'; + if ($this->queue['settings']['backupSettings']['notes'] === '') { + $this->queue['settings']['backupSettings']['notes'] = 'Backup taking while processing module installer queue with ID: ' . $this->queue['id']; + } - // $now = new \DateTime('now'); + return $this->basepackages->backuprestore->init()->backup($this->queue['settings']['backupSettings']); + } - // $this->zip->open(base_path($this->backupLocation . '/' . $now->format('Y_m_d_H_i_s') . '.zip'), $this->zip::CREATE); + protected function rollBack() + { + // + } - // $framework = []; - // $framework['dir'] = []; - // $framework['file'] = []; + protected function registerRunPrecheckProgressMethods() + { + $this->runPrecheckProgressMethods = []; - // $rootContents = $this->localContent->listContents('/'); - - // foreach ($rootContents as $rootKey => $rootValue) { - // if ($rootValue['type'] === 'dir') { - // if ($rootValue['path'] !== '.backups' && - // $rootValue['path'] !== '.git' && - // $rootValue['path'] !== 'vendor' - // ) { - // array_push($framework['dir'], $rootValue['path']); - // } - // } else if ($rootValue['type'] === 'file') { - // if ($rootValue['path'] !== '.gitignore' && - // $rootValue['path'] !== '.htaccess.example' - // ) { - // array_push($framework['file'], $rootValue['path']); - // } - // } - // } - - // foreach ($framework['dir'] as $dirKey => $dirValue) { - // $rootDirContents[$dirValue] = $this->localContent->listContents($dirValue, true); - // } - - // foreach ($rootDirContents as $rootDirContentsKey => $rootDirContentsValue) { - // if (count($rootDirContentsValue) > 0) { - // foreach ($rootDirContentsValue as $subDirectoryKey => $subDirectory) { - // if ($subDirectory['type'] === 'dir') { - // $this->zip->addEmptyDir($subDirectory['dirname']); - // } else if ($subDirectory['type'] === 'file') { - // $this->zip->addFile($subDirectory['path']); - // } - // } - // } else { - // $this->zip->addEmptyDir($rootDirContentsKey); - // } - // }; - - // foreach ($framework['file'] as $fileKey => $fileValue) { - // $this->zip->addFile($fileValue); - // } - - // $this->zip->close(); - - // $this->packagesData->backupFile = $now->format('Y_m_d_H_i_s') . '.zip'; - - // $this->packagesData->responseCode = 0; - // } - - // protected function processInstall() - // { - // foreach ($this->modulesToInstall as $moduleToInstallKey => $moduleToInstall) { - - // $repoNameArr = explode('/', $moduleToInstall['repo']); - // $repoName = end($repoNameArr); - - // $this->downloadPackagesAndDependencies($moduleToInstall); - - // $contents = $this->extractDownloadedPackagesAndDependencies( - // $moduleToInstall['name'], - // $repoName, - // $moduleToInstall['type'] - // ); - - // if ($contents) { - // $files = $this->copyFilesToDestination( - // $contents, - // $moduleToInstall['name'], - // $repoName, - // $moduleToInstall['type'] - // ); - // } - - - // $this->{$moduleToInstall['type']}->update( - // [ - // 'id' => $moduleToInstall['id'], - // 'installed' => 1, - // 'files' => json_encode($files), - // ] - // ); - // } - // } - - // protected function processUpdate() - // { - // $files = []; - - // foreach ($this->modulesToInstall as $moduleToInstallKey => $moduleToInstall) { - // // - // //Delete only files first - // //Check if directory is empty, then delete directory - // //check if directory is html_compiled, if so, then scan directory, delete all files first and then all directories. - // //Copy all files. - // // - // var_dump(json_decode($this->{$moduleToInstall['type']}->getById($moduleToInstall['id'])->getAllArr()['files'], true)); - // // $repoNameArr = explode('/', $moduleToInstall['repo']); - // // $repoName = end($repoNameArr); - - // // $this->downloadPackagesAndDependencies($moduleToInstall); - - // // $contents = $this->extractDownloadedPackagesAndDependencies( - // // $moduleToInstall['name'], - // // $repoName, - // // $moduleToInstall['type'] - // // ); - - // // if ($contents) { - // // $files = $this->copyFilesToDestination( - // // $contents, - // // $moduleToInstall['name'], - // // $repoName, - // // $moduleToInstall['type'] - // // ); - // // } - - - // // $this->{$moduleToInstall['type']}->update( - // // [ - // // 'id' => $moduleToInstall['id'], - // // 'installed' => 1, - // // 'files' => json_encode($files), - // // ] - // // ); - // } - // } - - // protected function copyFilesToDestination($contents, $name, $repoName, $type) - // { - // $installedFiles = []; - // $installedFiles['dir'] = []; - // $installedFiles['files'] = []; - - // foreach ($contents as $contentKey => $content) { - // $destDir = - // str_replace( - // $this->downloadLocation . '/' . strtolower($repoName) . '-master/', - // '', - // $content['dirname'] - // ); - - // if ($content['type'] === 'dir') { - - // $this->localContent->createDirectory($destDir . '/' . $content['basename']); - - // array_push($installedFiles['dir'], $destDir . '/' . $content['basename']); - - // } else if ($content['type'] === 'file') { - - // if ($content['basename'] !== '.gitkeep') { - - // $this->localContent->copy($content['path'], $destDir . '/' . $content['basename']); - - // array_push($installedFiles['files'], $destDir . '/' . $content['basename']); - // } - - // } - // } - - // return $installedFiles; - // // if ($type === 'components' || $type === 'packages' || $type === 'middlewares') { - // // if ($type === 'components') { - // // $this->localContent->write( - // // $type . '/'. $this->appName . '/Install/' . $this->componentName . '/files.info', json_encode($installedFiles) - // // ); - // // } else if ($type === 'packages') { - // // $this->localContent->write( - // // $type . '/'. $this->appName . '/Install/' . $this->packageName . '/files.info', json_encode($installedFiles) - // // ); - // // } else if ($type === 'middlewares') { - // // $this->localContent->write( - // // $type . '/'. $this->appName . '/Install/' . $this->middlewareName . '/files.info', json_encode($installedFiles) - // // ); - // // } - // // } else { - // // $this->localContent->write($type . '/'. $this->appName . '/files.info', json_encode($installedFiles)); - // // } - // } - - protected function deleteDownloads() - { - $downloadsToDelete = $this->localContent->listContents('.downloads', true); - - $downloadedFiles = []; - $downloadedFiles['dir'] = []; - $downloadedFiles['files'] = []; - - foreach ($downloadsToDelete as $key => $value) { - if ($value['type'] === 'dir') { - array_push($downloadedFiles['dir'], $value['path']); - } else if ($value['type'] === 'file') { - array_push($downloadedFiles['files'], $value['path']); - } - } - - if (count($downloadedFiles['files']) > 0) { - foreach ($downloadedFiles['files'] as $fileKey => $file) { - $this->localContent->delete($file); - } - } - - if (count($downloadedFiles['dir']) > 0) { - foreach ($downloadedFiles['dir'] as $dirKey => $dir) { - $this->localContent->deleteDir($dir); - } - } - } - - protected function rollBack() - { - // - } - - protected function registerRunProcessPrecheckProgressMethods() - { - $this->runProcessPrecheckProgressMethods = []; - - foreach ($this->queue['tasks']['analysed'] as $taskName => $modulesTypes) { - if (($taskName === 'first' || $taskName === 'install' || $taskName === 'update') && - count($modulesTypes) > 0 - ) { - foreach ($modulesTypes as $moduleType => $modules) { - if ((is_array($modules) && count($modules) === 0) || - !is_array($modules) - ) { - continue; - } + foreach ($this->queue['tasks']['analysed'] as $taskName => $modulesTypes) { + if (($taskName === 'first' || $taskName === 'install' || $taskName === 'update') && + count($modulesTypes) > 0 + ) { + foreach ($modulesTypes as $moduleType => $modules) { + if ((is_array($modules) && count($modules) === 0) || + !is_array($modules) + ) { + continue; + } foreach ($modules as $module) { if ($taskName === 'first' && $moduleType === 'external') { if (isset($module['hasPatch']) && $module['hasPatch'] === true) { - array_push($this->runProcessPrecheckProgressMethods, + array_push($this->runPrecheckProgressMethods, [ 'method' => 'precheckQueueData-' . $module['root_module']['id'] . '-' . strtolower(str_replace(' ', '', $module['root_module']['name'])), 'text' => 'Perform precheck for module ' . $module['root_module']['name'] . ' (' . ucfirst($module['root_module']['module_type']) . ') ...', 'args' => [$taskName, $module['root_module']], ] ); - array_push($this->runProcessPrecheckProgressMethods, + array_push($this->runPrecheckProgressMethods, [ 'method' => 'downloadModulesFromRepo-' . $module['root_module']['id'] . '-' . strtolower(str_replace(' ', '', $module['root_module']['name'])), 'text' => 'Download module ' . $module['root_module']['name'] . ' (' . ucfirst($module['root_module']['module_type']) . ') files from repository...', @@ -1198,14 +775,14 @@ protected function registerRunProcessPrecheckProgressMethods() 'remoteWeb' => true ] ); - array_push($this->runProcessPrecheckProgressMethods, + array_push($this->runPrecheckProgressMethods, [ 'method' => 'extractModulesDownloadedFromRepo-' . $module['root_module']['id'] . '-' . strtolower(str_replace(' ', '', $module['root_module']['name'])), 'text' => 'Extracting downloaded module ' . $module['root_module']['name'] . ' (' . ucfirst($module['root_module']['module_type']) . ')...' ] ); } - array_push($this->runProcessPrecheckProgressMethods, + array_push($this->runPrecheckProgressMethods, [ 'method' => 'processExternalPackages-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), 'text' => 'Perform precheck for external package ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ') ...', @@ -1221,14 +798,14 @@ protected function registerRunProcessPrecheckProgressMethods() if ($taskName === 'first' && $moduleType === 'external') { continue; } else { - array_push($this->runProcessPrecheckProgressMethods, + array_push($this->runPrecheckProgressMethods, [ 'method' => 'precheckQueueData-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), 'text' => 'Perform precheck for module ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ') ...', 'args' => [$taskName, $module], ] ); - array_push($this->runProcessPrecheckProgressMethods, + array_push($this->runPrecheckProgressMethods, [ 'method' => 'downloadModulesFromRepo-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), 'text' => 'Download module ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ') files from repository...', @@ -1236,13 +813,13 @@ protected function registerRunProcessPrecheckProgressMethods() 'remoteWeb' => true ] ); - array_push($this->runProcessPrecheckProgressMethods, + array_push($this->runPrecheckProgressMethods, [ 'method' => 'extractModulesDownloadedFromRepo-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), 'text' => 'Extracting downloaded module ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...' ] ); - array_push($this->runProcessPrecheckProgressMethods, + array_push($this->runPrecheckProgressMethods, [ 'method' => 'runRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), 'text' => 'Running rsync --dry-run for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', @@ -1255,28 +832,62 @@ protected function registerRunProcessPrecheckProgressMethods() } } - $this->basepackages->progress->registerMethods($this->runProcessPrecheckProgressMethods); + $this->basepackages->progress->registerMethods($this->runPrecheckProgressMethods); } protected function registerRunProcessProgressMethods() { - // $this->runProcessProgressMethods = - // [ - // [ - // 'method' => 'unzipBackupFiles', - // 'text' => 'Unzipping backup file...' - // ], - // [ - // 'method' => 'performStructureRestore', - // 'text' => 'Restore file structure...' - // ], - // [ - // 'method' => 'performDbRestore', - // 'text' => 'Restore databases...' - // ] - // ]; - - // $this->basepackages->progress->registerMethods($this->runProcessProgressMethods); + $this->runProcessProgressMethods = []; + + foreach ($this->queue['tasks']['analysed'] as $taskName => $modulesTypes) { + if (($taskName === 'first' || $taskName === 'install' || $taskName === 'update') && + count($modulesTypes) > 0 + ) { + foreach ($modulesTypes as $moduleType => $modules) { + if ((is_array($modules) && count($modules) === 0) || + !is_array($modules) + ) { + continue; + } + + foreach ($modules as $module) { + if ($taskName === 'first' && $moduleType === 'external') { + array_push($this->runProcessProgressMethods, + [ + 'method' => 'processExternalPackages-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + 'text' => 'Perform precheck for external package ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ') ...', + 'args' => [$taskName, $module], + ] + ); + } else { + continue; + } + } + + foreach ($modules as $module) { + if ($taskName === 'first' && $moduleType === 'external') { + continue; + } else { + array_push($this->runProcessProgressMethods, + [ + 'method' => 'createBackup', + 'text' => 'Creating filesystem and database backup...' + ] + ); + // array_push($this->runProcessProgressMethods, + // [ + // 'method' => 'runRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + // 'text' => 'Running rsync --dry-run for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', + // 'args' => [$taskName, $module, true], + // ] + // ); + } + } + } + } + } + + $this->basepackages->progress->registerMethods($this->runProcessProgressMethods); } protected function initApi($data, $sink = null, $method = null) @@ -1403,4 +1014,455 @@ protected function getComposerJsonFile() return false; } } + + // protected function checkDependencies() + // { + // if (count($this->modulesToProcess) === 0) { + // return true; + // } + + // // var_dump($this->modulesToProcess);die(); + // foreach ($this->modulesToProcess as $moduleName => $module) { + // $this->preCheckResult[$moduleName] = []; + // $this->preCheckResult[$moduleName]['module'] = $module['module']; + // $this->preCheckResult[$moduleName]['result'] = 'success'; + // $this->preCheckResult[$moduleName]['logs'] = ''; + + // $names = explode('-', $moduleName); + + // try { + // $jsonFile = $this->helper->decode($this->localContent->read($module['location'] . 'Install/' . substr($names[1], 0, -1) . '.json'), true); + // } catch (\throwable $e) { + // $this->preCheckResult[$moduleName]['result'] = 'error'; + // $this->preCheckResult[$moduleName]['logs'] .= 'Reading module ' . $moduleName . ' install JSON file resulted in error. '; + + // continue;//move onto the next one. + // } + + // // Make sure we have an entry for all module dependencies. Even if there are no dependencies, we need to make sure we have empty array for them. + // if (!isset($jsonFile['dependencies']) || + // (isset($jsonFile['dependencies']) && + // (!isset($jsonFile['dependencies']['core']) || + // !isset($jsonFile['dependencies']['components']) || + // !isset($jsonFile['dependencies']['packages']) || + // !isset($jsonFile['dependencies']['middlewares']) || + // !isset($jsonFile['dependencies']['views']))) + // ) { + // $this->preCheckResult[$moduleName]['result'] = 'error'; + // $this->preCheckResult[$moduleName]['logs'] .= 'Reading module ' . $moduleName . ' dependencies resulted in error. '; + + // continue;//move onto the next one. + // } + + // //Check Core dependency + // if (Version::greaterThan($jsonFile['dependencies']['core']['version'], $this->core->getVersion())) { + // //Lets check for latest release on Core as required version is greater than installed version. + // $core = $this->modules->packages->getPackageByName('core'); + // $core = $this->modules->manager->updateModuleRepoDetails($core); + + // if ($core) { + // $this->preCheckResult[$moduleName]['result'] = 'warning'; + // $this->preCheckResult[$moduleName]['logs'] .= 'Module ' . $moduleName . ' needs core version : ' . $core['update_version'] . '. Installed version of core is : ' . $core['version'] . '. Adding Core to list of updates. '; + + // $this->preCheckResult['core'] = []; + // $this->preCheckResult['core']['module'] = $core; + // $this->preCheckResult['core']['result'] = 'warning'; + // $name = $module['module']['name']; + // if (isset($module['module']['display_name'])) { + // $name = $module['module']['display_name']; + // } + // $this->preCheckResult['core']['logs'] = 'Added to queue as required by module : ' . $name . '. '; + // } + // } + + // // + // } + + // var_dump($this->preCheckResult);die(); + // // $this->getLatestRepositoryModulesData(); + + // ${$this->postData()['type']} = + // $this->{$this->postData()['type']}->getById($this->postData()['id'])->getAllArr(); + + // $dependencies = + // json_decode(${$this->postData()['type']}['dependencies'], true); + + // $checkForDependencies = $this->checkRegisteredDependencies($dependencies); + + // if (is_array($checkForDependencies)) { + // $this->packagesData->responseCode = 1; + + // $this->packagesData->responseMessage = + // 'Dependency ' . $checkForDependencies['name'] . ' not found!
' . + // 'Check repository ' . $checkForDependencies['repo'] . ' for further details.'; + + // return $this->packagesData; + // } + + // return true; + // } + + // protected function checkRegisteredDependencies($dependencies) + // { + // $found = true; + + // $this->dependenciesToDownload = []; + + // foreach ($dependencies as $dependencyKey => $dependencyValue) { + // if ($dependencyKey === 'app') { + // $dependencyKey = $dependencyKey . 's'; + // } + + // if (!isset($dependencyValue['name'])) { //if dependency is an array + // foreach ($dependencyValue as $multiDependencyKey => $multiDependencyValue) { + + // $thisDependency = + // $this->{$dependencyKey}->getAll( + // [ + // 'name' => $multiDependencyValue['name'], + // 'repo' => $multiDependencyValue['repo'], + // 'version' => $multiDependencyValue['version'] + // ] + // ); + + // if (!$thisDependency) { + + // $thisDependency = + // $this->{$dependencyKey}->getAll( + // [ + // 'name' => $multiDependencyValue['name'], + // 'repo' => $multiDependencyValue['repo'], + // 'update_version' => $multiDependencyValue['version'], + // ] + // ); + + // if ($thisDependency) { + + // if ($thisDependency[0]->get('update_available') === 1) { + + // $multiDependencyValue['type'] = $dependencyKey; + // $multiDependencyValue['id'] = $thisDependency[0]->get('id'); + // array_push($this->dependenciesToDownload, $multiDependencyValue); + // } + + // $found = true; + + // } else { + // $found = $multiDependencyValue; + + // return $found; + // } + // } else { + // if ($thisDependency[0]->get('installed') === 0) { + + // $multiDependencyValue['type'] = $dependencyKey; + // $multiDependencyValue['id'] = $thisDependency[0]->get('id'); + // array_push($this->dependenciesToDownload, $multiDependencyValue); + // } + + // $found = true; + // } + // } + // } else { + + // $thisDependency = + // $this->{$dependencyKey}->getAll( + // [ + // 'name' => $dependencyValue['name'], + // 'repo' => $dependencyValue['repo'], + // 'version' => $dependencyValue['version'], + // ] + // ); + + // if (!$thisDependency) { + + // $thisDependency = + // $this->{$dependencyKey}->getAll( + // [ + // 'name' => $dependencyValue['name'], + // 'repo' => $dependencyValue['repo'], + // 'update_version' => $dependencyValue['version'], + // ] + // ); + + // if ($thisDependency) { + + // if ($thisDependency[0]->get('update_available') === 1) { + + // $dependencyValue['type'] = $dependencyKey; + // $dependencyValue['id'] = $thisDependency[0]->get('id'); + // array_push($this->dependenciesToDownload, $dependencyValue); + + // } + + // $found = true; + + // } else { + // $found = $dependencyValue; + + // return $found; + // } + + // } else { + // if ($thisDependency[0]->get('installed') === 0) { + + // $dependencyValue['type'] = $dependencyKey; + // $dependencyValue['id'] = $thisDependency[0]->get('id'); + // array_push($this->dependenciesToDownload, $dependencyValue); + + // } + + // $found = true; + // } + // } + // } + + // return $found; + // } + + + + // protected function getLatestRepositoryModulesData() + // { + // $repositories = getAllArr($this->repositories->getAll()); + + // if (count($repositories) > 0) { + // $modules = $this->packages->use(Modules::class); + + // foreach ($repositories as $repositoryKey => $repositoryValue) { + // $sync = $modules->syncRemoteWithLocal($repositoryValue['id']); + + // if ($sync->packagesData['responseCode'] === 1) { + // $this->packagesData->responseCode = 1; + + // $this->packagesData->responseMessage = 'Error Syncing with repository ' . $repositoryValue['name']; + + // return $this->packagesData; + // } + // } + // } + // } + + // protected function createBackup() + // { + // trace([$this->queue]); + // $this->basepackages->backuprestore->init()->backup(); + + // + // $this->backupLocation = '.backups/'; + + // $now = new \DateTime('now'); + + // $this->zip->open(base_path($this->backupLocation . '/' . $now->format('Y_m_d_H_i_s') . '.zip'), $this->zip::CREATE); + + // $framework = []; + // $framework['dir'] = []; + // $framework['file'] = []; + + // $rootContents = $this->localContent->listContents('/'); + + // foreach ($rootContents as $rootKey => $rootValue) { + // if ($rootValue['type'] === 'dir') { + // if ($rootValue['path'] !== '.backups' && + // $rootValue['path'] !== '.git' && + // $rootValue['path'] !== 'vendor' + // ) { + // array_push($framework['dir'], $rootValue['path']); + // } + // } else if ($rootValue['type'] === 'file') { + // if ($rootValue['path'] !== '.gitignore' && + // $rootValue['path'] !== '.htaccess.example' + // ) { + // array_push($framework['file'], $rootValue['path']); + // } + // } + // } + + // foreach ($framework['dir'] as $dirKey => $dirValue) { + // $rootDirContents[$dirValue] = $this->localContent->listContents($dirValue, true); + // } + + // foreach ($rootDirContents as $rootDirContentsKey => $rootDirContentsValue) { + // if (count($rootDirContentsValue) > 0) { + // foreach ($rootDirContentsValue as $subDirectoryKey => $subDirectory) { + // if ($subDirectory['type'] === 'dir') { + // $this->zip->addEmptyDir($subDirectory['dirname']); + // } else if ($subDirectory['type'] === 'file') { + // $this->zip->addFile($subDirectory['path']); + // } + // } + // } else { + // $this->zip->addEmptyDir($rootDirContentsKey); + // } + // }; + + // foreach ($framework['file'] as $fileKey => $fileValue) { + // $this->zip->addFile($fileValue); + // } + + // $this->zip->close(); + + // $this->packagesData->backupFile = $now->format('Y_m_d_H_i_s') . '.zip'; + + // $this->packagesData->responseCode = 0; + // } + + // protected function processInstall() + // { + // foreach ($this->modulesToInstall as $moduleToInstallKey => $moduleToInstall) { + + // $repoNameArr = explode('/', $moduleToInstall['repo']); + // $repoName = end($repoNameArr); + + // $this->downloadPackagesAndDependencies($moduleToInstall); + + // $contents = $this->extractDownloadedPackagesAndDependencies( + // $moduleToInstall['name'], + // $repoName, + // $moduleToInstall['type'] + // ); + + // if ($contents) { + // $files = $this->copyFilesToDestination( + // $contents, + // $moduleToInstall['name'], + // $repoName, + // $moduleToInstall['type'] + // ); + // } + + + // $this->{$moduleToInstall['type']}->update( + // [ + // 'id' => $moduleToInstall['id'], + // 'installed' => 1, + // 'files' => json_encode($files), + // ] + // ); + // } + // } + + // protected function processUpdate() + // { + // $files = []; + + // foreach ($this->modulesToInstall as $moduleToInstallKey => $moduleToInstall) { + // // + // //Delete only files first + // //Check if directory is empty, then delete directory + // //check if directory is html_compiled, if so, then scan directory, delete all files first and then all directories. + // //Copy all files. + // // + // var_dump(json_decode($this->{$moduleToInstall['type']}->getById($moduleToInstall['id'])->getAllArr()['files'], true)); + // // $repoNameArr = explode('/', $moduleToInstall['repo']); + // // $repoName = end($repoNameArr); + + // // $this->downloadPackagesAndDependencies($moduleToInstall); + + // // $contents = $this->extractDownloadedPackagesAndDependencies( + // // $moduleToInstall['name'], + // // $repoName, + // // $moduleToInstall['type'] + // // ); + + // // if ($contents) { + // // $files = $this->copyFilesToDestination( + // // $contents, + // // $moduleToInstall['name'], + // // $repoName, + // // $moduleToInstall['type'] + // // ); + // // } + + + // // $this->{$moduleToInstall['type']}->update( + // // [ + // // 'id' => $moduleToInstall['id'], + // // 'installed' => 1, + // // 'files' => json_encode($files), + // // ] + // // ); + // } + // } + + // protected function copyFilesToDestination($contents, $name, $repoName, $type) + // { + // $installedFiles = []; + // $installedFiles['dir'] = []; + // $installedFiles['files'] = []; + + // foreach ($contents as $contentKey => $content) { + // $destDir = + // str_replace( + // $this->downloadLocation . '/' . strtolower($repoName) . '-master/', + // '', + // $content['dirname'] + // ); + + // if ($content['type'] === 'dir') { + + // $this->localContent->createDirectory($destDir . '/' . $content['basename']); + + // array_push($installedFiles['dir'], $destDir . '/' . $content['basename']); + + // } else if ($content['type'] === 'file') { + + // if ($content['basename'] !== '.gitkeep') { + + // $this->localContent->copy($content['path'], $destDir . '/' . $content['basename']); + + // array_push($installedFiles['files'], $destDir . '/' . $content['basename']); + // } + + // } + // } + + // return $installedFiles; + // // if ($type === 'components' || $type === 'packages' || $type === 'middlewares') { + // // if ($type === 'components') { + // // $this->localContent->write( + // // $type . '/'. $this->appName . '/Install/' . $this->componentName . '/files.info', json_encode($installedFiles) + // // ); + // // } else if ($type === 'packages') { + // // $this->localContent->write( + // // $type . '/'. $this->appName . '/Install/' . $this->packageName . '/files.info', json_encode($installedFiles) + // // ); + // // } else if ($type === 'middlewares') { + // // $this->localContent->write( + // // $type . '/'. $this->appName . '/Install/' . $this->middlewareName . '/files.info', json_encode($installedFiles) + // // ); + // // } + // // } else { + // // $this->localContent->write($type . '/'. $this->appName . '/files.info', json_encode($installedFiles)); + // // } + // } + + // protected function deleteDownloads() + // { + // $downloadsToDelete = $this->localContent->listContents('.downloads', true); + + // $downloadedFiles = []; + // $downloadedFiles['dir'] = []; + // $downloadedFiles['files'] = []; + + // foreach ($downloadsToDelete as $key => $value) { + // if ($value['type'] === 'dir') { + // array_push($downloadedFiles['dir'], $value['path']); + // } else if ($value['type'] === 'file') { + // array_push($downloadedFiles['files'], $value['path']); + // } + // } + + // if (count($downloadedFiles['files']) > 0) { + // foreach ($downloadedFiles['files'] as $fileKey => $file) { + // $this->localContent->delete($file); + // } + // } + + // if (count($downloadedFiles['dir']) > 0) { + // foreach ($downloadedFiles['dir'] as $dirKey => $dir) { + // $this->localContent->deleteDir($dir); + // } + // } + // } } \ No newline at end of file diff --git a/system/Base/Providers/ModulesServiceProvider/Model/ServiceProviderModulesQueues.php b/system/Base/Providers/ModulesServiceProvider/Model/ServiceProviderModulesQueues.php index 77b67fe99..8c6af898e 100644 --- a/system/Base/Providers/ModulesServiceProvider/Model/ServiceProviderModulesQueues.php +++ b/system/Base/Providers/ModulesServiceProvider/Model/ServiceProviderModulesQueues.php @@ -27,4 +27,6 @@ class ServiceProviderModulesQueues extends BaseModel public $sync; public $total; + + public $settings; } \ No newline at end of file diff --git a/system/Base/Providers/ModulesServiceProvider/Queues.php b/system/Base/Providers/ModulesServiceProvider/Queues.php index bdab9b752..4a7039e67 100644 --- a/system/Base/Providers/ModulesServiceProvider/Queues.php +++ b/system/Base/Providers/ModulesServiceProvider/Queues.php @@ -2,6 +2,7 @@ namespace System\Base\Providers\ModulesServiceProvider; +use Phalcon\Filter\Validation\Validator\Email; use System\Base\BasePackage; use System\Base\Providers\ModulesServiceProvider\Model\ServiceProviderModulesQueues; use z4kn4fein\SemVer\Version; @@ -16,8 +17,6 @@ class Queues extends BasePackage protected $results; - // protected $coreExternalDependencies; - public function init(bool $resetCache = false) { return $this; @@ -52,7 +51,29 @@ protected function addActiveQueue() 'remove' => [] ] ), - 'total' => 0 + 'total' => 0, + 'settings' => $this->helper->encode( + [ + 'backupSettings' => + [ + 'backup' => true, + 'apps_dir' => true, + 'systems_dir' => true, + 'public_dir' => true, + 'private_dir' => true, + 'external_dir' => true, + 'html_compiled' => false, + 'var_dir' => false, + 'external_vendor_dir' => false, + 'old_backups' => false, + 'database' => true, + 'keys' => true, + 'password_protect' => $this->basepackages->utils->generateNewPassword()['password'], + 'notes' => '', + ], + 'emailReport' => $this->access->auth->account()['email'] + ] + ) ]; if ($this->add($queue)) { @@ -181,6 +202,109 @@ public function modifyQueue($data) return false; } + public function saveQueueSettings($data) + { + $queue = $this->getById((int) $data['id']); + + if (!$queue) { + $this->addResponse('Queue with ID not found', 1); + + return false; + } + + $noOptions = true; + array_walk($data['settings']['backupSettings'], function(&$setting, $index) use (&$noOptions) { + if ($index === 'notes' || + $index === 'password_protect' + ) { + return; + } + + if ($setting !== '') { + if ($setting == 'true') { + $setting = true; + $noOptions = false; + } else { + $setting = false; + } + } else { + $setting = false; + } + }); + + + if ($data['settings']['backupSettings']['keys'] === true && + $data['settings']['backupSettings']['password_protect'] === '' + ) { + $this->addResponse('Password is required if keys are being backed up!', 1); + + return false; + } + + if ($noOptions) {//No option selected disables backup. + $data['settings']['backupSettings']['backup'] = false; + $data['settings']['backupSettings']['password_protect'] = ''; + $data['settings']['backupSettings']['notes'] = ''; + } else { + $data['settings']['backupSettings']['backup'] = true; + } + + if ($data['settings']['emailReport'] !== '') { + $emails = explode(',', $data['settings']['emailReport']); + + if (count($emails) > 1) { + array_walk($emails, function(&$email, $index) use (&$emails) { + $email = trim($email); + + if ($email === '') { + unset($emails[$index]); + } + }); + } else { + $emails[0] = trim($emails[0]); + } + + foreach ($emails as $email) { + $validation = $this->validateData(['email' => $email]); + + if ($validation !== true) { + $this->addResponse($validation, 1); + + return false; + } + } + } + + $queue['settings'] = array_replace($queue['settings'], $data['settings']); + + if ($this->update($queue)) { + $this->addResponse('Queue settings updated'); + + return true; + } + + $this->addResponse('Error updating queue settings', 1); + } + + protected function validateData(array $data) + { + $this->validation->init(); + $this->validation->add('email', Email::class, ["message" => "Enter valid email."]); + + $validated = $this->validation->validate($data)->jsonSerialize(); + + if (count($validated) > 0) { + $messages = 'Error: '; + + foreach ($validated as $key => $value) { + $messages .= $value['message'] . ' '; + } + return $messages . ' (' . $data['email'] . ')'; + } else { + return true; + } + } + protected function getTasksCount(&$queue, $analyse = false) { $queue['total'] = 0; From 4f441de75aaaa2f73f66e29fd96ead8761050d7f Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Thu, 23 Jan 2025 21:18:20 +1100 Subject: [PATCH 24/34] Fix issue #581 --- .../html/system/tools/backuprestore/form.html | 8 ++--- .../tools/backuprestore/form/backup.html | 4 +-- .../Packages/BackupRestore.php | 34 ++++++++++++------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/apps/Core/Views/Default/html/system/tools/backuprestore/form.html b/apps/Core/Views/Default/html/system/tools/backuprestore/form.html index d627d451e..db48b95d1 100644 --- a/apps/Core/Views/Default/html/system/tools/backuprestore/form.html +++ b/apps/Core/Views/Default/html/system/tools/backuprestore/form.html @@ -72,7 +72,7 @@ '{{componentId}}-{{sectionId}}-public_dir' : { }, '{{componentId}}-{{sectionId}}-private_dir' : { }, '{{componentId}}-{{sectionId}}-external_dir' : { }, - '{{componentId}}-{{sectionId}}-html_compiled' : { }, + '{{componentId}}-{{sectionId}}-html_compiled_dir' : { }, '{{componentId}}-{{sectionId}}-var_dir' : { }, '{{componentId}}-{{sectionId}}-external_vendor_dir' : { afterInit : function() { @@ -86,7 +86,7 @@ }); } }, - '{{componentId}}-{{sectionId}}-old_backups' : { }, + '{{componentId}}-{{sectionId}}-old_backups_dir' : { }, '{{componentId}}-{{sectionId}}-database' : { afterInit : function() { $('#{{componentId}}-{{sectionId}}-database').click(function() { @@ -141,11 +141,11 @@ postData['systems_dir'] = $('#{{componentId}}-{{sectionId}}-systems_dir')[0].checked; postData['public_dir'] = $('#{{componentId}}-{{sectionId}}-public_dir')[0].checked; postData['private_dir'] = $('#{{componentId}}-{{sectionId}}-private_dir')[0].checked; - postData['html_compiled'] = $('#{{componentId}}-{{sectionId}}-html_compiled')[0].checked; + postData['html_compiled_dir'] = $('#{{componentId}}-{{sectionId}}-html_compiled_dir')[0].checked; postData['var_dir'] = $('#{{componentId}}-{{sectionId}}-var_dir')[0].checked; postData['external_dir'] = $('#{{componentId}}-{{sectionId}}-external_dir')[0].checked; postData['external_vendor_dir'] = $('#{{componentId}}-{{sectionId}}-external_vendor_dir')[0].checked; - postData['old_backups'] = $('#{{componentId}}-{{sectionId}}-old_backups')[0].checked; + postData['old_backups_dir'] = $('#{{componentId}}-{{sectionId}}-old_backups_dir')[0].checked; postData['database'] = $('#{{componentId}}-{{sectionId}}-database')[0].checked; postData['keys'] = $('#{{componentId}}-{{sectionId}}-keys')[0].checked; postData['password_protect'] = $('#{{componentId}}-{{sectionId}}-password_protect').val(); diff --git a/apps/Core/Views/Default/html/system/tools/backuprestore/form/backup.html b/apps/Core/Views/Default/html/system/tools/backuprestore/form/backup.html index 08a7c4102..3b9a175d8 100644 --- a/apps/Core/Views/Default/html/system/tools/backuprestore/form/backup.html +++ b/apps/Core/Views/Default/html/system/tools/backuprestore/form/backup.html @@ -125,7 +125,7 @@ 'componentName' : componentName, 'componentId' : componentId, 'sectionId' : sectionId, - 'fieldId' : 'html_compiled', + 'fieldId' : 'html_compiled_dir', 'fieldLabel' : false, 'fieldHelp' : true, 'fieldHelpTooltipContent' : 'Compiled Templates Directory? Note: This can be regenerated.', @@ -198,7 +198,7 @@ 'componentName' : componentName, 'componentId' : componentId, 'sectionId' : sectionId, - 'fieldId' : 'old_backups', + 'fieldId' : 'old_backups_dir', 'fieldLabel' : false, 'fieldHelp' : true, 'fieldHelpTooltipContent' : 'Old backup files? This will increase the total size of the backup depending on how many backups you have taken before.', diff --git a/system/Base/Providers/BasepackagesServiceProvider/Packages/BackupRestore.php b/system/Base/Providers/BasepackagesServiceProvider/Packages/BackupRestore.php index 8bf038de4..5d4cbd55c 100644 --- a/system/Base/Providers/BasepackagesServiceProvider/Packages/BackupRestore.php +++ b/system/Base/Providers/BasepackagesServiceProvider/Packages/BackupRestore.php @@ -73,7 +73,8 @@ protected function withProgress($method, $arguments) public function backup(array $data) { set_time_limit(300);//5 mins - $tokenkey = array_search($this->security->getRequestToken(), $data); + + $tokenkey = array_search($this->security->getRequestToken(), $data, true); if ($tokenkey) { unset($data[$tokenkey]); } @@ -102,7 +103,6 @@ public function backup(array $data) $this->backupInfo['dbs'] = []; $this->backupInfo['dirs'] = []; $this->backupInfo['files'] = []; - $this->backupInfo['notes'] = $data['notes']; if (isset($this->backupInfo['request']['keys']) && $this->backupInfo['request']['keys'] == 'true' || isset($this->backupInfo['request']['database']) && $this->backupInfo['request']['database'] == 'true' @@ -125,17 +125,25 @@ public function backup(array $data) } } + $noFilesOptions = true; + foreach ($data as $key => $value) { + if (str_contains($key, '_dir') && $value == 'true') { + $noFilesOptions = false; + } + } + if ($noFilesOptions) { + $this->basepackages->progress->unregisterMethods(['generateStructure']); + } + + if (!isset($this->backupInfo['request']['database']) || + (isset($this->backupInfo['request']['database']) && $this->backupInfo['request']['database'] != 'true') + ) { + $this->basepackages->progress->unregisterMethods(['performDbBackup']); + } + $this->basepackages->progress->preCheckComplete(); foreach ($this->backupProgressMethods as $method) { - if ($method['method'] === 'performDbBackup') { - if (!isset($this->backupInfo['request']['database']) || - (isset($this->backupInfo['request']['database']) && $this->backupInfo['request']['database'] != 'true') - ) { - continue; - } - } - if ($this->withProgress($method['method'], $data) === false) { return false; } @@ -178,7 +186,7 @@ protected function generateStructure(array $data) } } - if (isset($this->backupInfo['request']['old_backups']) && $this->backupInfo['request']['old_backups'] == 'true') { + if (isset($this->backupInfo['request']['old_backups_dir']) && $this->backupInfo['request']['old_backups_dir'] == 'true') { $this->getContent($this->basepackages->utils->scanDir('.backups/')); $this->getContent($this->basepackages->utils->scanDir('.backupsdb/')); $this->getContent($this->basepackages->utils->scanDir('.backupsff/')); @@ -645,7 +653,7 @@ protected function getContent($localContent) foreach ($localContent['dirs'] as $key => $dir) { $key = $dirsKeyCount + $key; - if (isset($this->backupInfo['request']['html_compiled']) && $this->backupInfo['request']['html_compiled'] == 'true') { + if (isset($this->backupInfo['request']['html_compiled_dir']) && $this->backupInfo['request']['html_compiled_dir'] == 'true') { $this->backupInfo['dirs'] = array_merge($this->backupInfo['dirs'], ['fo' . $key => $dir]); } else { if (strpos($dir, 'Html_compiled') === false) { @@ -656,7 +664,7 @@ protected function getContent($localContent) foreach ($localContent['files'] as $key => $file) { $key = $filesKeyCount + $key; - if (isset($this->backupInfo['request']['html_compiled']) && $this->backupInfo['request']['html_compiled'] == 'true') { + if (isset($this->backupInfo['request']['html_compiled_dir']) && $this->backupInfo['request']['html_compiled_dir'] == 'true') { $this->backupInfo['files'] = array_merge($this->backupInfo['files'], ['fi' . $key => $file]); } else { if (strpos($file, 'Html_compiled') === false) { From 3c074d1ca0131d3c19294abaf35b1718a0537a7e Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Thu, 23 Jan 2025 21:20:23 +1100 Subject: [PATCH 25/34] Fix issue #582 --- .../Tools/Backuprestore/BackuprestoreComponent.php | 4 ++-- .../html/system/tools/backuprestore/form.html | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/Core/Components/System/Tools/Backuprestore/BackuprestoreComponent.php b/apps/Core/Components/System/Tools/Backuprestore/BackuprestoreComponent.php index 1f9d823b8..8b968897a 100644 --- a/apps/Core/Components/System/Tools/Backuprestore/BackuprestoreComponent.php +++ b/apps/Core/Components/System/Tools/Backuprestore/BackuprestoreComponent.php @@ -38,13 +38,13 @@ public function viewAction() [ 'uuidLocation' => '.backups/', 'storagesId' => $storage['id'], - 'orphan' => 0 + 'orphan' => false ] ]; } else { $params = [ - 'conditions' => [['uuid_location', '=', '.backups/'], ['storages_id', '=', $storage['id']], ['orphan', '=', 0]] + 'conditions' => [['uuid_location', '=', '.backups/'], ['storages_id', '=', $storage['id']], ['orphan', '=', false]] ]; } diff --git a/apps/Core/Views/Default/html/system/tools/backuprestore/form.html b/apps/Core/Views/Default/html/system/tools/backuprestore/form.html index db48b95d1..cc8398394 100644 --- a/apps/Core/Views/Default/html/system/tools/backuprestore/form.html +++ b/apps/Core/Views/Default/html/system/tools/backuprestore/form.html @@ -427,14 +427,14 @@ } $('#body').off('dropzoneInitDone'); $('#body').on('dropzoneInitDone', function() { - if (dataCollectionSection['admin-backuprestore-main-backup_upload_restore']) { - dataCollectionSection['admin-backuprestore-main-backup_upload_restore']['onSuccess'] = function(file, response) { - if (response.responseData && response.responseData.name && response.responseData.uuid) { - var newOption = new Option(response.responseData.name, response.responseData.uuid, false, false); + if (dataCollectionSection['core-backuprestore-main-backup_upload_restore']) { + dataCollectionSection['core-backuprestore-main-backup_upload_restore']['onSuccess'] = function(file, response) { + if (response.responseData && response.responseData.org_file_name && response.responseData.uuid) { + var newOption = new Option(response.responseData.org_file_name, response.responseData.uuid, false, false); $('#{{componentId}}-{{sectionId}}-backups').append(newOption).val(response.responseData.uuid).trigger('change'); - dataCollectionSectionForm['funcs']['addedNewBackupOption'](response.responseData.uuid, response.responseData.name); - paginatedPNotify('success', {text: 'File ' + response.responseData.name + ' uploaded and ready to be restored.'}); - dataCollectionSection['admin-backuprestore-main-backup_upload_restore']['reset'](); + dataCollectionSectionForm['funcs']['addedNewBackupOption'](response.responseData.uuid, response.responseData.org_file_name); + paginatedPNotify('success', {text: 'File ' + response.responseData.org_file_name + ' uploaded and ready to be restored.'}); + dataCollectionSection['core-backuprestore-main-backup_upload_restore']['reset'](); } }; } From f2b2871312eae970cc19636f5c1efb8608d45ccf Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Thu, 23 Jan 2025 21:20:45 +1100 Subject: [PATCH 26/34] update #34 --- apps/Core/Views/Default/html/modules/analyse.html | 8 ++++---- apps/Core/Views/Default/html/modules/settings.html | 14 +++++++------- .../Providers/ModulesServiceProvider/Installer.php | 4 +++- .../Providers/ModulesServiceProvider/Queues.php | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/Core/Views/Default/html/modules/analyse.html b/apps/Core/Views/Default/html/modules/analyse.html index 97a9971f3..61601a194 100644 --- a/apps/Core/Views/Default/html/modules/analyse.html +++ b/apps/Core/Views/Default/html/modules/analyse.html @@ -232,11 +232,11 @@ postData['settings']['backupSettings']['systems_dir'] = $('#{{componentId}}-{{sectionId}}-systems_dir')[0].checked; postData['settings']['backupSettings']['public_dir'] = $('#{{componentId}}-{{sectionId}}-public_dir')[0].checked; postData['settings']['backupSettings']['private_dir'] = $('#{{componentId}}-{{sectionId}}-private_dir')[0].checked; - postData['settings']['backupSettings']['html_compiled'] = $('#{{componentId}}-{{sectionId}}-html_compiled')[0].checked; + postData['settings']['backupSettings']['html_compiled_dir'] = $('#{{componentId}}-{{sectionId}}-html_compiled_dir')[0].checked; postData['settings']['backupSettings']['var_dir'] = $('#{{componentId}}-{{sectionId}}-var_dir')[0].checked; postData['settings']['backupSettings']['external_dir'] = $('#{{componentId}}-{{sectionId}}-external_dir')[0].checked; postData['settings']['backupSettings']['external_vendor_dir'] = $('#{{componentId}}-{{sectionId}}-external_vendor_dir')[0].checked; - postData['settings']['backupSettings']['old_backups'] = $('#{{componentId}}-{{sectionId}}-old_backups')[0].checked; + postData['settings']['backupSettings']['old_backups_dir'] = $('#{{componentId}}-{{sectionId}}-old_backups_dir')[0].checked; postData['settings']['backupSettings']['database'] = $('#{{componentId}}-{{sectionId}}-database')[0].checked; postData['settings']['backupSettings']['keys'] = $('#{{componentId}}-{{sectionId}}-keys')[0].checked; postData['settings']['backupSettings']['password_protect'] = $('#{{componentId}}-{{sectionId}}-password_protect').val().trim(); @@ -490,7 +490,7 @@ '{{componentId}}-{{sectionId}}-public_dir' : { }, '{{componentId}}-{{sectionId}}-private_dir' : { }, '{{componentId}}-{{sectionId}}-external_dir' : { }, - '{{componentId}}-{{sectionId}}-html_compiled' : { }, + '{{componentId}}-{{sectionId}}-html_compiled_dir' : { }, '{{componentId}}-{{sectionId}}-var_dir' : { }, '{{componentId}}-{{sectionId}}-external_vendor_dir' : { afterInit : function() { @@ -504,7 +504,7 @@ }); } }, - '{{componentId}}-{{sectionId}}-old_backups' : { }, + '{{componentId}}-{{sectionId}}-old_backups_dir' : { }, '{{componentId}}-{{sectionId}}-database' : { afterInit : function() { $('#{{componentId}}-{{sectionId}}-database').click(function() { diff --git a/apps/Core/Views/Default/html/modules/settings.html b/apps/Core/Views/Default/html/modules/settings.html index f6e6baeec..a0686984f 100644 --- a/apps/Core/Views/Default/html/modules/settings.html +++ b/apps/Core/Views/Default/html/modules/settings.html @@ -6,7 +6,7 @@ {% set settingsBackupHTMLCompiledDirChecked = false %} {% set settingsBackupVarDirChecked = false %} {% set settingsBackupExternalVendorDirChecked = false %} -{% set settingsBackupOldBackupsChecked = false %} +{% set settingsBackupOldBackupsDirChecked = false %} {% set settingsBackupDatabaseChecked = false %} {% set settingsBackupKeysChecked = false %} {% if queue['settings']['backupSettings']['apps_dir'] == 'true' %} @@ -24,7 +24,7 @@ {% if queue['settings']['backupSettings']['external_dir'] == 'true' %} {% set settingsBackupExternalDirChecked = true %} {% endif %} -{% if queue['settings']['backupSettings']['html_compiled'] == 'true' %} +{% if queue['settings']['backupSettings']['html_compiled_dir'] == 'true' %} {% set settingsBackupHTMLCompiledDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['var_dir'] == 'true' %} @@ -33,8 +33,8 @@ {% if queue['settings']['backupSettings']['external_vendor_dir'] == 'true' %} {% set settingsBackupExternalVendorDirChecked = true %} {% endif %} -{% if queue['settings']['backupSettings']['old_backups'] == 'true' %} - {% set settingsBackupOldBackupsChecked = true %} +{% if queue['settings']['backupSettings']['old_backups_dir'] == 'true' %} + {% set settingsBackupOldBackupsDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['database'] == 'true' %} {% set settingsBackupDatabaseChecked = true %} @@ -172,7 +172,7 @@ 'componentName' : componentName, 'componentId' : componentId, 'sectionId' : sectionId, - 'fieldId' : 'html_compiled', + 'fieldId' : 'html_compiled_dir', 'fieldLabel' : false, 'fieldHelp' : true, 'fieldHelpTooltipContent' : 'Compiled Templates Directory? Note: This can be regenerated.', @@ -245,14 +245,14 @@ 'componentName' : componentName, 'componentId' : componentId, 'sectionId' : sectionId, - 'fieldId' : 'old_backups', + 'fieldId' : 'old_backups_dir', 'fieldLabel' : false, 'fieldHelp' : true, 'fieldHelpTooltipContent' : 'Old backup files? This will increase the total size of the backup depending on how many backups you have taken before.', 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'danger', - 'fieldCheckboxChecked' : settingsBackupOldBackupsChecked, + 'fieldCheckboxChecked' : settingsBackupOldBackupsDirChecked, 'fieldCheckboxLabel' : 'OLD BACKUP FILES', 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, diff --git a/system/Base/Providers/ModulesServiceProvider/Installer.php b/system/Base/Providers/ModulesServiceProvider/Installer.php index a9b7ffa66..977aebb63 100644 --- a/system/Base/Providers/ModulesServiceProvider/Installer.php +++ b/system/Base/Providers/ModulesServiceProvider/Installer.php @@ -730,8 +730,10 @@ protected function createBackup() return true; } + unset($this->queue['settings']['backupSettings']['backup']); + if ($this->queue['settings']['backupSettings']['notes'] === '') { - $this->queue['settings']['backupSettings']['notes'] = 'Backup taking while processing module installer queue with ID: ' . $this->queue['id']; + $this->queue['settings']['backupSettings']['notes'] = 'Backup taken while processing module installer queue with ID: ' . $this->queue['id']; } return $this->basepackages->backuprestore->init()->backup($this->queue['settings']['backupSettings']); diff --git a/system/Base/Providers/ModulesServiceProvider/Queues.php b/system/Base/Providers/ModulesServiceProvider/Queues.php index 4a7039e67..1d7d8a337 100644 --- a/system/Base/Providers/ModulesServiceProvider/Queues.php +++ b/system/Base/Providers/ModulesServiceProvider/Queues.php @@ -62,10 +62,10 @@ protected function addActiveQueue() 'public_dir' => true, 'private_dir' => true, 'external_dir' => true, - 'html_compiled' => false, + 'html_compiled_dir' => false, 'var_dir' => false, 'external_vendor_dir' => false, - 'old_backups' => false, + 'old_backups_dir' => false, 'database' => true, 'keys' => true, 'password_protect' => $this->basepackages->utils->generateNewPassword()['password'], From 221fd435ed3023e9ccb758f1accf5004ffe4ff2d Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Fri, 24 Jan 2025 16:32:03 +1100 Subject: [PATCH 27/34] update #34 --- .../Views/Default/html/modules/analyse.html | 3 + .../Views/Default/html/modules/settings.html | 178 ++++++++++++++---- .../ModulesServiceProvider/Installer.php | 88 +++++---- .../ModulesServiceProvider/Queues.php | 17 +- 4 files changed, 211 insertions(+), 75 deletions(-) diff --git a/apps/Core/Views/Default/html/modules/analyse.html b/apps/Core/Views/Default/html/modules/analyse.html index 61601a194..23ae10323 100644 --- a/apps/Core/Views/Default/html/modules/analyse.html +++ b/apps/Core/Views/Default/html/modules/analyse.html @@ -242,6 +242,8 @@ postData['settings']['backupSettings']['password_protect'] = $('#{{componentId}}-{{sectionId}}-password_protect').val().trim(); postData['settings']['backupSettings']['notes'] = $('#{{componentId}}-{{sectionId}}-notes').val().trim(); postData['settings']['emailReport'] = $('#{{componentId}}-{{sectionId}}-email_report').val().trim(); + postData['settings']['rsync'] = { }; + postData['settings']['rsync']['deleteDestinationFiles'] = $('#{{componentId}}-{{sectionId}}-delete_destination_files')[0].checked; $.post('{{links.url("modules/saveQueueSettings")}}', postData, function(response) { if (response.tokenKey && response.token) { @@ -534,6 +536,7 @@ '{{componentId}}-{{sectionId}}-password_protect' : { }, '{{componentId}}-{{sectionId}}-notes' : { }, '{{componentId}}-{{sectionId}}-email_report' : { }, + '{{componentId}}-{{sectionId}}-delete_destination_files' : { }, '{{componentId}}-{{sectionId}}-form' : $.extend(dataCollectionSectionForm, { rules: { }, diff --git a/apps/Core/Views/Default/html/modules/settings.html b/apps/Core/Views/Default/html/modules/settings.html index a0686984f..f8b348c4f 100644 --- a/apps/Core/Views/Default/html/modules/settings.html +++ b/apps/Core/Views/Default/html/modules/settings.html @@ -1,50 +1,76 @@ -{% set settingsBackupAppsDirChecked = false %} -{% set settingsBackupSystemsDirChecked = false %} -{% set settingsBackupPublicDirChecked = false %} -{% set settingsBackupPrivateDirChecked = false %} -{% set settingsBackupExternalDirChecked = false %} -{% set settingsBackupHTMLCompiledDirChecked = false %} -{% set settingsBackupVarDirChecked = false %} -{% set settingsBackupExternalVendorDirChecked = false %} -{% set settingsBackupOldBackupsDirChecked = false %} -{% set settingsBackupDatabaseChecked = false %} -{% set settingsBackupKeysChecked = false %} +{% set settingsBackupSettingsAppsDirChecked = false %} +{% set settingsBackupSettingsSystemsDirChecked = false %} +{% set settingsBackupSettingsPublicDirChecked = false %} +{% set settingsBackupSettingsPrivateDirChecked = false %} +{% set settingsBackupSettingsExternalDirChecked = false %} +{% set settingsBackupSettingsHTMLCompiledDirChecked = false %} +{% set settingsBackupSettingsVarDirChecked = false %} +{% set settingsBackupSettingsExternalVendorDirChecked = false %} +{% set settingsBackupSettingsOldBackupsDirChecked = false %} +{% set settingsBackupSettingsDatabaseChecked = false %} +{% set settingsBackupSettingsKeysChecked = false %} {% if queue['settings']['backupSettings']['apps_dir'] == 'true' %} - {% set settingsBackupAppsDirChecked = true %} + {% set settingsBackupSettingsAppsDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['systems_dir'] == 'true' %} - {% set settingsBackupSystemsDirChecked = true %} + {% set settingsBackupSettingsSystemsDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['public_dir'] == 'true' %} - {% set settingsBackupPublicDirChecked = true %} + {% set settingsBackupSettingsPublicDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['private_dir'] == 'true' %} - {% set settingsBackupPrivateDirChecked = true %} + {% set settingsBackupSettingsPrivateDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['external_dir'] == 'true' %} - {% set settingsBackupExternalDirChecked = true %} + {% set settingsBackupSettingsExternalDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['html_compiled_dir'] == 'true' %} - {% set settingsBackupHTMLCompiledDirChecked = true %} + {% set settingsBackupSettingsHTMLCompiledDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['var_dir'] == 'true' %} - {% set settingsBackupVarDirChecked = true %} + {% set settingsBackupSettingsVarDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['external_vendor_dir'] == 'true' %} - {% set settingsBackupExternalVendorDirChecked = true %} + {% set settingsBackupSettingsExternalVendorDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['old_backups_dir'] == 'true' %} - {% set settingsBackupOldBackupsDirChecked = true %} + {% set settingsBackupSettingsOldBackupsDirChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['database'] == 'true' %} - {% set settingsBackupDatabaseChecked = true %} + {% set settingsBackupSettingsDatabaseChecked = true %} {% endif %} {% if queue['settings']['backupSettings']['keys'] == 'true' %} - {% set settingsBackupKeysChecked = true %} + {% set settingsBackupSettingsKeysChecked = true %} +{% endif %} +{% set settingsRSyncDeleteDestinationFilesChecked = false %} +{% if queue['settings']['rsync']['deleteDestinationFiles'] == 'true' %} + {% set settingsRSyncDeleteDestinationFilesChecked = true %} {% endif %}
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'backup_settings', + 'fieldLabel' : 'BACKUP SETTINGS', + 'fieldLabelLegend' : true, + 'fieldHidden' : false, + 'fieldType' : 'html', + 'fieldBazScan' : false, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazJstreeSearch' : true, + 'fieldHtmlContent' : '' + ] + )}} +
+
{{adminltetags.useTag('fields', @@ -60,8 +86,8 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'success', - 'fieldCheckboxLabel' : 'BACKUP APPS DIRECTORY', - 'fieldCheckboxChecked' : settingsBackupAppsDirChecked, + 'fieldCheckboxLabel' : 'APPS DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupSettingsAppsDirChecked, 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, 'fieldBazPostOnUpdate' : false, @@ -83,8 +109,8 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'success', - 'fieldCheckboxLabel' : 'BACKUP SYSTEMS DIRECTORY', - 'fieldCheckboxChecked' : settingsBackupSystemsDirChecked, + 'fieldCheckboxLabel' : 'SYSTEMS DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupSettingsSystemsDirChecked, 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, 'fieldBazPostOnUpdate' : false, @@ -108,8 +134,8 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'success', - 'fieldCheckboxLabel' : 'BACKUP PUBLIC DIRECTORY', - 'fieldCheckboxChecked' : settingsBackupPublicDirChecked, + 'fieldCheckboxLabel' : 'PUBLIC DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupSettingsPublicDirChecked, 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, 'fieldBazPostOnUpdate' : false, @@ -131,8 +157,8 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'success', - 'fieldCheckboxLabel' : 'BACKUP PRIVATE DIRECTORY', - 'fieldCheckboxChecked' : settingsBackupPrivateDirChecked, + 'fieldCheckboxLabel' : 'PRIVATE DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupSettingsPrivateDirChecked, 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, 'fieldBazPostOnUpdate' : false, @@ -156,8 +182,8 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'success', - 'fieldCheckboxLabel' : 'BACKUP EXTERNAL DIRECTORY', - 'fieldCheckboxChecked' : settingsBackupExternalDirChecked, + 'fieldCheckboxLabel' : 'EXTERNAL DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupSettingsExternalDirChecked, 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, 'fieldBazPostOnUpdate' : false, @@ -179,7 +205,7 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'warning', - 'fieldCheckboxChecked' : settingsBackupHTMLCompiledDirChecked, + 'fieldCheckboxChecked' : settingsBackupSettingsHTMLCompiledDirChecked, 'fieldCheckboxLabel' : 'COMPILED HTML DIRECTORY', 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, @@ -204,7 +230,7 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'warning', - 'fieldCheckboxChecked' : settingsBackupVarDirChecked, + 'fieldCheckboxChecked' : settingsBackupSettingsVarDirChecked, 'fieldCheckboxLabel' : 'VAR DIRECTORY', 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, @@ -227,8 +253,8 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'warning', - 'fieldCheckboxLabel' : 'BACKUP EXTERNAL VENDOR DIRECTORY', - 'fieldCheckboxChecked' : settingsBackupExternalVendorDirChecked, + 'fieldCheckboxLabel' : 'EXTERNAL VENDOR DIRECTORY', + 'fieldCheckboxChecked' : settingsBackupSettingsExternalVendorDirChecked, 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, 'fieldBazPostOnUpdate' : false, @@ -252,8 +278,8 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'danger', - 'fieldCheckboxChecked' : settingsBackupOldBackupsDirChecked, - 'fieldCheckboxLabel' : 'OLD BACKUP FILES', + 'fieldCheckboxChecked' : settingsBackupSettingsOldBackupsDirChecked, + 'fieldCheckboxLabel' : 'OLD BACKUP FILES DIRECTORY', 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, 'fieldBazPostOnUpdate' : false, @@ -275,7 +301,7 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'success', - 'fieldCheckboxChecked' : settingsBackupDatabaseChecked, + 'fieldCheckboxChecked' : settingsBackupSettingsDatabaseChecked, 'fieldCheckboxLabel' : 'DATABASE', 'fieldBazJstreeSearch' : true, 'fieldBazPostOnCreate' : false, @@ -300,7 +326,7 @@ 'fieldRequired' : false, 'fieldType' : 'checkbox', 'fieldCheckboxType' : 'danger', - 'fieldCheckboxChecked' : settingsBackupKeysChecked, + 'fieldCheckboxChecked' : settingsBackupSettingsKeysChecked, 'fieldDisabled' : true, 'fieldCheckboxLabel' : 'SECURITY AND DB KEYS', 'fieldBazJstreeSearch' : true, @@ -345,7 +371,7 @@ 'componentId' : componentId, 'sectionId' : sectionId, 'fieldId' : 'notes', - 'fieldLabel' : 'Backup Notes', + 'fieldLabel' : 'Notes', 'fieldType' : 'textarea', 'fieldDataMaxLength' : 2048, 'fieldHelp' : true, @@ -363,6 +389,28 @@

+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'report_settings', + 'fieldLabel' : 'REPORT SETTINGS', + 'fieldLabelLegend' : true, + 'fieldHidden' : false, + 'fieldType' : 'html', + 'fieldBazScan' : false, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazJstreeSearch' : true, + 'fieldHtmlContent' : '' + ] + )}} +
+
{{adminltetags.useTag('fields', @@ -386,6 +434,54 @@ )}}
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'rsync_settings', + 'fieldLabel' : 'RSYNC SETTINGS', + 'fieldLabelLegend' : true, + 'fieldHidden' : false, + 'fieldType' : 'html', + 'fieldBazScan' : false, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazJstreeSearch' : true, + 'fieldHtmlContent' : '' + ] + )}} +
+
+
+
+ {{adminltetags.useTag('fields', + [ + 'component' : component, + 'componentName' : componentName, + 'componentId' : componentId, + 'sectionId' : sectionId, + 'fieldId' : 'delete_destination_files', + 'fieldLabel' : false, + 'fieldHelp' : true, + 'fieldHelpTooltipContent' : 'RSync delete destination files? Disable if you have any custom code installed, else RSync will delete the files that are not found in the source.', + 'fieldRequired' : false, + 'fieldType' : 'checkbox', + 'fieldCheckboxType' : 'danger', + 'fieldCheckboxChecked' : settingsRSyncDeleteDestinationFilesChecked, + 'fieldCheckboxLabel' : 'RSYNC DELETE DESTINATION FILES?', + 'fieldBazJstreeSearch' : true, + 'fieldBazPostOnCreate' : false, + 'fieldBazPostOnUpdate' : false, + 'fieldBazScan' : true + ] + )}} +
+
\ No newline at end of file diff --git a/system/Base/Providers/ModulesServiceProvider/Installer.php b/system/Base/Providers/ModulesServiceProvider/Installer.php index 977aebb63..f388738a4 100644 --- a/system/Base/Providers/ModulesServiceProvider/Installer.php +++ b/system/Base/Providers/ModulesServiceProvider/Installer.php @@ -575,8 +575,10 @@ protected function runRsync($args) if ($precheck) { $this->queue['results'][$taskName][$module['module_type']][$module['id']]['precheck'] = 'fail'; - $preCheckQueueLogs = &$this->queue['results'][$taskName][$module['module_type']][$module['id']]['precheck_logs']; + } else { + $this->queue['results'][$taskName][$module['module_type']][$module['id']]['result'] = 'fail'; + $resultQueueLogs = &$this->queue['results'][$taskName][$module['module_type']][$module['id']]['result_logs']; } if ($module['module_type'] === 'packages' && @@ -603,20 +605,26 @@ protected function runRsync($args) } try { - $rsync = new Rsync([ - Rsync::CONF_CWD => base_path('var/tmp/installer/' . $this->zipFile['name'] . '/' . $this->zipFile['name']), - Rsync::CONF_OPTIONS => - [ - Rsync::OPT_DRY_RUN => $precheck, - Rsync::OPT_VERBOSE => true, - Rsync::OPT_ARCHIVE => true, - Rsync::OPT_HUMAN_READABLE => true, - Rsync::OPT_CHECKSUM => true, - Rsync::OPT_DELETE_AFTER => true, - Rsync::OPT_INCLUDE => $includeFiles, - Rsync::OPT_EXCLUDE => ['*'], - ] - ]); + $rsyncSettings = + [ + Rsync::CONF_CWD => base_path('var/tmp/installer/' . $this->zipFile['name'] . '/' . $this->zipFile['name']), + Rsync::CONF_OPTIONS => + [ + Rsync::OPT_DRY_RUN => $precheck, + Rsync::OPT_VERBOSE => true, + Rsync::OPT_ARCHIVE => true, + Rsync::OPT_HUMAN_READABLE => true, + Rsync::OPT_CHECKSUM => true, + Rsync::OPT_INCLUDE => $includeFiles, + Rsync::OPT_EXCLUDE => ['*'], + ] + ]; + + if ($this->queue['settings']['rsync']['deleteDestinationFiles']) { + $rsyncSettings[Rsync::CONF_OPTIONS][Rsync::OPT_DELETE_AFTER] = true; + } + + $rsync = new Rsync($rsyncSettings); if ($module['module_type'] === 'packages' && str_contains($module['name'], 'Core') @@ -651,13 +659,15 @@ protected function runRsync($args) } } - if (str_starts_with($output, 'deleting')) { - if (!str_ends_with($output, '/') && - !str_ends_with($output, '.git') && - !str_ends_with($output, 'keys') - ) { - $output = str_replace('deleting ', '', $output); - array_push($deleteFiles, $output); + if ($this->queue['settings']['rsync']['deleteDestinationFiles']) { + if (str_starts_with($output, 'deleting')) { + if (!str_ends_with($output, '/') && + !str_ends_with($output, '.git') && + !str_ends_with($output, 'keys') + ) { + $output = str_replace('deleting ', '', $output); + array_push($deleteFiles, $output); + } } } }); @@ -665,7 +675,18 @@ protected function runRsync($args) if ($precheck) { $this->queue['results'][$taskName][$module['module_type']][$module['id']]['precheck'] = 'pass'; - $preCheckQueueLogs = $this->helper->encode(['modifiedFiles' => $modifiedFiles, 'deleteFiles' => $deleteFiles]); + if ($this->queue['settings']['rsync']['deleteDestinationFiles']) { + $preCheckQueueLogs = $this->helper->encode(['modifiedFiles' => $modifiedFiles, 'deleteFiles' => $deleteFiles]); + } else { + $preCheckQueueLogs = $this->helper->encode(['modifiedFiles' => $modifiedFiles]); + } + } else { + $this->queue['results'][$taskName][$module['module_type']][$module['id']]['result'] = 'pass'; + if ($this->queue['settings']['rsync']['deleteDestinationFiles']) { + $resultQueueLogs = $this->helper->encode(['modifiedFiles' => $modifiedFiles, 'deleteFiles' => $deleteFiles]); + } else { + $resultQueueLogs = $this->helper->encode(['modifiedFiles' => $modifiedFiles]); + } } // trace(varsToDump : [$modifiedFiles, $deleteFiles], object: true); @@ -689,7 +710,10 @@ protected function runRsync($args) $preCheckQueueLogs ); } else { - // + return $this->preCheckHasErrors( + $rsyncError, + $resultQueueLogs + ); } } @@ -730,8 +754,6 @@ protected function createBackup() return true; } - unset($this->queue['settings']['backupSettings']['backup']); - if ($this->queue['settings']['backupSettings']['notes'] === '') { $this->queue['settings']['backupSettings']['notes'] = 'Backup taken while processing module installer queue with ID: ' . $this->queue['id']; } @@ -876,13 +898,13 @@ protected function registerRunProcessProgressMethods() 'text' => 'Creating filesystem and database backup...' ] ); - // array_push($this->runProcessProgressMethods, - // [ - // 'method' => 'runRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), - // 'text' => 'Running rsync --dry-run for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', - // 'args' => [$taskName, $module, true], - // ] - // ); + array_push($this->runProcessProgressMethods, + [ + 'method' => 'runRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + 'text' => 'Running rsync for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', + 'args' => [$taskName, $module, false], + ] + ); } } } diff --git a/system/Base/Providers/ModulesServiceProvider/Queues.php b/system/Base/Providers/ModulesServiceProvider/Queues.php index 1d7d8a337..6618cc1eb 100644 --- a/system/Base/Providers/ModulesServiceProvider/Queues.php +++ b/system/Base/Providers/ModulesServiceProvider/Queues.php @@ -71,6 +71,10 @@ protected function addActiveQueue() 'password_protect' => $this->basepackages->utils->generateNewPassword()['password'], 'notes' => '', ], + 'rsync' => + [ + 'deleteDestinationFiles' => false + ], 'emailReport' => $this->access->auth->account()['email'] ] ) @@ -232,7 +236,6 @@ public function saveQueueSettings($data) } }); - if ($data['settings']['backupSettings']['keys'] === true && $data['settings']['backupSettings']['password_protect'] === '' ) { @@ -275,6 +278,18 @@ public function saveQueueSettings($data) } } + array_walk($data['settings']['rsync'], function(&$setting, $index) { + if ($setting !== '') { + if ($setting == 'true') { + $setting = true; + } else { + $setting = false; + } + } else { + $setting = false; + } + }); + $queue['settings'] = array_replace($queue['settings'], $data['settings']); if ($this->update($queue)) { From 75210b4246c03435517ca8ed8740100e6d853f81 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Mon, 27 Jan 2025 00:25:31 +1100 Subject: [PATCH 28/34] update #34 test DB update. --- system/Base/Installer/Packages/Setup.php | 349 +---------------- .../Base/Installer/Packages/Setup/Schema.php | 364 ++++++++++++++++++ .../Packages/Setup/Schema/TestModel.php | 18 + .../Packages/Setup/Schema/TestSchema.php | 56 +++ .../ModulesServiceProvider/Installer.php | 98 ++++- 5 files changed, 528 insertions(+), 357 deletions(-) create mode 100644 system/Base/Installer/Packages/Setup/Schema.php create mode 100644 system/Base/Installer/Packages/Setup/Schema/TestModel.php create mode 100644 system/Base/Installer/Packages/Setup/Schema/TestSchema.php diff --git a/system/Base/Installer/Packages/Setup.php b/system/Base/Installer/Packages/Setup.php index 054ee5e86..5c5bfbe08 100644 --- a/system/Base/Installer/Packages/Setup.php +++ b/system/Base/Installer/Packages/Setup.php @@ -30,124 +30,10 @@ use System\Base\Installer\Packages\Setup\Register\Providers\App\Type as RegisterCoreAppType; use System\Base\Installer\Packages\Setup\Register\Providers\Core as RegisterCore; use System\Base\Installer\Packages\Setup\Register\Providers\Domain as RegisterDomain; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\ActivityLogs; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\AddressBook; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\ApiClientServices\ApiClientServices; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\ApiClientServices\ApiClientServicesCalls; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\ApiClientServices\Apis\Repos; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Dashboards; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Dashboards\Widgets as DashboardsWidgets; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\EmailQueue; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\EmailServices; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Filters; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Geo\Cities; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Geo\CitiesIp2LocationV4; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Geo\CitiesIp2LocationV6; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Geo\Countries; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Geo\States; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Geo\Timezones; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\ImportExport; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Menus; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Messenger; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Murls; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Notes; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Notifications; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Storages; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Storages\StoragesLocal; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Templates; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Accounts; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Accounts\Agents; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Accounts\CanLogin; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Accounts\Identifiers; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Accounts\Security; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Accounts\Sessions; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Accounts\Tunnels; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Profiles; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Users\Roles; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Widgets; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Workers\Jobs; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Workers\Schedules; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Workers\Tasks; -use System\Base\Installer\Packages\Setup\Schema\Basepackages\Workers\Workers; -use System\Base\Installer\Packages\Setup\Schema\Modules\Bundles; -use System\Base\Installer\Packages\Setup\Schema\Modules\Components; -use System\Base\Installer\Packages\Setup\Schema\Modules\Middlewares; -use System\Base\Installer\Packages\Setup\Schema\Modules\Packages; -use System\Base\Installer\Packages\Setup\Schema\Modules\Queues; -use System\Base\Installer\Packages\Setup\Schema\Modules\Views; -use System\Base\Installer\Packages\Setup\Schema\Modules\Views\Settings; -use System\Base\Installer\Packages\Setup\Schema\Providers\Access\IpFilter; -use System\Base\Installer\Packages\Setup\Schema\Providers\Api as SPApi; -use System\Base\Installer\Packages\Setup\Schema\Providers\Api\AccessTokens; -use System\Base\Installer\Packages\Setup\Schema\Providers\Api\AuthorizationCodes; -use System\Base\Installer\Packages\Setup\Schema\Providers\Api\Clients; -use System\Base\Installer\Packages\Setup\Schema\Providers\Api\RefreshTokens; -use System\Base\Installer\Packages\Setup\Schema\Providers\Api\Scopes; -use System\Base\Installer\Packages\Setup\Schema\Providers\Apps; -use System\Base\Installer\Packages\Setup\Schema\Providers\Apps\Types; -use System\Base\Installer\Packages\Setup\Schema\Providers\Cache; -use System\Base\Installer\Packages\Setup\Schema\Providers\Core; -use System\Base\Installer\Packages\Setup\Schema\Providers\Domains; -use System\Base\Installer\Packages\Setup\Schema\Providers\Logs; +use System\Base\Installer\Packages\Setup\Schema; use System\Base\Installer\Packages\Setup\Write\Configs; use System\Base\Installer\Packages\Setup\Write\Pdo; -use System\Base\Providers\AccessServiceProvider\Model\ServiceProviderAccessIpFilter; -use System\Base\Providers\ApiServiceProvider\Model\ServiceProviderApi; -use System\Base\Providers\ApiServiceProvider\Model\ServiceProviderApiAccessTokens; -use System\Base\Providers\ApiServiceProvider\Model\ServiceProviderApiAuthorizationCodes; -use System\Base\Providers\ApiServiceProvider\Model\ServiceProviderApiClients; -use System\Base\Providers\ApiServiceProvider\Model\ServiceProviderApiRefreshTokens; -use System\Base\Providers\ApiServiceProvider\Model\ServiceProviderApiScopes; -use System\Base\Providers\AppsServiceProvider\Model\ServiceProviderApps; -use System\Base\Providers\AppsServiceProvider\Model\ServiceProviderAppsTypes; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\ApiClientServices\BasepackagesApiClientServices; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\ApiClientServices\BasepackagesApiClientServicesCalls; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesActivityLogs; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesAddressBook; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesDashboards; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesFilters; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesImportExport; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesMenus; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesMurls; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesNotes; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesNotifications; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesStorages; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesTemplates; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\BasepackagesWidgets; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Dashboards\BasepackagesDashboardsWidgets; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Email\BasepackagesEmailQueue; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Email\BasepackagesEmailServices; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Geo\BasepackagesGeoCities; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Geo\BasepackagesGeoCitiesIp2locationv4; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Geo\BasepackagesGeoCitiesIp2locationv6; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Geo\BasepackagesGeoCountries; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Geo\BasepackagesGeoStates; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Geo\BasepackagesGeoTimezones; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Messenger\BasepackagesMessenger; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Storages\BasepackagesStoragesLocal; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\Accounts\BasepackagesUsersAccountsAgents; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\Accounts\BasepackagesUsersAccountsCanlogin; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\Accounts\BasepackagesUsersAccountsIdentifiers; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\Accounts\BasepackagesUsersAccountsSecurity; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\Accounts\BasepackagesUsersAccountsSessions; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\Accounts\BasepackagesUsersAccountsTunnels; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\BasepackagesUsersAccounts; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\BasepackagesUsersProfiles; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Users\BasepackagesUsersRoles; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Workers\BasepackagesWorkersJobs; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Workers\BasepackagesWorkersSchedules; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Workers\BasepackagesWorkersTasks; -use System\Base\Providers\BasepackagesServiceProvider\Packages\Model\Workers\BasepackagesWorkersWorkers; -use System\Base\Providers\CoreServiceProvider\Model\ServiceProviderCore; use System\Base\Providers\DatabaseServiceProvider\Ff; -use System\Base\Providers\DomainsServiceProvider\Model\ServiceProviderDomains; -use System\Base\Providers\ModulesServiceProvider\Model\ServiceProviderModulesQueues; -use System\Base\Providers\ModulesServiceProvider\Modules\Model\ModulesBundles; -use System\Base\Providers\ModulesServiceProvider\Modules\Model\ModulesComponents; -use System\Base\Providers\ModulesServiceProvider\Modules\Model\ModulesMiddlewares; -use System\Base\Providers\ModulesServiceProvider\Modules\Model\ModulesPackages; -use System\Base\Providers\ModulesServiceProvider\Modules\Model\ModulesViews; -use System\Base\Providers\ModulesServiceProvider\Modules\Model\ModulesViewsSettings; class Setup { @@ -472,236 +358,7 @@ protected function checkDbEmpty() protected function buildSchema() { - $databases = [ - 'service_provider_core' => [ - 'schema' => new Core, - 'model' => new ServiceProviderCore, - ], - 'service_provider_apps' => [ - 'schema' => new Apps, - 'model' => new ServiceProviderApps, - ], - 'service_provider_apps_types' => [ - 'schema' => new Types, - 'model' => new ServiceProviderAppsTypes, - ], - 'service_provider_access_ip_filter' => [ - 'schema' => new IpFilter, - 'model' => new ServiceProviderAccessIpFilter, - ], - 'service_provider_domains' => [ - 'schema' => new Domains, - 'model' => new ServiceProviderDomains, - ], - 'service_provider_modules_queues' => [ - 'schema' => new Queues, - 'model' => new ServiceProviderModulesQueues, - ], - 'modules_bundles' => [ - 'schema' => new Bundles, - 'model' => new ModulesBundles, - ], - 'modules_components' => [ - 'schema' => new Components, - 'model' => new ModulesComponents, - ], - 'modules_packages' => [ - 'schema' => new Packages, - 'model' => new ModulesPackages, - ], - 'modules_middlewares' => [ - 'schema' => new Middlewares, - 'model' => new ModulesMiddlewares, - ], - 'modules_views' => [ - 'schema' => new Views, - 'model' => new ModulesViews, - ], - 'modules_views_settings' => [ - 'schema' => new Settings, - 'model' => new ModulesViewsSettings, - ], - 'basepackages_email_services' => [ - 'schema' => new EmailServices, - 'model' => new BasepackagesEmailServices, - ], - 'basepackages_email_queue' => [ - 'schema' => new EmailQueue, - 'model' => new BasepackagesEmailQueue, - ], - 'basepackages_users_accounts' => [ - 'schema' => new Accounts, - 'model' => new BasepackagesUsersAccounts, - ], - 'basepackages_users_accounts_security' => [ - 'schema' => new Security, - 'model' => new BasepackagesUsersAccountsSecurity, - ], - 'basepackages_users_accounts_canlogin' => [ - 'schema' => new CanLogin, - 'model' => new BasepackagesUsersAccountsCanlogin, - ], - 'basepackages_users_accounts_sessions' => [ - 'schema' => new Sessions, - 'model' => new BasepackagesUsersAccountsSessions, - ], - 'basepackages_users_accounts_identifiers' => [ - 'schema' => new Identifiers, - 'model' => new BasepackagesUsersAccountsIdentifiers, - ], - 'basepackages_users_accounts_agents' => [ - 'schema' => new Agents, - 'model' => new BasepackagesUsersAccountsAgents, - ], - 'basepackages_users_accounts_tunnels' => [ - 'schema' => new Tunnels, - 'model' => new BasepackagesUsersAccountsTunnels, - ], - 'basepackages_users_profiles' => [ - 'schema' => new Profiles, - 'model' => new BasepackagesUsersProfiles, - ], - 'basepackages_users_roles' => [ - 'schema' => new Roles, - 'model' => new BasepackagesUsersRoles, - ], - 'basepackages_menus' => [ - 'schema' => new Menus, - 'model' => new BasepackagesMenus, - ], - 'basepackages_murls' => [ - 'schema' => new Murls, - 'model' => new BasepackagesMurls, - ], - 'basepackages_filters' => [ - 'schema' => new Filters, - 'model' => new BasepackagesFilters, - ], - 'basepackages_geo_countries' => [ - 'schema' => new Countries, - 'model' => new BasepackagesGeoCountries, - ], - 'basepackages_geo_states' => [ - 'schema' => new States, - 'model' => new BasepackagesGeoStates, - ], - 'basepackages_geo_cities' => [ - 'schema' => new Cities, - 'model' => new BasepackagesGeoCities, - ], - 'basepackages_geo_cities_ip2locationv4' => [ - 'schema' => new CitiesIp2LocationV4, - 'model' => new BasepackagesGeoCitiesIp2locationv4, - ], - 'basepackages_geo_cities_ip2locationv6' => [ - 'schema' => new CitiesIp2LocationV6, - 'model' => new BasepackagesGeoCitiesIp2locationv6, - ], - 'basepackages_geo_timezones' => [ - 'schema' => new Timezones, - 'model' => new BasepackagesGeoTimezones, - ], - 'basepackages_address_book' => [ - 'schema' => new AddressBook, - 'model' => new BasepackagesAddressBook, - ], - 'basepackages_storages' => [ - 'schema' => new Storages, - 'model' => new BasepackagesStorages, - ], - 'basepackages_storages_local' => [ - 'schema' => new StoragesLocal, - 'model' => new BasepackagesStoragesLocal, - ], - 'basepackages_activity_logs' => [ - 'schema' => new ActivityLogs, - 'model' => new BasepackagesActivityLogs, - ], - 'basepackages_notes' => [ - 'schema' => new Notes, - 'model' => new BasepackagesNotes, - ], - 'basepackages_notifications' => [ - 'schema' => new Notifications, - 'model' => new BasepackagesNotifications, - ], - 'basepackages_workers_workers' => [ - 'schema' => new Workers, - 'model' => new BasepackagesWorkersWorkers, - ], - 'basepackages_workers_schedules' => [ - 'schema' => new Schedules, - 'model' => new BasepackagesWorkersSchedules, - ], - 'basepackages_workers_tasks' => [ - 'schema' => new Tasks, - 'model' => new BasepackagesWorkersTasks, - ], - 'basepackages_workers_jobs' => [ - 'schema' => new Jobs, - 'model' => new BasepackagesWorkersJobs, - ], - 'basepackages_import_export' => [ - 'schema' => new ImportExport, - 'model' => new BasepackagesImportExport, - ], - 'basepackages_templates' => [ - 'schema' => new Templates, - 'model' => new BasepackagesTemplates, - ], - 'basepackages_dashboards' => [ - 'schema' => new Dashboards, - 'model' => new BasepackagesDashboards, - ], - 'basepackages_dashboards_widgets' => [ - 'schema' => new DashboardsWidgets, - 'model' => new BasepackagesDashboardsWidgets, - ], - 'basepackages_widgets' => [ - 'schema' => new Widgets, - 'model' => new BasepackagesWidgets, - ], - 'basepackages_messenger' => [ - 'schema' => new Messenger, - 'model' => new BasepackagesMessenger, - ], - 'basepackages_api_client_services' => [ - 'schema' => new ApiClientServices, - 'model' => new BasepackagesApiClientServices, - ], - 'basepackages_api_client_services_calls' => [ - 'schema' => new ApiClientServicesCalls, - 'model' => new BasepackagesApiClientServicesCalls, - ], - 'basepackages_api_client_services_apis_repos'=> [ - 'schema' => new Repos, - 'model' => null - ], - 'service_provider_api' => [ - 'schema' => new SPApi, - 'model' => new ServiceProviderApi, - ], - 'service_provider_api_access_tokens' => [ - 'schema' => new AccessTokens, - 'model' => new ServiceProviderApiAccessTokens, - ], - 'service_provider_api_authorization_codes' => [ - 'schema' => new AuthorizationCodes, - 'model' => new ServiceProviderApiAuthorizationCodes, - ], - 'service_provider_api_clients' => [ - 'schema' => new Clients, - 'model' => new ServiceProviderApiClients, - ], - 'service_provider_api_refresh_tokens' => [ - 'schema' => new RefreshTokens, - 'model' => new ServiceProviderApiRefreshTokens, - ], - 'service_provider_api_scopes' => [ - 'schema' => new Scopes, - 'model' => new ServiceProviderApiScopes, - ], - ]; + $databases = (new Schema)->getSchema(); if (isset($this->postData['databasetype']) && $this->postData['databasetype'] !== 'ff') { foreach ($databases as $tableName => $tableClass) { @@ -722,7 +379,7 @@ protected function buildSchema() $tableName = $tableClass['model']->getSource(); } - $config = $this->ff->generateConfig($tableName, $tableClass['schema'], $tableClass['model'], $this->db); + $config = $this->ff->generateConfig($tableName, $tableClass['schema'], $tableClass['model']); $schema = $this->ff->generateSchema($tableName, $tableClass['schema'], $tableClass['model']); $this->ff->store($tableName, $config, $schema, $this->ff)->deleteStore(); diff --git a/system/Base/Installer/Packages/Setup/Schema.php b/system/Base/Installer/Packages/Setup/Schema.php new file mode 100644 index 000000000..c63350e71 --- /dev/null +++ b/system/Base/Installer/Packages/Setup/Schema.php @@ -0,0 +1,364 @@ + [ + 'schema' => new Core, + 'model' => new ServiceProviderCore, + ], + 'service_provider_apps' => [ + 'schema' => new Apps, + 'model' => new ServiceProviderApps, + ], + 'service_provider_apps_types' => [ + 'schema' => new Types, + 'model' => new ServiceProviderAppsTypes, + ], + 'service_provider_access_ip_filter' => [ + 'schema' => new IpFilter, + 'model' => new ServiceProviderAccessIpFilter, + ], + 'service_provider_domains' => [ + 'schema' => new Domains, + 'model' => new ServiceProviderDomains, + ], + 'service_provider_modules_queues' => [ + 'schema' => new Queues, + 'model' => new ServiceProviderModulesQueues, + ], + 'modules_bundles' => [ + 'schema' => new Bundles, + 'model' => new ModulesBundles, + ], + 'modules_components' => [ + 'schema' => new Components, + 'model' => new ModulesComponents, + ], + 'modules_packages' => [ + 'schema' => new Packages, + 'model' => new ModulesPackages, + ], + 'modules_middlewares' => [ + 'schema' => new Middlewares, + 'model' => new ModulesMiddlewares, + ], + 'modules_views' => [ + 'schema' => new Views, + 'model' => new ModulesViews, + ], + 'modules_views_settings' => [ + 'schema' => new Settings, + 'model' => new ModulesViewsSettings, + ], + 'basepackages_email_services' => [ + 'schema' => new EmailServices, + 'model' => new BasepackagesEmailServices, + ], + 'basepackages_email_queue' => [ + 'schema' => new EmailQueue, + 'model' => new BasepackagesEmailQueue, + ], + 'basepackages_users_accounts' => [ + 'schema' => new Accounts, + 'model' => new BasepackagesUsersAccounts, + ], + 'basepackages_users_accounts_security' => [ + 'schema' => new Security, + 'model' => new BasepackagesUsersAccountsSecurity, + ], + 'basepackages_users_accounts_canlogin' => [ + 'schema' => new CanLogin, + 'model' => new BasepackagesUsersAccountsCanlogin, + ], + 'basepackages_users_accounts_sessions' => [ + 'schema' => new Sessions, + 'model' => new BasepackagesUsersAccountsSessions, + ], + 'basepackages_users_accounts_identifiers' => [ + 'schema' => new Identifiers, + 'model' => new BasepackagesUsersAccountsIdentifiers, + ], + 'basepackages_users_accounts_agents' => [ + 'schema' => new Agents, + 'model' => new BasepackagesUsersAccountsAgents, + ], + 'basepackages_users_accounts_tunnels' => [ + 'schema' => new Tunnels, + 'model' => new BasepackagesUsersAccountsTunnels, + ], + 'basepackages_users_profiles' => [ + 'schema' => new Profiles, + 'model' => new BasepackagesUsersProfiles, + ], + 'basepackages_users_roles' => [ + 'schema' => new Roles, + 'model' => new BasepackagesUsersRoles, + ], + 'basepackages_menus' => [ + 'schema' => new Menus, + 'model' => new BasepackagesMenus, + ], + 'basepackages_murls' => [ + 'schema' => new Murls, + 'model' => new BasepackagesMurls, + ], + 'basepackages_filters' => [ + 'schema' => new Filters, + 'model' => new BasepackagesFilters, + ], + 'basepackages_geo_countries' => [ + 'schema' => new Countries, + 'model' => new BasepackagesGeoCountries, + ], + 'basepackages_geo_states' => [ + 'schema' => new States, + 'model' => new BasepackagesGeoStates, + ], + 'basepackages_geo_cities' => [ + 'schema' => new Cities, + 'model' => new BasepackagesGeoCities, + ], + 'basepackages_geo_cities_ip2locationv4' => [ + 'schema' => new CitiesIp2LocationV4, + 'model' => new BasepackagesGeoCitiesIp2locationv4, + ], + 'basepackages_geo_cities_ip2locationv6' => [ + 'schema' => new CitiesIp2LocationV6, + 'model' => new BasepackagesGeoCitiesIp2locationv6, + ], + 'basepackages_geo_timezones' => [ + 'schema' => new Timezones, + 'model' => new BasepackagesGeoTimezones, + ], + 'basepackages_address_book' => [ + 'schema' => new AddressBook, + 'model' => new BasepackagesAddressBook, + ], + 'basepackages_storages' => [ + 'schema' => new Storages, + 'model' => new BasepackagesStorages, + ], + 'basepackages_storages_local' => [ + 'schema' => new StoragesLocal, + 'model' => new BasepackagesStoragesLocal, + ], + 'basepackages_activity_logs' => [ + 'schema' => new ActivityLogs, + 'model' => new BasepackagesActivityLogs, + ], + 'basepackages_notes' => [ + 'schema' => new Notes, + 'model' => new BasepackagesNotes, + ], + 'basepackages_notifications' => [ + 'schema' => new Notifications, + 'model' => new BasepackagesNotifications, + ], + 'basepackages_workers_workers' => [ + 'schema' => new Workers, + 'model' => new BasepackagesWorkersWorkers, + ], + 'basepackages_workers_schedules' => [ + 'schema' => new Schedules, + 'model' => new BasepackagesWorkersSchedules, + ], + 'basepackages_workers_tasks' => [ + 'schema' => new Tasks, + 'model' => new BasepackagesWorkersTasks, + ], + 'basepackages_workers_jobs' => [ + 'schema' => new Jobs, + 'model' => new BasepackagesWorkersJobs, + ], + 'basepackages_import_export' => [ + 'schema' => new ImportExport, + 'model' => new BasepackagesImportExport, + ], + 'basepackages_templates' => [ + 'schema' => new Templates, + 'model' => new BasepackagesTemplates, + ], + 'basepackages_dashboards' => [ + 'schema' => new Dashboards, + 'model' => new BasepackagesDashboards, + ], + 'basepackages_dashboards_widgets' => [ + 'schema' => new DashboardsWidgets, + 'model' => new BasepackagesDashboardsWidgets, + ], + 'basepackages_widgets' => [ + 'schema' => new Widgets, + 'model' => new BasepackagesWidgets, + ], + 'basepackages_messenger' => [ + 'schema' => new Messenger, + 'model' => new BasepackagesMessenger, + ], + 'basepackages_api_client_services' => [ + 'schema' => new ApiClientServices, + 'model' => new BasepackagesApiClientServices, + ], + 'basepackages_api_client_services_calls' => [ + 'schema' => new ApiClientServicesCalls, + 'model' => new BasepackagesApiClientServicesCalls, + ], + 'basepackages_api_client_services_apis_repos'=> [ + 'schema' => new Repos, + 'model' => null + ], + 'service_provider_api' => [ + 'schema' => new SPApi, + 'model' => new ServiceProviderApi, + ], + 'service_provider_api_access_tokens' => [ + 'schema' => new AccessTokens, + 'model' => new ServiceProviderApiAccessTokens, + ], + 'service_provider_api_authorization_codes' => [ + 'schema' => new AuthorizationCodes, + 'model' => new ServiceProviderApiAuthorizationCodes, + ], + 'service_provider_api_clients' => [ + 'schema' => new Clients, + 'model' => new ServiceProviderApiClients, + ], + 'service_provider_api_refresh_tokens' => [ + 'schema' => new RefreshTokens, + 'model' => new ServiceProviderApiRefreshTokens, + ], + 'service_provider_api_scopes' => [ + 'schema' => new Scopes, + 'model' => new ServiceProviderApiScopes, + ], + 'service_provider_api_scopes' => [ + 'schema' => new Scopes, + 'model' => new ServiceProviderApiScopes, + ], + 'test_schema' => [ + 'schema' => new \System\Base\Installer\Packages\Setup\Schema\TestSchema, + 'model' => new \System\Base\Installer\Packages\Setup\Schema\TestModel, + ], + ]; + } +} \ No newline at end of file diff --git a/system/Base/Installer/Packages/Setup/Schema/TestModel.php b/system/Base/Installer/Packages/Setup/Schema/TestModel.php new file mode 100644 index 000000000..847371220 --- /dev/null +++ b/system/Base/Installer/Packages/Setup/Schema/TestModel.php @@ -0,0 +1,18 @@ + [ + new Column( + 'id', + [ + 'type' => Column::TYPE_INTEGER, + 'notNull' => true, + 'autoIncrement' => true, + 'primary' => true, + ] + ), + new Column( + 'key', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 4096, + 'notNull' => true, + ] + ), + new Column( + 'query', + [ + 'type' => Column::TYPE_JSON, + 'notNull' => true, + ] + ), + new Column( + 'status', + [ + 'type' => Column::TYPE_TINYINTEGER, + 'size' => 1, + 'notNull' => false, + ] + ), + new Column( + 'bool', + [ + 'type' => Column::TYPE_BOOLEAN, + 'notNull' => false, + ] + ) + ] + ]; + } +} \ No newline at end of file diff --git a/system/Base/Providers/ModulesServiceProvider/Installer.php b/system/Base/Providers/ModulesServiceProvider/Installer.php index f388738a4..89dc709f3 100644 --- a/system/Base/Providers/ModulesServiceProvider/Installer.php +++ b/system/Base/Providers/ModulesServiceProvider/Installer.php @@ -12,6 +12,7 @@ use League\Flysystem\UnableToRetrieveMetadata; use League\Flysystem\UnableToWriteFile; use System\Base\BasePackage; +use System\Base\Installer\Packages\Setup\Schema; use xobotyi\rsync\Rsync; use z4kn4fein\SemVer\Version; @@ -47,6 +48,8 @@ class Installer extends BasePackage protected $updatedBy; + protected $storesToIndex = []; + public function init($process = 'precheck') { $this->queue = $this->modules->queues->getActiveQueue(); @@ -582,7 +585,7 @@ protected function runRsync($args) } if ($module['module_type'] === 'packages' && - str_contains($module['name'], 'Core') + $module['name'] === 'Core' ) { $includeFiles = [ @@ -627,7 +630,7 @@ protected function runRsync($args) $rsync = new Rsync($rsyncSettings); if ($module['module_type'] === 'packages' && - str_contains($module['name'], 'Core') + $module['name'] === 'Core' ) { $rsync->sync( '.', @@ -717,6 +720,72 @@ protected function runRsync($args) } } + protected function updateSchema($args) + { + $taskName = $args[0]; + $module = $args[1]; + + if ($module['module_type'] === 'packages' && + $module['name'] === 'Core' + ) { + $databases = (new Schema)->getSchema(); + } else { + // + } + + // trace(varsToDump : [$this->config], object: true); + if (isset($this->config['databasetype']) && $this->config['databasetype'] !== 'ff') { + + + foreach ($databases as $tableName => $tableClass) { + if (method_exists($tableClass['schema'], 'columns')) { + $table = $this->describe($tableClass['model']->getSource()); + trace(varsToDump : [$table]); + + $this->db->createTable($tableName, $this->config['db']['dbname'], $tableClass['schema']->columns()); + } + if (method_exists($tableClass['schema'], 'indexes')) { + $this->addIndex($tableName, $tableClass['schema']->indexes()); + } + } + } + + if (isset($this->config['databasetype']) && $this->config['databasetype'] !== 'db') { + foreach ($databases as $tableName => $tableClass) { + if ($tableClass['model'] && $tableClass['model']->getSource()) { + $tableName = $tableClass['model']->getSource(); + } + + $config = $this->ff->generateConfig($tableName, $tableClass['schema'], $tableClass['model']); + $schema = $this->ff->generateSchema($tableName, $tableClass['schema'], $tableClass['model']); + + $this->ff->store($tableName, $config, $schema, $this->ff); + + if (method_exists($tableClass['schema'], 'indexes')) { + array_push($this->storesToIndex, $tableName); + } + } + } + + return true; + } + + protected function performIndexing() + { + if (isset($this->config['databasetype']) && + $this->config['databasetype'] !== 'db' && + count($this->storesToIndex) > 0 + ) { + foreach ($this->storesToIndex as $storeToIndex) { + $store = $this->ff->store($storeToIndex); + + $store->reIndexStore(); + } + } + + return true; + } + public function cleanup(array $what) { if (in_array('composer', $what)) { @@ -892,17 +961,24 @@ protected function registerRunProcessProgressMethods() if ($taskName === 'first' && $moduleType === 'external') { continue; } else { + // array_push($this->runProcessProgressMethods, + // [ + // 'method' => 'createBackup', + // 'text' => 'Creating filesystem and database backup...' + // ] + // ); + // array_push($this->runProcessProgressMethods, + // [ + // 'method' => 'runRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + // 'text' => 'Running rsync for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', + // 'args' => [$taskName, $module, false], + // ] + // ); array_push($this->runProcessProgressMethods, [ - 'method' => 'createBackup', - 'text' => 'Creating filesystem and database backup...' - ] - ); - array_push($this->runProcessProgressMethods, - [ - 'method' => 'runRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), - 'text' => 'Running rsync for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', - 'args' => [$taskName, $module, false], + 'method' => 'updateSchema-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + 'text' => 'Running schema update for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', + 'args' => [$taskName, $module], ] ); } From a29fe9e5a29675cb0c3d9098dff8dcb7b0d59671 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Wed, 29 Jan 2025 01:09:00 +1100 Subject: [PATCH 29/34] update #34 test DB update --- system/Base/BasePackage.php | 23 +++- .../Packages/Setup/Schema/TestSchema.php | 18 ++++ .../Providers/CoreServiceProvider/Core.php | 9 +- .../CoreServiceProvider/Install/Package.php | 100 ++++++++++++++++++ .../ModulesServiceProvider/Installer.php | 63 ++--------- 5 files changed, 153 insertions(+), 60 deletions(-) create mode 100644 system/Base/Providers/CoreServiceProvider/Install/Package.php diff --git a/system/Base/BasePackage.php b/system/Base/BasePackage.php index e656bccb8..350c49883 100644 --- a/system/Base/BasePackage.php +++ b/system/Base/BasePackage.php @@ -2009,16 +2009,33 @@ public function createTable(string $table, string $dbName, array $columns, $drop } } - public function alterTable(string $method, string $table, array $columns, $schemaName = '') + public function alterTable(string $method, string $table, mixed $columns, array $currentColumn = null, string $schemaName = '') { $method = $method . 'Column'; try { - foreach ($columns as $column) { + if (is_array($columns)) { + foreach ($columns as $column) { + if ($method === 'addColumn') { + $this->db->{$method}( + $table, + $schemaName, + $column + ); + } else if ($method === 'modifyColumn') { + $this->db->{$method}( + $table, + $schemaName, + $column, + $currentColumn + ); + } + } + } else if (is_string($columns) && $method === 'dropColumn') { $this->db->{$method}( $table, $schemaName, - $column + $columns ); } diff --git a/system/Base/Installer/Packages/Setup/Schema/TestSchema.php b/system/Base/Installer/Packages/Setup/Schema/TestSchema.php index 1c139cfbd..a5819dc9d 100644 --- a/system/Base/Installer/Packages/Setup/Schema/TestSchema.php +++ b/system/Base/Installer/Packages/Setup/Schema/TestSchema.php @@ -3,6 +3,7 @@ namespace System\Base\Installer\Packages\Setup\Schema; use Phalcon\Db\Column; +use Phalcon\Db\Index; class TestSchema { @@ -22,6 +23,14 @@ public function columns() ), new Column( 'key', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 100, + 'notNull' => true, + ] + ), + new Column( + 'key2', [ 'type' => Column::TYPE_VARCHAR, 'size' => 4096, @@ -50,6 +59,15 @@ public function columns() 'notNull' => false, ] ) + ], + 'indexes' => [ + new Index( + 'column_UNIQUE', + [ + 'key' + ], + 'UNIQUE' + ) ] ]; } diff --git a/system/Base/Providers/CoreServiceProvider/Core.php b/system/Base/Providers/CoreServiceProvider/Core.php index 3da36d4b3..df1be7c1e 100644 --- a/system/Base/Providers/CoreServiceProvider/Core.php +++ b/system/Base/Providers/CoreServiceProvider/Core.php @@ -183,7 +183,7 @@ public function restoreDb($data) $fileInfo = $this->basepackages->storages->getFileInfo($data['id']); if ($fileInfo) { - if ($this->zip->open(base_path($fileInfo['uuid_location'] . $fileInfo['org_file_name']))) { + if ($this->zip->open(base_path($fileInfo['uuid_location'] . $fileInfo['org_file_name'])) === true) { $backupInfo = $this->zip->getFromName('backupInfo.json'); if (!$backupInfo) { @@ -523,6 +523,7 @@ public function maintainFf($data) try { $storeToMaintain->reIndexStore(); } catch (\Exception $e) { + trace([$e]); $this->addResponse($e->getMessage(), 1); return false; @@ -660,7 +661,7 @@ public function restoreFf($data) $fileInfo = $this->basepackages->storages->getFileInfo($data['id']); if ($fileInfo) { - if ($this->zip->open(base_path($fileInfo['uuid_location'] . $fileInfo['org_file_name']))) { + if ($this->zip->open(base_path($fileInfo['uuid_location'] . $fileInfo['org_file_name'])) === true) { $backupInfo = $this->zip->getFromName('backupInfo.json'); if (!$backupInfo) { @@ -885,7 +886,7 @@ protected function zipBackupFiles() return false; } - $this->zip::close(); + $this->zip->close(); return true; } @@ -909,7 +910,7 @@ protected function addToZip($absolutePath, $relativePath, $encrypt = true, $pass $this->zip->deleteIndex($this->zip->numFiles - 1); } - $this->zip::close(); + $this->zip->close(); $this->addResponse('Could not set provided password for file ' . $name, 1, []); diff --git a/system/Base/Providers/CoreServiceProvider/Install/Package.php b/system/Base/Providers/CoreServiceProvider/Install/Package.php new file mode 100644 index 000000000..eab8616e9 --- /dev/null +++ b/system/Base/Providers/CoreServiceProvider/Install/Package.php @@ -0,0 +1,100 @@ +installer = $installer; + + $databases = (new Schema)->getSchema(); + + //Do version specific update for any future version upgrades. + // if ($this->core->core['version'] === 'x.x.x') { + //Do this + // } + // trace(varsToDump : [$this->core->core], object: true); + + if (isset($this->config['databasetype']) && $this->config['databasetype'] !== 'ff') { + $dbTablesList = $this->describe(); + + foreach ($databases as $tableName => $tableClass) { + if ($tableClass['model'] && $tableClass['model']->getSource()) { + $tableName = $tableClass['model']->getSource(); + } + + if (method_exists($tableClass['schema'], 'columns')) { + if ($this->tableExists($tableName)) { + $dbTableColumns = $this->describe($tableName); + + $dbTableColumnsList = []; + + if ($dbTableColumns && is_array($dbTableColumns) && count($dbTableColumns) > 0) { + foreach ($dbTableColumns as $tableColumn) { + $dbTableColumnsList[$tableColumn->getName()] = $tableColumn; + } + } + + if (isset($tableClass['schema']->columns()['columns']) && count($tableClass['schema']->columns()['columns']) > 0) { + foreach ($tableClass['schema']->columns()['columns'] as $schemaKey => $schemaColumn) { + if (isset($dbTableColumnsList[$schemaColumn->getName()])) { + $this->alterTable('modify', $tableName, [$schemaColumn]); + } else { + $this->alterTable('add', $tableName, [$schemaColumn]); + } + unset($dbTableColumnsList[$schemaColumn->getName()]); + } + + if (count($dbTableColumnsList) > 0) { + foreach ($dbTableColumnsList as $dbTableColumn) { + $this->alterTable('drop', $tableName, $dbTableColumn->getName()); + } + } + } + } else { + $this->db->createTable($tableName, $this->config['db']['dbname'], $tableClass['schema']->columns()); + } + } + + // $dbTableIndexes = $this->describe($tableName, true); + // var_dump($dbTableIndexes); + // if (method_exists($tableClass['schema'], 'indexes')) { + // $this->addIndex($tableName, $tableClass['schema']->indexes()); + // } + } + } + + if (isset($this->config['databasetype']) && $this->config['databasetype'] !== 'db') { + $storesToIndex = []; + + foreach ($databases as $tableName => $tableClass) { + if ($tableClass['model'] && $tableClass['model']->getSource()) { + $tableName = $tableClass['model']->getSource(); + } + + $config = $this->ff->generateConfig($tableName, $tableClass['schema'], $tableClass['model']); + $schema = $this->ff->generateSchema($tableName, $tableClass['schema'], $tableClass['model']); + + $this->ff->store($tableName, $config, $schema, $this->ff); + + if (method_exists($tableClass['schema'], 'indexes')) { + array_push($storesToIndex, $tableName); + } + } + + if (count($storesToIndex) > 0) { + foreach ($storesToIndex as $storeToIndex) { + ($this->ff->store($storeToIndex))->reIndexStore(); + } + } + } + + return true; + } +} \ No newline at end of file diff --git a/system/Base/Providers/ModulesServiceProvider/Installer.php b/system/Base/Providers/ModulesServiceProvider/Installer.php index 89dc709f3..02aa842bb 100644 --- a/system/Base/Providers/ModulesServiceProvider/Installer.php +++ b/system/Base/Providers/ModulesServiceProvider/Installer.php @@ -13,6 +13,7 @@ use League\Flysystem\UnableToWriteFile; use System\Base\BasePackage; use System\Base\Installer\Packages\Setup\Schema; +use System\Base\Providers\CoreServiceProvider\Install\Package as CorePackage; use xobotyi\rsync\Rsync; use z4kn4fein\SemVer\Version; @@ -720,7 +721,7 @@ protected function runRsync($args) } } - protected function updateSchema($args) + protected function runModuleInstallScripts($args) { $taskName = $args[0]; $module = $args[1]; @@ -728,61 +729,17 @@ protected function updateSchema($args) if ($module['module_type'] === 'packages' && $module['name'] === 'Core' ) { - $databases = (new Schema)->getSchema(); + try { + (new CorePackage)->install($this); + } catch (\throwable $e) { + trace([$e]); + //Store $e somewhere + return false; + } } else { // } - // trace(varsToDump : [$this->config], object: true); - if (isset($this->config['databasetype']) && $this->config['databasetype'] !== 'ff') { - - - foreach ($databases as $tableName => $tableClass) { - if (method_exists($tableClass['schema'], 'columns')) { - $table = $this->describe($tableClass['model']->getSource()); - trace(varsToDump : [$table]); - - $this->db->createTable($tableName, $this->config['db']['dbname'], $tableClass['schema']->columns()); - } - if (method_exists($tableClass['schema'], 'indexes')) { - $this->addIndex($tableName, $tableClass['schema']->indexes()); - } - } - } - - if (isset($this->config['databasetype']) && $this->config['databasetype'] !== 'db') { - foreach ($databases as $tableName => $tableClass) { - if ($tableClass['model'] && $tableClass['model']->getSource()) { - $tableName = $tableClass['model']->getSource(); - } - - $config = $this->ff->generateConfig($tableName, $tableClass['schema'], $tableClass['model']); - $schema = $this->ff->generateSchema($tableName, $tableClass['schema'], $tableClass['model']); - - $this->ff->store($tableName, $config, $schema, $this->ff); - - if (method_exists($tableClass['schema'], 'indexes')) { - array_push($this->storesToIndex, $tableName); - } - } - } - - return true; - } - - protected function performIndexing() - { - if (isset($this->config['databasetype']) && - $this->config['databasetype'] !== 'db' && - count($this->storesToIndex) > 0 - ) { - foreach ($this->storesToIndex as $storeToIndex) { - $store = $this->ff->store($storeToIndex); - - $store->reIndexStore(); - } - } - return true; } @@ -976,7 +933,7 @@ protected function registerRunProcessProgressMethods() // ); array_push($this->runProcessProgressMethods, [ - 'method' => 'updateSchema-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + 'method' => 'runModuleInstallScripts-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), 'text' => 'Running schema update for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', 'args' => [$taskName, $module], ] From c7b40bc7997c70d102d1430c56190c809ef29ad2 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Thu, 30 Jan 2025 01:02:20 +1100 Subject: [PATCH 30/34] Initial commit for #584. --- .../Providers/DatabaseServiceProvider/Ff.php | 37 +++++---- .../Ff/Classes/IndexHandler.php | 76 +++++++++++++++---- .../DatabaseServiceProvider/Ff/Store.php | 30 +++++++- 3 files changed, 112 insertions(+), 31 deletions(-) diff --git a/system/Base/Providers/DatabaseServiceProvider/Ff.php b/system/Base/Providers/DatabaseServiceProvider/Ff.php index 43465378b..37a72a2e5 100644 --- a/system/Base/Providers/DatabaseServiceProvider/Ff.php +++ b/system/Base/Providers/DatabaseServiceProvider/Ff.php @@ -316,6 +316,7 @@ public function generateSchema($tableName, $tableClass, $tableModel) public function generateConfig($tableName, $tableClass, $tableModel) { $config = []; + $config['indexes'] = []; if ($tableModel) { $config['model'] = get_class($tableModel); @@ -325,11 +326,19 @@ public function generateConfig($tableName, $tableClass, $tableModel) return $config; } + if (!isset($tableClass->columns()['columns'])) { + return $config; + } + + if (is_array($tableClass->columns()['columns']) && count($tableClass->columns()['columns']) === 0) { + return $config; + } + if (!isset($tableClass->columns()['indexes']) && !method_exists($tableClass, 'indexes')) { return $config; } - if ((isset($tableClass->columns()['indexes']) && count($tableClass->columns()['indexes']) === 0) || + if ((isset($tableClass->columns()['indexes']) && count($tableClass->columns()['indexes']) === 0) && (method_exists($tableClass, 'indexes') && count($tableClass->indexes()) === 0) ) { return $config; @@ -344,6 +353,13 @@ public function generateConfig($tableName, $tableClass, $tableModel) } if (method_exists($tableClass, 'indexes')) { + $columns = []; + $columnsTypeToIndex = [0,2,5,7,9,14];//int, chars, varchars + + foreach ($tableClass->columns()['columns'] as $column) { + $columns[$column->getName()] = $column; + } + foreach ($tableClass->indexes() as $index) { if ($index->getType() === 'UNIQUE' && $index->getColumns() && count($index->getColumns()) > 0) { if (isset($config['uniqueFields']) && count($config['uniqueFields']) > 0) { @@ -354,24 +370,17 @@ public function generateConfig($tableName, $tableClass, $tableModel) } if ($index->getType() === 'INDEX' && $index->getColumns() && count($index->getColumns()) > 0) { - if (isset($config['indexes']) && count($config['indexes']) > 0) { - $config['indexes'] = array_merge($config['indexes'], $index->getColumns()); - } else { - $config['indexes'] = $index->getColumns(); + foreach ($index->getColumns() as $indexColumn) { + if (isset($columns[$indexColumn])) { + if (in_array($columns[$indexColumn]->getType(), $columnsTypeToIndex)) { + $config['indexes'] = array_merge($config['indexes'], $index->getColumns()); + } + } } } } } - if (!isset($tableClass->columns()['columns'])) { - return $config; - } - - if (is_array($tableClass->columns()['columns']) && count($tableClass->columns()['columns']) === 0) { - return $config; - } - - return $config; } diff --git a/system/Base/Providers/DatabaseServiceProvider/Ff/Classes/IndexHandler.php b/system/Base/Providers/DatabaseServiceProvider/Ff/Classes/IndexHandler.php index de0110ab9..4eeea181b 100644 --- a/system/Base/Providers/DatabaseServiceProvider/Ff/Classes/IndexHandler.php +++ b/system/Base/Providers/DatabaseServiceProvider/Ff/Classes/IndexHandler.php @@ -14,6 +14,12 @@ class IndexHandler protected $minIndexChars = 3; + protected $multiWords = true; + + protected $multiWordsSeparator = ' '; + + protected $minMultiWordsChars = 5; + protected $folderPermissions = 0777; public function __construct(array $storeConfiguration) @@ -39,6 +45,15 @@ public function __construct(array $storeConfiguration) if (isset($this->storeConfiguration['min_index_chars'])) { $this->minIndexChars = $this->storeConfiguration['min_index_chars']; } + if (isset($this->storeConfiguration['multi_words'])) { + $this->multiWords = $this->storeConfiguration['multi_words']; + } + if (isset($this->storeConfiguration['multi_words_separator'])) { + $this->multiWordsSeparator = $this->storeConfiguration['multi_words_separator']; + } + if (isset($this->storeConfiguration['min_multi_words_chars'])) { + $this->minMultiWordsChars = $this->storeConfiguration['min_multi_words_chars']; + } } public function setIndex(string $content) @@ -53,31 +68,60 @@ public function setIndex(string $content) if (isset($content[$index])) { IoHelper::createFolder($this->indexesPath . $index . '/', $this->folderPermissions); - if (is_string($content[$index])) { - $indexChars = strtolower(mb_substr($content[$index], 0, $this->minIndexChars, 'UTF-8')); - } else { - $indexChars = $content[$index]; - } + if ($this->multiWords === true) { + if (is_string($content[$index])) { + $contentArr = explode($this->multiWordsSeparator, $content[$index]); - try { - $indexFile = $this->getIndex($index, $indexChars); + if (count($contentArr) > 1) { + foreach ($contentArr as $content) { + if (strlen($content) < $this->minMultiWordsChars) { + continue; + } - $indexJson = json_decode($indexFile, true); - } catch (\Exception $e) { - $indexJson = []; - } + $indexChars = strtolower(mb_substr($content, 0, $this->minIndexChars, 'UTF-8')); + + $this->writeIndex($indexPointer, $index, $indexChars, $content); + } + } else { + $indexChars = strtolower(mb_substr($content[$index], 0, $this->minIndexChars, 'UTF-8')); - if (isset($indexJson[$content[$index]])) { - if (!in_array($indexPointer, $indexJson[$content[$index]])) { - array_push($indexJson[$content[$index]], $indexPointer); + $this->writeIndex($indexPointer, $index, $indexChars, $content[$index]); + } + } else { + $this->writeIndex($indexPointer, $index, $content[$index], $content[$index]); } } else { - $indexJson[$content[$index]] = [$indexPointer]; + if (is_string($content[$index])) { + $indexChars = strtolower(mb_substr($content[$index], 0, $this->minIndexChars, 'UTF-8')); + + $this->writeIndex($indexPointer, $index, $indexChars, $content[$index]); + } else { + $this->writeIndex($indexPointer, $index, $content[$index], $content[$index]); + } } + } + } + } - IoHelper::writeContentToFile($this->indexesPath . $index . '/' . $indexChars . '.json', json_encode($indexJson)); + protected function writeIndex($indexPointer, $index, $indexChars, $content) + { + try { + $indexFile = $this->getIndex($index, $indexChars); + + $indexJson = json_decode($indexFile, true); + } catch (\Exception $e) { + $indexJson = []; + } + + if (isset($indexJson[$content])) { + if (!in_array($indexPointer, $indexJson[$content])) { + array_push($indexJson[$content], $indexPointer); } + } else { + $indexJson[$content] = [$indexPointer]; } + + IoHelper::writeContentToFile($this->indexesPath . $index . '/' . $indexChars . '.json', json_encode($indexJson)); } public function getIndex($index, $indexChars) diff --git a/system/Base/Providers/DatabaseServiceProvider/Ff/Store.php b/system/Base/Providers/DatabaseServiceProvider/Ff/Store.php index 3a109ce88..a5eeaf694 100644 --- a/system/Base/Providers/DatabaseServiceProvider/Ff/Store.php +++ b/system/Base/Providers/DatabaseServiceProvider/Ff/Store.php @@ -29,6 +29,10 @@ class Store protected $indexesPath = ''; protected $indexing = false; protected $minIndexChars = 3; + protected $multiWords = true; + protected $multiWordsSeparator = ' '; + protected $minMultiWordsChars = 5; + protected $indexes = []; protected $model = null; @@ -137,7 +141,7 @@ public function getSchemaMetaData($relations = false) $rmd['storeRelations'][$column] = $relationsStore->getSchemaMetaData(); $rmd['storeRelations'][$column]['relationStore'] = $relation[2]; } catch (\Exception $e) { - // + throw $e; } } } @@ -1206,6 +1210,27 @@ protected function setConfigurationAndSchema(array $configuration = [], array $s $this->minIndexChars = $configuration["minIndexChars"]; } + if (array_key_exists("multiWords", $configuration)) { + if (!is_bool($configuration["multiWords"])) { + throw new InvalidConfigurationException("multiWords has to be a boolean"); + } + + $this->multiWords = $configuration["multiWords"]; + } + + if (array_key_exists("multiWordsSeparator", $configuration)) { + $this->multiWordsSeparator = $configuration["multiWordsSeparator"]; + } + + if (array_key_exists("minMultiWordsChars", $configuration)) { + if (!is_int($configuration["minMultiWordsChars"])) { + throw new InvalidConfigurationException("minMultiWordsChars has to be an integer"); + } + + $this->minMultiWordsChars = $configuration["minMultiWordsChars"]; + } + + if (array_key_exists("indexes", $configuration)) { if (!is_array($configuration["indexes"])) { throw new InvalidConfigurationException("indexes has to be an array"); @@ -1319,6 +1344,9 @@ protected function storeConfiguration() "folder_permissions" => $this->folderPermissions, "indexing" => $this->indexing, "min_index_chars" => $this->minIndexChars, + "multi_words" => $this->multiWords, + "multi_words_separator" => $this->multiWordsSeparator, + "min_multi_words_chars" => $this->minMultiWordsChars, "uniqueFields" => $this->uniqueFields, "indexes" => $this->indexes, "storePath" => $this->storePath, From 867cd585e4fd46b6e5d5b5789c6d0ea47d1d899d Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Thu, 30 Jan 2025 23:30:14 +1100 Subject: [PATCH 31/34] update #584 --- .../DatabaseServiceProvider/Ff/Classes/DocumentFinder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/Base/Providers/DatabaseServiceProvider/Ff/Classes/DocumentFinder.php b/system/Base/Providers/DatabaseServiceProvider/Ff/Classes/DocumentFinder.php index 9a5f162b3..f8d2bd5dd 100644 --- a/system/Base/Providers/DatabaseServiceProvider/Ff/Classes/DocumentFinder.php +++ b/system/Base/Providers/DatabaseServiceProvider/Ff/Classes/DocumentFinder.php @@ -59,6 +59,8 @@ public function findDocuments(bool $getOneDocument, bool $reduceAndJoinPossible) unset($queryBuilderProperties); if ($this->storeConfiguration['indexing']) { + // This has to be rewritten to include multiple keywords using spaces + // Example: If we want to search for wes aus, it should search for all entries with Wes keyword and that also includes Aus keyword. if (count($conditions) > 0) { foreach ($conditions as $condition) { if (isset($condition[0]) && From bc94527dc05cf04fa6ac535b5bb81eb08c3775ab Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Fri, 31 Jan 2025 18:27:55 +1100 Subject: [PATCH 32/34] update #332 - Cleanup db schema and remove collation as collation is defined during setup. --- .../Setup/Schema/Basepackages/AddressBook.php | 3 --- .../ApiClientServices/ApiClientServices.php | 5 +---- .../ApiClientServicesCalls.php | 5 +---- .../Setup/Schema/Basepackages/Geo/Cities.php | 21 +++---------------- .../Basepackages/Geo/CitiesIp2LocationV4.php | 13 ++---------- .../Basepackages/Geo/CitiesIp2LocationV6.php | 13 ++---------- .../Schema/Basepackages/Geo/Countries.php | 3 --- .../Setup/Schema/Basepackages/Geo/States.php | 13 ++---------- .../Schema/Basepackages/Geo/Timezones.php | 3 --- .../Setup/Schema/Basepackages/Maintenance.php | 3 --- .../Setup/Schema/Basepackages/Messenger.php | 3 --- .../Setup/Schema/Basepackages/Murls.php | 5 +---- .../Schema/Basepackages/Users/Accounts.php | 3 --- .../Basepackages/Users/Accounts/Agents.php | 3 --- .../Basepackages/Users/Accounts/CanLogin.php | 3 --- .../Users/Accounts/Identifiers.php | 3 --- .../Basepackages/Users/Accounts/Security.php | 3 --- .../Basepackages/Users/Accounts/Sessions.php | 3 --- .../Schema/Basepackages/Users/Profiles.php | 3 --- .../Setup/Schema/Basepackages/Users/Roles.php | 3 --- .../Setup/Schema/Basepackages/Widgets.php | 3 --- .../Packages/Setup/Schema/Modules/Bundles.php | 3 --- .../Setup/Schema/Modules/Components.php | 3 --- .../Setup/Schema/Modules/Middlewares.php | 3 --- .../Setup/Schema/Modules/Packages.php | 3 --- .../Packages/Setup/Schema/Modules/Views.php | 3 --- .../Schema/Providers/Access/IpFilter.php | 3 --- .../Packages/Setup/Schema/Providers/Api.php | 3 --- .../Schema/Providers/Api/AccessTokens.php | 3 --- .../Providers/Api/AuthorizationCodes.php | 3 --- .../Setup/Schema/Providers/Api/Clients.php | 3 --- .../Schema/Providers/Api/RefreshTokens.php | 3 --- .../Setup/Schema/Providers/Api/Scopes.php | 3 --- .../Setup/Schema/Providers/Api/Users.php | 3 --- .../Packages/Setup/Schema/Providers/Apps.php | 3 --- .../Setup/Schema/Providers/Apps/Types.php | 3 --- 36 files changed, 12 insertions(+), 150 deletions(-) diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/AddressBook.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/AddressBook.php index 6550d3818..b59416fb2 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/AddressBook.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/AddressBook.php @@ -126,9 +126,6 @@ public function columns() 'notNull' => false, ] ), - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/ApiClientServices/ApiClientServices.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/ApiClientServices/ApiClientServices.php index a490f06ca..dc83f3c29 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/ApiClientServices/ApiClientServices.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/ApiClientServices/ApiClientServices.php @@ -89,10 +89,7 @@ public function columns() 'notNull' => false, ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' - ], + ] ]; } } \ No newline at end of file diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/ApiClientServices/ApiClientServicesCalls.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/ApiClientServices/ApiClientServicesCalls.php index 9cb1f925f..b84a9f681 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/ApiClientServices/ApiClientServicesCalls.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/ApiClientServices/ApiClientServicesCalls.php @@ -71,10 +71,7 @@ public function columns() 'notNull' => false, ] ), - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' - ], + ] ]; } } \ No newline at end of file diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Cities.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Cities.php index 48f6669d9..ee10f96a9 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Cities.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Cities.php @@ -76,9 +76,6 @@ public function columns() 'notNull' => false, ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } @@ -88,22 +85,10 @@ public function indexes() return [ new Index( - 'column_name_index', - [ - 'name' - ], - 'INDEX' - ), - new Index( - 'column_state_id_index', - [ - 'state_id' - ], - 'INDEX' - ), - new Index( - 'column_country_id_index', + 'column_INDEX', [ + 'name', + 'state_id', 'country_id' ], 'INDEX' diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/CitiesIp2LocationV4.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/CitiesIp2LocationV4.php index a45f893dd..6ed3e3428 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/CitiesIp2LocationV4.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/CitiesIp2LocationV4.php @@ -44,9 +44,6 @@ public function columns() 'notNull' => true, ] ), - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } @@ -56,15 +53,9 @@ public function indexes() return [ new Index( - 'column_range_start_index', - [ - 'range_start' - ], - 'INDEX' - ), - new Index( - 'column_range_end_index', + 'column_INDEX', [ + 'range_start', 'range_end' ], 'INDEX' diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/CitiesIp2LocationV6.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/CitiesIp2LocationV6.php index b51c8d320..9c7c305cc 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/CitiesIp2LocationV6.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/CitiesIp2LocationV6.php @@ -44,9 +44,6 @@ public function columns() 'notNull' => true, ] ), - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } @@ -56,15 +53,9 @@ public function indexes() return [ new Index( - 'column_range_start_index', - [ - 'range_start' - ], - 'INDEX' - ), - new Index( - 'column_range_end_index', + 'column_INDEX', [ + 'range_start', 'range_end' ], 'INDEX' diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Countries.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Countries.php index f87934fa7..b9b35387d 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Countries.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Countries.php @@ -171,9 +171,6 @@ public function columns() 'notNull' => false, ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_unicode_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/States.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/States.php index d29c749f1..4ed97dae0 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/States.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/States.php @@ -69,9 +69,6 @@ public function columns() 'notNull' => false, ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } @@ -81,15 +78,9 @@ public function indexes() return [ new Index( - 'column_name_index', - [ - 'name' - ], - 'INDEX' - ), - new Index( - 'column_country_id_index', + 'column_INDEX', [ + 'name', 'country_id' ], 'INDEX' diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Timezones.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Timezones.php index ced66d1c3..01299fe39 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Timezones.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Geo/Timezones.php @@ -89,9 +89,6 @@ public function columns() 'notNull' => false, ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Maintenance.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Maintenance.php index 761b172e6..062a29e5e 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Maintenance.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Maintenance.php @@ -136,9 +136,6 @@ public function columns() 'notNull' => false ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Messenger.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Messenger.php index 80d1db898..27e2306c4 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Messenger.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Messenger.php @@ -78,9 +78,6 @@ public function columns() 'default' => 'CURRENT_TIMESTAMP' ] ), - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_unicode_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Murls.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Murls.php index dcc59cd7f..9831ebabb 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Murls.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Murls.php @@ -89,9 +89,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } @@ -101,7 +98,7 @@ public function indexes() return [ new Index( - 'murl_index', + 'column_INDEX', [ 'murl' ], diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts.php index dfb3a9ccb..4880798db 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts.php @@ -77,9 +77,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Agents.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Agents.php index 1a3d6cee6..28e593278 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Agents.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Agents.php @@ -73,9 +73,6 @@ public function columns() 'notNull' => false ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/CanLogin.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/CanLogin.php index 7d840bd54..5221f5c69 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/CanLogin.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/CanLogin.php @@ -41,9 +41,6 @@ public function columns() 'notNull' => true, ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Identifiers.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Identifiers.php index 7ee70c952..02fd1f95c 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Identifiers.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Identifiers.php @@ -70,9 +70,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Security.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Security.php index 89fc9a559..1e2a733ef 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Security.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Security.php @@ -167,9 +167,6 @@ public function columns() 'notNull' => false ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Sessions.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Sessions.php index 365da9cda..3417c5092 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Sessions.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Accounts/Sessions.php @@ -54,9 +54,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Profiles.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Profiles.php index 04830f63d..4bfe32a5e 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Profiles.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Profiles.php @@ -145,9 +145,6 @@ public function columns() ] ) ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' - ], 'indexes' => [ new Index( 'column_UNIQUE', diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Roles.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Roles.php index 76b08b3eb..24f107379 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Roles.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Users/Roles.php @@ -60,9 +60,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Widgets.php b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Widgets.php index ade53351b..996de14ca 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Basepackages/Widgets.php +++ b/system/Base/Installer/Packages/Setup/Schema/Basepackages/Widgets.php @@ -74,9 +74,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Modules/Bundles.php b/system/Base/Installer/Packages/Setup/Schema/Modules/Bundles.php index bf8786d96..e015ad5d4 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Modules/Bundles.php +++ b/system/Base/Installer/Packages/Setup/Schema/Modules/Bundles.php @@ -139,9 +139,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Modules/Components.php b/system/Base/Installer/Packages/Setup/Schema/Modules/Components.php index 15bcc4c9d..dad56a6d0 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Modules/Components.php +++ b/system/Base/Installer/Packages/Setup/Schema/Modules/Components.php @@ -234,9 +234,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Modules/Middlewares.php b/system/Base/Installer/Packages/Setup/Schema/Modules/Middlewares.php index 00fceedf1..41d5d05a4 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Modules/Middlewares.php +++ b/system/Base/Installer/Packages/Setup/Schema/Modules/Middlewares.php @@ -205,9 +205,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Modules/Packages.php b/system/Base/Installer/Packages/Setup/Schema/Modules/Packages.php index e9937bef7..6a331bf1f 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Modules/Packages.php +++ b/system/Base/Installer/Packages/Setup/Schema/Modules/Packages.php @@ -212,9 +212,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Modules/Views.php b/system/Base/Installer/Packages/Setup/Schema/Modules/Views.php index 517b51c84..1d4cc8f11 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Modules/Views.php +++ b/system/Base/Installer/Packages/Setup/Schema/Modules/Views.php @@ -220,9 +220,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Access/IpFilter.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Access/IpFilter.php index 57732dbb0..b1d11d9ad 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Access/IpFilter.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Access/IpFilter.php @@ -88,9 +88,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Api.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Api.php index 6da0e3c82..229a09b31 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Api.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Api.php @@ -254,9 +254,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/AccessTokens.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/AccessTokens.php index 7f819c946..f574220ef 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/AccessTokens.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/AccessTokens.php @@ -78,9 +78,6 @@ public function columns() 'notNull' => false ] ), - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/AuthorizationCodes.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/AuthorizationCodes.php index a941b1c69..aae6796b4 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/AuthorizationCodes.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/AuthorizationCodes.php @@ -86,9 +86,6 @@ public function columns() 'notNull' => false ] ), - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Clients.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Clients.php index 8e43a2654..0f1c23019 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Clients.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Clients.php @@ -162,9 +162,6 @@ public function columns() 'notNull' => false ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/RefreshTokens.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/RefreshTokens.php index 1a72aebf9..eb869ca46 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/RefreshTokens.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/RefreshTokens.php @@ -78,9 +78,6 @@ public function columns() 'notNull' => false ] ), - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Scopes.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Scopes.php index df53c01fe..3ac8dceaa 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Scopes.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Scopes.php @@ -52,9 +52,6 @@ public function columns() 'notNull' => true, ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ], 'indexes' => [ new Index( diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Users.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Users.php index 68c4b3ff4..c5169dd89 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Users.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Api/Users.php @@ -18,9 +18,6 @@ public function columns() 'notNull' => true, ] ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Apps.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Apps.php index 06af75300..daa2c9cec 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Apps.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Apps.php @@ -170,9 +170,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } diff --git a/system/Base/Installer/Packages/Setup/Schema/Providers/Apps/Types.php b/system/Base/Installer/Packages/Setup/Schema/Providers/Apps/Types.php index 82b072600..27afc465c 100644 --- a/system/Base/Installer/Packages/Setup/Schema/Providers/Apps/Types.php +++ b/system/Base/Installer/Packages/Setup/Schema/Providers/Apps/Types.php @@ -136,9 +136,6 @@ public function columns() ], 'UNIQUE' ) - ], - 'options' => [ - 'TABLE_COLLATION' => 'utf8mb4_general_ci' ] ]; } From eb46319d266c62d14f2454e2a02db642a73dc341 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Sat, 1 Feb 2025 03:56:37 +1100 Subject: [PATCH 33/34] update #34 --- .../Packages/Setup/Schema/TestSchema.php | 16 +- .../CoreServiceProvider/Install/Package.php | 97 +++++++++- .../ModulesServiceProvider/Installer.php | 175 ++++++++++++++---- 3 files changed, 239 insertions(+), 49 deletions(-) diff --git a/system/Base/Installer/Packages/Setup/Schema/TestSchema.php b/system/Base/Installer/Packages/Setup/Schema/TestSchema.php index a5819dc9d..eabbe81cd 100644 --- a/system/Base/Installer/Packages/Setup/Schema/TestSchema.php +++ b/system/Base/Installer/Packages/Setup/Schema/TestSchema.php @@ -33,7 +33,7 @@ public function columns() 'key2', [ 'type' => Column::TYPE_VARCHAR, - 'size' => 4096, + 'size' => 100, 'notNull' => true, ] ), @@ -71,4 +71,18 @@ public function columns() ] ]; } + + public function indexes() + { + return + [ + new Index( + 'column_INDEX', + [ + 'key2' + ], + 'INDEX' + ) + ]; + } } \ No newline at end of file diff --git a/system/Base/Providers/CoreServiceProvider/Install/Package.php b/system/Base/Providers/CoreServiceProvider/Install/Package.php index eab8616e9..d673a8f62 100644 --- a/system/Base/Providers/CoreServiceProvider/Install/Package.php +++ b/system/Base/Providers/CoreServiceProvider/Install/Package.php @@ -9,22 +9,39 @@ class Package extends BasePackage { protected $installer; + protected $databases; + public function install($installer) { $this->installer = $installer; - $databases = (new Schema)->getSchema(); + $this->databases = (new Schema)->getSchema(); + + $this->preInstall(); + + $this->installDb(); + + $this->postInstall(); + + return true; + } + protected function preInstall() + { //Do version specific update for any future version upgrades. // if ($this->core->core['version'] === 'x.x.x') { - //Do this + //Do something // } - // trace(varsToDump : [$this->core->core], object: true); + return true; + } + + protected function installDb() + { if (isset($this->config['databasetype']) && $this->config['databasetype'] !== 'ff') { $dbTablesList = $this->describe(); - foreach ($databases as $tableName => $tableClass) { + foreach ($this->databases as $tableName => $tableClass) { if ($tableClass['model'] && $tableClass['model']->getSource()) { $tableName = $tableClass['model']->getSource(); } @@ -62,18 +79,71 @@ public function install($installer) } } - // $dbTableIndexes = $this->describe($tableName, true); - // var_dump($dbTableIndexes); - // if (method_exists($tableClass['schema'], 'indexes')) { - // $this->addIndex($tableName, $tableClass['schema']->indexes()); - // } + $indexList = []; + if (isset($tableClass['schema']->columns()['indexes'])) { + $indexList = array_merge($indexList, $tableClass['schema']->columns()['indexes']); + } + + if (method_exists($tableClass['schema'], 'indexes')) { + $indexList = array_merge($indexList, $tableClass['schema']->indexes()); + } + + if (count($indexList) > 0) { + $dbTableIndexes = $this->describe($tableName, true); + + //New Indexes + foreach ($indexList as $indexListKey => $index) { + $indexList[$index->getName()] = $index; + + if (!isset($dbTableIndexes[$index->getName()])) { + try { + $this->addIndex($tableName, [$index]); + } catch (\throwable $e) { + throw $e; + } + } else { + $dbIndexColumns = $dbTableIndexes[$index->getName()]->getColumns(); + $newIndexColumns = $index->getColumns(); + + if (count(array_diff($newIndexColumns, $dbIndexColumns)) > 0 || + count(array_diff($dbIndexColumns, $newIndexColumns)) > 0 + ) { + try { + $this->dropIndex($tableName, $index->getName()); + $this->addIndex($tableName, [$index]); + } catch (\throwable $e) { + throw $e; + } + } + } + + unset($indexList[$indexListKey]); + } + + $dbTableIndexes = $this->describe($tableName, true); + + //Drop any indexes that are removed + foreach ($dbTableIndexes as $dbTableIndexKey => $dbTableIndex) { + if (strtolower($dbTableIndexKey) === 'primary') { + continue; + } + + if (!isset($indexList[$dbTableIndexKey])) { + try { + $this->dropIndex($tableName, $dbTableIndexKey); + } catch (\throwable $e) { + throw $e; + } + } + } + } } } if (isset($this->config['databasetype']) && $this->config['databasetype'] !== 'db') { $storesToIndex = []; - foreach ($databases as $tableName => $tableClass) { + foreach ($this->databases as $tableName => $tableClass) { if ($tableClass['model'] && $tableClass['model']->getSource()) { $tableName = $tableClass['model']->getSource(); } @@ -97,4 +167,11 @@ public function install($installer) return true; } + + protected function postInstall() + { + //Do anything after installation. + + return true; + } } \ No newline at end of file diff --git a/system/Base/Providers/ModulesServiceProvider/Installer.php b/system/Base/Providers/ModulesServiceProvider/Installer.php index 02aa842bb..ee2865f8d 100644 --- a/system/Base/Providers/ModulesServiceProvider/Installer.php +++ b/system/Base/Providers/ModulesServiceProvider/Installer.php @@ -202,7 +202,7 @@ protected function precheckQueueData($args) $preCheckQueueLogs = &$this->queue['results']['first']['packages'][$module['id']]['precheck_logs']; - return $this->preCheckHasErrors( + return $this->queueHasErrors( $this->modules->manager->packagesData->responseMessage ?? 'Could not retrieve repository information for module: ' . $module['name'], $preCheckQueueLogs ); @@ -211,7 +211,7 @@ protected function precheckQueueData($args) $preCheckQueueLogs = &$this->queue['results'][$taskName][$module['module_type']][$module['id']]['precheck_logs']; - return $this->preCheckHasErrors( + return $this->queueHasErrors( $this->modules->manager->packagesData->responseMessage ?? 'Could not retrieve repository information for module: ' . $module['name'], $preCheckQueueLogs ); @@ -233,7 +233,7 @@ protected function processExternalPackages($args) if (!isset($module['composerJsonFile']['extra']['patches'][$module['name']])) { $this->cleanup(['composer']); - return $this->preCheckHasErrors( + return $this->queueHasErrors( 'External packages should have package defined, but are missing from the composer json file for : ' . $module['name'], $preCheckQueueLogs ); @@ -252,7 +252,7 @@ protected function processExternalPackages($args) if (count($patches['files']) === 0) { $this->cleanup(['composer']); - return $this->preCheckHasErrors( + return $this->queueHasErrors( 'External package requires a patch which is missing from the repository : ' . $module['root_module']['repo'], $preCheckQueueLogs ); @@ -264,7 +264,7 @@ protected function processExternalPackages($args) if (count($patches['files']) !== count($module['composerJsonFile']['extra']['patches'][$module['name']])) { $this->cleanup(['composer']); - return $this->preCheckHasErrors( + return $this->queueHasErrors( 'External package number of patches do not match what is defined in the composer json file for repository : ' . $module['root_module']['repo'], $preCheckQueueLogs ); @@ -284,7 +284,7 @@ protected function processExternalPackages($args) if (in_array('false', $foundAll)) { $this->cleanup(['composer']); - return $this->preCheckHasErrors( + return $this->queueHasErrors( 'External package all patches not found in the external/patches directory as per the composer json file for repository : ' . $module['root_module']['repo'], $preCheckQueueLogs ); @@ -299,7 +299,7 @@ protected function processExternalPackages($args) } catch (FilesystemException | UnableToCopyFile $e) { $this->cleanup(['composer']); - return $this->preCheckHasErrors('Error copying file : ' . $fileName, $preCheckQueueLogs); + return $this->queueHasErrors('Error copying file : ' . $fileName, $preCheckQueueLogs); } } @@ -310,7 +310,7 @@ protected function processExternalPackages($args) } catch (FilesystemException | UnableToWriteFile $e) { $this->cleanup(['composer']); - return $this->preCheckHasErrors( + return $this->queueHasErrors( 'Error writing file external package composer file : ' . $externalComposerFileName, $preCheckQueueLogs ); @@ -336,28 +336,34 @@ protected function processExternalPackages($args) } catch (\throwable | UnableToReadFile $e) { $this->cleanup(['composer']); - return $this->preCheckHasErrors($e->getMessage(), $preCheckQueueLogs); + return $this->queueHasErrors($e->getMessage(), $preCheckQueueLogs); } if ($app !== 0) { $this->cleanup(['composer']); - return $this->preCheckHasErrors('Precheck for composer package failed : ' . $module['name'], $preCheckQueueLogs); + return $this->queueHasErrors('Precheck for composer package failed : ' . $module['name'], $preCheckQueueLogs); } } else { $this->cleanup(['composer']); - return $this->preCheckHasErrors('Incorrect external package type: ' . $module['name'], $preCheckQueueLogs); + return $this->queueHasErrors('Incorrect external package type: ' . $module['name'], $preCheckQueueLogs); } return true; } - protected function preCheckHasErrors($errorMessage, &$preCheckQueueLogs) + protected function queueHasErrors($errorMessage, &$queueLogs, $precheck = true) { - $preCheckQueueLogs = $errorMessage; + $queueLogs = $errorMessage; - $this->addResponse('Precheck has errors! Check logs.', 1, ['queue' => $this->queue]); + if ($precheck) { + $queueType = 'Precheck'; + } else { + $queueType = 'Process'; + } + + $this->addResponse($queueType . ' has errors! Check logs.', 1, ['queue' => $this->queue]); $this->basepackages->progress->resetProgress(); @@ -599,7 +605,10 @@ protected function runRsync($args) 'external/patches/***', 'apps', 'apps/Core/***', - 'system/***' + 'system', + 'system/Base/***', + 'system/Cli/***', + 'system/Bootstrap.php' ]; } else { $includeFiles = @@ -608,6 +617,16 @@ protected function runRsync($args) ]; } + $this->modulesToInstallOrUpdate = $this->modules->manager->getModuleInfo( + [ + 'module_type' => $module['module_type'], + 'module_id' => $module['id'] + ] + ); + + $this->zipFile['name'] = $this->modulesToInstallOrUpdate['repo_details']['details']['name'] . '-' . + $this->modulesToInstallOrUpdate['repo_details']['latestRelease']['name']; + try { $rsyncSettings = [ @@ -620,7 +639,7 @@ protected function runRsync($args) Rsync::OPT_HUMAN_READABLE => true, Rsync::OPT_CHECKSUM => true, Rsync::OPT_INCLUDE => $includeFiles, - Rsync::OPT_EXCLUDE => ['*'], + Rsync::OPT_EXCLUDE => ['*'] ] ]; @@ -646,7 +665,6 @@ protected function runRsync($args) if ($rsync->getExitCode() == 0) { $outputArr = explode(PHP_EOL, $rsync->getStdout()); - // trace([$outputArr], false, false, true); $modifiedFiles = []; $deleteFiles = []; @@ -693,8 +711,6 @@ protected function runRsync($args) } } - // trace(varsToDump : [$modifiedFiles, $deleteFiles], object: true); - return true; } catch (\throwable $e) { if (str_contains($e->getMessage(), 'No such file or directory')) { @@ -709,14 +725,15 @@ protected function runRsync($args) } if ($precheck) { - return $this->preCheckHasErrors( + return $this->queueHasErrors( $rsyncError, $preCheckQueueLogs ); } else { - return $this->preCheckHasErrors( + return $this->queueHasErrors( $rsyncError, - $resultQueueLogs + $resultQueueLogs, + false ); } } @@ -726,6 +743,9 @@ protected function runModuleInstallScripts($args) $taskName = $args[0]; $module = $args[1]; + $this->queue['results'][$taskName][$module['module_type']][$module['id']]['result'] = 'pass'; + $resultQueueLogs = &$this->queue['results'][$taskName][$module['module_type']][$module['id']]['result_logs']; + if ($module['module_type'] === 'packages' && $module['name'] === 'Core' ) { @@ -733,8 +753,80 @@ protected function runModuleInstallScripts($args) (new CorePackage)->install($this); } catch (\throwable $e) { trace([$e]); - //Store $e somewhere - return false; + $this->queue['results'][$taskName][$module['module_type']][$module['id']]['result'] = 'fail'; + + return $this->queueHasErrors( + $e->getMessage(), + $resultQueueLogs, + false + ); + } + } else { + // + } + + return true; + } + + protected function updateVersion($args) + { + $taskName = $args[0]; + $module = $args[1]; + + $this->queue['results'][$taskName][$module['module_type']][$module['id']]['result'] = 'pass'; + $resultQueueLogs = &$this->queue['results'][$taskName][$module['module_type']][$module['id']]['result_logs']; + + if ($module['module_type'] === 'packages' && + $module['name'] === 'Core' + ) { + try { + $versionArr = explode(' -> ', $module['version']); + + if (count($versionArr) !== 2) { + return $this->queueHasErrors( + 'Incorrect number of versions for Core. Please contact developer.', + $resultQueueLogs, + false + ); + } + + $package = $this->modules->packages->getPackageById($module['id']); + + if (!$package) { + return $this->queueHasErrors( + 'Package core not found with the ID provided. Please contact developer.', + $resultQueueLogs, + false + ); + } + + if ($package['version'] !== $versionArr[0] && + $package['update_version'] !== $versionArr[1] + ) { + return $this->queueHasErrors( + 'Module information received by installer is incorrect. Please contact developer.', + $resultQueueLogs, + false + ); + } + + $package['version'] = $package['update_version']; + $package['updated_on'] = date('c'); + + if ($this->access->auth->account() && isset($this->access->auth->account()['id'])) { + $package['updated_by'] = $this->access->auth->account()['id']; + } + + $this->modules->packages->update($package); + } catch (\throwable $e) { + trace([$e]); + $this->queue['results'][$taskName][$module['module_type']][$module['id']]['result'] = 'fail'; + + return $this->queueHasErrors( + $e->getMessage(), + $resultQueueLogs, + false + ); } } else { // @@ -918,23 +1010,30 @@ protected function registerRunProcessProgressMethods() if ($taskName === 'first' && $moduleType === 'external') { continue; } else { - // array_push($this->runProcessProgressMethods, - // [ - // 'method' => 'createBackup', - // 'text' => 'Creating filesystem and database backup...' - // ] - // ); - // array_push($this->runProcessProgressMethods, - // [ - // 'method' => 'runRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), - // 'text' => 'Running rsync for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', - // 'args' => [$taskName, $module, false], - // ] - // ); + array_push($this->runProcessProgressMethods, + [ + 'method' => 'createBackup', + 'text' => 'Creating filesystem and database backup...' + ] + ); + array_push($this->runProcessProgressMethods, + [ + 'method' => 'runRsync-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + 'text' => 'Running rsync for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', + 'args' => [$taskName, $module, false], + ] + ); array_push($this->runProcessProgressMethods, [ 'method' => 'runModuleInstallScripts-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), - 'text' => 'Running schema update for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', + 'text' => 'Running module install scripts for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', + 'args' => [$taskName, $module], + ] + ); + array_push($this->runProcessProgressMethods, + [ + 'method' => 'updateVersion-' . $module['id'] . '-' . strtolower(str_replace(' ', '', $module['name'])), + 'text' => 'Updating version for ' . $module['name'] . ' (' . ucfirst($module['module_type']) . ')...', 'args' => [$taskName, $module], ] ); From 7a004f89d70f97712d5231ffb95f399db6ca7cf2 Mon Sep 17 00:00:00 2001 From: "Gurdeep Singh (Guru)" Date: Sat, 1 Feb 2025 04:01:27 +1100 Subject: [PATCH 34/34] Issue #582 Minor fixes. --- .../System/Tools/Backuprestore/BackuprestoreComponent.php | 2 +- .../html/system/tools/backuprestore/analyse/analysis.html | 4 ++-- .../Packages/BackupRestore.php | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/Core/Components/System/Tools/Backuprestore/BackuprestoreComponent.php b/apps/Core/Components/System/Tools/Backuprestore/BackuprestoreComponent.php index 8b968897a..aced6f136 100644 --- a/apps/Core/Components/System/Tools/Backuprestore/BackuprestoreComponent.php +++ b/apps/Core/Components/System/Tools/Backuprestore/BackuprestoreComponent.php @@ -19,7 +19,7 @@ public function viewAction() $this->getNewToken(); if (isset($this->getData()['analyse']) && $this->getData()['analyse'] == 'info') { - $backupInfoFile = $this->basepackages->backuprestore->analyseBackinfoFile($this->getData()['id']); + $backupInfoFile = $this->basepackages->backuprestore->init('analyse')->analyseBackinfoFile($this->getData()['id']); if ($backupInfoFile) { return $this->view->getPartial('backuprestore/analyse/analysis', ['backupInfoFile' => $backupInfoFile]); diff --git a/apps/Core/Views/Default/html/system/tools/backuprestore/analyse/analysis.html b/apps/Core/Views/Default/html/system/tools/backuprestore/analyse/analysis.html index 158ebbb80..35729de9b 100644 --- a/apps/Core/Views/Default/html/system/tools/backuprestore/analyse/analysis.html +++ b/apps/Core/Views/Default/html/system/tools/backuprestore/analyse/analysis.html @@ -57,7 +57,7 @@
- {% if backupInfoFile['request']['html_compiled'] == 'true' %} + {% if backupInfoFile['request']['html_compiled_dir'] == 'true' %} Yes {% else %} No @@ -83,7 +83,7 @@
- {% if backupInfoFile['request']['old_backups'] == 'true' %} + {% if backupInfoFile['request']['old_backups_dir'] == 'true' %} Yes {% else %} No diff --git a/system/Base/Providers/BasepackagesServiceProvider/Packages/BackupRestore.php b/system/Base/Providers/BasepackagesServiceProvider/Packages/BackupRestore.php index 5d4cbd55c..75964d015 100644 --- a/system/Base/Providers/BasepackagesServiceProvider/Packages/BackupRestore.php +++ b/system/Base/Providers/BasepackagesServiceProvider/Packages/BackupRestore.php @@ -42,11 +42,13 @@ public function init($process = 'backup') $this->localContent->createDirectory('var/tmp/backups/'); } - $this->basepackages->progress->deleteProgressFile(); - if ($process === 'backup') { + $this->basepackages->progress->deleteProgressFile(); + $this->registerBackupProgressMethods(); } else if ($process === 'restore') { + $this->basepackages->progress->deleteProgressFile(); + $this->registerRestoreProgressMethods(); } @@ -599,7 +601,7 @@ public function analyseBackinfoFile($id) $fileInfo = $this->basepackages->storages->getFileInfo($id); if ($fileInfo) { - if ($this->zip->open(base_path($fileInfo['uuid_location'] . $fileInfo['org_file_name']))) { + if ($this->zip->open(base_path($fileInfo['uuid_location'] . $fileInfo['org_file_name'])) === true) { $backupInfo = $this->zip->getFromName('backupInfo.json'); if (!$backupInfo) {