Adds getExtensionInstallClass and setInstallMethodScript to its own class. #950

This commit is contained in:
2022-08-20 18:02:48 +02:00
parent 154cd5ae1e
commit a0fda76abd
14 changed files with 516 additions and 244 deletions

View File

@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo
Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have!
You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.1.4) with **ALL** its features and **ALL** concepts totally open-source and free!
You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.1.5) with **ALL** its features and **ALL** concepts totally open-source and free!
> Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45)
@ -140,14 +140,14 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015
+ *Last Build*: 9th July, 2022
+ *Version*: 3.1.4
+ *Last Build*: 20th August, 2022
+ *Version*: 3.1.5
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **311349**
+ *Line count*: **311839**
+ *Field count*: **2002**
+ *File count*: **2050**
+ *Folder count*: **349**
+ *File count*: **2055**
+ *Folder count*: **351**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com).
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)

View File

@ -29271,227 +29271,6 @@ function vdm_dkim() {
);
}
public function getExtensionInstallClass(&$extension)
{
// yes we are adding it
$script = PHP_EOL . '/**';
$script .= PHP_EOL . ' * ' . $extension->official_name
. ' script file.';
$script .= PHP_EOL . ' *';
$script .= PHP_EOL . ' * @package ' . $extension->class_name;
$script .= PHP_EOL . ' */';
$script .= PHP_EOL . 'class ' . $extension->installer_class_name;
$script .= PHP_EOL . '{';
// set constructor
if (isset($extension->add_php_script_construct)
&& $extension->add_php_script_construct == 1
&& StringHelper::check(
$extension->php_script_construct
))
{
$script .= $this->setInstallMethodScript(
'construct', $extension->php_script_construct
);
}
// add PHP in extension install
$addScriptMethods = array('php_preflight', 'php_postflight',
'php_method');
$addScriptTypes = array('install', 'update', 'uninstall',
'discover_install');
// set some buckets for sorting
$function_install = array();
$function_update = array();
$function_uninstall = array();
$has_php_preflight = false;
$function_php_preflight = array('install' => array(),
'uninstall' => array(),
'discover_install' => array(),
'update' => array());
$has_php_postflight = false;
$function_php_postflight = array('install' => array(),
'uninstall' => array(),
'discover_install' => array(),
'update' => array());
// the function sorter
foreach ($addScriptMethods as $scriptMethod)
{
foreach ($addScriptTypes as $scriptType)
{
if (isset(
$extension->{'add_' . $scriptMethod . '_' . $scriptType}
)
&& $extension->{'add_' . $scriptMethod . '_' . $scriptType}
== 1
&& StringHelper::check(
$extension->{$scriptMethod . '_' . $scriptType}
))
{
// add to the main methods
if ('php_method' === $scriptMethod)
{
${'function_' . $scriptType}[]
= $extension->{$scriptMethod . '_' . $scriptType};
}
else
{
${'function_' . $scriptMethod}[$scriptType][]
= $extension->{$scriptMethod
. '_' . $scriptType};
${'has_' . $scriptMethod} = true;
}
}
}
}
// now add the install script.
if (ArrayHelper::check($function_install))
{
$script .= $this->setInstallMethodScript(
'install', $function_install
);
}
// now add the update script.
if (ArrayHelper::check($function_update))
{
$script .= $this->setInstallMethodScript(
'update', $function_update
);
}
// now add the uninstall script.
if (ArrayHelper::check($function_uninstall))
{
$script .= $this->setInstallMethodScript(
'uninstall', $function_uninstall
);
}
// now add the preflight script.
if ($has_php_preflight)
{
$script .= $this->setInstallMethodScript(
'preflight', $function_php_preflight
);
}
// now add the postflight script.
if ($has_php_postflight)
{
$script .= $this->setInstallMethodScript(
'postflight', $function_php_postflight
);
}
$script .= PHP_EOL . '}' . PHP_EOL;
return $script;
}
protected function setInstallMethodScript($function_name, &$scripts)
{
$script = '';
// build function
switch ($function_name)
{
case 'install':
case 'update':
case 'uninstall':
// the main function types
$script = PHP_EOL . PHP_EOL . $this->_t(1) . '/**';
$script .= PHP_EOL . $this->_t(1) . ' * Called on '
. $function_name;
$script .= PHP_EOL . $this->_t(1) . ' *';
$script .= PHP_EOL . $this->_t(1)
. ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script';
$script .= PHP_EOL . $this->_t(1) . ' *';
$script .= PHP_EOL . $this->_t(1)
. ' * @return boolean True on success';
$script .= PHP_EOL . $this->_t(1) . ' */';
$script .= PHP_EOL . $this->_t(1) . 'public function '
. $function_name . '($adapter)';
$script .= PHP_EOL . $this->_t(1) . '{';
$script .= PHP_EOL . implode(PHP_EOL . PHP_EOL, $scripts);
// return true
if ('uninstall' !== $function_name)
{
$script .= PHP_EOL . $this->_t(2) . 'return true;';
}
break;
case 'preflight':
case 'postflight':
// the pre/post function types
$script = PHP_EOL . PHP_EOL . $this->_t(1) . '/**';
$script .= PHP_EOL . $this->_t(1)
. ' * Called before any type of action';
$script .= PHP_EOL . $this->_t(1) . ' *';
$script .= PHP_EOL . $this->_t(1)
. ' * @param string $route Which action is happening (install|uninstall|discover_install|update)';
$script .= PHP_EOL . $this->_t(1)
. ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script';
$script .= PHP_EOL . $this->_t(1) . ' *';
$script .= PHP_EOL . $this->_t(1)
. ' * @return boolean True on success';
$script .= PHP_EOL . $this->_t(1) . ' */';
$script .= PHP_EOL . $this->_t(1) . 'public function '
. $function_name . '($route, $adapter)';
$script .= PHP_EOL . $this->_t(1) . '{';
$script .= PHP_EOL . $this->_t(2) . '//' . $this->setLine(
__LINE__
) . ' get application';
$script .= PHP_EOL . $this->_t(2)
. '$app = JFactory::getApplication();' . PHP_EOL;
// add the default version check (TODO) must make this dynamic
if ('preflight' === $function_name)
{
$script .= PHP_EOL . $this->_t(2) . '//' . $this->setLine(
__LINE__
) . ' the default for both install and update';
$script .= PHP_EOL . $this->_t(2)
. '$jversion = new JVersion();';
$script .= PHP_EOL . $this->_t(2)
. "if (!\$jversion->isCompatible('3.8.0'))";
$script .= PHP_EOL . $this->_t(2) . '{';
$script .= PHP_EOL . $this->_t(3)
. "\$app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error');";
$script .= PHP_EOL . $this->_t(3) . 'return false;';
$script .= PHP_EOL . $this->_t(2) . '}' . PHP_EOL;
}
// now add the scripts
foreach ($scripts as $route => $_script)
{
if (ArrayHelper::check($_script))
{
// set the if and script
$script .= PHP_EOL . $this->_t(2) . "if ('" . $route
. "' === \$route)";
$script .= PHP_EOL . $this->_t(2) . '{';
$script .= PHP_EOL . implode(
PHP_EOL . PHP_EOL, $_script
);
$script .= PHP_EOL . $this->_t(2) . '}' . PHP_EOL;
}
}
// return true
$script .= PHP_EOL . $this->_t(2) . 'return true;';
break;
case 'construct':
// the __construct script
$script = PHP_EOL . PHP_EOL . $this->_t(1) . '/**';
$script .= PHP_EOL . $this->_t(1) . ' * Constructor';
$script .= PHP_EOL . $this->_t(1) . ' *';
$script .= PHP_EOL . $this->_t(1)
. ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script';
$script .= PHP_EOL . $this->_t(1) . ' */';
$script .= PHP_EOL . $this->_t(1)
. 'public function __construct($adapter)';
$script .= PHP_EOL . $this->_t(1) . '{';
$script .= PHP_EOL . $scripts;
break;
default:
// oops error
return '';
}
// close the function
$script .= PHP_EOL . $this->_t(1) . '}';
return $script;
}
/**
* check if a translation should be added
*

View File

@ -19,6 +19,7 @@ use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Componentbuilder\Extension\InstallScript;
/**
* Infusion class
@ -2393,7 +2394,7 @@ class Infusion extends Interpretation
// INSTALLCLASS
$this->fileContentDynamic[$module->key][$this->hhh
. 'INSTALLCLASS' . $this->hhh]
= $this->getExtensionInstallClass($module);
= (new InstallScript($module))->get();
}
// FIELDSET
if (isset($module->form_files)
@ -2455,7 +2456,7 @@ class Infusion extends Interpretation
// INSTALLCLASS
$this->fileContentDynamic[$plugin->key][$this->hhh
. 'INSTALLCLASS' . $this->hhh]
= $this->getExtensionInstallClass($plugin);
= (new InstallScript($plugin))->get();
}
// FIELDSET
if (isset($plugin->form_files)

View File

@ -392,7 +392,7 @@ class ComponentbuilderModelAjax extends ListModel
else
{
// download link of the latest version
$download = "https://git.vdm.dev/api/v1/repos/joomla/Component-Builder/archive/" . $tags[0]->name . ".zip?access_token=" . $token;
$download = "https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/" . $tags[0]->name . ".zip?access_token=" . $token;
return ['notice' => '<small><span style="color:red;"><span class="icon-warning-circle"></span>' . JText::_('COM_COMPONENTBUILDER_OUT_OF_DATE') . '!</span> <a style="color:green;" href="' .
$download . '" title="' . JText::_('COM_COMPONENTBUILDER_YOU_CAN_DIRECTLY_DOWNLOAD_THE_LATEST_UPDATE_OR_USE_THE_JOOMLA_UPDATE_AREA') . '">' . JText::_('COM_COMPONENTBUILDER_DOWNLOAD_UPDATE') . '!</a></small>'];

File diff suppressed because one or more lines are too long