diff --git a/componentbuilderactionlogcompiler.xml b/componentbuilderactionlogcompiler.xml index fe4ba8c..a9e7bd1 100644 --- a/componentbuilderactionlogcompiler.xml +++ b/componentbuilderactionlogcompiler.xml @@ -1,13 +1,14 @@ PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER - 27th July, 2024 + 14th August, 2024 Llewellyn van der Merwe joomla@vdm.io https://dev.vdm.io Copyright (C) 2015 Vast Development Method. All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt - 2.0.0 + 4.0.0 + VDM\Plugin\Extension\ComponentbuilderActionLogCompiler PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_XML_DESCRIPTION @@ -15,18 +16,19 @@ - en-GB/en-GB.plg_extension_componentbuilderactionlogcompiler.ini - en-GB/en-GB.plg_extension_componentbuilderactionlogcompiler.sys.ini + en-GB/plg_extension_componentbuilderactionlogcompiler.ini + en-GB/plg_extension_componentbuilderactionlogcompiler.sys.ini - componentbuilderactionlogcompiler.php + services index.html - language + services + src - + diff --git a/language/en-GB/en-GB.plg_extension_componentbuilderactionlogcompiler.ini b/language/en-GB/plg_extension_componentbuilderactionlogcompiler.ini similarity index 85% rename from language/en-GB/en-GB.plg_extension_componentbuilderactionlogcompiler.ini rename to language/en-GB/plg_extension_componentbuilderactionlogcompiler.ini index 99a3431..6aca2ba 100644 --- a/language/en-GB/en-GB.plg_extension_componentbuilderactionlogcompiler.ini +++ b/language/en-GB/plg_extension_componentbuilderactionlogcompiler.ini @@ -1,6 +1,6 @@ PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER="Extension - Componentbuilder ActionLog Compiler" -PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_DESCRIPTION="This plugin is used to improve your action log integration with Joomla for your component during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field./// not ready" -PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder ActionLog Compiler (v.2.0.0)

This plugin is used to improve your action log integration with Joomla for your component during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field./// not ready

Created by Llewellyn van der Merwe
Development started 10th March, 2024

" +PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_DESCRIPTION="This plugin is used to improve your action log integration with Joomla for your component during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field." +PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder ActionLog Compiler (v.4.0.0)

This plugin is used to improve your action log integration with Joomla for your component during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.

Created by Llewellyn van der Merwe
Development started 10th March, 2024

" PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_COMPONENT_ACTIVATION="Component Activation" PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_ACTIVATE_OPTION_LABEL="Activate Options" PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_ACTIVATE_OPTION_DESCRIPTION="You can select the kind of activation control you would like to use. All will target all components, and Selected will let you select only those you want to be active." diff --git a/language/en-GB/en-GB.plg_extension_componentbuilderactionlogcompiler.sys.ini b/language/en-GB/plg_extension_componentbuilderactionlogcompiler.sys.ini similarity index 85% rename from language/en-GB/en-GB.plg_extension_componentbuilderactionlogcompiler.sys.ini rename to language/en-GB/plg_extension_componentbuilderactionlogcompiler.sys.ini index 99a3431..6aca2ba 100644 --- a/language/en-GB/en-GB.plg_extension_componentbuilderactionlogcompiler.sys.ini +++ b/language/en-GB/plg_extension_componentbuilderactionlogcompiler.sys.ini @@ -1,6 +1,6 @@ PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER="Extension - Componentbuilder ActionLog Compiler" -PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_DESCRIPTION="This plugin is used to improve your action log integration with Joomla for your component during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field./// not ready" -PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder ActionLog Compiler (v.2.0.0)

This plugin is used to improve your action log integration with Joomla for your component during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field./// not ready

Created by Llewellyn van der Merwe
Development started 10th March, 2024

" +PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_DESCRIPTION="This plugin is used to improve your action log integration with Joomla for your component during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field." +PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder ActionLog Compiler (v.4.0.0)

