Kaynağa Gözat

Cleanup import venues script

Alan Lam 4 yıl önce
ebeveyn
işleme
9ca6c4608d
1 değiştirilmiş dosya ile 18 ekleme ve 6 silme
  1. 18 6
      tasks/import_venues.php

+ 18 - 6
tasks/import_venues.php

@@ -12,22 +12,34 @@
 
 require "../initialise.php";
 
-if($argc < 3) {
-	die(sprintf("Usage: php %s [PATH] [CUSTOMER ID] [REGION CODE]\n", basename(__FILE__)));
+if($argc < 4) {
+	echo sprintf("Usage: php %s [PATH] [CUSTOMER ID] [REGION CODE]\n", basename(__FILE__));
+	exit(0);
 }
 
+[$script, $path, $customer_id, $region_code] = $argv;
+
 $script = array_shift($argv);
 $path = array_shift($argv);
 $customer_id = array_shift($argv);
 $region_code = array_shift($argv);
 
-if(!file_exists($path)) die($path . " not found.");
+if(!file_exists($path)) {
+	echo $path . " not found.\n";
+	exit(1);
+}
 
 $customer = Customer::get($customer_id);
-if(!$customer) die("Customer not found.");
+if(!$customer) {
+	echo "Customer not found.\n";
+	exit(1);
+}
 
 $confirm = trim(readline($customer->name . ": Confirm Y/N: "));
-if($confirm !== "Y") die("Aborted");
+if($confirm !== "Y") {
+	echo "Aborted.\n";
+	exit(0);
+}
 
 $handle = fopen($path, "rb");
 
@@ -89,7 +101,7 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
 					break;
 
 				default:
-					throw new Exception("Unknown field name: {$field_name}");
+					throw new RuntimeException("Unknown field name: {$field_name}");
 			}
 		}
 		continue;