Changeset 27507 for documentation/trunk

Show
Ignore:
Timestamp:
29.05.2013 12:47:32 (7 years ago)
Author:
jmt12
Message:

Ensuring the downloadable versions of the XML exports are stored in a writable location, are now downloaded as archives (ZIP and TGZ) containing the XML and images, and clean up old files left lying around

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • documentation/trunk/php/gs-manual-export.php

    r25026 r27507  
    1919 
    2020// 0. Initialization 
    21 $xml_source_path = '/research/jmt12/gsdl-docs/temp'; 
     21 
    2222// - we have a counter to assign identifiers to text blocks etc without ids 
    2323$text_id_counter = 1; 
     
    4444{ 
    4545  $_REQUEST['a'] = 'store'; // Try to store the file to disk 
     46} 
     47 
     48$var_path = filecat(array($base_path, 'var')); 
     49$timestamp = time(); 
     50//$xml_source_path = '**PATH TO GSDL MANUALS**' 
     51$xml_source_path = '/tmp'; 
     52if ($_REQUEST['a'] == 'download') 
     53{ 
     54  // Clear out previous exports 
     55  recursiveRemove($var_path, '/greenstone/greenstone-documentation/php/var'); 
     56  // New export 
     57  $xml_source_path = fileCat(array($var_path, $timestamp)); 
    4658} 
    4759 
     
    6678echo '<p><b>Manual:</b> ' . $_REQUEST['m'] . ' <b>Language:</b> ' . $_REQUEST['l'] . "</p>\n<hr/>\n"; 
    6779// 1. Create the XML output file handle 
    68 $xml_file_path = ''; 
    69 if ($_REQUEST['a'] == 'download') 
    70 { 
    71   $xml_file_path = fileCat(array($base_path, 'var', ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml')); 
    72 } 
    73 else 
    74 { 
    75   // - construct the path using the information we've been provided as arguments 
    76   $xml_file_dir = $xml_source_path . '/' . $_REQUEST['l']; 
    77   mkAllDir($xml_file_dir, 0755); 
    78   $xml_file_path = $xml_file_dir . '/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml'; 
    79   // - backup any existing file 
    80   if (file_exists($xml_file_path)) 
    81   { 
    82     $xml_backup_file_path = $xml_file_path . '.bak'; 
    83     if (!rename($xml_file_path, $xml_backup_file_path)) 
    84     { 
    85       printError('Failed to rename existing manual file for backup'); 
    86     } 
    87   } 
    88 } 
     80// - construct the path using the information we've been provided as arguments 
     81$xml_file_dir = $xml_source_path . '/' . $_REQUEST['l']; 
     82mkAllDir($xml_file_dir); 
     83$xml_file_path = $xml_file_dir . '/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml'; 
     84// - backup any existing file 
     85if (file_exists($xml_file_path)) 
     86{ 
     87  $xml_backup_file_path = $xml_file_path . '.bak'; 
     88  if (!rename($xml_file_path, $xml_backup_file_path)) 
     89  { 
     90    printError('Failed to rename existing manual file for backup'); 
     91  } 
     92} 
     93 
    8994// - and create a handle to the new file 
    9095$xml_out = fopen($xml_file_path, 'w'); 
     
    226231fwrite($xml_out, '</Manual>' . "\n"); 
    227232fclose($xml_out); 
     233chmod($xml_file_path, 0664); 
    228234 
    229235// 6. Complete! 
     
    231237if ($_REQUEST['a'] == 'download') 
    232238{ 
    233   echo '<p>Click <a href="var/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml">here</a> to download XML file</p>' . "\n"; 
     239  // Zip up the manual files 
     240  $zip_file = ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.zip'; 
     241  $zip_path = fileCat(array($xml_source_path, $zip_file)); 
     242  $zip_command = 'zip -r "' . $zip_path . '" . > /dev/null 2>&1'; 
     243  //cho '<p><b>[DEBUG]</b> zip_command:' . $zip_command . '</p>'; 
     244  $tgz_file = ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.tgz'; 
     245  $tgz_path = fileCat(array($xml_source_path, $tgz_file)); 
     246  $tgz_command = 'tar -czf "' . $tgz_path . '" * > /dev/null 2>&1'; 
     247  //cho '<p><b>[DEBUG]</b> tgz_command:' . $tgz_command . '</p>'; 
     248  // We need to move to the document folder so that archives have sensible paths 
     249  $original_cwd = getcwd(); 
     250  chdir($xml_file_dir); 
     251  system($zip_command); 
     252  system($tgz_command); 
     253  // Go back 
     254  chdir($original_cwd); 
     255  // Links are ready 
     256  echo '<p>Download XML file plus images as: <a href="var/' . $timestamp . '/' . $zip_file . '">ZIP</a> or <a href="var/' . $timestamp . '/' . $tgz_file . '">TGZ</a></p>' . "\n"; 
    234257} 
    235258echo '<p>Click <a href="' . $dokuwiki_url . '/doku.php?id=' . $_REQUEST['l'] . ':manuals:' . $_REQUEST['m'] . '">here</a> to return to dokuwiki</p>' . "\n"; 
     
    12051228    $image_source_path = $dokuwiki_path . '/data/media/' . $_REQUEST['l'] . '/manuals/images/' . strtolower($filename); 
    12061229    $image_destination_dir = $xml_source_path . '/' . $_REQUEST['l'] . '/images'; 
    1207     mkAllDir($image_destination_dir, 0755); 
     1230    mkAllDir($image_destination_dir); 
    12081231    $image_destination_path = $image_destination_dir . '/' . $filename; 
    12091232    if (copy($image_source_path, $image_destination_path)) 
    12101233    { 
    12111234      echo '[copying file: ' . $filename . "] \n"; 
     1235      chmod($image_destination_path, 0664); 
    12121236    } 
    12131237    else