diff --git a/src/Service/DbService.php b/src/Service/DbService.php index f58c58c2f5e3e131f0581fc8467f68edf5a38588..9cb2b15f9c24efcbb36b16eda8afd01519072e42 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 52d1098faa6fe51710ff36de380c3b4a0800c52d..bfc10ec2af0f6a185e4e05934857f6f1a69e151c 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() {