Permalink
Browse files

simplify generate.php; use the php system temp directory for better W…

…AMP support
  • Loading branch information...
1 parent e99e779 commit 7c258423d87552dafabe0bade224e3e77a310a09 @benbalter benbalter committed Aug 13, 2012
Showing with 24 additions and 25 deletions.
  1. +24 −25 includes/generate.php
View
@@ -50,35 +50,29 @@
}
-//create temporary scratch directory
-$dir['tmp'] = '/tmp/' . md5( time() );
-
-// Check for a value in the report directory constant.
-if (DGS_REPORT_DIR) {
- // Files will be created in the specified report directory and will not be zipped.
- $dir['rpt'] = DGS_REPORT_DIR;
-}
// Files will be created in a temporary directory and added to zip file.
-// Create the temporary directory.
-mkdir( $dir['tmp'] );
-// Create zip file.
-$zipfile = "{$report->agency}-report.zip";
-foreach ($dir as $id => $loc) {
- //json
- file_put_contents( $loc . '/digitalstrategy.json', json_encode( $report ) );
+//create temporary scratch directory in PHP's default temp directory
+//this allows the project to run on both unix and WAMP systems (e.g., where /tmp/ doesn't exist)
+$dir = sys_get_temp_dir() . '/dgs-' . md5( time() );
+mkdir( $dir );
- //xml
- $xml = new SimpleXMLElement( '<report></report>' );
- $xml = dgs_to_xml( $report, $xml );
- file_put_contents( $loc . '/digitalstrategy.xml', dgs_tidy_xml( $xml ) );
+//generate the payload
- //html
- file_put_contents( $loc . '/digitalstrategy.html', dgs_to_html( $report ) );
-}
+//json
+file_put_contents( $dir . '/digitalstrategy.json', json_encode( $report ) );
-$zip = "{$dir['tmp']}/$zipfile";
-dgs_zip( $dir['tmp'], $zip );
+//xml
+$xml = new SimpleXMLElement( '<report></report>' );
+$xml = dgs_to_xml( $report, $xml );
+file_put_contents( $dir . '/digitalstrategy.xml', dgs_tidy_xml( $xml ) );
+
+//html
+file_put_contents( $dir . '/digitalstrategy.html', dgs_to_html( $report ) );
+
+// Create zip file.
+$filename = "{$report->agency}-report.zip";
+dgs_zip( $dir, "{$dir}/$filename" );
//send headers
header( 'Content-Type: application/zip' );
@@ -88,7 +82,12 @@
//read file
readfile( $zip );
+//Check for a value in the report directory constant
+//if it exists, move the files into the report directory for easy access before clearing the scratch directory
+if ( DGS_REPORT_DIR )
+ copy( $dir, DGS_REPORT_DIR );
+
//cleanup
-dgs_cleanup( $dir['tmp'] );
+dgs_cleanup( $dir );
exit();

0 comments on commit 7c25842

Please sign in to comment.