Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert installer plugins to service providers #40146

Merged
merged 10 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cypress.config.dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = defineConfig({
specPattern: [
'tests/cypress/integration/install/*.cy.{js,jsx,ts,tsx}',
'tests/cypress/integration/administrator/**/*.cy.{js,jsx,ts,tsx}',
'tests/cypress/integration/site/**/*.cy.{js,jsx,ts,tsx}'
'tests/cypress/integration/site/**/*.cy.{js,jsx,ts,tsx}',
'tests/cypress/integration/plugins/**/*.cy.{js,jsx,ts,tsx}',
],
supportFile: 'tests/cypress/support/index.js',
scrollBehavior: 'center',
Expand Down
7 changes: 4 additions & 3 deletions plugins/installer/folderinstaller/folderinstaller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.6.0</version>
<description>PLG_INSTALLER_FOLDERINSTALLER_PLUGIN_XML_DESCRIPTION</description>

<namespace path="src">Joomla\Plugin\Installer\Folder</namespace>
<files>
<filename plugin="folderinstaller">folderinstaller.php</filename>
<folder plugin="folderinstaller">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>

<languages>
<language tag="en-GB">language/en-GB/plg_installer_folderinstaller.ini</language>
<language tag="en-GB">language/en-GB/plg_installer_folderinstaller.sys.ini</language>
Expand Down
47 changes: 47 additions & 0 deletions plugins/installer/folderinstaller/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Installer.folderinstaller
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Installer\Folder\Extension\FolderInstaller;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new FolderInstaller(
$dispatcher,
(array) PluginHelper::getPlugin('installer', 'folderinstaller')
);
$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

/**
* @package Joomla.Plugin
* @subpackage Installer.folderInstaller
* @subpackage Installer.folderinstaller
*
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt

* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

use Joomla\CMS\Language\Text;
namespace Joomla\Plugin\Installer\Folder\Extension;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;

Expand All @@ -23,13 +22,14 @@
*
* @since 3.6.0
*/
class PlgInstallerFolderInstaller extends CMSPlugin
final class FolderInstaller extends CMSPlugin
{
/**
* Application object.
*
* @var \Joomla\CMS\Application\CMSApplication
* @since 4.0.0
* @deprecated 5.0 Is needed for template overrides, use getApplication instead
laoneo marked this conversation as resolved.
Show resolved Hide resolved
*/
protected $app;

Expand All @@ -47,7 +47,7 @@ public function onInstallerAddInstallationTab()

$tab = [];
$tab['name'] = 'folder';
$tab['label'] = Text::_('PLG_INSTALLER_FOLDERINSTALLER_TEXT');
$tab['label'] = $this->getApplication()->getLanguage()->_('PLG_INSTALLER_FOLDERINSTALLER_TEXT');

// Render the input
ob_start();
Expand Down
4 changes: 2 additions & 2 deletions plugins/installer/folderinstaller/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

Text::script('PLG_INSTALLER_FOLDERINSTALLER_NO_INSTALL_PATH');

$this->app->getDocument()->getWebAssetManager()
$this->getApplication()->getDocument()->getWebAssetManager()
laoneo marked this conversation as resolved.
Show resolved Hide resolved
->registerAndUseScript(
'plg_installer_folderinstaller.folderinstaller',
'plg_installer_folderinstaller/folderinstaller.js',
Expand All @@ -34,7 +34,7 @@
</label>
<div class="controls">
<input type="text" id="install_directory" name="install_directory" class="form-control"
value="<?php echo $this->app->getInput()->get('install_directory', $this->app->get('tmp_path')); ?>">
value="<?php echo $this->getApplication()->getInput()->get('install_directory', $this->getApplication()->get('tmp_path')); ?>">
</div>
</div>
<div class="control-group">
Expand Down
4 changes: 3 additions & 1 deletion plugins/installer/override/override.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>4.0.0</version>
<description>PLG_INSTALLER_OVERRIDE_PLUGIN_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Installer\Override</namespace>
<files>
<filename plugin="override">override.php</filename>
<folder plugin="override">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_installer_override.ini</language>
Expand Down
49 changes: 49 additions & 0 deletions plugins/installer/override/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Installer.override
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Installer\Override\Extension\Override;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Override(
$dispatcher,
(array) PluginHelper::getPlugin('installer', 'override')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt

* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

use Joomla\CMS\Application\CMSApplicationInterface;
namespace Joomla\Plugin\Installer\Override\Extension;

use Joomla\CMS\Date\Date;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\ParameterType;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -25,14 +25,9 @@
*
* @since 4.0.0
*/
class PlgInstallerOverride extends CMSPlugin
final class Override extends CMSPlugin
{
/**
* Application object.
*
* @var CMSApplicationInterface
*/
protected $app;
use DatabaseAwareTrait;

/**
* Load the language file on instantiation.
Expand All @@ -43,14 +38,6 @@ class PlgInstallerOverride extends CMSPlugin
*/
protected $autoloadLanguage = true;

/**
* Database object
*
* @var \Joomla\Database\DatabaseInterface
* @since 4.0.0
*/
protected $db;

/**
* Method to get com_templates model instance.
*
Expand All @@ -66,7 +53,7 @@ class PlgInstallerOverride extends CMSPlugin
public function getModel($name = 'Template', $prefix = 'Administrator')
{
/** @var \Joomla\Component\Templates\Administrator\Extension\TemplatesComponent $templateProvider */
$templateProvider = $this->app->bootComponent('com_templates');
$templateProvider = $this->getApplication()->bootComponent('com_templates');

/** @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
$model = $templateProvider->getMVCFactory()->createModel($name, $prefix);
Expand All @@ -84,7 +71,7 @@ public function getModel($name = 'Template', $prefix = 'Administrator')
public function purge()
{
// Delete stored session value.
$session = $this->app->getSession();
$session = $this->getApplication()->getSession();
$session->remove('override.beforeEventFiles');
$session->remove('override.afterEventFiles');
}
Expand All @@ -103,7 +90,7 @@ public function storeBeforeEventFiles()

// Get list and store in session.
$list = $this->getOverrideCoreList();
$this->app->getSession()->set('override.beforeEventFiles', $list);
$this->getApplication()->getSession()->set('override.beforeEventFiles', $list);
}

/**
Expand All @@ -117,7 +104,7 @@ public function storeAfterEventFiles()
{
// Get list and store in session.
$list = $this->getOverrideCoreList();
$this->app->getSession()->set('override.afterEventFiles', $list);
$this->getApplication()->getSession()->set('override.afterEventFiles', $list);
}

/**
Expand All @@ -131,7 +118,7 @@ public function storeAfterEventFiles()
*/
public function getUpdatedFiles($action)
{
$session = $this->app->getSession();
$session = $this->getApplication()->getSession();

$after = $session->get('override.afterEventFiles');
$before = $session->get('override.beforeEventFiles');
Expand Down Expand Up @@ -190,7 +177,7 @@ public function finalize($result)
$link = 'index.php?option=com_templates&view=templates';

if ($num != 0) {
$this->app->enqueueMessage(Text::plural('PLG_INSTALLER_OVERRIDE_N_FILE_UPDATED', $num, $link), 'notice');
$this->getApplication()->enqueueMessage(Text::plural('PLG_INSTALLER_OVERRIDE_N_FILE_UPDATED', $num, $link), 'notice');
$this->saveOverrides($result);
}

Expand Down Expand Up @@ -288,7 +275,7 @@ public function onInstallerAfterInstaller()
*/
public function load($id, $exid)
{
$db = $this->db;
$db = $this->getDatabase();

// Create a new query object.
$query = $db->getQuery(true);
Expand Down Expand Up @@ -335,10 +322,12 @@ private function saveOverrides($pks)
'client_id',
];

$db = $this->getDatabase();

// Create an insert query.
$insertQuery = $this->db->getQuery(true)
->insert($this->db->quoteName('#__template_overrides'))
->columns($this->db->quoteName($columns));
$insertQuery = $db->getQuery(true)
->insert($db->quoteName('#__template_overrides'))
->columns($db->quoteName($columns));

foreach ($pks as $pk) {
$date = new Date('now');
Expand All @@ -351,25 +340,25 @@ private function saveOverrides($pks)
}

if ($this->load($pk->id, $pk->extension_id)) {
$updateQuery = $this->db->getQuery(true)
->update($this->db->quoteName('#__template_overrides'))
$updateQuery = $db->getQuery(true)
->update($db->quoteName('#__template_overrides'))
->set(
[
$this->db->quoteName('modified_date') . ' = :modifiedDate',
$this->db->quoteName('action') . ' = :pkAction',
$this->db->quoteName('state') . ' = 0',
$db->quoteName('modified_date') . ' = :modifiedDate',
$db->quoteName('action') . ' = :pkAction',
$db->quoteName('state') . ' = 0',
]
)
->where($this->db->quoteName('hash_id') . ' = :pkId')
->where($this->db->quoteName('extension_id') . ' = :exId')
->where($db->quoteName('hash_id') . ' = :pkId')
->where($db->quoteName('extension_id') . ' = :exId')
->bind(':modifiedDate', $modifiedDate)
->bind(':pkAction', $pk->action)
->bind(':pkId', $pk->id)
->bind(':exId', $pk->extension_id, ParameterType::INTEGER);

// Set the query using our newly populated query object and execute it.
$this->db->setQuery($updateQuery);
$this->db->execute();
$db->setQuery($updateQuery);
$db->execute();

continue;
}
Expand Down Expand Up @@ -402,8 +391,8 @@ private function saveOverrides($pks)
}

if (!empty($bindArray)) {
$this->db->setQuery($insertQuery);
$this->db->execute();
$db->setQuery($insertQuery);
$db->execute();
}
}
}
7 changes: 4 additions & 3 deletions plugins/installer/packageinstaller/packageinstaller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.6.0</version>
<description>PLG_INSTALLER_PACKAGEINSTALLER_PLUGIN_XML_DESCRIPTION</description>

<namespace path="src">Joomla\Plugin\Installer\Package</namespace>
<files>
<filename plugin="packageinstaller">packageinstaller.php</filename>
<folder plugin="packageinstaller">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>

<languages>
<language tag="en-GB">language/en-GB/plg_installer_packageinstaller.ini</language>
<language tag="en-GB">language/en-GB/plg_installer_packageinstaller.sys.ini</language>
Expand Down
Loading