summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-10-26 17:06:44 -0400
committerJon Pugh2017-10-26 17:06:44 -0400
commit9475fcca38be0433bdfe87a01a39a4ac0c052382 (patch)
tree5afd959a880bc14e601eb318cbcfeac10510e2ae
parent301865db6d6b00fede8a79a703c162441ad3aeee (diff)
Add "connect()" method to DbService and trigger when verifying sites.4.x-remove-legacy
-rw-r--r--src/Service/DbService.php41
-rw-r--r--src/ServiceSubscription.php5
2 files changed, 45 insertions, 1 deletions
diff --git a/src/Service/DbService.php b/src/Service/DbService.php
index f58c58c..9cb2b15 100644
--- a/src/Service/DbService.php
+++ b/src/Service/DbService.php
@@ -11,6 +11,7 @@ namespace Aegir\Provision\Service;
//require_once DRUSH_BASE_PATH . '/commands/core/rsync.core.inc';
use Aegir\Provision\Service;
+use Aegir\Provision\ServiceSubscription;
/**
* Class DbService
@@ -23,6 +24,8 @@ class DbService extends Service
const SERVICE = 'db';
const SERVICE_NAME = 'Database Server';
+
+ public $dsn = '';
/**
* Implements Service::server_options()
@@ -60,7 +63,43 @@ class DbService extends Service
'db_password' => 'The password used to access the database. Default: Automatically generated.',
];
}
-//
+
+ /**
+ * React to the `provision verify` command.
+ */
+ function verify() {
+ $this->connect();
+
+ $this->context->logger->warning('Hello DB SERVER!');
+ }
+
+ /**
+ * React to the `provision verify` command.
+ */
+ function verifySubscription(ServiceSubscription $serviceSubscription) {
+ $this->subscription = $serviceSubscription;
+ $this->connect();
+ $this->subscription->context->logger->warning('Hi Subscriber. Is your DB ok?');
+ }
+
+ function connect() {
+ $host = $this->subscription->server->getProperty('remote_host');
+ $db = $this->subscription->properties['db_name'];
+ $this->dsn = "mysql:dbname=$db;host=$host";
+ $user = isset($this->subscription->properties['db_user']) ? $this->subscription->properties['db_user'] : '';
+ $pass = isset($this->subscription->properties['db_pass']) ? $this->subscription->properties['db_pass'] : '';
+ try {
+ $this->conn = new \PDO($this->dsn, $user, $pass);
+ return $this->conn;
+ }
+ catch (\PDOException $e) {
+
+ throw new \Exception("Unable to connect. Check database connection info with `provision status {$this->subscription->context->name}`: " . $e->getMessage());
+ }
+ }
+
+
+ //
// /**
// * Register the db handler for sites, based on the db_server option.
// */
diff --git a/src/ServiceSubscription.php b/src/ServiceSubscription.php
index 52d1098..bfc10ec 100644
--- a/src/ServiceSubscription.php
+++ b/src/ServiceSubscription.php
@@ -15,12 +15,17 @@ class ServiceSubscription {
public $service;
public $server;
public $type;
+ public $properties = [];
function __construct($context, $server, $service_name) {
$this->context = $context;
$this->server = $server;
$this->service = $server->getService($service_name);
$this->type = $server->getService($service_name)->type;
+
+ if (isset($context->config['service_subscriptions'][$service_name]['properties'])) {
+ $this->properties = $context->config['service_subscriptions'][$service_name]['properties'];
+ }
}
public function verify() {