php-censor/PHPCI/Plugin/Mysql.php

58 lines
1.4 KiB
PHP
Raw Normal View History

2013-05-10 13:28:43 +02:00
<?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/
*/
2013-05-10 13:28:43 +02:00
namespace PHPCI\Plugin;
use PDO;
2013-05-10 13:28:43 +02:00
class Mysql implements \PHPCI\Plugin
{
protected $phpci;
protected $queries = array();
protected $host;
protected $user;
protected $pass;
2013-05-10 13:28:43 +02:00
public function __construct(\PHPCI\Builder $phpci, array $options = array())
{
$this->phpci = $phpci;
$this->queries = $options;
$db = \b8\Database::getConnection('write')->getDetails();
$this->host = PHPCI_DB_HOST;
$this->user = $db['user'];
$this->pass = $db['pass'];
$buildSettings = $phpci->getConfig('build_settings');
if(isset($buildSettings['mysql'])) {
$sql = $buildSettings['mysql'];
$this->host = !empty($sql['host']) ? $sql['host'] : $this->host;
$this->user = !empty($sql['user']) ? $sql['user'] : $this->user;
$this->pass = array_key_exists('pass', $sql) ? $sql['pass'] : $this->pass;
}
2013-05-10 13:28:43 +02:00
}
public function execute()
{
try {
$pdo = new PDO('mysql: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;
2013-05-10 13:28:43 +02:00
}
return true;
2013-05-10 13:28:43 +02:00
}
}