Skip to content

Commit

Permalink
#62: Automatically move legacy plugins directory to new location
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Rombauts committed Dec 13, 2017
1 parent 13ff2a7 commit 684a81f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
1 change: 0 additions & 1 deletion plugins/.gitignore

This file was deleted.

44 changes: 35 additions & 9 deletions src/Joomlatools/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,18 @@ public function run(Input\InputInterface $input = null, Output\OutputInterface $

$this->configureIO($this->_input, $this->_output);

if (!file_exists($this->getConsoleHome()))
{
$result = @mkdir($this->getConsoleHome(), 0775, true);

if (!$result)
{
$output->writeln(sprintf('<error>Unable to write to home directory: %s. Please check write permissions.</error>', getenv('HOME')));
}
}
$this->_setup();

$this->_loadPlugins();

parent::run($this->_input, $this->_output);
}

/**
* Get the home directory path
*
* @return string Path to the Joomlatools Console home directory
*/
public function getConsoleHome()
{
return rtrim(getenv('HOME'), '/') . '/.joomlatools-console';
Expand Down Expand Up @@ -204,6 +201,35 @@ public function getPlugins()
return $this->_plugins;
}

/**
* Set up environment
*/
protected function _setup()
{
if (!file_exists($this->getConsoleHome()))
{
$result = @mkdir($this->getConsoleHome(), 0775, true);

if (!$result) {
$this->_output->writeln(sprintf('<error>Unable to write to home directory: %s. Please check write permissions.</error>', getenv('HOME')));
}
}

// Handle legacy plugin directory
if (is_writable($this->getConsoleHome()) && !file_exists($this->getPluginPath()))
{
$old = realpath(dirname(__FILE__) . '/../../../plugins/');

if (file_exists($old))
{
$this->_output->writeln('<comment>Moving legacy plugin directory to ~/.joomlatools-console/plugins.</comment>');

$cmd = sprintf('mv %s %s', escapeshellarg($old), escapeshellarg($this->getPluginPath()));
exec($cmd);
}
}
}

/**
* Loads plugins into the application.
*/
Expand Down

0 comments on commit 684a81f

Please sign in to comment.