From 7698583a2b774b68ef1a24f87023c8385d671f9f Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Thu, 13 Jun 2019 18:55:17 +0000
Subject: [PATCH] Factor out common section out of proxy_bus.php and proxy_tram.php

---
 stops/populate_db.php |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/stops/populate_db.php b/stops/populate_db.php
index 3364d2d..845ec95 100644
--- a/stops/populate_db.php
+++ b/stops/populate_db.php
@@ -9,17 +9,21 @@
 $pdo->query('DROP TABLE IF EXISTS stop_search');
 $pdo->query('CREATE TABLE stop_search (
 	word VARCHAR(60),
-	id INT
+	id VARCHAR(255)
 )');
+
+function processStops($st, $stops) {
+	foreach($stops as $id => $name) {
+		foreach(split_stop_name($name) as $word) {
+			$st->execute([$word, $id]);
+			$st->closeCursor();
+		}
+	}
+}
 
 $pdo->beginTransaction();
 $st = $pdo->prepare('INSERT INTO stop_search (word, id) VALUES (?, ?)');
-foreach($stops as $id => $name) {
-	foreach(split_stop_name($name) as $word) {
-		$st->execute(array($word, $id));
-		$st->closeCursor();
-	}
-}
+processStops($st, $stops);
 $pdo->commit();
 
 $pdo->query('CREATE INDEX stop_search_word ON stop_search (word COLLATE NOCASE)');

--
Gitblit v1.9.1