Adds getExtensionInstallClass and setInstallMethodScript to its own class. #950
This commit is contained in:
@ -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
|
||||
*
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user