This plugin is used to improve your action log integration with Joomla for your component during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.

Created by Llewellyn van der Merwe
Development started 10th March, 2024

" PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_COMPONENT_ACTIVATION="Component Activation" PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_ACTIVATE_OPTION_LABEL="Activate Options" PLG_EXTENSION_COMPONENTBUILDERACTIONLOGCOMPILER_ACTIVATE_OPTION_DESCRIPTION="You can select the kind of activation control you would like to use. All will target all components, and Selected will let you select only those you want to be active." diff --git a/script.php b/script.php index 7d25754..a97009b 100644 --- a/script.php +++ b/script.php @@ -13,15 +13,129 @@ defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Factory; +use Joomla\CMS\Version; +use Joomla\CMS\Installer\InstallerAdapter; use Joomla\CMS\Language\Text; -use Joomla\CMS\Filesystem\File; -use Joomla\CMS\Filesystem\Folder; +use Joomla\Filesystem\File; +use Joomla\Filesystem\Folder; /** * Extension - Componentbuilder ActionLog Compiler script file. * - * @package PlgExtensionComponentbuilderActionLogCompiler + * @package ComponentbuilderActionLogCompiler */ class plgExtensionComponentbuilderActionLogCompilerInstallerScript { + /** + * The CMS Application. + * + * @since 4.4.2 + */ + protected $app; + + /** + * A list of files to be deleted + * + * @var array + * @since 3.6 + */ + protected array $deleteFiles = []; + + /** + * A list of folders to be deleted + * + * @var array + * @since 3.6 + */ + protected array $deleteFolders = []; + + /** + * Constructor + * + * @param InstallerAdapter $adapter The object responsible for running this script + */ + public function __construct($adapter) + { + // get application + $this->app = Factory::getApplication(); + + if (is_file(JPATH_ROOT . '/plugins/extension/componentbuilderactionlogcompiler/componentbuilderactionlogcompiler.php')) + { + $this->deleteFiles[] = '/plugins/extension/componentbuilderactionlogcompiler/componentbuilderactionlogcompiler.php'; + } + } + + /** + * Called before any type of action + * + * @param string $route Which action is happening (install|uninstall|discover_install|update) + * @param InstallerAdapter $adapter The object responsible for running this script + * + * @return boolean True on success + */ + public function preflight($route, $adapter) + { + // set application to local method var, just use $this->app in future [we will drop $app in J6] + $app = $this->app; + + // the default for both install and update + $jversion = new Version(); + if (!$jversion->isCompatible('5.0.0')) + { + $app->enqueueMessage('Please upgrade to at least Joomla! 5.0.0 before continuing!', 'error'); + return false; + } + + // remove old files and folders + $this->removeFiles(); + + return true; + } + + /** + * Called before any type of action + * + * @param string $route Which action is happening (install|uninstall|discover_install|update) + * @param InstallerAdapter $adapter The object responsible for running this script + * + * @return boolean True on success + */ + public function postflight($route, $adapter) + { + // set application to local method var, just use $this->app in future [we will drop $app in J6] + $app = $this->app; + + return true; + } + + /** + * Remove the files and folders in the given array from + * + * @return void + * @since 5.0.2 + */ + protected function removeFiles() + { + if (!empty($this->deleteFiles)) + { + foreach ($this->deleteFiles as $file) + { + if (is_file(JPATH_ROOT . $file) && !File::delete(JPATH_ROOT . $file)) + { + echo Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $file) . '
'; + } + } + } + + if (!empty($this->deleteFolders)) + { + foreach ($this->deleteFolders as $folder) + { + if (is_dir(JPATH_ROOT . $folder) && !Folder::delete(JPATH_ROOT . $folder)) + { + echo Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $folder) . '
'; + } + } + } + } } diff --git a/services/index.html b/services/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/services/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/services/provider.php b/services/provider.php new file mode 100644 index 0000000..981565f --- /dev/null +++ b/services/provider.php @@ -0,0 +1,47 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +use Joomla\CMS\Factory; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Extension\PluginInterface; +use Joomla\Event\DispatcherInterface; +use Joomla\DI\ServiceProviderInterface; +use Joomla\DI\Container; +use VDM\Plugin\Extension\ComponentbuilderActionLogCompiler\Extension\ComponentbuilderActionLogCompiler; + +return new class () implements ServiceProviderInterface { + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 4.3.0 + */ + public function register(Container $container) + { + $container->set( + PluginInterface::class, + function (Container $container) { + $plugin = new ComponentbuilderActionLogCompiler( + $container->get(DispatcherInterface::class), + (array) PluginHelper::getPlugin('extension', 'componentbuilderactionlogcompiler') + ); + $plugin->setApplication(Factory::getApplication()); + + return $plugin; + } + ); + } +}; diff --git a/componentbuilderactionlogcompiler.php b/src/Extension/ComponentbuilderActionLogCompiler.php similarity index 94% rename from componentbuilderactionlogcompiler.php rename to src/Extension/ComponentbuilderActionLogCompiler.php index 61999e7..5e2be01 100644 --- a/componentbuilderactionlogcompiler.php +++ b/src/Extension/ComponentbuilderActionLogCompiler.php @@ -8,30 +8,35 @@ * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace VDM\Plugin\Extension\ComponentbuilderActionLogCompiler\Extension; -// No direct access to this file -defined('_JEXEC') or die('Restricted access'); - +// The power autoloader for this project (JPATH_ADMINISTRATOR) area. +$power_autoloader = JPATH_ADMINISTRATOR . '/components/com_componentbuilder/src/Helper/PowerloaderHelper.php'; +if (file_exists($power_autoloader)) +{ + require_once $power_autoloader; +} + use Joomla\CMS\Application\CMSApplication; use Joomla\CMS\Plugin\CMSPlugin; -use Joomla\Registry\Registry; -use VDM\Joomla\Utilities\ArrayHelper; -use VDM\Joomla\Componentbuilder\Compiler\Factory; - -JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'); - +use Joomla\Registry\Registry; use VDM\Joomla\Componentbuilder\Compiler\Factory as CFactory; use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix; use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent; -use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line; +use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line; +use VDM\Joomla\Utilities\ArrayHelper; +use Joomla\Event\SubscriberInterface; + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); /** * Extension - Componentbuilder ActionLog Compiler plugin. * * @package ComponentbuilderActionLogCompiler - * @since 2.0.0 + * @since 4.0.0 */ -class PlgExtensionComponentbuilderActionLogCompiler extends CMSPlugin +final class ComponentbuilderActionLogCompiler extends CMSPlugin implements SubscriberInterface { /** * Affects constructor behavior. If true, language files will be loaded automatically. @@ -537,9 +542,25 @@ class PlgExtensionComponentbuilderActionLogCompiler extends CMSPlugin // only check if there are active if (ArrayHelper::check($this->componentsActive)) { - return in_array((int) Factory::_('Config')->component_id, $this->componentsActive); + return in_array((int) CFactory::_('Config')->component_id, $this->componentsActive); } return false; } + + /** + * Returns an array of events this subscriber will listen to. + * + * @return array + * + * @since 5.0.0 + */ + public static function getSubscribedEvents(): array + { + return [ + 'jcb_ce_onAfterGetComponentData' => 'jcb_ce_onAfterGetComponentData', + 'jcb_ce_onAfterBuildFilesContent' => 'jcb_ce_onAfterBuildFilesContent', + 'jcb_ce_onAfterModelViewData' => 'jcb_ce_onAfterModelViewData' + ]; + } } diff --git a/src/Extension/index.html b/src/Extension/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/src/Extension/index.html @@ -0,0 +1 @@ + \ No newline at end of file