summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-11-17 21:02:42 (GMT)
committerJon Pugh2017-11-17 21:02:42 (GMT)
commitbef367cdc4cf89755e75df477754e6304067e77d (patch)
tree67980d8a05cae9e326444f7ab95c64edd4b5f8d2
parenteaa000ec227caf1f7312f14648ddfc5c692de638 (diff)
Giving Service BuilderAwareTrait and use taskExec() for apache restart. Adding a hidden example of using Robo Tasks in Platform verification.
-rw-r--r--src/Context/PlatformContext.php7
-rw-r--r--src/Provision.php13
-rw-r--r--src/Robo/ProvisionCollectionBuilder.php34
-rw-r--r--src/Service.php34
4 files changed, 81 insertions, 7 deletions
diff --git a/src/Context/PlatformContext.php b/src/Context/PlatformContext.php
index 79955f9..01eb590 100644
--- a/src/Context/PlatformContext.php
+++ b/src/Context/PlatformContext.php
@@ -74,6 +74,13 @@ class PlatformContext extends ContextSubscriber implements ConfigurationInterfac
$this->application->io->customLite($this->getProperty('root'), 'Root: ', 'info');
$this->application->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())
+ ->run();
+
return parent::verify();
}
}
diff --git a/src/Provision.php b/src/Provision.php
index 2a825ec..a9a5831 100644
--- a/src/Provision.php
+++ b/src/Provision.php
@@ -6,6 +6,7 @@ namespace Aegir\Provision;
use Aegir\Provision\Console\Config;
use Aegir\Provision\Commands\ExampleCommands;
+use Aegir\Provision\Robo\ProvisionCollectionBuilder;
use Aegir\Provision\Robo\ProvisionExecutor;
use Aegir\Provision\Robo\ProvisionTasks;
use League\Container\Container;
@@ -110,7 +111,7 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger
// in the container. "collectionBuilder" used for the actual command that
// was executed, and "builder" to be used with non-command classes.
$tasks = new ProvisionTasks();
- $builder = new CollectionBuilder($tasks);
+ $builder = new ProvisionCollectionBuilder($tasks);
$tasks->setBuilder($builder);
$container->add('builder', $builder);
$container->add('executor', ProvisionExecutor::class)
@@ -126,4 +127,14 @@ class Provision implements ConfigAwareInterface, ContainerAwareInterface, Logger
{
return $this->output();
}
+
+ /**
+ * Temporary helper to allow public access to input.
+ *
+ * @return \Symfony\Component\Console\Input\InputInterface
+ */
+ public function getInput()
+ {
+ return $this->input();
+ }
}
diff --git a/src/Robo/ProvisionCollectionBuilder.php b/src/Robo/ProvisionCollectionBuilder.php
new file mode 100644
index 0000000..6f9e515
--- /dev/null
+++ b/src/Robo/ProvisionCollectionBuilder.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Aegir\Provision\Robo;
+
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerAwareTrait;
+use Psr\Log\LoggerInterface;
+use Psr\Log\LoggerTrait;
+use Robo\Collection\CollectionBuilder;
+use Robo\Collection\NestedCollectionInterface;
+use Robo\Common\CommandArguments;
+use Robo\Common\ExecCommand;
+use Robo\Common\ExecTrait;
+use Robo\Common\OutputAdapter;
+use Robo\Common\TaskIO;
+use Robo\Result;
+use Robo\ResultData;
+use Symfony\Component\Process\Process;
+
+class ProvisionCollectionBuilder extends CollectionBuilder {
+
+ /**
+ * @var string|\Robo\Contract\CommandInterface
+ */
+ protected $command;
+
+ /**
+ * @var \Robo\Contract\TaskInterface
+ */
+ protected $currentTask;
+
+ use TaskIO;
+
+} \ No newline at end of file
diff --git a/src/Service.php b/src/Service.php
index d548609..b59e435 100644
--- a/src/Service.php
+++ b/src/Service.php
@@ -8,9 +8,15 @@
namespace Aegir\Provision;
-class Service
+use Robo\Common\BuilderAwareTrait;
+use Robo\Common\OutputAdapter;
+use Robo\Contract\BuilderAwareInterface;
+
+class Service implements BuilderAwareInterface
{
+ use BuilderAwareTrait;
+
public $type;
public $properties;
@@ -40,12 +46,15 @@ class Service
*/
const SERVICE_NAME = 'Service Name';
- function __construct($service_config, $provider_context)
+ function __construct($service_config, Context $provider_context)
{
$this->provider = $provider_context;
$this->application = $provider_context->application;
$this->type = $service_config['type'];
$this->properties = $service_config['properties'];
+ if ($provider_context->getBuilder()) {
+ $this->setBuilder($provider_context->getBuilder());
+ }
}
/**
@@ -103,14 +112,19 @@ class Service
return TRUE;
}
else {
- try {
- $this->application->provision->getOutput()->exec($this->properties['restart_command'], 'Restarting service...');
+ $task = $this->application->provision->getBuilder()->taskExec($this->properties['restart_command'])
+ ->silent(!$this->application->io->isVerbose())
+ ;
+
+ /** @var \Robo\Result $result */
+ $result = $task->run();
+ if ($result->wasSuccessful()) {
$this->application->io->successLite('Service restarted.');
sleep(1);
return TRUE;
}
- catch (\Exception $e) {
- $this->application->io->errorLite('Unable to restart service: ' . $e->getMessage());
+ else {
+ $this->application->io->errorLite('Unable to restart service:' . $result->getOutputData());
}
}
return FALSE;
@@ -265,4 +279,12 @@ class Service
// ];
}
+
+ /**
+ * @return \Aegir\Provision\Robo\ProvisionBuilder
+ */
+ function getBuilder()
+ {
+ return $this->builder;
+ }
} \ No newline at end of file