Release of v5.0.1-alpha3

Add in JCB gitea push feature to help maintain JCB core features. Add extending options to interfaces.
This commit is contained in:
2024-06-05 17:08:34 +02:00
parent aba1267f8e
commit 0c9a098335
40 changed files with 1642 additions and 672 deletions

View File

@@ -57,6 +57,17 @@ class Config extends BaseConfig
$this->config = $config ?: JoomlaFactory::getConfig();
}
/**
* get Gitea Username
*
* @return string the access token
* @since 3.2.0
*/
protected function getGiteausername(): ?string
{
return $this->custom_gitea_username ?? $this->params->get('gitea_username');
}
/**
* get Gitea Access Token
*
@@ -95,6 +106,22 @@ class Config extends BaseConfig
return null;
}
/**
* get Custom Gitea Username
*
* @return string the custom access token
* @since 3.2.0
*/
protected function getCustomgiteausername(): ?string
{
if ($this->add_custom_gitea_url == 2)
{
return $this->params->get('custom_gitea_username');
}
return null;
}
/**
* get Custom Gitea Access Token
*
@@ -148,6 +175,12 @@ class Config extends BaseConfig
$paths = $this->params->get('super_powers_core_repos');
}
// get the users own power repo (can overwrite all)
if (!empty($this->gitea_username))
{
$repos[$this->gitea_username . '.super-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'super-powers', 'branch' => 'master'];
}
if (!empty($paths) && is_array($paths))
{
foreach ($paths as $path)
@@ -845,6 +878,11 @@ class Config extends BaseConfig
{
// some defaults repos we need by JCB
$repos = [];
// get the users own power repo (can overwrite all)
if (!empty($this->gitea_username))
{
$repos[$this->gitea_username . '.joomla-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'joomla-powers', 'branch' => 'master'];
}
$repos[$this->joomla_powers_core_organisation . '.joomla-powers'] = (object) ['owner' => $this->joomla_powers_core_organisation, 'repo' => 'joomla-powers', 'branch' => 'master'];
return $repos;
@@ -866,15 +904,12 @@ class Config extends BaseConfig
/**
* Get joomla power approved paths
*
* @return array The paths to the repositories on Gitea
* @return array The approved paths to the repositories on Gitea
* @since 3.2.0
*/
protected function getApprovedjoomlapaths(): array
{
// some defaults repos we need by JCB
$approved = $this->joomla_powers_init_repos;
return array_values($approved);
return array_values($this->joomla_powers_init_repos);
}
/**

View File

@@ -244,7 +244,7 @@ class Data
);
// Make sure the icon is only an icon path
if (strpos($item->icon, '#') !== false)
if (isset($item->icon) && strpos($item->icon, '#') !== false)
{
$item->icon = strstr($item->icon, '#', true);
}

View File

@@ -207,96 +207,192 @@ final class JoomlaPower implements PowerInterface
}
/**
* Set a power
* Set a Joomla power
*
* @param string $guid The global unique id of the power
* @param string $guid The global unique id of the power
*
* @return bool true on successful setting of a power
* @return bool true on successful setting of a power
* @since 3.2.1
*/
private function set(string $guid): bool
{
// check if we have been here before
// Check if power is already set
if ($this->isPowerSet($guid))
{
return $this->state[$guid];
}
elseif ($this->isGuidValid($guid))
// Validate GUID
if (!$this->isGuidValid($guid))
{
// get the power data
$this->active[$guid] = $this->getPowerData($guid);
$this->state[$guid] = false;
return false;
}
if (is_object($this->active[$guid]))
// Get the power data
$this->active[$guid] = $this->getPowerData($guid);
// Validate power data object
if ($this->active[$guid] === null)
{
return $this->handlePowerNotFound($guid);
}
// Prevent recursive loading of the same power
$this->state[$guid] = true;
// Convert settings to array if valid JSON
$settings = $this->convertSettingsToArray(
$this->active[$guid]->settings
);
// Set the target version if settings array is valid
if (!$this->setTargetVersion($guid, $settings))
{
return false;
}
// Set class name and namespace
$this->setClassAndNamespace($guid);
return true;
}
/**
* Convert settings JSON string to array
*
* @param string $settingsJson
*
* @return array|null
* @since 3.2.2
*/
private function convertSettingsToArray(string $settingsJson): ?array
{
if (JsonHelper::check($settingsJson))
{
return json_decode($settingsJson, true);
}
return null;
}
/**
* Set the target version based on Joomla version and settings
*
* @param string $guid
* @param array|null $settings
*
* @return bool
* @since 3.2.2
*/
private function setTargetVersion(string $guid, ?array $settings): bool
{
$joomla_version = $this->config->joomla_version;
if (!$joomla_version || !ArrayHelper::check($settings))
{
return false;
}
$joomla_version_target = null;
$target_found = false;
foreach ($settings as $namespace)
{
// Set default values for all versions
if ($namespace['joomla_version'] == 0)
{
// make sure that in recursion we
// don't try to load this power again
// since during the load of a power we also load
// all powers linked to it
$this->state[$guid] = true;
$this->setNamespaceAndType($guid, $namespace);
$target_found = true;
}
// convert settings to an array
if (JsonHelper::check($this->active[$guid]->settings))
{
$this->active[$guid]->settings = $settings
= json_decode($this->active[$guid]->settings, true);
}
// set a target version
$joomla_version = $this->config->joomla_version;
if ($joomla_version && ArrayHelper::check($settings))
{
foreach ($settings as $namespace)
{
if ($joomla_version == $namespace['joomla_version'] ||
$namespace['joomla_version'] == 0)
{
$this->active[$guid]->namespace = $namespace['namespace'];
$this->active[$guid]->type = $namespace['type'] ?? 'class';
break;
}
}
$this->active[$guid]->class_name =
$this->extractLastNameFromNamespace($this->active[$guid]->namespace);
$this->active[$guid]->_namespace =
$this->removeLastNameFromNamespace($this->active[$guid]->namespace);
// set the approved super power values
$this->setSuperPowers($guid);
return true;
}
// Check for direct target version
if ($joomla_version == $namespace['joomla_version'])
{
$joomla_version_target = $namespace;
break;
}
}
// we failed to get the power,
// so we raise an error message
// only if guid is valid
if ($this->isGuidValid($guid))
if ($joomla_version_target)
{
// now we search for it via the super power paths
if (empty($this->retry[$guid]) && $this->superpower->load($guid, ['remote', 'local']))
{
// we found it and it was loaded into the database
unset($this->state[$guid]);
unset($this->active[$guid]);
// we make sure that this retry only happen once! (just in-case...)
$this->retry[$guid] = true;
// so we try to load it again
return $this->set($guid);
}
$this->setNamespaceAndType($guid, $joomla_version_target);
$target_found = true;
}
if (!$target_found)
{
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_PJOOMLA_POWER_BGUIDSB_NOT_FOUNDP', $guid),
Text::sprintf('COM_COMPONENTBUILDER_PJOOMLA_POWER_BGUIDSB_WAS_FOUND_BUT_MISSING_A_NAMESPACE_VALUE_FOR_JOOMLA_SP', $guid, $joomla_version),
'Error'
);
$this->state[$guid] = false;
return false;
}
// let's not try again
return true;
}
/**
* Set namespace and type for the active power
*
* @param string $guid
* @param array $namespace
*
* @since 3.2.2
*/
private function setNamespaceAndType(string $guid, array $namespace): void
{
$this->active[$guid]->namespace = $namespace['namespace'];
$this->active[$guid]->type = $namespace['type'] ?? 'class';
}
/**
* Set class name and namespace for the active power
*
* @param string $guid
*
* @since 3.2.2
*/
private function setClassAndNamespace(string $guid): void
{
$this->active[$guid]->class_name = $this->extractLastNameFromNamespace(
$this->active[$guid]->namespace
);
$this->active[$guid]->_namespace = $this->removeLastNameFromNamespace(
$this->active[$guid]->namespace
);
}
/**
* Handle power not found scenario
*
* @param string $guid
*
* @return bool
* @since 3.2.2
*/
private function handlePowerNotFound(string $guid): bool
{
if (empty($this->retry[$guid]) && $this->superpower->load($guid, ['remote', 'local']))
{
// Retry loading the power
unset($this->state[$guid]);
unset($this->active[$guid]);
$this->retry[$guid] = true;
return $this->set($guid);
}
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_PJOOMLA_POWER_BGUIDSB_NOT_FOUNDP', $guid),
'Error'
);
$this->state[$guid] = false;
return false;

