changeset 827:2e18d8102504

Initial import of faptool.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 24 Nov 2014 23:33:24 +0200
parents 8bee2554d95e
children d9cd51966dcf
files faptool.php
diffstat 1 files changed, 100 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/faptool.php	Mon Nov 24 23:33:24 2014 +0200
@@ -0,0 +1,100 @@
+#!/usr/bin/php
+<?
+require_once "mconfig.inc.php";
+require_once "msite.inc.php";
+
+stCheckCLIExec();
+
+
+//
+// Create directories
+//
+function stMakeDir($path, $perm)
+{
+  if (!file_exists($path))
+  {
+    echo " - Creating ".$path."\n";
+    if (mkdir($path, $perm, TRUE) === false)
+      die("Could not create directory '".$path."'\n");
+  }
+}
+
+
+function stInitializeDirs()
+{
+  global $setEntryPath, $setPreviewPath, $setThumbDir,
+    $setEntryPathPerms, $setPrevPathPerms;
+
+  echo "Checking for missing directories ...\n";
+  stMakeDir($setEntryPath, $setEntryPathPerms);
+  stMakeDir($setPreviewPath, $setPrevPathPerms);
+
+  foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
+  {
+    stMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms);
+    stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms);
+    stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir), $setPrevPathPerms));
+  }
+}
+
+
+//
+// Main program starts
+//
+if ($argc < 2)
+{
+  echo
+    "faptool - Do stuff with FAPWeb database\n".
+    "(C) Copyright 2014 ccr/TNSP\n".
+    "\n".
+    "Usage: ".$argv[0]." <mode> [args]\n".
+    "Where mode is one of following:\n".
+    "\n".
+    "  init\n".
+    "     Create directories for entries and previews, if needed.\n".
+    "\n".
+    "\n";
+  exit;
+}
+
+// Try to connect to database
+$spec = stGetSetting("sqlDB");
+if (($db = stConnectSQLDBSpec($spec)) === false)
+  die("Could not connect to SQL database '".$spec."'.\n");
+
+echo "Using database spec '".$spec."'.\n";
+
+// Fetch non-"hardcoded" settings from SQL database
+stReloadSettings();
+
+// Set some globals for our benefit
+$setEntryPath = stGetSetting("entryPath");
+$setPreviewPath = stGetSetting("previewPath");
+$setPreviewURL = stGetSetting("previewURL");
+$setThumbDir = stGetSetting("thumbnailSubDir");
+$setEntryPathPerms = stGetSetting("previewPathPerms", 0711);
+$setPrevPathPerms = stGetSetting("previewPathPerms", 0711);
+
+if ($setEntryPath === FALSE || $setPreviewPath === FALSE ||
+    $setPreviewURL === FALSE || $setThumbDir === FALSE)
+{
+  die("Some required settings not defined in mconfig.inc.php!\n";
+}
+
+
+// Act according to specified command
+switch (substr(stCArgLC(1), 0, 4))
+{
+  case "init":
+    //
+    // Initialize the data directories etc
+    //
+    stInitializeDirs();
+    break;
+
+  default:
+    echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n";
+    break;
+}
+
+?>
\ No newline at end of file