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;
|
2013-05-16 01:51:48 +02:00
|
|
|
use PDO;
|
2013-05-10 13:28:43 +02:00
|
|
|
|
|
|
|
class Mysql implements \PHPCI\Plugin
|
|
|
|
{
|
|
|
|
protected $phpci;
|
|
|
|
protected $queries = array();
|
|
|
|
|
2013-05-16 01:51:48 +02:00
|
|
|
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;
|
2013-05-16 01:51:48 +02:00
|
|
|
|
|
|
|
$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()
|
|
|
|
{
|
2013-05-16 01:51:48 +02:00
|
|
|
try {
|
|
|
|
$pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
2013-05-10 16:00:24 +02:00
|
|
|
|
2013-05-16 01:51:48 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-05-16 01:51:48 +02:00
|
|
|
return true;
|
2013-05-10 13:28:43 +02:00
|
|
|
}
|
|
|
|
}
|