Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
218 changes: 218 additions & 0 deletions libraries/src/Console/ExtensionDiscoverInstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
<?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 ExtensionDiscoverInstallCommand extends AbstractCommand
{
/**
* The default command name
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected static $defaultName = 'extension:discoverinstall';

/**
* 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 __DEPLOY_VERSION__
*/
public const DISCOVER_FAILED = 1;

/**
* Exit Code For Discover Success
*
* @since __DEPLOY_VERSION__
*/
public const DISCOVER_SUCCESSFUL = 0;

/**
* Instantiate the command.
*
* @param DatabaseInterface $db Database connector
*
* @since __DEPLOY_VERSION__
*/
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 and install all extensions or a specified extension');
$this->setHelp($help);
}

/**
* Used for discovering extensions
*
* @param string $eid Id of the extension
*
* @return boolean
*
* @throws \Exception
* @since __DEPLOY_VERSION__
*/
public function processDiscover($eid): bool
{
$jInstaller = new Installer;
$result = true;

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))
{
$this->ioStyle->warning('There was a problem installing the extension with ID ' . $eidToDiscover->extension_id . '.');
$result = false;
}
}

if (empty($eidsToDiscover))
{
$this->ioStyle->warning('There is no extension to discover and install.');
}

return $result;
}
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 and install the extension with ID ' . $eid);

return self::DISCOVER_FAILED;
}

$this->ioStyle->success('Extension with ID ' . $eid . ' discovered and installed successfully.');

return self::DISCOVER_SUCCESSFUL;
}
else
{
$result = $this->processDiscover(-1);

if (!$result)
{
$this->ioStyle->error('Unable to discover and install all extensions');

return self::DISCOVER_FAILED;
}

$this->ioStyle->success('All extensions discovered and installed successfully.');

return self::DISCOVER_SUCCESSFUL;
}
}
}
30 changes: 16 additions & 14 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\ExtensionDiscoverInstallCommand;
use Joomla\CMS\Console\ExtensionRemoveCommand;
use Joomla\CMS\Console\ExtensionsListCommand;
use Joomla\CMS\Console\FinderIndexCommand;
Expand Down Expand Up @@ -145,20 +146,21 @@ function (Container $container)
function (Container $container)
{
$mapping = [
SessionGcCommand::getDefaultName() => SessionGcCommand::class,
SessionMetadataGcCommand::getDefaultName() => SessionMetadataGcCommand::class,
ExportCommand::getDefaultName() => ExportCommand::class,
ImportCommand::getDefaultName() => ImportCommand::class,
SiteDownCommand::getDefaultName() => SiteDownCommand::class,
SiteUpCommand::getDefaultName() => SiteUpCommand::class,
SetConfigurationCommand::getDefaultName() => SetConfigurationCommand::class,
GetConfigurationCommand::getDefaultName() => GetConfigurationCommand::class,
ExtensionsListCommand::getDefaultName() => ExtensionsListCommand::class,
CheckJoomlaUpdatesCommand::getDefaultName() => CheckJoomlaUpdatesCommand::class,
ExtensionRemoveCommand::getDefaultName() => ExtensionRemoveCommand::class,
ExtensionInstallCommand::getDefaultName() => ExtensionInstallCommand::class,
UpdateCoreCommand::getDefaultName() => UpdateCoreCommand::class,
FinderIndexCommand::getDefaultName() => FinderIndexCommand::class,
SessionGcCommand::getDefaultName() => SessionGcCommand::class,
SessionMetadataGcCommand::getDefaultName() => SessionMetadataGcCommand::class,
ExportCommand::getDefaultName() => ExportCommand::class,
ImportCommand::getDefaultName() => ImportCommand::class,
SiteDownCommand::getDefaultName() => SiteDownCommand::class,
SiteUpCommand::getDefaultName() => SiteUpCommand::class,
SetConfigurationCommand::getDefaultName() => SetConfigurationCommand::class,
GetConfigurationCommand::getDefaultName() => GetConfigurationCommand::class,
ExtensionsListCommand::getDefaultName() => ExtensionsListCommand::class,
CheckJoomlaUpdatesCommand::getDefaultName() => CheckJoomlaUpdatesCommand::class,
ExtensionRemoveCommand::getDefaultName() => ExtensionRemoveCommand::class,
ExtensionInstallCommand::getDefaultName() => ExtensionInstallCommand::class,
ExtensionDiscoverInstallCommand::getDefaultName() => ExtensionDiscoverInstallCommand::class,
UpdateCoreCommand::getDefaultName() => UpdateCoreCommand::class,
FinderIndexCommand::getDefaultName() => FinderIndexCommand::class,
];

return new WritableContainerLoader($container, $mapping);
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\ExtensionDiscoverInstallCommand;
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(
ExtensionDiscoverInstallCommand::class,
function (Container $container)
{
return new ExtensionDiscoverInstallCommand($container->get('db'));
},
true
);

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