/**
* {@inheritdoc}
*/
public function saveRun(Run $run)
{
// Just UPDATE title
if ($run->getId()) {
$stmt = $this->connection->prepare('UPDATE bl_run SET title = :title WHERE id = :id');
$stmt->bindValue('title', $run->getTitle());
$stmt->bindValue('id', $run->getId());
$stmt->execute();
return $this;
}
// Insert the run
$stmt = $this->connection->prepare('INSERT INTO bl_run (title, project_name, properties, created_at) VALUES (:title, :project_name, :properties, :created_at)');
$stmt->bindValue('title', $run->getTitle());
$stmt->bindValue('project_name', $run->getProjectName());
$stmt->bindValue('properties', json_encode($run->getProperties()));
$stmt->bindValue('created_at', $run->getCreatedAt(), "datetime");
$stmt->execute();
$run->setId($this->connection->lastInsertId());
// Insert units
foreach ($run->getUnits() as $unit) {
$stmt = $this->connection->prepare('
INSERT INTO bl_run_unit
(run_id, feature, created_at, started_at, finished_at, return_code, output_files)
VALUES
(:run_id, :feature, :created_at, :started_at, :finished_at, :return_code, :output_files)
');
$stmt->bindValue('run_id', $run->getId());
$stmt->bindValue('feature', $unit->getFeature());
$stmt->bindValue('created_at', $unit->getCreatedAt(), "datetime");
$stmt->bindValue('started_at', $unit->getStartedAt(), "datetime");
$stmt->bindValue('finished_at', $unit->getFinishedAt(), "datetime");
$stmt->bindValue('return_code', $unit->getReturnCode());
$stmt->bindValue('output_files', json_encode($unit->getOutputFiles()->toArrayOfID()));
$stmt->execute();
$unit->setId($this->connection->lastInsertId());
}
return $this;
}