Add optional datetime format for fixtures

This allows to use the same insertionStrategy class for MySQL
and PgSQL, as they only differ in the datetime format.

refs #4417
This commit is contained in:
Jannis Moßhammer 2013-07-16 16:37:16 +02:00
parent 0e6de0718e
commit c0b5aa962d
3 changed files with 6 additions and 3 deletions

View File

@ -30,6 +30,7 @@ class DataSourceTestSetup implements SetupStrategy, InsertionStrategy
} elseif ($type == 'pgsql') {
$this->setupStrategy = new PgSQLSetupStrategy();
$this->insertionStrategy = new PDOInsertionStrategy();
$this->insertionStrategy->datetimeFormat = "Y-m-d H:i:s";
} else {
throw new \Exception('Unsupported backend '.$type);
}

View File

@ -10,7 +10,7 @@ class ObjectFlags {
public $in_downtime = 0;
public $time = 0;
public function ObjectFlags($ageInSeconds = null) {
public function __construct($ageInSeconds = null) {
if(!is_int($ageInSeconds))
$ageInSeconds = 0;
$this->time = time()-$ageInSeconds;

View File

@ -8,6 +8,8 @@ class PDOInsertionStrategy {
private $fixture;
private $connection;
public $datetimeFormat = "U";
public function setConnection($connection) {
$this->connection = $connection;
}
@ -62,7 +64,7 @@ class PDOInsertionStrategy {
$host["icon_image"], $host["notes_url"], $host["action_url"]
));
$insertHostStatusQuery->execute(array(
$this->objectId, $host["state"], $flags->time, $flags->notifications,
$this->objectId, $host["state"], date($this->datetimeFormat, $flags->time), $flags->notifications,
$flags->active_checks, $flags->passive_checks, $flags->flapping, $flags->in_downtime));
foreach($host["contacts"] as $contact) {
@ -112,7 +114,7 @@ class PDOInsertionStrategy {
$service["notes_url"], $service["action_url"], $service["icon_image"]
));
$insertServiceStatusQuery->execute(array(
$this->objectId, $service["state"], $flags->time, $flags->notifications,
$this->objectId, $service["state"], date($this->datetimeFormat, $flags->time), $flags->notifications,
$flags->active_checks, $flags->passive_checks, $flags->flapping, $flags->in_downtime));
foreach($service["contacts"] as $contact) {