From 44033a4911680620c813a475e765bc59e7a990bc Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 20 Nov 2019 22:28:04 +0100 Subject: [PATCH] cleanup and tests added for ci/cd --- Controller/ApiController.php | 129 ++++-------------- Models/AccountPermission.php | 3 +- Models/GroupPermission.php | 3 +- .../GroupTagSelectorPopupView.php | 16 +++ .../GroupTagSelector/GroupTagSelectorView.php | 14 ++ 5 files changed, 63 insertions(+), 102 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 7164047..29908c5 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -902,6 +902,15 @@ final class ApiController extends Controller ]]); } + /** + * Update the system or a module + * + * @param array $toUpdate Array of updte resources + * + * @return void + * + * @since 1.0.0 + */ private function apiUpdate(array $toUpdate) : void { // this is only a temp... in the future this logic will change but for current purposes this is the easiest way to implement updates @@ -911,10 +920,19 @@ final class ApiController extends Controller \mkdir($dest); $this->downloadUpdate($update['download_url'], $dest . '/' . $update['name']); $this->runUpdate($dest . '/' . $update['name']); - $this->cleanupUpdate(__DIR__ . '/../Updates/' . $dest); } } + /** + * Package to download + * + * @param string $url Url to download from + * @param string $dest Local destination of the download + * + * @return void + * + * @since 1.0.0 + */ private function downloadUpdate(string $url, string $dest) : void { // this is only a temp... in the future this logic will change but for current purposes this is the easiest way to implement updates @@ -925,106 +943,17 @@ final class ApiController extends Controller File::put($dest, $updateFile); } + /** + * Run the update + * + * @param string $updateFile Update file/package + * + * @return void + * + * @since 1.0.0 + */ private function runUpdate(string $updateFile) : void { - $updateContent = \file_get_contents($updateFile); - if ($updateContent === false) { - return; - } - - $package = \json_decode($updateContent, true); - $updatePath = \dirname($updateFile); - $subPath = $package['type'] === 'Modules/' ? $package['name'] : ''; - - foreach ($package['add'] as $src => $dest) { - $src = StringUtils::startsWith($src, 'http') ? $src : $updatePath . '/' . $subPath . $src; - $dest = __DIR__ . '/../../../' . $package['type'] . '/' . $subPath . $dest; - - $this->updateAdd($src, $dest); - } - - foreach ($package['remove'] as $src => $dest) { - $dest = __DIR__ . '/../../../' . $package['type'] . '/' . $subPath . $dest; - - $this->updateRemove($dest); - } - - foreach ($package['replace'] as $src => $dest) { - $src = StringUtils::startsWith($src, 'http') ? $src : $updatePath . '/' . $subPath . $src; - $dest = __DIR__ . '/../../../' . $package['type'] . '/' . $subPath . $dest; - - $this->updateReplace($src, $dest); - } - - foreach ($package['move'] as $src => $dest) { - $src = __DIR__ . '/../../../' . $package['type'] . '/' . $subPath . $src; - $dest = __DIR__ . '/../../../' . $package['type'] . '/' . $subPath . $dest; - - $this->updateMove($src, $dest); - } - - foreach ($package['run'] as $dest) { - $dest = $updatePath . '/' . $dest; - - $this->updateRun($dest); - } - - foreach ($package['cmd'] as $cmd) { - $this->updateCmd($cmd); - } - } - - private function updateAdd(string $src, string $dest) : void - { - if (StringUtils::startsWith($src, 'http')) { - $request = new Request(new Http($src)); - $request->setMethod(RequestMethod::GET); - - $content = Rest::request($request)->getBody(); - File::put($dest, $content, ContentPutMode::CREATE); - } else { - if (\is_dir($src)) { - Directory::copy($src, $dest); - } else { - File::copy($src, $dest); - } - } - } - - private function updateRemove(string $dest) : void - { - if (\is_dir($dest)) { - Directory::delete($dest); - } else { - File::delete($dest); - } - } - - private function updateReplace(string $src, string $dest) : void - { - $this->updateRemove($dest); - $this->updateAdd($src, $dest); - } - - private function updateMove(string $src, string $dest) : void - { - $this->updateAdd($src, $dest); - $this->updateRemove($src); - } - - private function updateRun(string $dest) : void - { - - } - - private function updateCmd(string $cmd) : void - { - - } - - private function cleanupUpdate(string $path) : void - { - // this is only a temp... in the future this logic will change but for current purposes this is the easiest way to implement updates - Directory::delete($path); + // todo: do package functions here of the packagemanager } } diff --git a/Models/AccountPermission.php b/Models/AccountPermission.php index 079afb1..6d4c50d 100644 --- a/Models/AccountPermission.php +++ b/Models/AccountPermission.php @@ -43,7 +43,8 @@ class AccountPermission extends PermissionAbstract * @param int $account Group id * @param null|int $unit Unit Unit to check (null if all are acceptable) * @param null|string $app App App to check (null if all are acceptable) - * @param null|string $module Module Module to check (null if all are acceptable) + * @param null|string $module Module to check (null if all are acceptable) + * @param int $from Module providing this permission * @param null|int $type Type (e.g. customer) (null if all are acceptable) * @param null|int $element (e.g. customer id) (null if all are acceptable) * @param null|int $component (e.g. address) (null if all are acceptable) diff --git a/Models/GroupPermission.php b/Models/GroupPermission.php index 2e2d898..9c29286 100644 --- a/Models/GroupPermission.php +++ b/Models/GroupPermission.php @@ -43,7 +43,8 @@ class GroupPermission extends PermissionAbstract * @param int $group Group id * @param null|int $unit Unit Unit to check (null if all are acceptable) * @param null|string $app App App to check (null if all are acceptable) - * @param null|string $module Module Module to check (null if all are acceptable) + * @param null|string $module Module to check (null if all are acceptable) + * @param int $from Module providing this permission * @param null|int $type Type (e.g. customer) (null if all are acceptable) * @param null|int $element (e.g. customer id) (null if all are acceptable) * @param null|int $component (e.g. address) (null if all are acceptable) diff --git a/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorPopupView.php b/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorPopupView.php index 5424258..24cf4c6 100644 --- a/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorPopupView.php +++ b/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorPopupView.php @@ -41,11 +41,27 @@ class GroupTagSelectorPopupView extends View $this->setTemplate('/Modules/Admin/Theme/Backend/Components/GroupTagSelector/group-selector-popup'); } + /** + * Set selector id + * + * @param string $id Id + * + * @return void + * + * @since 1.0.0 + */ public function setId(string $id) : void { $this->id = $id; } + /** + * Get selector id + * + * @return string + * + * @since 1.0.0 + */ public function getId() : string { return $this->id; diff --git a/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorView.php b/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorView.php index f543126..66784b9 100644 --- a/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorView.php +++ b/Theme/Backend/Components/GroupTagSelector/GroupTagSelectorView.php @@ -45,11 +45,25 @@ class GroupTagSelectorView extends View $this->addData('group-selector-popup', $view); } + /** + * Get selector id + * + * @return string + * + * @since 1.0.0 + */ public function getId() : string { return $this->id; } + /** + * Is required? + * + * @return bool + * + * @since 1.0.0 + */ public function isRequired() : bool { return $this->isRequired;