changeset 50:184a4188555c

Move CLI helper functions to createdb.php, as they are now only used there.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 05 Oct 2013 04:14:21 +0300
parents ba33b18c03b5
children 7bdf89601ba0
files createdb.php msite.inc.php
diffstat 2 files changed, 37 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/createdb.php	Sat Oct 05 04:09:05 2013 +0300
+++ b/createdb.php	Sat Oct 05 04:14:21 2013 +0300
@@ -3,8 +3,43 @@
 require "mconfig.inc.php";
 require "msite.inc.php";
 
-// We don't want to be run from anywhere else than commandline
-stCheckCLIOrDie();
+//
+// CLI utility helper functions
+//
+function stCArg($index)
+{
+  global $argc, $argv;
+  if ($index < $argc)
+    return $argv[$index];
+  else
+    return FALSE;
+}
+
+function stCArgLC($index)
+{
+  global $argc, $argv;
+  if ($index < $argc)
+    return strtolower($argv[$index]);
+  else
+    return FALSE;
+}
+
+
+function stCSQLError($sql)
+{
+  global $db;
+  die("Error executing SQL query: ".implode("; ", $db->errorInfo())." in statement \"".$sql."\"\n");
+  exit;
+}
+
+
+// Check if we are running from commandline or not
+if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"]))
+{
+  header("Status: 404 Not Found");
+  die();
+}
+
 
 
 // The defaults we put in
--- a/msite.inc.php	Sat Oct 05 04:09:05 2013 +0300
+++ b/msite.inc.php	Sat Oct 05 04:14:21 2013 +0300
@@ -377,46 +377,6 @@
 
 
 //
-// CLI utility helper functions
-//
-function stCArg($index)
-{
-  global $argc, $argv;
-  if ($index < $argc)
-    return $argv[$index];
-  else
-    return FALSE;
-}
-
-function stCArgLC($index)
-{
-  global $argc, $argv;
-  if ($index < $argc)
-    return strtolower($argv[$index]);
-  else
-    return FALSE;
-}
-
-
-function stCSQLError($sql)
-{
-  global $db;
-  die("Error executing SQL query: ".implode("; ", $db->errorInfo())." in statement \"".$sql."\"\n");
-  exit;
-}
-
-
-function stCheckCLIOrDie()
-{
-  if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"]))
-  {
-    header("Status: 404 Not Found");
-    die();
-  }
-}
-
-
-//
 // Site-specific common functions .. these should be elsewhere
 //
 function stPrintAttendee($item, $row, $edit, $eclass = "")