From 690baa5dc86bde05c17e1e204e2f298d3fb2c511 Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Fri, 20 May 2022 15:28:58 +0300 Subject: [PATCH 1/8] Package filter in the Extensions: Manage page --- .../com_installer/forms/filter_manage.xml | 10 ++++ .../com_installer/src/Field/PackageField.php | 37 ++++++++++++ .../src/Helper/InstallerHelper.php | 59 +++++++++++++++++++ .../com_installer/src/Model/ManageModel.php | 23 ++++++-- .../language/en-GB/com_installer.ini | 3 + 5 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 administrator/components/com_installer/src/Field/PackageField.php diff --git a/administrator/components/com_installer/forms/filter_manage.xml b/administrator/components/com_installer/forms/filter_manage.xml index 950370ea07c6a..892e22669aeb9 100644 --- a/administrator/components/com_installer/forms/filter_manage.xml +++ b/administrator/components/com_installer/forms/filter_manage.xml @@ -28,6 +28,16 @@ + + + + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\Component\Installer\Administrator\Field; + +use Joomla\CMS\Form\Field\ListField; +use Joomla\Component\Installer\Administrator\Helper\InstallerHelper; + +/** + * Package field. + * + * Selects the extension ID of an extension of the "package" type. + * + * @since __DEPLOY_VERSION__ + */ +class PackageField extends ListField +{ + /** + * Method to get the field options. + * + * @return array The field option objects. + * @since __DEPLOY_VERSION__ + */ + protected function getOptions() + { + $options = InstallerHelper::getPackageOptions(); + + return array_merge($options, parent::getOptions()); + } + +} diff --git a/administrator/components/com_installer/src/Helper/InstallerHelper.php b/administrator/components/com_installer/src/Helper/InstallerHelper.php index 83c7f39d6efa9..86118dcbc02da 100644 --- a/administrator/components/com_installer/src/Helper/InstallerHelper.php +++ b/administrator/components/com_installer/src/Helper/InstallerHelper.php @@ -16,6 +16,7 @@ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Object\CMSObject; +use Joomla\Database\DatabaseDriver; use Joomla\Database\ParameterType; use SimpleXMLElement; @@ -119,6 +120,64 @@ public static function getStateOptions() return $options; } + /** + * Get a list of filter options for extensions of the "package" type. + * + * @return array + * @since __DEPLOY_VERSION__ + */ + public static function getPackageOptions(): array + { + $options = []; + + /** @var DatabaseDriver $db The application's database driver object */ + $db = Factory::getContainer()->get('DatabaseDriver'); + $query = $db->getQuery(true) + ->select( + [ + $db->quoteName('extension_id'), + $db->quoteName('name'), + $db->quoteName('element') + ] + ) + ->from($db->quoteName('#__extensions')) + ->where($db->quoteName('type') . ' = ' . $db->quote('package')); + $extensions = $db->setQuery($query)->loadObjectList() ?: []; + + if (empty($extensions)) + { + return $options; + } + + $language = Factory::getApplication()->getLanguage(); + $arrayKeys = array_map( + function (object $entry) use ($language): string + { + $language->load($entry->element, JPATH_ADMINISTRATOR); + + return Text::_($entry->name); + }, + $extensions + ); + $arrayValues = array_map( + function (object $entry): int + { + return $entry->extension_id; + }, + $extensions + ); + + $extensions = array_combine($arrayKeys, $arrayValues); + ksort($extensions); + + foreach ($extensions as $label => $id) + { + $options[] = HTMLHelper::_('select.option', $id, $label); + } + + return $options; + } + /** * Get a list of filter options for the application statuses. * diff --git a/administrator/components/com_installer/src/Model/ManageModel.php b/administrator/components/com_installer/src/Model/ManageModel.php index 7d43ecc26dd4e..df2c255eb2eaa 100644 --- a/administrator/components/com_installer/src/Model/ManageModel.php +++ b/administrator/components/com_installer/src/Model/ManageModel.php @@ -80,6 +80,7 @@ protected function populateState($ordering = 'name', $direction = 'asc') // Load the filter state. $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); $this->setState('filter.client_id', $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', null, 'int')); + $this->setState('filter.package_id', $this->getUserStateFromRequest($this->context . '.filter.package_id', 'filter_package_id', null, 'int')); $this->setState('filter.status', $this->getUserStateFromRequest($this->context . '.filter.status', 'filter_status', '', 'string')); $this->setState('filter.type', $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string')); $this->setState('filter.folder', $this->getUserStateFromRequest($this->context . '.filter.folder', 'filter_folder', '', 'string')); @@ -329,11 +330,12 @@ protected function getListQuery() ->where('state = 0'); // Process select filters. - $status = $this->getState('filter.status', ''); - $type = $this->getState('filter.type'); - $clientId = $this->getState('filter.client_id', ''); - $folder = $this->getState('filter.folder'); - $core = $this->getState('filter.core', ''); + $status = $this->getState('filter.status', ''); + $type = $this->getState('filter.type'); + $clientId = $this->getState('filter.client_id', ''); + $folder = $this->getState('filter.folder'); + $core = $this->getState('filter.core', ''); + $packageId = $this->getState('filter.package_id', ''); if ($status !== '') { @@ -367,6 +369,17 @@ protected function getListQuery() ->bind(':clientid', $clientId, ParameterType::INTEGER); } + if ($packageId !== '') + { + $packageId = (int) $packageId; + $query->where( + '((' . $db->quoteName('package_id') . ' = :package_id) OR ' + . '(' . $db->quoteName('extension_id') . ' = :package_id_2))' + ) + ->bind(':package_id', $packageId, ParameterType::INTEGER) + ->bind(':package_id_2', $packageId, ParameterType::INTEGER); + } + if ($folder) { $folder = $folder === '*' ? '' : $folder; diff --git a/administrator/language/en-GB/com_installer.ini b/administrator/language/en-GB/com_installer.ini index 7ecb634a9d45a..17363b737533a 100644 --- a/administrator/language/en-GB/com_installer.ini +++ b/administrator/language/en-GB/com_installer.ini @@ -102,6 +102,8 @@ COM_INSTALLER_LANGUAGES_AVAILABLE_LANGUAGES="Available Languages" COM_INSTALLER_LANGUAGES_FILTER_SEARCH_DESC="Search in language name and language tag." COM_INSTALLER_LANGUAGES_FILTER_SEARCH_LABEL="Search Languages" COM_INSTALLER_LANGUAGES_TABLE_CAPTION="Table of Available Languages" +COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_LABEL="Package" +COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_DESC="Search for a package extension and extensions included with that package extension." COM_INSTALLER_MANAGE_FILTER_SEARCH_DESC="Search in extension name. Prefix with ID: to search for an extension ID." COM_INSTALLER_MANAGE_FILTER_SEARCH_LABEL="Search Extensions" COM_INSTALLER_MANAGE_TABLE_CAPTION="Table of Extensions" @@ -280,6 +282,7 @@ COM_INSTALLER_VALUE_CORE_SELECT="- Select Extensions -" COM_INSTALLER_VALUE_CORE_YES="Core Extensions" COM_INSTALLER_VALUE_FOLDER_NONAPPLICABLE="N/A" COM_INSTALLER_VALUE_FOLDER_SELECT="- Select Folder -" +COM_INSTALLER_VALUE_PACKAGE_ID_SELECT="- Package -" COM_INSTALLER_VALUE_STATE_SELECT="- Select Status -" COM_INSTALLER_VALUE_SUPPORTED_EXISTS="Download Key valid" COM_INSTALLER_VALUE_SUPPORTED_MISSING="Download Key invalid" From d27a78c1bcb4b9c622cf7e7a2715644617a5166b Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Fri, 20 May 2022 17:35:36 +0300 Subject: [PATCH 2/8] Update administrator/components/com_installer/forms/filter_manage.xml Co-authored-by: Konstantin Kolos --- administrator/components/com_installer/forms/filter_manage.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_installer/forms/filter_manage.xml b/administrator/components/com_installer/forms/filter_manage.xml index 892e22669aeb9..fd2971720f916 100644 --- a/administrator/components/com_installer/forms/filter_manage.xml +++ b/administrator/components/com_installer/forms/filter_manage.xml @@ -32,7 +32,7 @@ name="package_id" type="package" label="COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_LABEL" - desc="COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_DESC" + description="COM_INSTALLER_MANAGE_FILTER_PACKAGE_ID_DESC" onchange="this.form.submit();" > From 39284209e15c30d68084833e11e0c181c9819911 Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Sat, 21 May 2022 10:15:44 +0300 Subject: [PATCH 3/8] Update administrator/components/com_installer/src/Field/PackageField.php Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com> --- .../components/com_installer/src/Field/PackageField.php | 1 - 1 file changed, 1 deletion(-) diff --git a/administrator/components/com_installer/src/Field/PackageField.php b/administrator/components/com_installer/src/Field/PackageField.php index f15495129744c..376a4647f92ad 100644 --- a/administrator/components/com_installer/src/Field/PackageField.php +++ b/administrator/components/com_installer/src/Field/PackageField.php @@ -33,5 +33,4 @@ protected function getOptions() return array_merge($options, parent::getOptions()); } - } From 21fcb920c303ffb55c3f99f9245bfbb9f9751320 Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Sat, 21 May 2022 10:18:24 +0300 Subject: [PATCH 4/8] Update administrator/components/com_installer/src/Helper/InstallerHelper.php Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com> --- .../components/com_installer/src/Helper/InstallerHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_installer/src/Helper/InstallerHelper.php b/administrator/components/com_installer/src/Helper/InstallerHelper.php index 86118dcbc02da..a6c8556edd488 100644 --- a/administrator/components/com_installer/src/Helper/InstallerHelper.php +++ b/administrator/components/com_installer/src/Helper/InstallerHelper.php @@ -131,7 +131,7 @@ public static function getPackageOptions(): array $options = []; /** @var DatabaseDriver $db The application's database driver object */ - $db = Factory::getContainer()->get('DatabaseDriver'); + $db = Factory::getContainer()->get(DatabaseDriver::class); $query = $db->getQuery(true) ->select( [ From 4f44c42c4df88f9a61db3bc59ba4107aadbfa9f4 Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Sat, 21 May 2022 10:18:42 +0300 Subject: [PATCH 5/8] Update administrator/components/com_installer/src/Model/ManageModel.php Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com> --- .../components/com_installer/src/Model/ManageModel.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/administrator/components/com_installer/src/Model/ManageModel.php b/administrator/components/com_installer/src/Model/ManageModel.php index df2c255eb2eaa..159ecf767ad94 100644 --- a/administrator/components/com_installer/src/Model/ManageModel.php +++ b/administrator/components/com_installer/src/Model/ManageModel.php @@ -373,11 +373,10 @@ protected function getListQuery() { $packageId = (int) $packageId; $query->where( - '((' . $db->quoteName('package_id') . ' = :package_id) OR ' - . '(' . $db->quoteName('extension_id') . ' = :package_id_2))' + '((' . $db->quoteName('package_id') . ' = :packageId1) OR ' + . '(' . $db->quoteName('extension_id') . ' = :packageId2))' ) - ->bind(':package_id', $packageId, ParameterType::INTEGER) - ->bind(':package_id_2', $packageId, ParameterType::INTEGER); + ->bind([':packageId1',':packageId2'], $packageId, ParameterType::INTEGER); } if ($folder) From d77fffb9f8242b84fe46e36c6247954ffb0223a0 Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Sat, 21 May 2022 10:20:52 +0300 Subject: [PATCH 6/8] Update administrator/components/com_installer/src/Helper/InstallerHelper.php Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com> --- .../com_installer/src/Helper/InstallerHelper.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/administrator/components/com_installer/src/Helper/InstallerHelper.php b/administrator/components/com_installer/src/Helper/InstallerHelper.php index a6c8556edd488..501b9adec5642 100644 --- a/administrator/components/com_installer/src/Helper/InstallerHelper.php +++ b/administrator/components/com_installer/src/Helper/InstallerHelper.php @@ -134,11 +134,13 @@ public static function getPackageOptions(): array $db = Factory::getContainer()->get(DatabaseDriver::class); $query = $db->getQuery(true) ->select( - [ - $db->quoteName('extension_id'), - $db->quoteName('name'), - $db->quoteName('element') - ] + $db->quoteName( + [ + 'extension_id', + 'name', + 'element', + ] + ) ) ->from($db->quoteName('#__extensions')) ->where($db->quoteName('type') . ' = ' . $db->quote('package')); From 3290ad53b1c4dadb0e791a855c2a51f51669e40c Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Sat, 21 May 2022 10:29:45 +0300 Subject: [PATCH 7/8] Update administrator/components/com_installer/src/Field/PackageField.php Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com> --- .../components/com_installer/src/Field/PackageField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_installer/src/Field/PackageField.php b/administrator/components/com_installer/src/Field/PackageField.php index 376a4647f92ad..63266de98edf4 100644 --- a/administrator/components/com_installer/src/Field/PackageField.php +++ b/administrator/components/com_installer/src/Field/PackageField.php @@ -31,6 +31,6 @@ protected function getOptions() { $options = InstallerHelper::getPackageOptions(); - return array_merge($options, parent::getOptions()); + return array_merge(parent::getOptions(), $options); } } From 7473cca7b59cc2990798ee9c0b8cf08b4c6a28d8 Mon Sep 17 00:00:00 2001 From: "Nicholas K. Dionysopoulos" Date: Sat, 21 May 2022 11:35:35 +0300 Subject: [PATCH 8/8] Update administrator/language/en-GB/com_installer.ini Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com> --- administrator/language/en-GB/com_installer.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/language/en-GB/com_installer.ini b/administrator/language/en-GB/com_installer.ini index 17363b737533a..7012fa0c5d09e 100644 --- a/administrator/language/en-GB/com_installer.ini +++ b/administrator/language/en-GB/com_installer.ini @@ -282,7 +282,7 @@ COM_INSTALLER_VALUE_CORE_SELECT="- Select Extensions -" COM_INSTALLER_VALUE_CORE_YES="Core Extensions" COM_INSTALLER_VALUE_FOLDER_NONAPPLICABLE="N/A" COM_INSTALLER_VALUE_FOLDER_SELECT="- Select Folder -" -COM_INSTALLER_VALUE_PACKAGE_ID_SELECT="- Package -" +COM_INSTALLER_VALUE_PACKAGE_ID_SELECT="- Select Package -" COM_INSTALLER_VALUE_STATE_SELECT="- Select Status -" COM_INSTALLER_VALUE_SUPPORTED_EXISTS="Download Key valid" COM_INSTALLER_VALUE_SUPPORTED_MISSING="Download Key invalid"