* @package PHPCI * @subpackage Plugins */ class Pgsql implements PluginInterface { /** * @var \PHPCI\Builder */ protected $phpci; /** * @var \PHPCI\Model\Build */ protected $build; /** * @var array */ protected $queries = array(); /** * @var string */ protected $host; /** * @var string */ protected $user; /** * @var string */ protected $pass; /** * @param Builder $phpci * @param Build $build * @param array $options */ public function __construct(Builder $phpci, Build $build, array $options = array()) { $this->phpci = $phpci; $this->build = $build; $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']; } } /** * {@inheritDocs} */ 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($this->phpci->interpolate($query)); } } catch (\Exception $ex) { $this->phpci->logFailure($ex->getMessage()); return false; } return true; } }