cleanup and tests added for ci/cd

This commit is contained in:
Dennis Eichhorn 2019-11-20 22:28:04 +01:00
parent 424a7dca3c
commit 44033a4911
5 changed files with 63 additions and 102 deletions

View File

@ -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
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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;