View File

@@ -756,7 +756,7 @@ class Power implements PowerInterface
}
/**
* Set Extend Class
* Set Extend
*
* @param string $guid The global unique id of the power
* @param array $use The use array
@@ -767,9 +767,29 @@ class Power implements PowerInterface
*/
private function setExtend(string $guid, array &$use, array &$as)
{
// does this extend something
$this->active[$guid]->extends_name = null;
// build the interface extends details
if ($this->active[$guid]->type === 'interface')
{
$this->setExtendInterface($guid, $use, $as);
}
else
{
$this->setExtendClass($guid, $use, $as);
}
}
/**
* Set Extend Class
*
* @param string $guid The global unique id of the power
* @param array $use The use array
* @param array $as The use as array
*
* @return void
* @since 3.2.0
*/
private function setExtendClass(string $guid, array &$use, array &$as)
{
// we first check for custom extending options
if ($this->active[$guid]->extends == -1
&& StringHelper::check($this->active[$guid]->extends_custom))
@@ -803,6 +823,89 @@ class Power implements PowerInterface
}
}
}
// reset it not found
else
{
$this->active[$guid]->extends = '';
$this->active[$guid]->extends_custom = '';
}
// always rest these for normal classes
$this->active[$guid]->extendsinterfaces = null;
$this->active[$guid]->extendsinterfaces_custom = '';
}
/**
* Set Extend Interface
*
* @param string $guid The global unique id of the power
* @param array $use The use array
* @param array $as The use as array
*
* @return void
* @since 3.2.2
*/
private function setExtendInterface(string $guid, array &$use, array &$as)
{
// does this extends interfaces
$this->active[$guid]->extendsinterfaces = (isset($this->active[$guid]->extendsinterfaces)
&& JsonHelper::check(
$this->active[$guid]->extendsinterfaces
)) ? json_decode((string)$this->active[$guid]->extendsinterfaces, true) : null;
if (ArrayHelper::check($this->active[$guid]->extendsinterfaces))
{
$bucket = [];
foreach ($this->active[$guid]->extendsinterfaces as $extend)
{
// we first check for custom extending options
if ($extend == -1
&& isset($this->active[$guid]->extendsinterfaces_custom)
&& StringHelper::check($this->active[$guid]->extendsinterfaces_custom))
{
// reserve extends custom for the linker
$this->active[$guid]->unchanged_extendsinterfaces_custom = $this->active[$guid]->extendsinterfaces_custom;
$bucket[] = $this->placeholder->update_(
$this->customcode->update($this->active[$guid]->extendsinterfaces_custom)
);
// just add once
unset($this->active[$guid]->extendsinterfaces_custom);
}
// does this extend existing
elseif (GuidHelper::valid($extend))
{
// check if it was set
if ($this->set($extend))
{
$extends_name = $this->get($extend, 1)->class_name;
// add to use
$use[] = $extend;
// add padding if the two names are the same
if ($extends_name === $this->active[$guid]->class_name)
{
$extends_name = $as[$extend]
= 'Extending' . $extends_name;
}
// get the name
$bucket[] = $extends_name;
}
}
}
if ($bucket !== [])
{
$this->active[$guid]->extends_name = implode(', ', $bucket);
}
}
else
{
$this->active[$guid]->extendsinterfaces = null;
$this->active[$guid]->extendsinterfaces_custom = '';
}
// always rest these for interfaces
$this->active[$guid]->extends = '';
$this->active[$guid]->extends_custom = '';
}
/**

View File

@@ -115,6 +115,8 @@ class Infusion
'unchanged_description' => 'description',
'extends' => 'extends',
'unchanged_extends_custom' => 'extends_custom',
'extendsinterfaces' => 'extendsinterfaces',
'unchanged_extendsinterfaces_custom' => 'extendsinterfaces_custom',
'guid' => 'guid',
'unchanged_head' => 'head',
'use_selection' => 'use_selection',

View File

@@ -113,9 +113,8 @@ class JoomlaPower implements ServiceProviderInterface
public function getGrep(Container $container): Grep
{
return new Grep(
$container->get('Config')->local_joomla_powers_repository_path,
$container->get('Config')->approved_joomla_paths,
$container->get('Gitea.Repository.Contents')
$container->get('Gitea.Repository.Contents'),
$container->get('Config')->approved_joomla_paths
);
}

View File

@@ -140,9 +140,9 @@ class Power implements ServiceProviderInterface
public function getGrep(Container $container): Grep
{
return new Grep(
$container->get('Config')->local_powers_repository_path,
$container->get('Gitea.Repository.Contents'),
$container->get('Config')->approved_paths,
$container->get('Gitea.Repository.Contents')
$container->get('Config')->local_powers_repository_path
);
}