phpci/PHPCI/Plugin/Pgsql.php

59 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2013-05-16 03:16:56 +02:00
/**
* 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;
/**
* 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(\PHPCI\Builder $phpci, 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'];
}
}
public function execute()
{
try {
$pdo = new PDO('pgsql:host=' . $this->host, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
foreach($this->queries as $query) {
$pdo->query($query);
}
}
catch(\Exception $ex) {
$this->phpci->logFailure($ex->getMessage());
return false;
}
return true;
}
}