Browse Source

Make every field optional in venue import script

Alan Lam 7 years ago
parent
commit
9b7cc767bf
2 changed files with 19 additions and 10 deletions
  1. 2 1
      composer.json
  2. 17 9
      tasks/import_venues.php

+ 2 - 1
composer.json

@@ -10,6 +10,7 @@
     "ext-gd": "*",
     "ext-exif": "*",
     "ext-mbstring": "*",
-    "robmorgan/phinx": "^0.11.1"
+    "robmorgan/phinx": "^0.11.1",
+	  "ext-readline": "*"
   }
 }

+ 17 - 9
tasks/import_venues.php

@@ -1,4 +1,4 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
 
 require "../initialise.php";
 
@@ -124,17 +124,25 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
 	if(!empty($region)) $location->region = $region;
 	if(!empty($area_manager)) $location->area_manager = $area_manager;
 
-	$hours_parts = [];
-	if($opening_hours) $hours_parts[] = "Opening Hours: $opening_hours";
-	if($closing_hours) $hours_parts[] = "Closing Hours: $closing_hours";
-	$location->opening_hours = implode("\n", $hours_parts);
+	if(!empty($opening_hours) || !empty($closing_hours)) {
+		$hours_parts = [];
+		if($opening_hours) $hours_parts[] = "Opening Hours: $opening_hours";
+		if($closing_hours) $hours_parts[] = "Closing Hours: $closing_hours";
+		$location->opening_hours = implode("\n", $hours_parts);
+	}
+
+
+	if(!empty($name)) {
+		$location->name = $name;
+		if(stripos($name, $city) === false) {
+			$location->name .= " ($city)";
+		}
+	}
 
-	$location->name = $name;
-	if(stripos($name, $city) === false) {
-		$location->name .= " ($city)";
+	if(!empty($address_1) && !empty($city)) {
+		$location->address_1 = str_replace(", $city", "", $address_1);
 	}
 
-	$location->address_1 = str_replace(", $city", "", $address_1);
 	if(!empty($postal_code)) $location->postal_code = $postal_code;
 
 	if(!$location->latitude) {