Merge pull request #403 from corpsee/sqlite-plugin
Added SQLite plugin, improved SQL plugins
This commit is contained in:
commit
aed38a0aca
|
@ -9,7 +9,6 @@
|
|||
|
||||
namespace PHPCI;
|
||||
|
||||
use PHPCI\Builder;
|
||||
use PHPCI\Model\Build;
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,24 +22,41 @@ use PHPCI\Model\Build;
|
|||
*/
|
||||
class Mysql implements \PHPCI\Plugin
|
||||
{
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* Database Connection
|
||||
* @var PDO
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
protected $pdo;
|
||||
|
||||
public function __construct(Builder $phpci, Build $build, array $options = array())
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
|
@ -74,19 +91,18 @@ class Mysql implements \PHPCI\Plugin
|
|||
|
||||
/**
|
||||
* Connects to MySQL and runs a specified set of queries.
|
||||
* @return boolean
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$success = true;
|
||||
|
||||
try {
|
||||
$opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
|
||||
$this->pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, $opts);
|
||||
$pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, $opts);
|
||||
|
||||
foreach ($this->queries as $query) {
|
||||
if (!is_array($query)) {
|
||||
// Simple query
|
||||
$this->pdo->query($this->phpci->interpolate($query));
|
||||
$pdo->query($this->phpci->interpolate($query));
|
||||
} elseif (isset($query['import'])) {
|
||||
// SQL file execution
|
||||
$this->executeFile($query['import']);
|
||||
|
@ -98,10 +114,14 @@ class Mysql implements \PHPCI\Plugin
|
|||
$this->phpci->logFailure($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return $success;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function executeFile($query)
|
||||
{
|
||||
if (!isset($query['file'])) {
|
||||
|
|
|
@ -21,18 +21,45 @@ use PHPCI\Model\Build;
|
|||
*/
|
||||
class Pgsql implements \PHPCI\Plugin
|
||||
{
|
||||
/**
|
||||
* @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->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->queries = $options;
|
||||
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
|
@ -47,6 +74,7 @@ class Pgsql implements \PHPCI\Plugin
|
|||
|
||||
/**
|
||||
* Connects to PgSQL and runs a specified set of queries.
|
||||
* @return boolean
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
|
@ -61,7 +89,6 @@ class Pgsql implements \PHPCI\Plugin
|
|||
$this->phpci->logFailure($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
81
PHPCI/Plugin/Sqlite.php
Normal file
81
PHPCI/Plugin/Sqlite.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* 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;
|
||||
use PHPCI\Builder;
|
||||
use PHPCI\Model\Build;
|
||||
|
||||
/**
|
||||
* SQLite Plugin — Provides access to a SQLite database.
|
||||
* @author Corpsee <poisoncorpsee@gmail.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Sqlite implements \PHPCI\Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCI\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCI\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $queries = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @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['sqlite'])) {
|
||||
$sql = $buildSettings['sqlite'];
|
||||
$this->path = $sql['path'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to SQLite and runs a specified set of queries.
|
||||
* @return boolean
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
try {
|
||||
$opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
|
||||
$pdo = new PDO('sqlite:' . $this->path, $opts);
|
||||
|
||||
foreach ($this->queries as $query) {
|
||||
$pdo->query($query);
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
$this->phpci->logFailure($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue