|
|
@@ -14,17 +14,18 @@ use Carbon\CarbonImmutable;
|
|
|
|
|
|
require "../initialise.php";
|
|
|
|
|
|
-if($argc < 4) {
|
|
|
- echo sprintf("Usage: php %s [PATH] [CUSTOMER ID] [REGION CODE]\n", basename(__FILE__));
|
|
|
+if($argc < 3) {
|
|
|
+ echo sprintf("Usage: php %s [PATH] [CUSTOMER ID]\n", basename(__FILE__));
|
|
|
exit(0);
|
|
|
}
|
|
|
|
|
|
$script = array_shift($argv);
|
|
|
$path = array_shift($argv);
|
|
|
$customer_id = array_shift($argv);
|
|
|
-$region_code = array_shift($argv);
|
|
|
|
|
|
+$dry_run = false;
|
|
|
$archive_missing = false;
|
|
|
+$region_code = "GB";
|
|
|
|
|
|
while($argv) {
|
|
|
$argument = array_shift($argv);
|
|
|
@@ -34,6 +35,14 @@ while($argv) {
|
|
|
$archive_missing = true;
|
|
|
break;
|
|
|
|
|
|
+ case "--region-code":
|
|
|
+ $region_code = array_shift($argv);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "--dry-run":
|
|
|
+ $dry_run = true;
|
|
|
+ break;
|
|
|
+
|
|
|
default:
|
|
|
throw new RuntimeException("Invalid argument: " . $argument);
|
|
|
}
|
|
|
@@ -55,7 +64,13 @@ foreach($customer->getLocations() as $location) {
|
|
|
$missing_locations[$location->id] = $location;
|
|
|
}
|
|
|
|
|
|
-$confirm = trim(readline($customer->name . ": Confirm Y/N: "));
|
|
|
+echo $customer->name . "\n";
|
|
|
+echo sprintf("Region Code: %s\n", $region_code);
|
|
|
+if($dry_run) {
|
|
|
+ echo "Dry run\n";
|
|
|
+}
|
|
|
+
|
|
|
+$confirm = trim(readline("Confirm Y/N: "));
|
|
|
if($confirm !== "Y") {
|
|
|
echo "Aborted.\n";
|
|
|
exit(0);
|
|
|
@@ -81,6 +96,8 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
|
|
|
case "Name": $name_column = $index; break;
|
|
|
case "Legal Entity Name": $legal_entity_name_column = $index; break;
|
|
|
|
|
|
+ case "Bar Name": $bar_name_column = $index; break;
|
|
|
+
|
|
|
case "Address": $address_column = $index; break;
|
|
|
case "Address 1": $address_1_column = $index; break;
|
|
|
case "Address 2": $address_2_column = $index; break;
|
|
|
@@ -130,6 +147,7 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
|
|
|
$internal_id = isset($internal_id_column) ? $data[$internal_id_column] : null;
|
|
|
$city = isset($city_column) ? $data[$city_column] : null;
|
|
|
$legal_entity_name = isset($legal_entity_name_column) ? $data[$legal_entity_name_column] : null;
|
|
|
+ $bar_name = isset($bar_name_column) ? $data[$bar_name_column] : null;
|
|
|
$region = isset($region_column) ? $data[$region_column] : null;
|
|
|
$area_manager = isset($area_manager_column) ? $data[$area_manager_column] : null;
|
|
|
$opening_hours = isset($opening_hours_column) ? $data[$opening_hours_column] : null;
|
|
|
@@ -176,7 +194,7 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- echo "Importing $internal_id - $city ... ";
|
|
|
+ echo "Importing $internal_id - $address_1 ($city) ($bar_name) ... ";
|
|
|
|
|
|
$location = Location::queryOne([
|
|
|
"customer_id" => $customer_id,
|
|
|
@@ -214,19 +232,23 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
|
|
|
$location->opening_hours = implode("\n", $hours_parts);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if(!empty($name)) {
|
|
|
$location->name = $name;
|
|
|
if($city && stripos($name, $city) === false) {
|
|
|
$location->name .= " ($city)";
|
|
|
}
|
|
|
+ if($bar_name) {
|
|
|
+ $location->name .= " ($bar_name)";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(!empty($address_1) && !empty($city)) {
|
|
|
$location->address_1 = str_replace(", $city", "", $address_1);
|
|
|
}
|
|
|
|
|
|
- if(!empty($postal_code)) $location->postal_code = $postal_code;
|
|
|
+ if(!empty($postal_code)) {
|
|
|
+ $location->postal_code = $postal_code;
|
|
|
+ }
|
|
|
|
|
|
if($archived !== null) {
|
|
|
$location->archived = $archived ? 1 : 0;
|
|
|
@@ -235,10 +257,8 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
|
|
|
$location->closed = $closed ? 1 : 0;
|
|
|
}
|
|
|
|
|
|
- if($region_code && !$location->latitude) {
|
|
|
-
|
|
|
+ if(!$dry_run && !$location->latitude) {
|
|
|
for($attempt = 0; $attempt < 2; $attempt++) {
|
|
|
-
|
|
|
switch($attempt) {
|
|
|
default:
|
|
|
case 0: $query = $location->getDisplayAddress(); break;
|
|
|
@@ -260,7 +280,13 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $success = $location->commit();
|
|
|
+ if($dry_run) {
|
|
|
+ $success = true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $success = $location->commit();
|
|
|
+ }
|
|
|
+
|
|
|
if(!$success) {
|
|
|
throw new RuntimeException("Commit failed.");
|
|
|
}
|