summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-11-20 19:21:50 (GMT)
committerJon Pugh2017-11-20 19:21:50 (GMT)
commitfb522e7add3af9f6f315f23e2dab73786734a115 (patch)
treeb216c4f8df04da99aa77d8e698a95e1f1462a877
parentcbd9cc0b3c7d745dc795aca1c86bfde17a3ef639 (diff)
- Allow Provision
- Replace ->application->io-> with getProvision()->io();
-rw-r--r--src/Command.php4
-rw-r--r--src/Command/ServicesCommand.php4
-rw-r--r--src/Common/ProvisionAwareTrait.php5
-rw-r--r--src/Context.php6
-rw-r--r--src/Context/PlatformContext.php6
-rw-r--r--src/Context/SiteContext.php6
-rw-r--r--src/Provision.php39
-rw-r--r--src/Service.php12
-rw-r--r--src/Service/Db/DbMysqlService.php2
-rw-r--r--src/Service/DbService.php28
-rw-r--r--src/Service/Http/Apache/Configuration/PlatformConfiguration.php2
-rw-r--r--src/Service/Http/Apache/Configuration/ServerConfiguration.php4
-rw-r--r--src/Service/Http/Apache/Configuration/SiteConfiguration.php2
13 files changed, 77 insertions, 43 deletions
diff --git a/src/Command.php b/src/Command.php
index eeedf56..543d552 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 <comment>provision save</comment> 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 6eebef5..fe4b84f 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 02620c3..ec1b8b0 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 b134514..d623fe2 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;
@@ -68,11 +67,6 @@ class Context implements BuilderAwareInterface
protected $properties = [];
/**
- * @var LoggerInterface
- */
- public $logger;
-
- /**
* Context constructor.
*
* @param $name
diff --git a/src/Context/PlatformContext.php b/src/Context/PlatformContext.php
index 04e7903..70fd20a 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 060556e..445e5a5 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 7a00023..401308f 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 e846916..2b6bbea 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 f3c750e..02f9716 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 bcd8066..8c9e948 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 53f55d8..6819bb3 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 3cbee74..0303d4c 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 fa5b0bc..1f7c4e1 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() {