Skip to content

Commit

Permalink
Update issue #34
Browse files Browse the repository at this point in the history
  • Loading branch information
oyeaussie committed Aug 21, 2024
1 parent cefbe3e commit e50194f
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 12 deletions.
4 changes: 4 additions & 0 deletions apps/Core/Packages/Adminltetags/Tags/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] :
Expand Down
7 changes: 7 additions & 0 deletions apps/Core/Views/Default/html/modules/analyse.html
Original file line number Diff line number Diff line change
Expand Up @@ -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] = '<pre>' + logObject[object] + '</pre>';
}
}
Expand Down Expand Up @@ -426,6 +431,8 @@
'modalSize' : 'xl',
'modalHeader' : true,
'modalFooter' : true,
'modalHeaderCloseButton' : true,
'modalEscClose' : true,
'modalTitle' : '<i class="fa fas fa-fw fa-th"></i> LOGS'
]
)}}
Expand Down
2 changes: 2 additions & 0 deletions system/Base/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" :
{
Expand All @@ -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"
}
Expand Down
131 changes: 124 additions & 7 deletions system/Base/Providers/ModulesServiceProvider/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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],
]
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public function __isset($key)
{
return array_key_exists($key, $this->packagesData);
}

public function reset()
{
$this->packagesData = [];
}
}
12 changes: 10 additions & 2 deletions system/Base/Providers/ModulesServiceProvider/Queues.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e50194f

Please sign in to comment.