A free, self-hostable news aggregator…
Fix filenames for files exported with CLI (#2932)
Marien Fressinaud8f188ffa8498
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.phpindex f2ae8238e..d4e1ae81c 100644--- a/app/Controllers/importExportController.php+++ b/app/Controllers/importExportController.php@@ -720,7 +720,21 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {return $return;}- public function exportFile($export_opml = true, $export_starred = false, $export_labelled = false, $export_feeds = array(), $maxFeedEntries = 50, $username = null) {+ /**+ * Export the files of a user and send them to the user by HTTP+ *+ * @param string $username+ * @param boolean $export_opml+ * @param boolean $export_starred+ * @param boolean $export_labelled+ * @param array|boolean $export_feeds The list of feeds ids to export, true to export all the feeds+ * @param integer $maxFeedEntries Limit the number of entries to export (default is 50)+ *+ * @throws FreshRSS_ZipMissing_Exception if we try to export more than two files and the zip extension doesn't exist+ *+ * @return integer The number of exported files+ */+ public function exportFile($username, $export_opml = true, $export_starred = false, $export_labelled = false, $export_feeds = array(), $maxFeedEntries = 50) {require_once(LIB_PATH . '/lib_opml.php');$this->catDAO = new FreshRSS_CategoryDAO($username);@@ -761,8 +775,9 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {$nb_files = count($export_files);if ($nb_files > 1) {// If there are more than 1 file to export, we need a ZIP archive.+ $filename = 'freshrss_' . $username . '_' . $day . '_export.zip';try {- $this->sendZip($export_files);+ $this->sendZip($filename, $export_files);} catch (Exception $e) {throw new FreshRSS_ZipMissing_Exception($e);}@@ -770,7 +785,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {// Only one file? Guess its type and export it.$filename = key($export_files);$type = self::guessFileType($filename);- $this->sendFile('freshrss_' . Minz_Session::param('currentUser', '_') . '_' . $filename, $export_files[$filename], $type);+ $this->sendFile('freshrss_' . $username . '_' . $filename, $export_files[$filename], $type);}return $nb_files;}@@ -794,11 +809,12 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {$nb_files = 0;try {$nb_files = $this->exportFile(- Minz_Request::param('export_opml', false),- Minz_Request::param('export_starred', false),- Minz_Request::param('export_labelled', false),- Minz_Request::param('export_feeds', array())- );+ Minz_Session::param('currentUser'),+ Minz_Request::param('export_opml', false),+ Minz_Request::param('export_starred', false),+ Minz_Request::param('export_labelled', false),+ Minz_Request::param('export_feeds', array())+ );} catch (FreshRSS_ZipMissing_Exception $zme) {# Oops, there is no ZIP extension!Minz_Request::bad(_t('feedback.import_export.export_no_zip_extension'),@@ -862,10 +878,11 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {/*** This method zips a list of files and returns it by HTTP.*+ * @param string $export_filename The name of the file to export* @param array $files list of files where key is filename and value the content.* @throws Exception if Zip extension is not loaded.*/- private function sendZip($files) {+ private function sendZip($export_filename, $files) {if (!extension_loaded('zip')) {throw new Exception();}@@ -883,8 +900,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {$zip->close();header('Content-Type: application/zip');header('Content-Length: ' . filesize($zip_file));- $day = date('Y-m-d');- header('Content-Disposition: attachment; filename="freshrss_' . Minz_Session::param('currentUser', '_') . '_' . $day . '_export.zip"');+ header('Content-Disposition: attachment; filename="' . $export_filename . '"');readfile($zip_file);unlink($zip_file);}diff --git a/cli/export-opml-for-user.php b/cli/export-opml-for-user.phpindex 8e7ed08f7..79bf1f1b3 100755--- a/cli/export-opml-for-user.php+++ b/cli/export-opml-for-user.php@@ -19,7 +19,7 @@ fwrite(STDERR, 'FreshRSS exporting OPML for user “' . $username . "”…\n");$importController = new FreshRSS_importExport_Controller();$ok = false;-$ok = $importController->exportFile(true, false, false, array(), 0, $username);+$ok = $importController->exportFile($username, true, false, false, array(), 0);invalidateHttpCache($username);diff --git a/cli/export-zip-for-user.php b/cli/export-zip-for-user.phpindex b89a55104..fcefa9ccf 100755--- a/cli/export-zip-for-user.php+++ b/cli/export-zip-for-user.php@@ -20,10 +20,9 @@ fwrite(STDERR, 'FreshRSS exporting ZIP for user “' . $username . "”…\n");$importController = new FreshRSS_importExport_Controller();$ok = false;+$number_entries = empty($options['max-feed-entries']) ? 100 : intval($options['max-feed-entries']);try {- $ok = $importController->exportFile(true, true, true, true,- empty($options['max-feed-entries']) ? 100 : intval($options['max-feed-entries']),- $username);+ $ok = $importController->exportFile($username, true, true, true, true, $number_entries);} catch (FreshRSS_ZipMissing_Exception $zme) {fail('FreshRSS error: Lacking php-zip extension!');}