From 31ac8bccdae86eeb150cb396c44ee88427120e3e Mon Sep 17 00:00:00 2001 From: Phil Burton Date: Mon, 21 Aug 2017 18:58:05 +0100 Subject: wip --- src/Script/Command/Site.php | 80 ------------------------------ src/Script/Command/Site/Create.php | 99 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 80 deletions(-) delete mode 100644 src/Script/Command/Site.php create mode 100644 src/Script/Command/Site/Create.php (limited to 'src/Script') diff --git a/src/Script/Command/Site.php b/src/Script/Command/Site.php deleted file mode 100644 index 8a6a8e7..0000000 --- a/src/Script/Command/Site.php +++ /dev/null @@ -1,80 +0,0 @@ -addArgument('name', InputArgument::REQUIRED, 'The name of the new site.'); - - $this - ->addArgument('domain', InputArgument::REQUIRED, 'The domain name of the new site.'); - - $this - ->setName('site:create') - ->setDescription('Create a new site.') - ->setHelp('This command allows you to create a new site.') - ; - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $taskCount = 6; - $output->writeln( - 'Creating new site with domain: ' - . $input->getArgument('domain') - . ' and name: ' - . $input->getArgument('name') - ); - - $progressBar = new ProgressBar($output, $taskCount); - $progressBar->setFormatDefinition('custom', ' %current%/%max% -- %message%'); - $progressBar->setFormat('custom'); - $progressBar->setMessage('Starting...'); - $progressBar->start(); - $progressBar->setMessage('Running pre-flight checks'); - - $progressBar->advance(); - try { - $create = new \App\Filesystem\CreateFile(DIPPER_ROOT . '/foo.test'); - $create = new \App\Filesystem\CreateDirectory(DIPPER_ROOT); - sleep(1); - } catch (\Exception $e) { - $output->writeln('Error with pre-flight checks'); - $output->writeln($e->getMessage()); - exit; - } - - $progressBar->advance(); - $progressBar->setMessage('Creating directory structure'); - sleep(1); - - $progressBar->advance(); - $progressBar->setMessage('Creating nginx config'); - sleep(1); - - $progressBar->advance(); - $progressBar->setMessage('Creating default index.php'); - sleep(1); - - $progressBar->advance(); - $progressBar->setMessage('Creating nginx config'); - sleep(1); - - $progressBar->advance(); - $progressBar->finish(); - - $output->writeln(''); - $output->writeln('Complete'); - } -} diff --git a/src/Script/Command/Site/Create.php b/src/Script/Command/Site/Create.php new file mode 100644 index 0000000..2526d2e --- /dev/null +++ b/src/Script/Command/Site/Create.php @@ -0,0 +1,99 @@ + + */ +class Create extends SyCommand +{ + /** + * Configure the command + * + * @author Phil Burton + */ + protected function configure() + { + $this->addArgument('name', InputArgument::REQUIRED, 'The name of the new site.'); + $this->addArgument('domain', InputArgument::REQUIRED, 'The domain name of the new site.'); + + $this + ->setName('site:create') + ->setDescription('Create a new site.') + ->setHelp('This command allows you to create a new site.'); + } + + /** + * Run the command + * + * @param InputInterface $input + * @param OutputInterface $output + * @author Phil Burton + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $taskCount = 6; + + $name = $input->getArgument('name'); + $domain = $input->getArgument('domain'); + + $output->writeln( + 'Creating new site with domain: ' + . $input->getArgument('domain') + . ' and name: ' + . $input->getArgument('name') + ); + + // Set-up progress bar + $progressBar = new ProgressBar($output, $taskCount); + $progressBar->setFormatDefinition('custom', ' %current%/%max% -- %message%'); + $progressBar->setFormat('custom'); + $progressBar->setMessage('Starting...'); + $progressBar->start(); + $progressBar->setMessage('Running pre-flight checks'); + + // Construct the file commands so we run checks first + $progressBar->advance(); + + $tasks = []; + + try { + $tasks['Creating site directory'] = new \App\Filesystem\CreateDirectory(SITES_ROOT . $name); + $tasks['Creating logs directory'] = new \App\Filesystem\CreateDirectory(SITES_ROOT . $name . '/logs'); + $tasks['Creating access log file'] = new \App\Filesystem\CreateFile(SITES_ROOT . $name . '/logs/' . $name . '.access_log'); + $tasks['Creating error log file'] = new \App\Filesystem\CreateFile(SITES_ROOT . $name . '/logs/' . $name . '.errors_log'); + $tasks['Creating web folder'] = new \App\Filesystem\CreateDirectory(SITES_ROOT . $name . '/web'); + $tasks['Creating directory index.php'] = new \App\Filesystem\CreateFile(SITES_ROOT . $name . '/web/index.php'); + $tasks['Creating nginx config file'] = new \App\Filesystem\CreateFile(CONFIG_ROOT . $name . '.conf'); + } catch (\Exception $e) { + $output->writeln('Error with pre-flight checks'); + $output->writeln($e->getMessage()); + exit; + } + + foreach ($tasks as $message => $task) { + // Create file in web root for execution + $progressBar->advance(); + $progressBar->setMessage($message); + $task->execute(); + sleep(1); + } + + + // Finish up + $progressBar->advance(); + $progressBar->finish(); + $output->writeln(''); + $output->writeln('Complete'); + } +} -- cgit v1.2.3