aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers/importExportController.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2020-04-30 12:11:51 +0200
committerGravatar GitHub <noreply@github.com> 2020-04-30 12:11:51 +0200
commit8f188ffa8498424653a3e6086ef99bbe1745cd29 (patch)
treee09c5dd3feb23cca561bae5eb3996df7bbfc536f /app/Controllers/importExportController.php
parent4ac868b30102c8fc9c2499a9b56e98c5c2a93ea0 (diff)
Fix filenames for files exported with CLI (#2932)
Filenames were created with the username of the current user. However, when we export the files with the CLI, the current user is "_". This commit makes the username always required in the `exportFile` method so we make sure to always manipulate a real value. Consequently, the filenames can be formatted correctly. Obviously, this has absolutely no impacts since the CLI doesn't consider the HTTP headers. It just makes things a bit more clear. It's a first step to remove the concept of "default user".
Diffstat (limited to 'app/Controllers/importExportController.php')
-rw-r--r--app/Controllers/importExportController.php38
1 files changed, 27 insertions, 11 deletions
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
index 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);
}