Added Sqlite plugin
This commit is contained in:
parent
66772d3bf1
commit
3e7c38df35
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