Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b94efea
discover
astridx Nov 28, 2020
45a7321
correction
astridx Nov 29, 2020
19a632d
correction
astridx Nov 29, 2020
4a1e74f
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into d…
astridx Nov 29, 2020
7a3958a
Update libraries/src/Console/ExtensionDiscoverCommand.php
laoneo Nov 29, 2020
63a6bbb
pass the db thorugh the container
alikon Nov 30, 2020
c4797cf
pass db through container
alikon Nov 30, 2020
0291467
Merge pull request #2 from alikon/patch-131
astridx Nov 30, 2020
416b4c4
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into d…
astridx Nov 30, 2020
0d4d36d
Merge branch 'discover' of https://github.com/astridx/joomla-cms into…
astridx Nov 30, 2020
b4ffab6
corrections
astridx Nov 30, 2020
2ad5c5c
Clean up doc blocks
wilsonge Dec 1, 2020
05ae5f1
New copyright format
wilsonge Dec 1, 2020
037729f
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into d…
astridx Dec 7, 2020
6888c3a
Update ExtensionDiscoverCommand.php
laoneo Dec 22, 2020
638c3d5
Update Application.php
laoneo Dec 22, 2020
20a590c
Update Console.php
laoneo Dec 22, 2020
a2e1326
ExtensionDiscoverInstall renamed to ExtensionDiscoverInstallCommand
alikon Dec 23, 2020
bf0ec1e
Merge branch 'discover' of https://github.com/astridx/joomla-cms into…
astridx Dec 23, 2020
d60d40c
Merge branch '4.0-dev' of https://github.com/joomla/joomla-cms into d…
astridx Dec 23, 2020
630e69f
Merge pull request #3 from alikon/patch-117
astridx Dec 23, 2020
1381942
Merge branch 'discover' of https://github.com/astridx/joomla-cms into…
astridx Dec 23, 2020
30130dc
correctin for discover all extensions, now it does not stopp, if one …
astridx Dec 23, 2020
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
212 changes: 212 additions & 0 deletions libraries/src/Console/ExtensionDiscoverCommand.php
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;

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

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:

$jInstaller = Installer::getInstance();

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.

Copy link
Copy Markdown
Member

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.


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;
}
}
}
2 changes: 2 additions & 0 deletions libraries/src/Service/Provider/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Console\CheckJoomlaUpdatesCommand;
use Joomla\CMS\Console\ExtensionInstallCommand;
use Joomla\CMS\Console\ExtensionDiscoverCommand;
use Joomla\CMS\Console\ExtensionRemoveCommand;
use Joomla\CMS\Console\ExtensionsListCommand;
use Joomla\CMS\Console\FinderIndexCommand;
Expand Down Expand Up @@ -157,6 +158,7 @@ function (Container $container)
CheckJoomlaUpdatesCommand::getDefaultName() => CheckJoomlaUpdatesCommand::class,
ExtensionRemoveCommand::getDefaultName() => ExtensionRemoveCommand::class,
ExtensionInstallCommand::getDefaultName() => ExtensionInstallCommand::class,
ExtensionDiscoverCommand::getDefaultName() => ExtensionDiscoverCommand::class,
UpdateCoreCommand::getDefaultName() => UpdateCoreCommand::class,
FinderIndexCommand::getDefaultName() => FinderIndexCommand::class,
];
Expand Down
10 changes: 10 additions & 0 deletions libraries/src/Service/Provider/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Joomla\CMS\Console\CheckJoomlaUpdatesCommand;
use Joomla\CMS\Console\ExtensionInstallCommand;
use Joomla\CMS\Console\ExtensionDiscoverCommand;
use Joomla\CMS\Console\ExtensionRemoveCommand;
use Joomla\CMS\Console\ExtensionsListCommand;
use Joomla\CMS\Console\FinderIndexCommand;
Expand Down Expand Up @@ -162,6 +163,15 @@ function (Container $container)
true
);

$container->share(
ExtensionDiscoverCommand::class,
function (Container $container)
{
return new ExtensionDiscoverCommand($container->get('db'));
},
true
);

$container->share(
UpdateCoreCommand::class,
function (Container $container)
Expand Down