- Fixes writable path check
This commit is contained in:
@ -17,6 +17,7 @@ class Export {
|
|||||||
public $segments;
|
public $segments;
|
||||||
public $subscribers_without_segment;
|
public $subscribers_without_segment;
|
||||||
public $subscriber_fields;
|
public $subscriber_fields;
|
||||||
|
public $export_path;
|
||||||
public $export_file;
|
public $export_file;
|
||||||
public $export_file_URL;
|
public $export_file_URL;
|
||||||
public $profiler_start;
|
public $profiler_start;
|
||||||
@ -28,22 +29,23 @@ class Export {
|
|||||||
$this->segments = $data['segments'];
|
$this->segments = $data['segments'];
|
||||||
$this->subscribers_without_segment = array_search(0, $this->segments);
|
$this->subscribers_without_segment = array_search(0, $this->segments);
|
||||||
$this->subscriber_fields = $data['subscriber_fields'];
|
$this->subscriber_fields = $data['subscriber_fields'];
|
||||||
|
$this->export_path = Env::$temp_path;
|
||||||
$this->export_file = $this->getExportFile($this->export_format_option);
|
$this->export_file = $this->getExportFile($this->export_format_option);
|
||||||
$this->export_file_URL = $this->getExportFileURL($this->export_file);
|
$this->export_file_URL = $this->getExportFileURL($this->export_file);
|
||||||
$this->profiler_start = microtime(true);
|
$this->profiler_start = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function process() {
|
function process() {
|
||||||
$subscribers = $this->getSubscribers();
|
|
||||||
$subscriber_custom_fields = $this->getSubscriberCustomFields();
|
|
||||||
$formatted_subscriber_fields = $this->formatSubscriberFields(
|
|
||||||
$this->subscriber_fields,
|
|
||||||
$subscriber_custom_fields
|
|
||||||
);
|
|
||||||
try {
|
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."));
|
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') {
|
if($this->export_format_option === 'csv') {
|
||||||
$CSV_file = fopen($this->export_file, 'w');
|
$CSV_file = fopen($this->export_file, 'w');
|
||||||
$format_CSV = function($row) {
|
$format_CSV = function($row) {
|
||||||
@ -181,7 +183,7 @@ class Export {
|
|||||||
|
|
||||||
function getExportFile($format) {
|
function getExportFile($format) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
Env::$temp_path . '/MailPoet_export_%s.%s',
|
$this->export_path . '/MailPoet_export_%s.%s',
|
||||||
substr(md5(time()), 0, 4),
|
substr(md5(time()), 0, 4),
|
||||||
$format
|
$format
|
||||||
);
|
);
|
||||||
|
@ -212,7 +212,7 @@ class ExportCest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function itRequiresWritableExportFile() {
|
function itRequiresWritableExportFile() {
|
||||||
$this->export->export_file = '/dev/random';
|
$this->export->export_path = '/fake_folder';
|
||||||
$result = $this->export->process();
|
$result = $this->export->process();
|
||||||
expect($result['errors'][0])
|
expect($result['errors'][0])
|
||||||
->equals("Couldn't save export file on the server.");
|
->equals("Couldn't save export file on the server.");
|
||||||
|
Reference in New Issue
Block a user