phpci/PHPCI/Plugin/Pgsql.php
2013-10-10 01:01:06 +01:00

66 lines
1.6 KiB
PHP

<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2013, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
*/
namespace PHPCI\Plugin;
use PDO;
use PHPCI\Builder;
use PHPCI\Model\Build;
/**
* PgSQL Plugin - Provides access to a PgSQL database.
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Plugins
*/
class Pgsql implements \PHPCI\Plugin
{
protected $phpci;
protected $queries = array();
protected $host;
protected $user;
protected $pass;
public function __construct(Builder $phpci, Build $build, array $options = array())
{
$this->phpci = $phpci;
$this->queries = $options;
$buildSettings = $phpci->getConfig('build_settings');
if (isset($buildSettings['pgsql'])) {
$sql = $buildSettings['pgsql'];
$this->host = $sql['host'];
$this->user = $sql['user'];
$this->pass = $sql['pass'];
}
}
/**
* Connects to PgSQL and runs a specified set of queries.
*/
public function execute()
{
try {
$opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$pdo = new PDO('pgsql:host=' . $this->host, $this->user, $this->pass, $opts);
foreach ($this->queries as $query) {
$pdo->query($query);
}
} catch (\Exception $ex) {
$this->phpci->logFailure($ex->getMessage());
return false;
}
return true;
}
}