Merge pull request #351 from mailpoet/import_language_update

Updates error messages displayed during import
This commit is contained in:
Jonathan Labreuille
2016-02-18 09:55:59 +01:00
4 changed files with 22 additions and 10 deletions

View File

@ -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', '<strong>' + response.data.totalExported + '</strong>')

View File

@ -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,19 +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_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) {
@ -178,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
);

View File

@ -211,6 +211,13 @@ class ExportCest {
expect(count($subscribers))->equals(2);
}
function itRequiresWritableExportFile() {
$this->export->export_path = '/fake_folder';
$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';

View File

@ -140,10 +140,10 @@
<input id="new_segment_name" type="text" name="name"/>
</p>
<p class="mailpoet_validation_error" data-error="segment_name_required">
<%= __('You need to specify a name') %>
<%= __('You need to specify a name.') %>
</p>
<p class="mailpoet_validation_error" data-error="segment_name_not_unique">
<%= __('This name is already taken') %>
<%= __('Another record already exists. Please specify a different "%1$s".')|format('name') %>
</p>
<p>
<label><%= __('Description') %>:</label>