changeset 991:3e9e0aa21a18

Add releases dumping.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 30 Nov 2014 03:12:53 +0200
parents 7d7bd913649c
children 5d04bd1a7a10
files faptool.php
diffstat 1 files changed, 46 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/faptool.php	Sat Nov 29 18:28:50 2014 +0200
+++ b/faptool.php	Sun Nov 30 03:12:53 2014 +0200
@@ -446,7 +446,7 @@
 }
 
 
-function wtUnpackEntry($compo, $entry, $pathPrefix, $useOrig, $cropNames)
+function wtUnpackEntry($compo, $entry, $pathPrefix, $useOrig, $cropNames, $copyOnly)
 {
   global $setEntryPath;
 
@@ -474,9 +474,12 @@
   if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === false)
     return FALSE;
 
-  $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames);
+  if ($copyOnly)
+    $dstFileBase = $useOrig ? $efile["origname"] : $efile["filename"];
+  else
+    $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames);
 
-  if ($edata["class"] == EFILE_ARCHIVE)
+  if (!$copyOnly && $edata["class"] == EFILE_ARCHIVE)
   {
     // Entry is an archive file ..
     $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, "")));
@@ -627,6 +630,7 @@
     "  entry <cmd> [args]\n".
     "    status [cid]  - List entries for all compos or <cid>.\n".
     "    unpack <path> - Create subdirs and copy all entries UNPACKED there.\n".
+    "    release <path> - Like unpack, but just copies files (does not unpack archives).\n".
 /*
     "    add <filename> '<name>' '<author>' - Add file as entry file\n".
     "              (works same as uploading from admin interface)\n".
@@ -783,7 +787,45 @@
         foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
         foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
         {
-          wtUnpackEntry($compo, $entry, $setPrefix, TRUE, 32);
+//          wtUnpackEntry($compo, $entry, $setPrefix, TRUE, 32, FALSE);
+          wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, FALSE);
+        }
+        break;
+
+      case "rel":
+        if (($setPrefix = stCArg(3)) == "")
+          die("Releases needs a destination path.\n");
+
+        if (!file_exists($setPrefix) || is_dir($setPrefix))
+        {
+          // Create new one
+          wtMakeDir($setPrefix, 0755);
+          
+          // Create results.txt if it does not exist
+          $resultsFile = stMakePath(FALSE, TRUE, array($setPrefix, "results.txt"));
+          if (!file_exists($resultsFile))
+          {
+            // Use a header file if it exists
+            $resultsHeader = "results.logo";
+            if (file_exists($resultsHeader) && is_file($resultsHeader))
+              $resultsText = file_get_contents($resultsHeader);
+            else
+            {
+              $resultsText = $pageTitle." results";
+              $resultsText .= "\n".str_repeat("=", strlen($resultsText))."-- -\n\n";
+            }
+
+            file_put_contents(
+              $resultsFile,
+              $resultsText.stGetCompoResultsASCIIStr(FALSE, 0)
+              );
+          }
+            
+          foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
+          foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
+          {
+            wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, TRUE);
+          }
         }
         break;