diff --git a/src/Command.php b/src/Command.php index eeedf568bef8547c8847fabcc35b5753fc9847b2..543d552c48f169e9725381ba51e22840ae328989 100644 --- a/src/Command.php +++ b/src/Command.php @@ -117,11 +117,11 @@ abstract class Command extends BaseCommand * Show a list of Contexts to the user for them to choose from. */ public function askForContext($question = 'Choose a context') { - if (empty($this->getApplication()->getAllContextsOptions())) { + if (empty($this->getProvision()->getAllContextsOptions())) { throw new \Exception('No contexts available! use provision save to create one.'); } - $this->context_name = $this->io->choice($question, $this->getApplication()->getAllContextsOptions()); + $this->context_name = $this->io->choice($question, $this->getProvision()->getAllContextsOptions()); } /** diff --git a/src/Command/ServicesCommand.php b/src/Command/ServicesCommand.php index 6eebef5f2d610cc35349f62a5815cefdbc78aace..fe4b84f639ee4df27d8af7bf2c3bc901b054773d 100644 --- a/src/Command/ServicesCommand.php +++ b/src/Command/ServicesCommand.php @@ -219,7 +219,7 @@ class ServicesCommand extends Command } // All other context types are associating with servers that provide the service. else { - if (empty($this->getApplication()->getServerOptions($service))) { + if (empty($this->getProvision()->getServerOptions($service))) { throw new \Exception("No servers providing $service service were found. Create one with `provision save` or use `provision services` to add to an existing server."); } @@ -228,7 +228,7 @@ class ServicesCommand extends Command $this->io->choice('Which server?', $this->getApplication()->getServerOptions($service)); // Then ask for all options. - $server_context = $this->getApplication()->getContext($server); + $server_context = $this->getProvision()->getContext($server); $properties = $this->askForServiceProperties($service); $this->io->info("Using $service service from server $server..."); diff --git a/src/Common/ProvisionAwareTrait.php b/src/Common/ProvisionAwareTrait.php index 02620c3ebecc0e2e26aaf6df3326d94347f03843..ec1b8b092e18efd8e7d9b56ea1b440c2e1d58fc3 100644 --- a/src/Common/ProvisionAwareTrait.php +++ b/src/Common/ProvisionAwareTrait.php @@ -28,6 +28,11 @@ trait ProvisionAwareTrait */ public function getProvision() { + + if (is_null($this->provision)) { + return Provision::getProvision(); + } + return $this->provision; } } diff --git a/src/Context.php b/src/Context.php index b13451491218a7e9c8c81785c6df3ee0779cd2e9..d623fe2c28f6d75aec14a1636852aa18d9d603c4 100644 --- a/src/Context.php +++ b/src/Context.php @@ -10,7 +10,6 @@ use Aegir\Provision\Common\ProvisionAwareTrait; use Aegir\Provision\Console\Config; use Consolidation\AnnotatedCommand\CommandFileDiscovery; use Drupal\Console\Core\Style\DrupalStyle; -use Psr\Log\LoggerInterface; use Robo\Common\BuilderAwareTrait; use Robo\Contract\BuilderAwareInterface; use Symfony\Component\Config\Definition\Builder\TreeBuilder; @@ -67,11 +66,6 @@ class Context implements BuilderAwareInterface */ protected $properties = []; - /** - * @var LoggerInterface - */ - public $logger; - /** * Context constructor. * diff --git a/src/Context/PlatformContext.php b/src/Context/PlatformContext.php index 04e79030cd9b72bcb52f66d82c6ce4e6e348d54f..70fd20a32816516979202c6592014410dc34629c 100644 --- a/src/Context/PlatformContext.php +++ b/src/Context/PlatformContext.php @@ -75,14 +75,14 @@ class PlatformContext extends ContextSubscriber implements ConfigurationInterfac */ public function verify() { - $this->application->io->customLite($this->getProperty('root'), 'Root: ', 'info'); - $this->application->io->customLite($this->config_path, 'Configuration File: ', 'info'); + $this->getProvision()->io()->customLite($this->getProperty('root'), 'Root: ', 'info'); + $this->getProvision()->io()->customLite($this->config_path, 'Configuration File: ', 'info'); // This is how you can use Robo Tasks in a platform verification call. // The "silent" method actually works here. // It only partially works in Service::restartServices()! $this->getBuilder()->taskExec('env') - ->silent(!$this->application->io->isVerbose()) + ->silent(!$this->getProvision()->io()->isVerbose()) ->run(); return parent::verify(); diff --git a/src/Context/SiteContext.php b/src/Context/SiteContext.php index 060556eb0017c204a91cf380dc02293fd4482840..445e5a56989f67fcedb688629d93677738e1245b 100644 --- a/src/Context/SiteContext.php +++ b/src/Context/SiteContext.php @@ -86,9 +86,9 @@ class SiteContext extends ContextSubscriber implements ConfigurationInterface */ public function verify() { - $this->application->io->customLite($this->getProperty('uri'), 'Site URL: ', 'info'); - $this->application->io->customLite($this->platform->getProperty('root'), 'Root: ', 'info'); - $this->application->io->customLite($this->config_path, 'Configuration File: ', 'info'); + $this->getProvision()->io()->customLite($this->getProperty('uri'), 'Site URL: ', 'info'); + $this->getProvision()->io()->customLite($this->platform->getProperty('root'), 'Root: ', 'info'); + $this->getProvision()->io()->customLite($this->config_path, 'Configuration File: ', 'info'); return parent::verify(); } diff --git a/src/Provision.php b/src/Provision.php index 7a0002313c40c4f8ab02c4b11615457877de6fa4..401308f84b5d9d6f73841483fb9f41bd6eb9954f 100644 --- a/src/Provision.php +++ b/src/Provision.php @@ -6,24 +6,25 @@ namespace Aegir\Provision; use Aegir\Provision\Console\Config; use Aegir\Provision\Commands\ExampleCommands; +use Aegir\Provision\Console\ConsoleOutput; use Aegir\Provision\Robo\ProvisionCollectionBuilder; use Aegir\Provision\Robo\ProvisionExecutor; use Aegir\Provision\Robo\ProvisionTasks; +use Drupal\Console\Core\Style\DrupalStyle; use League\Container\Container; use League\Container\ContainerAwareInterface; use League\Container\ContainerAwareTrait; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; -use Robo\Collection\CollectionBuilder; use Robo\Common\BuilderAwareTrait; use Robo\Common\ConfigAwareTrait; use Robo\Common\IO; use Robo\Contract\BuilderAwareInterface; use Robo\Contract\ConfigAwareInterface; use Robo\Contract\IOAwareInterface; -use Robo\Log\RoboLogger; use Robo\Robo; use Robo\Runner as RoboRunner; +use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -142,6 +143,40 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger return $this->input(); } + /** + * Gets Logger object. + * Returns the currently active Logger instance. + * + * @return \Psr\Log\LoggerInterface + */ + public function getLogger() + { + return $this->logger; + } + + /** + * Provide access to DrupalStyle object. + * + * @return \Drupal\Console\Core\Style\DrupalStyle + */ + public function io() + { + if (!$this->io) { + $this->io = new DrupalStyle($this->input(), $this->output()); + } + return $this->io; + } + + /** + * Get a new Provision + * @return \Aegir\Provision\Provision + */ + static function getProvision() { + $input = new ArgvInput(); + $output = new ConsoleOutput(); + $config = new Config(); + return new Provision($config, $input, $output); + } /** * Load all contexts into Context objects. diff --git a/src/Service.php b/src/Service.php index e846916aa22a56fb77f0a5f4cce61ffa1873c392..2b6bbeacf3678e071f3d8a22d9ced02742ba4545 100644 --- a/src/Service.php +++ b/src/Service.php @@ -110,19 +110,19 @@ class Service implements BuilderAwareInterface return TRUE; } else { - $task = $this->application->getProvision()->getBuilder()->taskExec($this->properties['restart_command']) - ->silent(!$this->application->io->isVerbose()) + $task = $this->getProvision()->getBuilder()->taskExec($this->properties['restart_command']) + ->silent(!$this->getProvision()->io()->isVerbose()) ; /** @var \Robo\Result $result */ $result = $task->run(); if ($result->wasSuccessful()) { - $this->application->io->successLite('Service restarted.'); + $this->getProvision()->io()->successLite('Service restarted.'); sleep(1); return TRUE; } else { - $this->application->io->errorLite('Unable to restart service:' . $result->getOutputData()); + $this->getProvision()->io()->errorLite('Unable to restart service:' . $result->getOutputData()); } } return FALSE; @@ -174,12 +174,12 @@ class Service implements BuilderAwareInterface try { $config = new $configuration_class($context, $this); $config->write(); - $context->application->io->successLite( + $context->getProvision()->io()->successLite( 'Wrote '.$config->description.' to '.$config->filename() ); } catch (\Exception $e) { - $context->application->io->errorLite( + $context->getProvision()->io()->errorLite( 'Unable to write '.$config->description.' to '.$config->filename() . ': ' . $e->getMessage() ); $success = FALSE; diff --git a/src/Service/Db/DbMysqlService.php b/src/Service/Db/DbMysqlService.php index f3c750eb3caf394f7b47e7854e645536800d23e2..02f9716ce66a6085922883e17f4a7373be52a060 100644 --- a/src/Service/Db/DbMysqlService.php +++ b/src/Service/Db/DbMysqlService.php @@ -34,7 +34,7 @@ class DbMysqlService extends DbService if ($this->database_exists($test)) { if (!$this->drop_database($test)) { - $this->provider->application->io->errorLite(strtr("Failed to drop database @dbname", ['@dbname' => $test])); + $this->provider->getProvision()->io()->errorLite(strtr("Failed to drop database @dbname", ['@dbname' => $test])); } return TRUE; } diff --git a/src/Service/DbService.php b/src/Service/DbService.php index bcd8066097c1767a65b495c09a26549a427ad9db..8c9e948c04fa7b9c432c7d5d562ca375b1b5d2b9 100644 --- a/src/Service/DbService.php +++ b/src/Service/DbService.php @@ -105,18 +105,18 @@ class DbService extends Service try { $this->connect(); $return = TRUE; - $this->provider->application->io->successLite('Successfully connected to database server!'); + $this->provider->getProvision()->io()->successLite('Successfully connected to database server!'); if ($this->can_create_database()) { - $this->provider->application->io->successLite('Provision can create new databases.'); + $this->provider->getProvision()->io()->successLite('Provision can create new databases.'); } else { - $this->provider->application->io->errorLite('Provision is unable to create databases.'); + $this->provider->getProvision()->io()->errorLite('Provision is unable to create databases.'); $return = FALSE; } if ($this->can_grant_privileges()) { - $this->provider->application->io->successLite('Provision can grant privileges on database users.'); + $this->provider->getProvision()->io()->successLite('Provision can grant privileges on database users.'); } else { - $this->provider->application->io->errorLite('Provision is unable to grant privileges on database users.'); + $this->provider->getProvision()->io()->errorLite('Provision is unable to grant privileges on database users.'); $return = FALSE; } @@ -125,7 +125,7 @@ class DbService extends Service ]; } catch (\PDOException $e) { - $this->provider->application->io->errorLite($e->getMessage()); + $this->provider->getProvision()->io()->errorLite($e->getMessage()); return [ 'service' => FALSE ]; @@ -156,13 +156,13 @@ class DbService extends Service try { $this->connect(); - $this->subscription->context->application->io->successLite('Successfully connected to database server.'); + $this->subscription->context->getProvision()->io()->successLite('Successfully connected to database server.'); return [ 'service' => TRUE ]; } catch (\PDOException $e) { - $this->subscription->context->application->io->errorLite($e->getMessage()); + $this->subscription->context->getProvision()->io()->errorLite($e->getMessage()); return [ 'service' => FALSE ]; @@ -215,11 +215,11 @@ class DbService extends Service $query = preg_replace_callback($this::PROVISION_QUERY_REGEXP, array($this, 'query_callback'), $query); try { - $this->provider->application->logger->notice("Running Query: {$query}"); + $this->provider->getProvision()->getLogger()->info("Running Query: {$query}"); $result = $this->conn->query($query); } catch (\PDOException $e) { - $this->provider->application->io->errorLite($e->getMessage()); + $this->provider->getProvision()->getLogger()->error($e->getMessage()); return FALSE; } @@ -381,13 +381,13 @@ class DbService extends Service } if ($this->database_exists($db_name)) { - $this->application->io->successLite(strtr("Database '@name' already exists.", [ + $this->getProvision()->io()->successLite(strtr("Database '@name' already exists.", [ '@name' => $db_name ])); } else { $this->create_database($db_name); - $this->application->io->successLite(strtr("Created database '@name'.", [ + $this->getProvision()->io()->successLite(strtr("Created database '@name'.", [ '@name' => $db_name, ])); } @@ -398,7 +398,7 @@ class DbService extends Service '@user' => $db_user ])); } - $this->application->io->successLite(strtr("Granted privileges to user '@user@@host' for database '@name'.", [ + $this->getProvision()->io()->successLite(strtr("Granted privileges to user '@user@@host' for database '@name'.", [ '@user' => $db_user, '@host' => $db_grant_host, '@name' => $db_name, @@ -408,7 +408,7 @@ class DbService extends Service $status = $this->database_exists($db_name); if ($status) { - $this->application->io->successLite(strtr("Database service configured for site @name.", [ + $this->getProvision()->io()->successLite(strtr("Database service configured for site @name.", [ '@name' => $site->name, ])); } diff --git a/src/Service/Http/Apache/Configuration/PlatformConfiguration.php b/src/Service/Http/Apache/Configuration/PlatformConfiguration.php index 53f55d8b0a3f4a6c70ff341aa48657d62209099f..6819bb3f03c813d3c7a74168ada5814b44df2868 100644 --- a/src/Service/Http/Apache/Configuration/PlatformConfiguration.php +++ b/src/Service/Http/Apache/Configuration/PlatformConfiguration.php @@ -21,7 +21,7 @@ class PlatformConfiguration extends Configuration { function filename() { $file = $this->context->name . '.conf'; - return $this->context->application->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $this->service->getType() . '/platform.d/' . $file; + return $this->context->getProvision()->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $this->service->getType() . '/platform.d/' . $file; } function process() diff --git a/src/Service/Http/Apache/Configuration/ServerConfiguration.php b/src/Service/Http/Apache/Configuration/ServerConfiguration.php index 3cbee7448a4551daaa6b42d8cadf18fd19a0d926..0303d4cb0596b321eaae3acc56e3cd992561ac6b 100644 --- a/src/Service/Http/Apache/Configuration/ServerConfiguration.php +++ b/src/Service/Http/Apache/Configuration/ServerConfiguration.php @@ -26,7 +26,7 @@ class ServerConfiguration extends Configuration { function filename() { if ($this->service->getType()) { $file = $this->service->getType() . '.conf'; - return $this->service->provider->application->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $file; + return $this->service->provider->getProvision()->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $file; } else { return FALSE; @@ -35,7 +35,7 @@ class ServerConfiguration extends Configuration { function process() { parent::process(); - $app_dir = $this->context->application->getConfig()->get('config_path') . '/' . $this->context->name . '/' . $this->service->getType(); + $app_dir = $this->context->getProvision()->getConfig()->get('config_path') . '/' . $this->context->name . '/' . $this->service->getType(); $this->data['http_port'] = $this->service->properties['http_port']; $this->data['include_statement'] = '# INCLUDE STATEMENT'; $this->data['http_pred_path'] = "{$app_dir}/pre.d"; diff --git a/src/Service/Http/Apache/Configuration/SiteConfiguration.php b/src/Service/Http/Apache/Configuration/SiteConfiguration.php index fa5b0bcc3a3fcd8adb35d4ab89f554e53e865732..1f7c4e12b74754514d573ec0f653a8ddafe15a24 100644 --- a/src/Service/Http/Apache/Configuration/SiteConfiguration.php +++ b/src/Service/Http/Apache/Configuration/SiteConfiguration.php @@ -23,7 +23,7 @@ class SiteConfiguration extends Configuration { function filename() { $file = $this->context->getProperty('uri') . '.conf'; - return $this->context->application->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $this->service->getType() . '/vhost.d/' . $file; + return $this->context->getProvision()->getConfig()->get('config_path') . '/' . $this->service->provider->name . '/' . $this->service->getType() . '/vhost.d/' . $file; } function process() {