-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[4.0][CLI] Add a task to discover extensions #31524
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b94efea
discover
astridx 45a7321
correction
astridx 19a632d
correction
astridx 4a1e74f
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into d…
astridx 7a3958a
Update libraries/src/Console/ExtensionDiscoverCommand.php
laoneo 63a6bbb
pass the db thorugh the container
alikon c4797cf
pass db through container
alikon 0291467
Merge pull request #2 from alikon/patch-131
astridx 416b4c4
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into d…
astridx 0d4d36d
Merge branch 'discover' of https://github.com/astridx/joomla-cms into…
astridx b4ffab6
corrections
astridx 2ad5c5c
Clean up doc blocks
wilsonge 05ae5f1
New copyright format
wilsonge 037729f
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into d…
astridx 6888c3a
Update ExtensionDiscoverCommand.php
laoneo 638c3d5
Update Application.php
laoneo 20a590c
Update Console.php
laoneo a2e1326
ExtensionDiscoverInstall renamed to ExtensionDiscoverInstallCommand
alikon bf0ec1e
Merge branch 'discover' of https://github.com/astridx/joomla-cms into…
astridx d60d40c
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into d…
astridx 630e69f
Merge pull request #3 from alikon/patch-117
astridx 1381942
Merge branch 'discover' of https://github.com/astridx/joomla-cms into…
astridx 30130dc
correctin for discover all extensions, now it does not stopp, if one …
astridx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| <?php | ||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\CMS\Console; | ||
|
|
||
| \defined('JPATH_PLATFORM') or die; | ||
|
|
||
| use Joomla\CMS\Installer\Installer; | ||
| use Joomla\Console\Command\AbstractCommand; | ||
| use Joomla\Database\DatabaseInterface; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
|
||
| /** | ||
| * Console command for discovering extensions | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class ExtensionDiscoverCommand extends AbstractCommand | ||
| { | ||
| /** | ||
| * The default command name | ||
| * | ||
| * @var string | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected static $defaultName = 'extension:discover'; | ||
|
|
||
| /** | ||
| * Stores the Input Object | ||
| * @var InputInterface | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| private $cliInput; | ||
|
|
||
| /** | ||
| * SymfonyStyle Object | ||
| * @var SymfonyStyle | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| private $ioStyle; | ||
|
|
||
| /** | ||
| * Database connector | ||
| * | ||
| * @var DatabaseInterface | ||
| * @since 4.0.0 | ||
| */ | ||
| private $db; | ||
|
|
||
| /** | ||
| * Exit Code For Discover Failure | ||
| * @since | ||
| */ | ||
| public const DISCOVER_FAILED = 1; | ||
|
|
||
| /** | ||
| * Exit Code For Discover Success | ||
| * @since | ||
| */ | ||
| public const DISCOVER_SUCCESSFUL = 0; | ||
|
|
||
| /** | ||
| * Instantiate the command. | ||
| * | ||
| * @param DatabaseInterface $db Database connector | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| public function __construct(DatabaseInterface $db) | ||
| { | ||
| $this->db = $db; | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * Configures the IO | ||
| * | ||
| * @param InputInterface $input Console Input | ||
| * @param OutputInterface $output Console Output | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| * | ||
| */ | ||
| private function configureIO(InputInterface $input, OutputInterface $output): void | ||
| { | ||
| $this->cliInput = $input; | ||
| $this->ioStyle = new SymfonyStyle($input, $output); | ||
| } | ||
|
|
||
| /** | ||
| * Initialise the command. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function configure(): void | ||
| { | ||
| $this->addOption('eid', null, InputOption::VALUE_REQUIRED, 'The ID of the extension to discover'); | ||
|
|
||
| $help = "<info>%command.name%</info> is used to discover extensions | ||
| \nYou can provide the following option to the command: | ||
| \n --eid: The ID of the extension | ||
| \nUsage: | ||
| \n <info>php %command.full_name% --eid=<id_of_the_extension></info>"; | ||
|
|
||
| $this->setDescription('Discover all extensions or a specified extension'); | ||
| $this->setHelp($help); | ||
| } | ||
|
|
||
| /** | ||
| * Used for discovering extensions | ||
| * | ||
| * @param string $eid Id of the extension | ||
| * | ||
| * @return boolean | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| * | ||
| * @throws \Exception | ||
| */ | ||
| public function processDiscover($eid): bool | ||
| { | ||
| $jInstaller = new Installer; | ||
|
|
||
| if ($eid === -1) | ||
| { | ||
| $db = $this->db; | ||
| $query = $db->getQuery(true) | ||
| ->select($db->quoteName(['extension_id'])) | ||
| ->from($db->quoteName('#__extensions')) | ||
| ->where($db->quoteName('state') . ' = -1'); | ||
| $db->setQuery($query); | ||
| $eidsToDiscover = $db->loadObjectList(); | ||
|
|
||
| foreach ($eidsToDiscover as $eidToDiscover) | ||
| { | ||
| if (!$jInstaller->discover_install($eidToDiscover->extension_id)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| $this->ioStyle->warning('There is no extension to discover.'); | ||
|
|
||
| return true; | ||
| } | ||
| else | ||
| { | ||
| return $jInstaller->discover_install($eid); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Internal function to execute the command. | ||
| * | ||
| * @param InputInterface $input The input to inject into the command. | ||
| * @param OutputInterface $output The output to inject into the command. | ||
| * | ||
| * @return integer The command exit code | ||
| * | ||
| * @throws \Exception | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function doExecute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| $this->configureIO($input, $output); | ||
|
|
||
| if ($eid = $this->cliInput->getOption('eid')) | ||
| { | ||
| $result = $this->processDiscover($eid); | ||
|
|
||
| if (!$result) | ||
| { | ||
| $this->ioStyle->error('Unable to discover extension with ID ' . $eid); | ||
|
|
||
| return self::DISCOVER_FAILED; | ||
| } | ||
|
|
||
| $this->ioStyle->success('Extension with ID ' . $eid . ' discovered successfully.'); | ||
|
|
||
| return self::DISCOVER_SUCCESSFUL; | ||
| } | ||
| else | ||
| { | ||
| $result = $this->processDiscover(-1); | ||
|
|
||
| if (!$result) | ||
| { | ||
| $this->ioStyle->error('Unable to discover all extensions'); | ||
|
|
||
| return self::DISCOVER_FAILED; | ||
| } | ||
|
|
||
| $this->ioStyle->success('All extensions discovered successfully.'); | ||
|
|
||
| return self::DISCOVER_SUCCESSFUL; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also inject the installer the same way as the database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installer isn’t available in the container. So I think we should make it optionally injectable in the constructor for testing. But still fine to run the init in the constructor if nothing is passed in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create the instance in the serviceprovider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laoneo @wilsonge
I would like to leave it that way in this PR because it is implemented in the same way in other places.
For example here:
joomla-cms/libraries/src/Console/ExtensionInstallCommand.php
Line 132 in fc55f96
I think it is confusing when things are different in a CMS. I agree with you that it should be changed. But then in all places. I would do this in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can do then a followup pr.