Skip to content

Commit

Permalink
Merge pull request joomla#11 from bosunski/milestone_two
Browse files Browse the repository at this point in the history
Milestone two
  • Loading branch information
alikon authored Jun 18, 2018
2 parents 7269fdf + e4d8158 commit 591ae56
Show file tree
Hide file tree
Showing 8 changed files with 640 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cli/joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
// We are a valid entry point.
const _JEXEC = 1;

/**
* Define the application's minimum supported PHP version as a constant so it can be referenced within the application.
*/
define('JOOMLA_MINIMUM_PHP', '7.0');

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
Expand Down
18 changes: 18 additions & 0 deletions libraries/src/Application/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Joomla\CMS\Console;
use Joomla\CMS\Extension\ExtensionManagerTrait;
use Joomla\CMS\Factory;
use Joomla\CMS\Version;
use Joomla\Input\Cli;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Console\Application;
Expand Down Expand Up @@ -178,6 +180,9 @@ protected function getDefaultCommands(): array
new Console\CleanCacheCommand,
new Console\CheckUpdatesCommand,
new Console\RemoveOldFilesCommand,
new Console\ExtensionsListCommand,
new Console\ExtensionInstallCommand,
new Console\ExtensionRemoveCommand,
new Console\CheckJoomlaUpdatesCommand,
]
);
Expand Down Expand Up @@ -263,4 +268,17 @@ public function setSession(SessionInterface $session): self

return $this;
}


/**
* Flush the media version to refresh versionable assets
*
* @return void
*
* @since 4.0
*/
public function flushAssets()
{
(new Version)->refreshMediaVersion();
}
}
197 changes: 197 additions & 0 deletions libraries/src/Console/ExtensionInstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @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\AbstractCommand;
use Joomla\CMS\Installer\InstallerHelper;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Input\InputArgument;

/**
* Console command for checking if there are pending extension updates
*
* @since 4.0.0
*/
class ExtensionInstallCommand extends AbstractCommand
{
/**
* Stores the Input Object
* @var
* @since 4.0
*/
private $cliInput;

/**
* SymfonyStyle Object
* @var
* @since 4.0
*/
private $ioStyle;

/**
* Configures the IO
*
* @return void
*
* @since 4.0
*/
private function configureIO()
{
$this->cliInput = $this->getApplication()->getConsoleInput();
$this->ioStyle = new SymfonyStyle($this->getApplication()->getConsoleInput(), $this->getApplication()->getConsoleOutput());
}

/**
* Execute the command.
*
* @return integer The exit code for the command.
*
* @since 4.0.0
*/
public function execute(): int
{
$this->configureIO();

$from = $this->cliInput->getArgument('from');

if ($from === 'path')
{
$result = $this->processPathInstallation($this->cliInput->getOption('path'));

if (!$result)
{
$this->ioStyle->error('Unable to install extension');
}
else
{
$this->ioStyle->success('Extension installed successfully.');
}
}
elseif ($from === 'url')
{
$result = $this->processUrlInstallation($this->cliInput->getOption('url'));

if (!$result)
{
$this->ioStyle->error('Unable to install extension');
}
else
{
$this->ioStyle->success('Extension installed successfully.');
}
}
else
{
$this->ioStyle->error('Invalid argument supplied for command.');
}

return 0;
}

/**
* Initialise the command.
*
* @return void
*
* @since 4.0.0
*/
protected function initialise()
{
$this->setName('extension:install');
$this->addArgument(
'from',
InputArgument::REQUIRED,
'From where do you want to install? (path OR url)'
);

$this->addOption('path', null, InputOption::VALUE_REQUIRED, 'The path to the extension');
$this->addOption('url', null, InputOption::VALUE_REQUIRED, 'The url to the extension');

$this->setDescription('Installs an extension from a URL or from a Path.');

$help = "The <info>%command.name%</info> is used for installing extensions \n
--path=<path_to_extension> OR --url=<url_to_download_extension> \n
<info>php %command.full_name%</info>";

$this->setHelp($help);
}

/**
* Used for installing extension from a path
*
* @param string $path Path to the extension zip file
*
* @return bool|int
*
* @since 4.0
*
* @throws \Exception
*/
public function processPathInstallation($path)
{
if (!file_exists($path))
{
$this->ioStyle->error('The file path specified does not exist.');
exit(2);
}

$tmp_path = $this->getApplication()->get('tmp_path');
$tmp_path = $tmp_path . '/' . basename($path);
$package = InstallerHelper::unpack($path, true);

if ($package['type'] === false)
{
return false;
}

$jInstaller = Installer::getInstance();
$result = $jInstaller->install($package['extractdir']);
InstallerHelper::cleanupInstall($tmp_path, $package['extractdir']);

return $result;
}


/**
* Used for installing extension from a URL
*
* @param string $url URL to the extension zip file
*
* @return bool
*
* @since 4.0
*
* @throws \Exception
*/
public function processUrlInstallation($url)
{
$filename = InstallerHelper::downloadPackage($url);

$tmp_path = $this->getApplication()->get('tmp_path');

$path = $tmp_path . '/' . basename($filename);
$package = InstallerHelper::unpack($path, true);

if ($package['type'] === false)
{
return false;
}

$jInstaller = Installer::getInstance();
$result = $jInstaller->install($package['extractdir']);
InstallerHelper::cleanupInstall($path, $package['extractdir']);

return $result;
}

}
125 changes: 125 additions & 0 deletions libraries/src/Console/ExtensionRemoveCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @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\CMS\MVC\Factory\MVCFactory;
use Joomla\CMS\Table\Table;
use Joomla\Console\AbstractCommand;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Input\InputArgument;


