2013-05-16 01:52:18 +02:00
|
|
|
<?php
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
2014-05-12 18:26:17 +02:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
2013-05-16 01:52:18 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Plugin;
|
2013-05-16 16:50:19 +02:00
|
|
|
|
2013-05-16 01:52:18 +02:00
|
|
|
use PDO;
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Builder;
|
|
|
|
use PHPCI\Model\Build;
|
2013-05-16 01:52:18 +02:00
|
|
|
|
2013-05-16 03:30:48 +02:00
|
|
|
/**
|
|
|
|
* PgSQL Plugin - Provides access to a PgSQL database.
|
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
2013-05-16 01:52:18 +02:00
|
|
|
class Pgsql implements \PHPCI\Plugin
|
|
|
|
{
|
2014-05-09 18:49:20 +02:00
|
|
|
/**
|
|
|
|
* @var \PHPCI\Builder
|
|
|
|
*/
|
2013-05-16 16:50:19 +02:00
|
|
|
protected $phpci;
|
2014-05-09 18:49:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \PHPCI\Model\Build
|
|
|
|
*/
|
2014-05-02 15:48:40 +02:00
|
|
|
protected $build;
|
2014-05-09 18:49:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-05-16 16:50:19 +02:00
|
|
|
protected $queries = array();
|
|
|
|
|
2014-05-09 18:49:20 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2013-05-16 16:50:19 +02:00
|
|
|
protected $host;
|
2014-05-09 18:49:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2013-05-16 16:50:19 +02:00
|
|
|
protected $user;
|
2014-05-09 18:49:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2013-05-16 16:50:19 +02:00
|
|
|
protected $pass;
|
|
|
|
|
2014-05-09 18:49:20 +02:00
|
|
|
/**
|
|
|
|
* @param Builder $phpci
|
|
|
|
* @param Build $build
|
|
|
|
* @param array $options
|
|
|
|
*/
|
2013-10-10 02:01:06 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-05-16 16:50:19 +02:00
|
|
|
{
|
2014-05-09 18:49:20 +02:00
|
|
|
$this->phpci = $phpci;
|
|
|
|
$this->build = $build;
|
2014-05-02 15:48:40 +02:00
|
|
|
$this->queries = $options;
|
2013-05-16 16:50:19 +02:00
|
|
|
|
|
|
|
$buildSettings = $phpci->getConfig('build_settings');
|
|
|
|
|
|
|
|
if (isset($buildSettings['pgsql'])) {
|
2014-05-02 15:48:40 +02:00
|
|
|
$sql = $buildSettings['pgsql'];
|
2013-05-16 16:50:19 +02:00
|
|
|
$this->host = $sql['host'];
|
|
|
|
$this->user = $sql['user'];
|
|
|
|
$this->pass = $sql['pass'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 18:17:29 +02:00
|
|
|
/**
|
|
|
|
* Connects to PgSQL and runs a specified set of queries.
|
2014-05-09 18:49:20 +02:00
|
|
|
* @return boolean
|
2013-05-16 18:17:29 +02:00
|
|
|
*/
|
2013-05-16 16:50:19 +02:00
|
|
|
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) {
|
2015-01-22 10:28:16 +01:00
|
|
|
$pdo->query($this->phpci->interpolate($query));
|
2013-05-16 16:50:19 +02:00
|
|
|
}
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
$this->phpci->logFailure($ex->getMessage());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|