namespace Drupal\Console\Command\Multisite;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
-use Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
*/
class NewCommand extends Command
{
- use CommandTrait;
-
protected $appRoot;
/**
null,
InputOption::VALUE_NONE,
$this->trans('commands.multisite.new.options.copy-default')
- );
+ )
+ ->setAliases(['mun']);
}
/**
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
$this->fs = new Filesystem();
$this->directory = $input->getArgument('directory');
if (!$this->directory) {
- $io->error($this->trans('commands.multisite.new.errors.subdir-empty'));
+ $this->getIo()->error($this->trans('commands.multisite.new.errors.subdir-empty'));
return 1;
}
if ($this->fs->exists($this->appRoot . '/sites/' . $this->directory)) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.multisite.new.errors.subdir-exists'),
$this->directory
}
if (!$this->fs->exists($this->appRoot . '/sites/default')) {
- $io->error($this->trans('commands.multisite.new.errors.default-missing'));
+ $this->getIo()->error($this->trans('commands.multisite.new.errors.default-missing'));
return 1;
}
try {
$this->fs->mkdir($this->appRoot . '/sites/' . $this->directory, 0755);
} catch (IOExceptionInterface $e) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.multisite.new.errors.mkdir-fail'),
$this->directory
$uri = $input->getArgument('uri');
try {
- $this->addToSitesFile($io, $uri);
+ $this->addToSitesFile($uri);
} catch (\Exception $e) {
- $io->error($e->getMessage());
+ $this->getIo()->error($e->getMessage());
return 1;
}
- $this->createFreshSite($io);
+ $this->createFreshSite();
return 0;
}
/**
* Adds line to sites.php that is needed for the new site to be recognized.
*
- * @param DrupalStyle $output
* @param string $uri
*
* @throws FileNotFoundException
*/
- protected function addToSitesFile(DrupalStyle $output, $uri)
+ protected function addToSitesFile($uri)
{
if ($this->fs->exists($this->appRoot . '/sites/sites.php')) {
$sites_is_dir = is_dir($this->appRoot . '/sites/sites.php');
$this->fs->dumpFile($this->appRoot . '/sites/sites.php', $sites_file_contents);
$this->fs->chmod($this->appRoot . '/sites/sites.php', 0640);
} catch (IOExceptionInterface $e) {
- $output->error('commands.multisite.new.errors.sites-other');
+ $this->getIo()->error('commands.multisite.new.errors.sites-other');
}
}
/**
* Copies detected default install alters settings.php to fit the new directory.
- *
- * @param DrupalStyle $io
*/
- protected function copyExistingInstall(DrupalStyle $io)
+ protected function copyExistingInstall()
{
if (!$this->fs->exists($this->appRoot . '/sites/default/settings.php')) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.multisite.new.errors.file-missing'),
'sites/default/settings.php'
$this->appRoot . '/sites/' . $this->directory . '/files'
);
} catch (IOExceptionInterface $e) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.multisite.new.errors.copy-fail'),
'sites/default/files',
return 1;
}
} else {
- $io->warning($this->trans('commands.multisite.new.warnings.missing-files'));
+ $this->getIo()->warning($this->trans('commands.multisite.new.warnings.missing-files'));
}
$settings = file_get_contents($this->appRoot . '/sites/default/settings.php');
$settings
);
} catch (IOExceptionInterface $e) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.multisite.new.errors.write-fail'),
'sites/' . $this->directory . '/settings.php'
return 1;
}
- $this->chmodSettings($io);
+ $this->chmodSettings();
- $io->success(
+ $this->getIo()->success(
sprintf(
$this->trans('commands.multisite.new.messages.copy-default'),
$this->directory
/**
* Creates site folder with clean settings.php file.
- *
- * @param DrupalStyle $io
*/
- protected function createFreshSite(DrupalStyle $io)
+ protected function createFreshSite()
{
if ($this->fs->exists($this->appRoot . '/sites/default/default.settings.php')) {
try {
$this->appRoot . '/sites/' . $this->directory . '/settings.php'
);
} catch (IOExceptionInterface $e) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.multisite.new.errors.copy-fail'),
$this->appRoot . '/sites/default/default.settings.php',
return 1;
}
} else {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.multisite.new.errors.file-missing'),
'sites/default/default.settings.php'
return 1;
}
- $this->chmodSettings($io);
+ $this->chmodSettings();
- $io->success(
+ $this->getIo()->success(
sprintf(
$this->trans('commands.multisite.new.messages.fresh-site'),
$this->directory
* The copy will have 444 permissions by default, which makes it readable by
* anyone. Also, Drupal likes being able to write to it during, for example,
* a fresh install.
- *
- * @param DrupalStyle $io
*/
- protected function chmodSettings(DrupalStyle $io)
+ protected function chmodSettings()
{
try {
$this->fs->chmod($this->appRoot . '/sites/' . $this->directory . '/settings.php', 0640);
} catch (IOExceptionInterface $e) {
- $io->error(
+ $this->getIo()->error(
sprintf(
$this->trans('commands.multisite.new.errors.chmod-fail'),
$this->appRoot . '/sites/' . $this->directory . '/settings.php'