Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function populateState($ordering = 'name', $direction = 'asc')
/**
* Method to get the database query.
*
* @return DatabaseQuery the database query
* @return DatabaseQuery The database query
*
* @since 3.1
*/
Expand Down Expand Up @@ -147,7 +147,7 @@ protected function getListQuery()
*
* Finds uninstalled extensions
*
* @return void
* @return int The count of discovered extensions
*
* @since 1.6
*/
Expand All @@ -173,6 +173,8 @@ public function discover()
$extensions[$key] = $install;
}

$count = 0;

foreach ($results as $result)
{
// Check if we have a match on the element
Expand All @@ -183,8 +185,11 @@ public function discover()
// Put it into the table
$result->check();
$result->store();
$count++;
}
}

return $count;
}

/**
Expand Down
166 changes: 166 additions & 0 deletions libraries/src/Console/ExtensionDiscoverCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2021 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\Component\Installer\Administrator\Model\DiscoverModel;
use Joomla\Console\Command\AbstractCommand;
use Joomla\Database\DatabaseInterface;
use Symfony\Component\Console\Command\Command;
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;

/**
* Instantiate the command.
*
* @since __DEPLOY_VERSION__
*/
public function __construct()
{
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
{
$help = "<info>%command.name%</info> is used to discover extensions
\nUsage:
\n <info>php %command.full_name%</info>";

$this->setDescription('Discover extensions');
$this->setHelp($help);
}

/**
* Used for discovering extensions
*
* @return integer The count of discovered extensions
*
* @throws \Exception
*
* @since __DEPLOY_VERSION__
*/
public function processDiscover(): int
{
$app = $this->getApplication();

$mvcFactory = $app->bootComponent('com_installer')->getMVCFactory();

$model = $mvcFactory->createModel('Discover', 'Administrator');

return $model->discover();
}

/**
* Used for finding the text for the note
*
* @param int $count The count of installed Extensions
*
* @return string The text for the note
*
* @since __DEPLOY_VERSION__
*/
public function getNote(int $count): string
{
if ($count < 1)
{
return 'No extensions were discovered.';
}
elseif ($count === 1)
{
return $count . ' extension has been discovered.';
}
else
{
return $count . ' extensions have been discovered.';
}
}

/**
* 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
*
* @since __DEPLOY_VERSION__
*/
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
$this->configureIO($input, $output);

$count = $this->processDiscover();

$this->ioStyle->note($this->getNote($count));

return Command::SUCCESS;
}
}
Loading