From 6b6842c72b28c1346ef501bc656ec3016d00e1c7 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Mon, 10 Jun 2019 20:49:08 +0000
Subject: [PATCH] Add procedure to match TTSS to GTFS via bus positions

---
 lib/database.php |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/lib/database.php b/lib/database.php
index 48ad047..2c86a7b 100644
--- a/lib/database.php
+++ b/lib/database.php
@@ -20,6 +20,18 @@
 		$this->addStatement = $this->pdo->prepare('INSERT OR REPLACE INTO vehicles (id, num, weight) VALUES (?, ?, ?)');
 	}
 	
+	public function beginTransaction() {
+		$this->pdo->beginTransaction();
+	}
+	
+	public function commit() {
+		$this->pdo->commit();
+	}
+	
+	public function rollback() {
+		$this->pdo->rollback();
+	}
+	
 	public function getById($id) {
 		$this->getByIdStatement->execute([$id]);
 		return $this->getByIdStatement->fetch();
@@ -39,9 +51,11 @@
 	}
 	
 	public function addMapping($mapping) {
+		$this->beginTransaction();
 		$weight = count($mapping);
 		foreach($mapping as $id => $vehicle) {
 			$this->add($id, (int)substr($vehicle['num'], 2), $weight);
 		}
+		$this->commit();
 	}
 }

--
Gitblit v1.9.1