/**
* Console command for checking if there are pending extension updates
*
* @since 4.0.0
*/
class ExtensionRemoveCommand extends AbstractCommand
{
/**
* Configures the IO
*
* @return void
*
* @since 4.0
*/
private function configureIO()
{
$this->cliInput = $this->getApplication()->getConsoleInput();
$this->ioStyle = new SymfonyStyle($this->getApplication()->getConsoleInput(), $this->getApplication()->getConsoleOutput());
}


/**
* Execute the command.
*
* @return integer The exit code for the command.
*
* @since 4.0.0
*/
public function execute(): int
{
$this->configureIO();
$extension_id = (int) $this->cliInput->getArgument('extension_id');

$extension = $this->getExtension($extension_id);

if (!$extension->load($extension_id))
{
$this->ioStyle->error("Extension with ID of $extension_id not found.");
return 0;
}

$response = $this->ioStyle->ask('Are you sure you want to remove this extension?', 'yes/no');

if (strtolower($response) === 'yes')
{
if ($extension->type && $extension->type != 'language')
{
$installer = Installer::getInstance();
$result = $installer->uninstall($extension->type, $extension_id);
if ($result)
{
$this->ioStyle->success('Extension removed!');
}
}
}
elseif (strtolower($response) === 'no')
{
$this->ioStyle->note('Extension not removed.');
return 0;
}
else
{
$this->ioStyle->warning('Invalid response');
return 2;
}
return 0;
}

/**
* Initialise the command.
*
* @return void
*
* @since 4.0.0
*/
protected function initialise()
{
$this->setName('extension:remove');
$this->addArgument(
'extension_id',
InputArgument::REQUIRED,
'ID of extension to be removed (run extension:list command to check)'
);

$this->setDescription('Removes an extension');

$help = "The <info>%command.name%</info> Removes an extension \n <info>php %command.full_name%</info>";
$this->setHelp($help);
}

/**
* Gets the extension from DB
*
* @param integer $extension_id ID of extension to be removed
*
* @return bool
*
* @since 4.0
*/
protected function getExtension($extension_id)
{
$row = Table::getInstance('extension');
return $row;
}
}
Loading

0 comments on commit 591ae56

Please sign in to comment.