@@ -17,135 +17,135 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class JobHandlerFile extends JobHandler |
19 | 19 | { |
20 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
21 | - const temp_folder_name = 'batch_temp_folder'; |
|
20 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
21 | + const temp_folder_name = 'batch_temp_folder'; |
|
22 | 22 | |
23 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
24 | - /** |
|
25 | - * @var \EEHI_File |
|
26 | - */ |
|
27 | - protected $_file_helper = null; |
|
23 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
24 | + /** |
|
25 | + * @var \EEHI_File |
|
26 | + */ |
|
27 | + protected $_file_helper = null; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * JobHandlerFile constructor. |
|
32 | - * |
|
33 | - * @param \EEHI_File|null $file_helper |
|
34 | - */ |
|
35 | - public function __construct(\EEHI_File $file_helper = null) |
|
36 | - { |
|
37 | - if (! $file_helper) { |
|
38 | - $this->_file_helper = new EEH_File(); |
|
39 | - } |
|
40 | - } |
|
30 | + /** |
|
31 | + * JobHandlerFile constructor. |
|
32 | + * |
|
33 | + * @param \EEHI_File|null $file_helper |
|
34 | + */ |
|
35 | + public function __construct(\EEHI_File $file_helper = null) |
|
36 | + { |
|
37 | + if (! $file_helper) { |
|
38 | + $this->_file_helper = new EEH_File(); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | - /** |
|
44 | - * Creates a file |
|
45 | - * |
|
46 | - * @param string $job_id |
|
47 | - * @param string $filename |
|
48 | - * @param string $filetype |
|
49 | - * @param string $bom initial content to place in the file. |
|
50 | - * @return string |
|
51 | - * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
52 | - */ |
|
53 | - public function create_file_from_job_with_name( |
|
54 | - $job_id, |
|
55 | - $filename, |
|
56 | - $filetype = 'application/ms-excel', |
|
57 | - $bom = "\xEF\xBB\xBF" |
|
58 | - ) { |
|
59 | - $filepath = ''; |
|
60 | - try { |
|
61 | - $base_folder = $this->get_base_folder(); |
|
62 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
64 | - ); |
|
65 | - if ($success) { |
|
66 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
67 | - $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id |
|
68 | - ); |
|
69 | - } |
|
70 | - if ($success) { |
|
71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . $filename; |
|
72 | - $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
73 | - } |
|
74 | - // let's add the .htaccess file so safari will open the file properly |
|
75 | - if ($success) { |
|
76 | - $extension = EEH_File::get_file_extension($filepath); |
|
77 | - EEH_File::write_to_file( |
|
78 | - $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . '.htaccess', |
|
79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
80 | - '.htaccess' |
|
81 | - ); |
|
82 | - } |
|
83 | - /** |
|
84 | - * Filters what initial content will be added to the file. |
|
85 | - * @param string $return_value. By default it's whatever was pased into |
|
86 | - * JobHandlerFile::create_file_from_job_with_name() |
|
87 | - * @param string $filename |
|
88 | - * @param string $filetype default 'application/ms-excel' |
|
89 | - * @param string $filepath |
|
90 | - */ |
|
91 | - EEH_File::write_to_file( |
|
92 | - $filepath, |
|
93 | - apply_filters( |
|
94 | - 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
95 | - $bom, |
|
96 | - $filename, |
|
97 | - $filetype, |
|
98 | - $filepath |
|
99 | - ) |
|
100 | - ); |
|
101 | - // those methods normally fail with an exception, but if not, let's do it |
|
102 | - if (! $success) { |
|
103 | - throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
104 | - } |
|
105 | - } catch (\EE_Error $e) { |
|
106 | - throw new BatchRequestException( |
|
107 | - sprintf( |
|
108 | - // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
109 | - __('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
110 | - $job_id, |
|
111 | - $e->getMessage() |
|
112 | - ), |
|
113 | - 500, |
|
114 | - $e |
|
115 | - ); |
|
116 | - } |
|
117 | - return $filepath; |
|
118 | - } |
|
42 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | + /** |
|
44 | + * Creates a file |
|
45 | + * |
|
46 | + * @param string $job_id |
|
47 | + * @param string $filename |
|
48 | + * @param string $filetype |
|
49 | + * @param string $bom initial content to place in the file. |
|
50 | + * @return string |
|
51 | + * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
52 | + */ |
|
53 | + public function create_file_from_job_with_name( |
|
54 | + $job_id, |
|
55 | + $filename, |
|
56 | + $filetype = 'application/ms-excel', |
|
57 | + $bom = "\xEF\xBB\xBF" |
|
58 | + ) { |
|
59 | + $filepath = ''; |
|
60 | + try { |
|
61 | + $base_folder = $this->get_base_folder(); |
|
62 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
63 | + $base_folder . JobHandlerFile::temp_folder_name |
|
64 | + ); |
|
65 | + if ($success) { |
|
66 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
67 | + $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id |
|
68 | + ); |
|
69 | + } |
|
70 | + if ($success) { |
|
71 | + $filepath = $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . $filename; |
|
72 | + $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
73 | + } |
|
74 | + // let's add the .htaccess file so safari will open the file properly |
|
75 | + if ($success) { |
|
76 | + $extension = EEH_File::get_file_extension($filepath); |
|
77 | + EEH_File::write_to_file( |
|
78 | + $base_folder . JobHandlerFile::temp_folder_name . DS . $job_id . DS . '.htaccess', |
|
79 | + 'AddType ' . $filetype . ' ' . $extension, |
|
80 | + '.htaccess' |
|
81 | + ); |
|
82 | + } |
|
83 | + /** |
|
84 | + * Filters what initial content will be added to the file. |
|
85 | + * @param string $return_value. By default it's whatever was pased into |
|
86 | + * JobHandlerFile::create_file_from_job_with_name() |
|
87 | + * @param string $filename |
|
88 | + * @param string $filetype default 'application/ms-excel' |
|
89 | + * @param string $filepath |
|
90 | + */ |
|
91 | + EEH_File::write_to_file( |
|
92 | + $filepath, |
|
93 | + apply_filters( |
|
94 | + 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
95 | + $bom, |
|
96 | + $filename, |
|
97 | + $filetype, |
|
98 | + $filepath |
|
99 | + ) |
|
100 | + ); |
|
101 | + // those methods normally fail with an exception, but if not, let's do it |
|
102 | + if (! $success) { |
|
103 | + throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
104 | + } |
|
105 | + } catch (\EE_Error $e) { |
|
106 | + throw new BatchRequestException( |
|
107 | + sprintf( |
|
108 | + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
109 | + __('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
110 | + $job_id, |
|
111 | + $e->getMessage() |
|
112 | + ), |
|
113 | + 500, |
|
114 | + $e |
|
115 | + ); |
|
116 | + } |
|
117 | + return $filepath; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Gets the URL to download the file |
|
122 | - * |
|
123 | - * @param string $filepath |
|
124 | - * @return string url to file |
|
125 | - */ |
|
126 | - public function get_url_to_file($filepath) |
|
127 | - { |
|
128 | - return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
129 | - } |
|
120 | + /** |
|
121 | + * Gets the URL to download the file |
|
122 | + * |
|
123 | + * @param string $filepath |
|
124 | + * @return string url to file |
|
125 | + */ |
|
126 | + public function get_url_to_file($filepath) |
|
127 | + { |
|
128 | + return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Gets the folder which will contain the "batch_temp_folder" |
|
133 | - * |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_base_folder() |
|
137 | - { |
|
138 | - return apply_filters( |
|
139 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
140 | - EVENT_ESPRESSO_UPLOAD_DIR |
|
141 | - ); |
|
142 | - } |
|
131 | + /** |
|
132 | + * Gets the folder which will contain the "batch_temp_folder" |
|
133 | + * |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_base_folder() |
|
137 | + { |
|
138 | + return apply_filters( |
|
139 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
140 | + EVENT_ESPRESSO_UPLOAD_DIR |
|
141 | + ); |
|
142 | + } |
|
143 | 143 | |
144 | - public function get_base_url() |
|
145 | - { |
|
146 | - return apply_filters( |
|
147 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
148 | - EVENT_ESPRESSO_UPLOAD_URL |
|
149 | - ); |
|
150 | - } |
|
144 | + public function get_base_url() |
|
145 | + { |
|
146 | + return apply_filters( |
|
147 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
148 | + EVENT_ESPRESSO_UPLOAD_URL |
|
149 | + ); |
|
150 | + } |
|
151 | 151 | } |