Release of v3.2.2-alpha3

Fix permission issue for admin views. Add extending options to interfaces.
This commit is contained in:
2024-06-05 16:29:28 +02:00
parent dfaaf15ca9
commit b67e534b9f
43 changed files with 1676 additions and 674 deletions

View File

@@ -12,14 +12,11 @@
namespace VDM\Joomla\Componentbuilder\Power;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Language\Text;
use VDM\Joomla\Gitea\Repository\Contents;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Componentbuilder\Interfaces\GrepInterface;
use VDM\Joomla\Interfaces\GrepInterface;
use VDM\Joomla\Abstraction\Grep as ExtendingGrep;
/**
@@ -32,114 +29,36 @@ use VDM\Joomla\Componentbuilder\Interfaces\GrepInterface;
*
* @since 3.2.0
*/
class Grep implements GrepInterface
final class Grep extends ExtendingGrep implements GrepInterface
{
/**
* The local path
* Load the remote repository index of powers
*
* @var string
* @since 3.2.0
**/
public ?string $path;
/**
* All approved paths
* @param object $path The repository path details
*
* @var array
* @since 3.2.0
**/
public ?array $paths;
/**
* Gitea Repository Contents
*
* @var Contents
* @since 3.2.0
**/
protected Contents $contents;
/**
* Joomla Application object
*
* @var CMSApplication
* @since 3.2.0
**/
protected CMSApplication $app;
/**
* Constructor.
*
* @param string $path The local path
* @param array $paths The approved paths
* @param Contents $contents The Gitea Repository Contents object.
* @param CMSApplication|null $app The CMS Application object.
*
* @throws \Exception
* @return void
* @since 3.2.0
*/
public function __construct(string $path, array $paths, Contents $contents, ?CMSApplication $app = null)
protected function remoteIndex(object &$path): void
{
$this->path = $path;
$this->paths = $paths;
$this->contents = $contents;
$this->app = $app ?: Factory::getApplication();
$this->init();
}
/**
* Get all remote powers GUID's
*
* @return array|null
* @since 3.2.0
*/
public function getRemotePowersGuid(): ?array
{
if (!is_array($this->paths) || $this->paths === [])
if (isset($path->index))
{
return null;
return;
}
$powers = [];
foreach ($this->paths as $path)
try
{
// Get local index
$this->remoteIndex($path);
if (isset($path->index) && is_object($path->index))
{
$powers = array_merge($powers, array_keys((array) $path->index));
}
$path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch);
}
return empty($powers) ? null : array_unique($powers);
}
/**
* Get a power
*
* @param string $guid The global unique id of the power
* @param array $order The search order
*
* @return object|null
* @since 3.2.0
*/
public function get(string $guid, array $order = ['local', 'remote']): ?object
{
// we can only search if we have paths
if (is_array($this->paths) && $this->paths !== [])
catch (\Exception $e)
{
foreach ($order as $target)
{
if (($function_name = $this->getFunctionName($target)) !== null &&
($power = $this->{$function_name}($guid)) !== null)
{
return $power;
}
}
}
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path->path, $e->getMessage()),
'Error'
);
return null;
$path->index = null;
}
}
/**
@@ -150,7 +69,7 @@ class Grep implements GrepInterface
* @return object|null
* @since 3.2.0
*/
private function searchLocal(string $guid): ?object
protected function searchLocal(string $guid): ?object
{
// we can only search if we have paths
if ($this->path && $this->paths)
@@ -178,7 +97,7 @@ class Grep implements GrepInterface
* @return object|null
* @since 3.2.0
*/
private function searchRemote(string $guid): ?object
protected function searchRemote(string $guid): ?object
{
// we can only search if we have paths
if ($this->path && $this->paths)
@@ -207,7 +126,7 @@ class Grep implements GrepInterface
* @return object|null
* @since 3.2.0
*/
private function getLocal(object $path, string $guid): ?object
protected function getLocal(object $path, string $guid): ?object
{
if (empty($path->local->{$guid}->settings) || empty($path->local->{$guid}->code))
{
@@ -240,7 +159,7 @@ class Grep implements GrepInterface
* @return object|null
* @since 3.2.0
*/
private function getRemote(object $path, string $guid): ?object
protected function getRemote(object $path, string $guid): ?object
{
if (empty($path->index->{$guid}->settings) || empty($path->index->{$guid}->code))
{
@@ -254,6 +173,14 @@ class Grep implements GrepInterface
// get the code
if (($code = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->power, $path->branch)) !== null)
{
// set the git details in params
$power->params = (object) [
'git' => [
'owner' => $path->owner,
'repo' => $path->repo,
'branch' => $path->branch
]
];
$power->main_class_code = $code;
return $power;
}
@@ -262,100 +189,6 @@ class Grep implements GrepInterface
return null;
}
/**
* Set path details
*
* @return void
* @since 3.2.0
*/
private function init()
{
if (is_array($this->paths) && $this->paths !== [])
{
foreach ($this->paths as $n => &$path)
{
if (isset($path->owner) && strlen($path->owner) > 1 &&
isset($path->repo) && strlen($path->repo) > 1)
{
// build the path
$path->path = trim($path->owner) . '/' . trim($path->repo);
// update the branch
if ($path->branch === 'default' || empty($path->branch))
{
$path->branch = null;
}
// set local path
if ($this->path && Folder::exists($this->path . '/' . $path->path))
{
$path->full_path = $this->path . '/' . $path->path;
}
}
else
{
unset($this->paths[$n]);
}
}
}
}
/**
* Load the local repository index of powers
*
* @param object $path The repository path details
*
* @return void
* @since 3.2.0
*/
private function localIndex(object &$path)
{
if (isset($path->local) || !isset($path->full_path))
{
return;
}
if (($content = FileHelper::getContent($path->full_path . '/super-powers.json', null)) !== null &&
JsonHelper::check($content))
{
$path->local = json_decode($content);
return;
}
$path->local = null;
}
/**
* Load the remote repository index of powers
*
* @param object $path The repository path details
*
* @return void
* @since 3.2.0
*/
private function remoteIndex(object &$path)
{
if (isset($path->index))
{
return;
}
try
{
$path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch);
}
catch (\Exception $e)
{
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path->path, $e->getMessage()),
'Error'
);
$path->index = null;
}
}
/**
* Load the remote file
*
@@ -367,7 +200,7 @@ class Grep implements GrepInterface
* @return mixed
* @since 3.2.0
*/
private function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch)
protected function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch)
{
try
{
@@ -387,18 +220,29 @@ class Grep implements GrepInterface
}
/**
* Get function name
* Load the local repository index of powers
*
* @param string $name The targeted function name
* @param object $path The repository path details
*
* @return string|null
* @return void
* @since 3.2.0
*/
private function getFunctionName(string $name): ?string
protected function localIndex(object &$path)
{
$function_name = 'search' . ucfirst(strtolower($name));
if (isset($path->local) || !isset($path->full_path))
{
return;
}
return method_exists($this, $function_name) ? $function_name : null;
if (($content = FileHelper::getContent($path->full_path . '/super-powers.json', null)) !== null &&
JsonHelper::check($content))
{
$path->local = json_decode($content);
return;
}
$path->local = null;
}
}