Index: include/lib_phpt_generator.inc.php =================================================================== RCS file: /repository/docweb/include/lib_phpt_generator.inc.php,v retrieving revision 1.4 diff -u -r1.4 lib_phpt_generator.inc.php --- include/lib_phpt_generator.inc.php 30 Nov 2006 16:42:09 -0000 1.4 +++ include/lib_phpt_generator.inc.php 2 Dec 2006 11:24:06 -0000 @@ -323,12 +323,76 @@ $myArchive->addString('test'.$row['id'].'.phpt', phpt_generate($row)); } + // Destructor, to correctly close the file + $myArchive->_Archive_Tar(); + readfile($archivePath); unlink($archivePath); } } +/** + * Generate a list of examples selected by flag + * + * @return null + */ +function phpt_generate_all($sqlite, $flags) +{ + + // select data + + $sql_query = 'SELECT id, + title, + location, + test, + skipif, + expected, + edit_date, + import_date, + flags + FROM tests + WHERE flags & '.$flags.' = '.$flags; + + $results = sqlite_query($sqlite, $sql_query); + + if (count($ids) === 1) { + phpt_download(sqlite_fetch_array($results, SQLITE_ASSOC)); + } else { + $flags_verbose = array(); + if ($flags & PHPT_FLAG_FILLED) { + $flags_verbose[] = 'filled'; + } + + if ($flags & PHPT_FLAG_APPROVED) { + $flags_verbose[] = 'approved'; + } + + if ($flags & PHPT_FLAG_IMPLEMENTED) { + $flags_verbose[] = 'implemented'; + } + + + $archivePath = '/tmp/phpt_'.implode('_', $flags_verbose).'.tgz'; + + header('Content-Type: application/gzip'); + header('Content-Disposition: attachment; filename='.basename($archivePath)); + + + + $myArchive = new Archive_Tar($archivePath, 'gz'); + + while ($row = sqlite_fetch_array($results, SQLITE_ASSOC)) { + $myArchive->addString('test'.$row['id'].'.phpt', phpt_generate($row)); + } + // Destructor, to correctly close the file + $myArchive->_Archive_Tar(); + + readfile($archivePath); + unlink($archivePath); + + } +} /** * Delete a list of tests * Index: www/phpt_generator.php =================================================================== RCS file: /repository/docweb/www/phpt_generator.php,v retrieving revision 1.2 diff -u -r1.2 phpt_generator.php --- www/phpt_generator.php 27 Nov 2006 18:50:21 -0000 1.2 +++ www/phpt_generator.php 2 Dec 2006 11:24:06 -0000 @@ -50,23 +50,11 @@ } /** - * Generate every tests + * Generate every filled tests */ if (isset($_REQUEST['generateAll'])) { - $sql_query = 'SELECT id - FROM tests - WHERE flags & '.PHPT_FLAG_FILLED; - - $results = sqlite_query($sqlite, $sql_query); - - $ids = array(); - - while($row = sqlite_fetch_array($results, SQLITE_ASSOC)) { - $ids[] = $row['id']; - } - - phpt_generate_list($sqlite, $ids); + phpt_generate_all($sqlite, PHPT_FLAG_FILLED); exit; }