From 854736fac7fd0f43aca23229685868ec23191978 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 12 Feb 2016 14:12:14 -0500 Subject: [PATCH 1/3] - Updates error messages --- views/subscribers/importExport/import/step2.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/subscribers/importExport/import/step2.html b/views/subscribers/importExport/import/step2.html index 938019f943..89b0b783f3 100644 --- a/views/subscribers/importExport/import/step2.html +++ b/views/subscribers/importExport/import/step2.html @@ -140,10 +140,10 @@

- <%= __('You need to specify a name') %> + <%= __('You need to specify a name.') %>

- <%= __('This name is already taken') %> + <%= __('Another record already exists. Please specify a different "%1$s".')|format('name') %>

From 636fa38ab65ec04bdd3e688ce94f4d2255bed3a5 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 16 Feb 2016 17:32:41 -0500 Subject: [PATCH 2/3] - Enables check for writable export file --- assets/js/src/subscribers/importExport/export.js | 2 +- lib/Subscribers/ImportExport/Export/Export.php | 3 +++ tests/unit/Subscribers/ImportExport/Export/ExportCest.php | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/assets/js/src/subscribers/importExport/export.js b/assets/js/src/subscribers/importExport/export.js index 9debbfe57a..1608784341 100644 --- a/assets/js/src/subscribers/importExport/export.js +++ b/assets/js/src/subscribers/importExport/export.js @@ -148,7 +148,7 @@ define( .done(function (response) { MailPoet.Modal.loading(false); if (response.result === false) { - MailPoet.Notice.error(response.error); + MailPoet.Notice.error(response.errors); } else { resultMessage = MailPoetI18n.exportMessage .replace('%1$s', '' + response.data.totalExported + '') diff --git a/lib/Subscribers/ImportExport/Export/Export.php b/lib/Subscribers/ImportExport/Export/Export.php index a0fc082a5c..2a295838b0 100644 --- a/lib/Subscribers/ImportExport/Export/Export.php +++ b/lib/Subscribers/ImportExport/Export/Export.php @@ -41,6 +41,9 @@ class Export { $subscriber_custom_fields ); try { + if(is_writable($this->export_file)) { + throw new \Exception(__("Couldn't save export file on the server.")); + } if($this->export_format_option === 'csv') { $CSV_file = fopen($this->export_file, 'w'); $format_CSV = function($row) { diff --git a/tests/unit/Subscribers/ImportExport/Export/ExportCest.php b/tests/unit/Subscribers/ImportExport/Export/ExportCest.php index 5db81bc9b8..cc0ea01427 100644 --- a/tests/unit/Subscribers/ImportExport/Export/ExportCest.php +++ b/tests/unit/Subscribers/ImportExport/Export/ExportCest.php @@ -211,6 +211,13 @@ class ExportCest { expect(count($subscribers))->equals(2); } + function itRequiresWritableExportFile() { + $this->export->export_file = '/dev/random'; + $result = $this->export->process(); + expect($result['errors'][0]) + ->equals("Couldn't save export file on the server."); + } + function itCanProcess() { $this->export->export_file = $this->export->getExportFile('csv'); $this->export->export_format_option = 'csv'; From b5864adf0637a6de794b237c297f6dfbf6cfcfe6 Mon Sep 17 00:00:00 2001 From: Vlad Date: Wed, 17 Feb 2016 11:47:20 -0500 Subject: [PATCH 3/3] - Fixes writable path check --- lib/Subscribers/ImportExport/Export/Export.php | 18 ++++++++++-------- .../ImportExport/Export/ExportCest.php | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/Subscribers/ImportExport/Export/Export.php b/lib/Subscribers/ImportExport/Export/Export.php index 2a295838b0..ef6978a9f5 100644 --- a/lib/Subscribers/ImportExport/Export/Export.php +++ b/lib/Subscribers/ImportExport/Export/Export.php @@ -17,6 +17,7 @@ class Export { public $segments; public $subscribers_without_segment; public $subscriber_fields; + public $export_path; public $export_file; public $export_file_URL; public $profiler_start; @@ -28,22 +29,23 @@ class Export { $this->segments = $data['segments']; $this->subscribers_without_segment = array_search(0, $this->segments); $this->subscriber_fields = $data['subscriber_fields']; + $this->export_path = Env::$temp_path; $this->export_file = $this->getExportFile($this->export_format_option); $this->export_file_URL = $this->getExportFileURL($this->export_file); $this->profiler_start = microtime(true); } function process() { - $subscribers = $this->getSubscribers(); - $subscriber_custom_fields = $this->getSubscriberCustomFields(); - $formatted_subscriber_fields = $this->formatSubscriberFields( - $this->subscriber_fields, - $subscriber_custom_fields - ); try { - if(is_writable($this->export_file)) { + if(is_writable($this->export_path) === false) { throw new \Exception(__("Couldn't save export file on the server.")); } + $subscribers = $this->getSubscribers(); + $subscriber_custom_fields = $this->getSubscriberCustomFields(); + $formatted_subscriber_fields = $this->formatSubscriberFields( + $this->subscriber_fields, + $subscriber_custom_fields + ); if($this->export_format_option === 'csv') { $CSV_file = fopen($this->export_file, 'w'); $format_CSV = function($row) { @@ -181,7 +183,7 @@ class Export { function getExportFile($format) { return sprintf( - Env::$temp_path . '/MailPoet_export_%s.%s', + $this->export_path . '/MailPoet_export_%s.%s', substr(md5(time()), 0, 4), $format ); diff --git a/tests/unit/Subscribers/ImportExport/Export/ExportCest.php b/tests/unit/Subscribers/ImportExport/Export/ExportCest.php index cc0ea01427..eba0978fb9 100644 --- a/tests/unit/Subscribers/ImportExport/Export/ExportCest.php +++ b/tests/unit/Subscribers/ImportExport/Export/ExportCest.php @@ -212,7 +212,7 @@ class ExportCest { } function itRequiresWritableExportFile() { - $this->export->export_file = '/dev/random'; + $this->export->export_path = '/fake_folder'; $result = $this->export->process(); expect($result['errors'][0]) ->equals("Couldn't save export file on the server.");