@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | apply_filters( |
48 | 48 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
49 | 49 | [ |
50 | - 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
51 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
52 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
50 | + 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
51 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION |
|
52 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
53 | 53 | ], |
54 | 54 | $this |
55 | 55 | ) |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | EE_Registry::instance()->CFG->map_settings->google_map_api_key |
66 | 66 | ) |
67 | 67 | ), |
68 | - 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
68 | + 'ee_gmap' => EE_HELPERS_ASSETS.'ee_gmap.js?ver=1.0', |
|
69 | 69 | ], |
70 | 70 | $this |
71 | 71 | ) |
@@ -22,63 +22,63 @@ |
||
22 | 22 | */ |
23 | 23 | class EventsArchiveIframe extends Iframe |
24 | 24 | { |
25 | - /** |
|
26 | - * EventsArchiveIframe constructor. |
|
27 | - * |
|
28 | - * @param EED_Events_Archive $EED_Events_Archive |
|
29 | - * @throws EE_Error |
|
30 | - * @throws ReflectionException |
|
31 | - */ |
|
32 | - public function __construct($EED_Events_Archive) |
|
33 | - { |
|
34 | - /** @var CurrentPage $current_page */ |
|
35 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
36 | - $current_page->setEspressoPage(true); |
|
37 | - add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
|
38 | - $EED_Events_Archive->event_list(); |
|
39 | - /** @var EspressoEvents $event_list */ |
|
40 | - $event_list = EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
|
41 | - $shortcode_content = $event_list->processShortcode(); |
|
42 | - if (empty($shortcode_content)) { |
|
43 | - return; |
|
44 | - } |
|
45 | - parent::__construct( |
|
46 | - esc_html__('Event List', 'event_espresso'), |
|
47 | - $shortcode_content |
|
48 | - ); |
|
49 | - $this->addStylesheets( |
|
50 | - apply_filters( |
|
51 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
52 | - [ |
|
53 | - 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
54 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
55 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
56 | - ], |
|
57 | - $this |
|
58 | - ) |
|
59 | - ); |
|
60 | - $this->addInlineStyles('ticket_selector', EED_Ticket_Selector::accentColorStyles()); |
|
61 | - $this->addScripts( |
|
62 | - apply_filters( |
|
63 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
64 | - [ |
|
65 | - 'gmap_api' => sprintf( |
|
66 | - 'https://maps.googleapis.com/maps/api/js?key=%s', |
|
67 | - apply_filters( |
|
68 | - 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
69 | - EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
70 | - ) |
|
71 | - ), |
|
72 | - 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
73 | - ], |
|
74 | - $this |
|
75 | - ) |
|
76 | - ); |
|
77 | - $this->addLocalizedVars( |
|
78 | - [ |
|
79 | - 'ee_gmap' => EEH_Maps::$gmap_vars, |
|
80 | - ], |
|
81 | - 'ee_gmap_vars' |
|
82 | - ); |
|
83 | - } |
|
25 | + /** |
|
26 | + * EventsArchiveIframe constructor. |
|
27 | + * |
|
28 | + * @param EED_Events_Archive $EED_Events_Archive |
|
29 | + * @throws EE_Error |
|
30 | + * @throws ReflectionException |
|
31 | + */ |
|
32 | + public function __construct($EED_Events_Archive) |
|
33 | + { |
|
34 | + /** @var CurrentPage $current_page */ |
|
35 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
36 | + $current_page->setEspressoPage(true); |
|
37 | + add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true'); |
|
38 | + $EED_Events_Archive->event_list(); |
|
39 | + /** @var EspressoEvents $event_list */ |
|
40 | + $event_list = EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents'); |
|
41 | + $shortcode_content = $event_list->processShortcode(); |
|
42 | + if (empty($shortcode_content)) { |
|
43 | + return; |
|
44 | + } |
|
45 | + parent::__construct( |
|
46 | + esc_html__('Event List', 'event_espresso'), |
|
47 | + $shortcode_content |
|
48 | + ); |
|
49 | + $this->addStylesheets( |
|
50 | + apply_filters( |
|
51 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
52 | + [ |
|
53 | + 'espresso_default' => is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
54 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
55 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
56 | + ], |
|
57 | + $this |
|
58 | + ) |
|
59 | + ); |
|
60 | + $this->addInlineStyles('ticket_selector', EED_Ticket_Selector::accentColorStyles()); |
|
61 | + $this->addScripts( |
|
62 | + apply_filters( |
|
63 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
64 | + [ |
|
65 | + 'gmap_api' => sprintf( |
|
66 | + 'https://maps.googleapis.com/maps/api/js?key=%s', |
|
67 | + apply_filters( |
|
68 | + 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
69 | + EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
70 | + ) |
|
71 | + ), |
|
72 | + 'ee_gmap' => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0', |
|
73 | + ], |
|
74 | + $this |
|
75 | + ) |
|
76 | + ); |
|
77 | + $this->addLocalizedVars( |
|
78 | + [ |
|
79 | + 'ee_gmap' => EEH_Maps::$gmap_vars, |
|
80 | + ], |
|
81 | + 'ee_gmap_vars' |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | } |
@@ -40,279 +40,279 @@ |
||
40 | 40 | */ |
41 | 41 | class FilesDataHandler |
42 | 42 | { |
43 | - /** |
|
44 | - * @var Request |
|
45 | - */ |
|
46 | - protected $request; |
|
43 | + /** |
|
44 | + * @var Request |
|
45 | + */ |
|
46 | + protected $request; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var CollectionInterface | FileSubmissionInterface[] |
|
50 | - */ |
|
51 | - protected $file_objects; |
|
48 | + /** |
|
49 | + * @var CollectionInterface | FileSubmissionInterface[] |
|
50 | + */ |
|
51 | + protected $file_objects; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var bool |
|
55 | - */ |
|
56 | - protected $initialized = false; |
|
53 | + /** |
|
54 | + * @var bool |
|
55 | + */ |
|
56 | + protected $initialized = false; |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * FilesDataHandler constructor. |
|
61 | - * |
|
62 | - * @param Request $request |
|
63 | - */ |
|
64 | - public function __construct(Request $request) |
|
65 | - { |
|
66 | - $this->request = $request; |
|
67 | - } |
|
59 | + /** |
|
60 | + * FilesDataHandler constructor. |
|
61 | + * |
|
62 | + * @param Request $request |
|
63 | + */ |
|
64 | + public function __construct(Request $request) |
|
65 | + { |
|
66 | + $this->request = $request; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * @return CollectionInterface | FileSubmissionInterface[] |
|
72 | - * @throws UnexpectedValueException |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @since 4.9.80.p |
|
75 | - */ |
|
76 | - protected function getFileObjects() |
|
77 | - { |
|
78 | - $this->initialize(); |
|
79 | - return $this->file_objects; |
|
80 | - } |
|
70 | + /** |
|
71 | + * @return CollectionInterface | FileSubmissionInterface[] |
|
72 | + * @throws UnexpectedValueException |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @since 4.9.80.p |
|
75 | + */ |
|
76 | + protected function getFileObjects() |
|
77 | + { |
|
78 | + $this->initialize(); |
|
79 | + return $this->file_objects; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Sets up the file objects from the request's $_FILES data. |
|
85 | - * |
|
86 | - * @throws UnexpectedValueException |
|
87 | - * @throws InvalidArgumentException |
|
88 | - * @throws InvalidInterfaceException |
|
89 | - * @since 4.9.80.p |
|
90 | - */ |
|
91 | - protected function initialize() |
|
92 | - { |
|
93 | - if ($this->initialized) { |
|
94 | - return; |
|
95 | - } |
|
96 | - $this->file_objects = new Collection( |
|
97 | - // collection interface |
|
98 | - 'EventEspresso\core\services\request\files\FileSubmissionInterface', |
|
99 | - // collection name |
|
100 | - 'submitted_files' |
|
101 | - ); |
|
102 | - $files_raw_data = $this->request->filesParams(); |
|
103 | - if (empty($files_raw_data)) { |
|
104 | - return; |
|
105 | - } |
|
106 | - if ($this->isStrangeFilesArray($files_raw_data)) { |
|
107 | - $data = $this->fixFilesDataArray($files_raw_data); |
|
108 | - } else { |
|
109 | - $data = $files_raw_data; |
|
110 | - } |
|
111 | - $this->createFileObjects($data); |
|
112 | - $this->initialized = true; |
|
113 | - } |
|
83 | + /** |
|
84 | + * Sets up the file objects from the request's $_FILES data. |
|
85 | + * |
|
86 | + * @throws UnexpectedValueException |
|
87 | + * @throws InvalidArgumentException |
|
88 | + * @throws InvalidInterfaceException |
|
89 | + * @since 4.9.80.p |
|
90 | + */ |
|
91 | + protected function initialize() |
|
92 | + { |
|
93 | + if ($this->initialized) { |
|
94 | + return; |
|
95 | + } |
|
96 | + $this->file_objects = new Collection( |
|
97 | + // collection interface |
|
98 | + 'EventEspresso\core\services\request\files\FileSubmissionInterface', |
|
99 | + // collection name |
|
100 | + 'submitted_files' |
|
101 | + ); |
|
102 | + $files_raw_data = $this->request->filesParams(); |
|
103 | + if (empty($files_raw_data)) { |
|
104 | + return; |
|
105 | + } |
|
106 | + if ($this->isStrangeFilesArray($files_raw_data)) { |
|
107 | + $data = $this->fixFilesDataArray($files_raw_data); |
|
108 | + } else { |
|
109 | + $data = $files_raw_data; |
|
110 | + } |
|
111 | + $this->createFileObjects($data); |
|
112 | + $this->initialized = true; |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
118 | - * |
|
119 | - * @param $files_data |
|
120 | - * @return bool |
|
121 | - * @throws UnexpectedValueException |
|
122 | - * @since 4.9.80.p |
|
123 | - */ |
|
124 | - protected function isStrangeFilesArray($files_data) |
|
125 | - { |
|
126 | - if (! is_array($files_data)) { |
|
127 | - throw new UnexpectedValueException( |
|
128 | - sprintf( |
|
129 | - esc_html__( |
|
130 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
131 | - 'event_espresso' |
|
132 | - ), |
|
133 | - (string) $files_data |
|
134 | - ) |
|
135 | - ); |
|
136 | - } |
|
137 | - $first_value = reset($files_data); |
|
138 | - if (! is_array($first_value)) { |
|
139 | - throw new UnexpectedValueException( |
|
140 | - sprintf( |
|
141 | - esc_html__( |
|
142 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
143 | - 'event_espresso' |
|
144 | - ), |
|
145 | - (string) $first_value |
|
146 | - ) |
|
147 | - ); |
|
148 | - } |
|
149 | - $first_sub_array_item = reset($first_value); |
|
150 | - if (is_array($first_sub_array_item)) { |
|
151 | - // not just a 2d array |
|
152 | - return true; |
|
153 | - } |
|
154 | - // yep, just 2d array |
|
155 | - return false; |
|
156 | - } |
|
116 | + /** |
|
117 | + * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
118 | + * |
|
119 | + * @param $files_data |
|
120 | + * @return bool |
|
121 | + * @throws UnexpectedValueException |
|
122 | + * @since 4.9.80.p |
|
123 | + */ |
|
124 | + protected function isStrangeFilesArray($files_data) |
|
125 | + { |
|
126 | + if (! is_array($files_data)) { |
|
127 | + throw new UnexpectedValueException( |
|
128 | + sprintf( |
|
129 | + esc_html__( |
|
130 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
131 | + 'event_espresso' |
|
132 | + ), |
|
133 | + (string) $files_data |
|
134 | + ) |
|
135 | + ); |
|
136 | + } |
|
137 | + $first_value = reset($files_data); |
|
138 | + if (! is_array($first_value)) { |
|
139 | + throw new UnexpectedValueException( |
|
140 | + sprintf( |
|
141 | + esc_html__( |
|
142 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
143 | + 'event_espresso' |
|
144 | + ), |
|
145 | + (string) $first_value |
|
146 | + ) |
|
147 | + ); |
|
148 | + } |
|
149 | + $first_sub_array_item = reset($first_value); |
|
150 | + if (is_array($first_sub_array_item)) { |
|
151 | + // not just a 2d array |
|
152 | + return true; |
|
153 | + } |
|
154 | + // yep, just 2d array |
|
155 | + return false; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - /** |
|
160 | - * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
161 | - * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
162 | - * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
163 | - * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
164 | - * |
|
165 | - * @param $files_data |
|
166 | - * @return array |
|
167 | - * @since 4.9.80.p |
|
168 | - */ |
|
169 | - protected function fixFilesDataArray($files_data) |
|
170 | - { |
|
171 | - $sane_files_array = []; |
|
172 | - foreach ($files_data as $top_level_name => $top_level_children) { |
|
173 | - $sub_array = []; |
|
174 | - $sane_files_array[ $top_level_name ] = []; |
|
175 | - foreach ($top_level_children as $file_data_part => $second_level_children) { |
|
176 | - foreach ($second_level_children as $next_level_name => $sub_values) { |
|
177 | - $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part); |
|
178 | - } |
|
179 | - $sane_files_array[ $top_level_name ] = array_replace_recursive( |
|
180 | - $sub_array, |
|
181 | - $sane_files_array[ $top_level_name ] |
|
182 | - ); |
|
183 | - } |
|
184 | - } |
|
185 | - return $sane_files_array; |
|
186 | - } |
|
159 | + /** |
|
160 | + * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
161 | + * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
162 | + * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
163 | + * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
164 | + * |
|
165 | + * @param $files_data |
|
166 | + * @return array |
|
167 | + * @since 4.9.80.p |
|
168 | + */ |
|
169 | + protected function fixFilesDataArray($files_data) |
|
170 | + { |
|
171 | + $sane_files_array = []; |
|
172 | + foreach ($files_data as $top_level_name => $top_level_children) { |
|
173 | + $sub_array = []; |
|
174 | + $sane_files_array[ $top_level_name ] = []; |
|
175 | + foreach ($top_level_children as $file_data_part => $second_level_children) { |
|
176 | + foreach ($second_level_children as $next_level_name => $sub_values) { |
|
177 | + $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part); |
|
178 | + } |
|
179 | + $sane_files_array[ $top_level_name ] = array_replace_recursive( |
|
180 | + $sub_array, |
|
181 | + $sane_files_array[ $top_level_name ] |
|
182 | + ); |
|
183 | + } |
|
184 | + } |
|
185 | + return $sane_files_array; |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
191 | - * |
|
192 | - * @param $data array|string |
|
193 | - * @param $type 'name', 'tmp_name', 'size', or 'error' |
|
194 | - * @return array |
|
195 | - * @since 4.9.80.p |
|
196 | - */ |
|
197 | - protected function organizeFilesData($data, $type) |
|
198 | - { |
|
199 | - if (! is_array($data)) { |
|
200 | - return [ |
|
201 | - $type => $data, |
|
202 | - ]; |
|
203 | - } |
|
204 | - $organized_data = []; |
|
205 | - foreach ($data as $input_name_part => $sub_inputs_or_value) { |
|
206 | - if (is_array($sub_inputs_or_value)) { |
|
207 | - $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
208 | - } else { |
|
209 | - $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value; |
|
210 | - } |
|
211 | - } |
|
212 | - return $organized_data; |
|
213 | - } |
|
189 | + /** |
|
190 | + * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
191 | + * |
|
192 | + * @param $data array|string |
|
193 | + * @param $type 'name', 'tmp_name', 'size', or 'error' |
|
194 | + * @return array |
|
195 | + * @since 4.9.80.p |
|
196 | + */ |
|
197 | + protected function organizeFilesData($data, $type) |
|
198 | + { |
|
199 | + if (! is_array($data)) { |
|
200 | + return [ |
|
201 | + $type => $data, |
|
202 | + ]; |
|
203 | + } |
|
204 | + $organized_data = []; |
|
205 | + foreach ($data as $input_name_part => $sub_inputs_or_value) { |
|
206 | + if (is_array($sub_inputs_or_value)) { |
|
207 | + $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
208 | + } else { |
|
209 | + $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value; |
|
210 | + } |
|
211 | + } |
|
212 | + return $organized_data; |
|
213 | + } |
|
214 | 214 | |
215 | 215 | |
216 | - /** |
|
217 | - * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
218 | - * to be in post data, with all the file's data located side-by-side in an array) and creates a |
|
219 | - * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`. |
|
220 | - * |
|
221 | - * @param array $organized_files $_FILES but organized like $_POST |
|
222 | - * @param array $name_parts_so_far for multidimensional HTML form names, |
|
223 | - * @throws UnexpectedValueException |
|
224 | - * @throws InvalidArgumentException |
|
225 | - * @since 4.9.80.p |
|
226 | - */ |
|
227 | - protected function createFileObjects($organized_files, $name_parts_so_far = []) |
|
228 | - { |
|
229 | - if (! is_array($organized_files)) { |
|
230 | - throw new UnexpectedValueException( |
|
231 | - sprintf( |
|
232 | - esc_html__( |
|
233 | - 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
234 | - 'event_espresso' |
|
235 | - ), |
|
236 | - (string) $organized_files |
|
237 | - ) |
|
238 | - ); |
|
239 | - } |
|
240 | - foreach ($organized_files as $key => $value) { |
|
241 | - $this_input_name_parts = $name_parts_so_far; |
|
242 | - array_push( |
|
243 | - $this_input_name_parts, |
|
244 | - $key |
|
245 | - ); |
|
246 | - if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
247 | - $html_name = $this->inputNameFromParts($this_input_name_parts); |
|
248 | - $this->file_objects->add( |
|
249 | - new FileSubmission( |
|
250 | - $value['name'], |
|
251 | - $value['tmp_name'], |
|
252 | - $value['size'], |
|
253 | - $value['error'] |
|
254 | - ), |
|
255 | - $html_name |
|
256 | - ); |
|
257 | - } else { |
|
258 | - $this->createFileObjects($value, $this_input_name_parts); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
216 | + /** |
|
217 | + * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
218 | + * to be in post data, with all the file's data located side-by-side in an array) and creates a |
|
219 | + * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`. |
|
220 | + * |
|
221 | + * @param array $organized_files $_FILES but organized like $_POST |
|
222 | + * @param array $name_parts_so_far for multidimensional HTML form names, |
|
223 | + * @throws UnexpectedValueException |
|
224 | + * @throws InvalidArgumentException |
|
225 | + * @since 4.9.80.p |
|
226 | + */ |
|
227 | + protected function createFileObjects($organized_files, $name_parts_so_far = []) |
|
228 | + { |
|
229 | + if (! is_array($organized_files)) { |
|
230 | + throw new UnexpectedValueException( |
|
231 | + sprintf( |
|
232 | + esc_html__( |
|
233 | + 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
234 | + 'event_espresso' |
|
235 | + ), |
|
236 | + (string) $organized_files |
|
237 | + ) |
|
238 | + ); |
|
239 | + } |
|
240 | + foreach ($organized_files as $key => $value) { |
|
241 | + $this_input_name_parts = $name_parts_so_far; |
|
242 | + array_push( |
|
243 | + $this_input_name_parts, |
|
244 | + $key |
|
245 | + ); |
|
246 | + if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
247 | + $html_name = $this->inputNameFromParts($this_input_name_parts); |
|
248 | + $this->file_objects->add( |
|
249 | + new FileSubmission( |
|
250 | + $value['name'], |
|
251 | + $value['tmp_name'], |
|
252 | + $value['size'], |
|
253 | + $value['error'] |
|
254 | + ), |
|
255 | + $html_name |
|
256 | + ); |
|
257 | + } else { |
|
258 | + $this->createFileObjects($value, $this_input_name_parts); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | 263 | |
264 | - /** |
|
265 | - * Takes the input name parts, like `['my', 'great', 'file', 'input1']` |
|
266 | - * and returns the HTML name for it, "my[great][file][input1]" |
|
267 | - * |
|
268 | - * @throws UnexpectedValueException |
|
269 | - * @since 4.9.80.p |
|
270 | - */ |
|
271 | - protected function inputNameFromParts($parts) |
|
272 | - { |
|
273 | - if (! is_array($parts)) { |
|
274 | - throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
|
275 | - } |
|
276 | - $generated_string = ''; |
|
277 | - foreach ($parts as $part) { |
|
278 | - $part = (string) $part; |
|
279 | - // wrap all but the first part in [] |
|
280 | - $generated_string .= $generated_string === '' ? $part : '[' . $part . ']'; |
|
281 | - } |
|
282 | - return $generated_string; |
|
283 | - } |
|
264 | + /** |
|
265 | + * Takes the input name parts, like `['my', 'great', 'file', 'input1']` |
|
266 | + * and returns the HTML name for it, "my[great][file][input1]" |
|
267 | + * |
|
268 | + * @throws UnexpectedValueException |
|
269 | + * @since 4.9.80.p |
|
270 | + */ |
|
271 | + protected function inputNameFromParts($parts) |
|
272 | + { |
|
273 | + if (! is_array($parts)) { |
|
274 | + throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
|
275 | + } |
|
276 | + $generated_string = ''; |
|
277 | + foreach ($parts as $part) { |
|
278 | + $part = (string) $part; |
|
279 | + // wrap all but the first part in [] |
|
280 | + $generated_string .= $generated_string === '' ? $part : '[' . $part . ']'; |
|
281 | + } |
|
282 | + return $generated_string; |
|
283 | + } |
|
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * Gets the input by the indicated $name_parts. |
|
288 | - * Eg if you're looking for an input named "my[great][file][input1]", $name_parts |
|
289 | - * should be `['my', 'great', 'file', 'input1']`. |
|
290 | - * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');` |
|
291 | - * |
|
292 | - * @param $name_parts |
|
293 | - * @return FileSubmissionInterface |
|
294 | - * @throws UnexpectedValueException |
|
295 | - * @since 4.9.80.p |
|
296 | - */ |
|
297 | - public function getFileObjectFromNameParts($name_parts) |
|
298 | - { |
|
299 | - return $this->getFileObjects()->get($this->inputNameFromParts($name_parts)); |
|
300 | - } |
|
286 | + /** |
|
287 | + * Gets the input by the indicated $name_parts. |
|
288 | + * Eg if you're looking for an input named "my[great][file][input1]", $name_parts |
|
289 | + * should be `['my', 'great', 'file', 'input1']`. |
|
290 | + * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');` |
|
291 | + * |
|
292 | + * @param $name_parts |
|
293 | + * @return FileSubmissionInterface |
|
294 | + * @throws UnexpectedValueException |
|
295 | + * @since 4.9.80.p |
|
296 | + */ |
|
297 | + public function getFileObjectFromNameParts($name_parts) |
|
298 | + { |
|
299 | + return $this->getFileObjects()->get($this->inputNameFromParts($name_parts)); |
|
300 | + } |
|
301 | 301 | |
302 | 302 | |
303 | - /** |
|
304 | - * Gets the FileSubmissionInterface corresponding to the HTML name provided. |
|
305 | - * |
|
306 | - * @param $html_name |
|
307 | - * @return mixed |
|
308 | - * @throws InvalidArgumentException |
|
309 | - * @throws UnexpectedValueException |
|
310 | - * @since 4.9.80.p |
|
311 | - */ |
|
312 | - public function getFileObject($html_name) |
|
313 | - { |
|
314 | - return $this->getFileObjects()->get($html_name); |
|
315 | - } |
|
303 | + /** |
|
304 | + * Gets the FileSubmissionInterface corresponding to the HTML name provided. |
|
305 | + * |
|
306 | + * @param $html_name |
|
307 | + * @return mixed |
|
308 | + * @throws InvalidArgumentException |
|
309 | + * @throws UnexpectedValueException |
|
310 | + * @since 4.9.80.p |
|
311 | + */ |
|
312 | + public function getFileObject($html_name) |
|
313 | + { |
|
314 | + return $this->getFileObjects()->get($html_name); |
|
315 | + } |
|
316 | 316 | } |
317 | 317 | // End of file FilesDataHandler.php |
318 | 318 | // Location: EventEspresso\core\services\request\files/FilesDataHandler.php |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | // collection name |
100 | 100 | 'submitted_files' |
101 | 101 | ); |
102 | - $files_raw_data = $this->request->filesParams(); |
|
102 | + $files_raw_data = $this->request->filesParams(); |
|
103 | 103 | if (empty($files_raw_data)) { |
104 | 104 | return; |
105 | 105 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | protected function isStrangeFilesArray($files_data) |
125 | 125 | { |
126 | - if (! is_array($files_data)) { |
|
126 | + if ( ! is_array($files_data)) { |
|
127 | 127 | throw new UnexpectedValueException( |
128 | 128 | sprintf( |
129 | 129 | esc_html__( |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ); |
136 | 136 | } |
137 | 137 | $first_value = reset($files_data); |
138 | - if (! is_array($first_value)) { |
|
138 | + if ( ! is_array($first_value)) { |
|
139 | 139 | throw new UnexpectedValueException( |
140 | 140 | sprintf( |
141 | 141 | esc_html__( |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | $sane_files_array = []; |
172 | 172 | foreach ($files_data as $top_level_name => $top_level_children) { |
173 | 173 | $sub_array = []; |
174 | - $sane_files_array[ $top_level_name ] = []; |
|
174 | + $sane_files_array[$top_level_name] = []; |
|
175 | 175 | foreach ($top_level_children as $file_data_part => $second_level_children) { |
176 | 176 | foreach ($second_level_children as $next_level_name => $sub_values) { |
177 | - $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part); |
|
177 | + $sub_array[$next_level_name] = $this->organizeFilesData($sub_values, $file_data_part); |
|
178 | 178 | } |
179 | - $sane_files_array[ $top_level_name ] = array_replace_recursive( |
|
179 | + $sane_files_array[$top_level_name] = array_replace_recursive( |
|
180 | 180 | $sub_array, |
181 | - $sane_files_array[ $top_level_name ] |
|
181 | + $sane_files_array[$top_level_name] |
|
182 | 182 | ); |
183 | 183 | } |
184 | 184 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | protected function organizeFilesData($data, $type) |
198 | 198 | { |
199 | - if (! is_array($data)) { |
|
199 | + if ( ! is_array($data)) { |
|
200 | 200 | return [ |
201 | 201 | $type => $data, |
202 | 202 | ]; |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | $organized_data = []; |
205 | 205 | foreach ($data as $input_name_part => $sub_inputs_or_value) { |
206 | 206 | if (is_array($sub_inputs_or_value)) { |
207 | - $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
207 | + $organized_data[$input_name_part] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
208 | 208 | } else { |
209 | - $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value; |
|
209 | + $organized_data[$input_name_part][$type] = $sub_inputs_or_value; |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | return $organized_data; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | protected function createFileObjects($organized_files, $name_parts_so_far = []) |
228 | 228 | { |
229 | - if (! is_array($organized_files)) { |
|
229 | + if ( ! is_array($organized_files)) { |
|
230 | 230 | throw new UnexpectedValueException( |
231 | 231 | sprintf( |
232 | 232 | esc_html__( |
@@ -270,14 +270,14 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function inputNameFromParts($parts) |
272 | 272 | { |
273 | - if (! is_array($parts)) { |
|
273 | + if ( ! is_array($parts)) { |
|
274 | 274 | throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
275 | 275 | } |
276 | 276 | $generated_string = ''; |
277 | 277 | foreach ($parts as $part) { |
278 | 278 | $part = (string) $part; |
279 | 279 | // wrap all but the first part in [] |
280 | - $generated_string .= $generated_string === '' ? $part : '[' . $part . ']'; |
|
280 | + $generated_string .= $generated_string === '' ? $part : '['.$part.']'; |
|
281 | 281 | } |
282 | 282 | return $generated_string; |
283 | 283 | } |
@@ -7,16 +7,16 @@ discard block |
||
7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
9 | 9 | if (! defined('DS')) { |
10 | - define('DS', '/'); |
|
10 | + define('DS', '/'); |
|
11 | 11 | } |
12 | 12 | if (! defined('PS')) { |
13 | - define('PS', PATH_SEPARATOR); |
|
13 | + define('PS', PATH_SEPARATOR); |
|
14 | 14 | } |
15 | 15 | if (! defined('SP')) { |
16 | - define('SP', ' '); |
|
16 | + define('SP', ' '); |
|
17 | 17 | } |
18 | 18 | if (! defined('EENL')) { |
19 | - define('EENL', "\n"); |
|
19 | + define('EENL', "\n"); |
|
20 | 20 | } |
21 | 21 | // define the plugin directory and URL |
22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/'); |
71 | 71 | // check for DOMPDF fonts in uploads |
72 | 72 | if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) { |
73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
74 | 74 | } |
75 | 75 | // just a handy constant occasionally needed for finding values representing infinity in the DB |
76 | 76 | // you're better to use this than its straight value (currently -1) in case you ever |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | define('EE_INF_IN_DB', -1); |
79 | 79 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
80 | 80 | if (! defined('EE_DEBUG')) { |
81 | - define('EE_DEBUG', false); |
|
81 | + define('EE_DEBUG', false); |
|
82 | 82 | } |
83 | 83 | // for older WP versions |
84 | 84 | if (! defined('MONTH_IN_SECONDS')) { |
85 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
85 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
86 | 86 | } |
@@ -7,78 +7,78 @@ |
||
7 | 7 | define('EE_MIN_PHP_VER_RECOMMENDED', '7.4'); |
8 | 8 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
9 | 9 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
10 | -if (! defined('DS')) { |
|
10 | +if ( ! defined('DS')) { |
|
11 | 11 | define('DS', '/'); |
12 | 12 | } |
13 | -if (! defined('PS')) { |
|
13 | +if ( ! defined('PS')) { |
|
14 | 14 | define('PS', PATH_SEPARATOR); |
15 | 15 | } |
16 | -if (! defined('SP')) { |
|
16 | +if ( ! defined('SP')) { |
|
17 | 17 | define('SP', ' '); |
18 | 18 | } |
19 | -if (! defined('EENL')) { |
|
19 | +if ( ! defined('EENL')) { |
|
20 | 20 | define('EENL', "\n"); |
21 | 21 | } |
22 | 22 | // define the plugin directory and URL |
23 | 23 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
24 | -define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . '/'); |
|
24 | +define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).'/'); |
|
25 | 25 | define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
26 | 26 | // main root folder paths |
27 | -define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages/'); |
|
28 | -define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core/'); |
|
29 | -define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules/'); |
|
30 | -define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public/'); |
|
31 | -define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes/'); |
|
32 | -define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets/'); |
|
33 | -define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods/'); |
|
34 | -define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated/'); |
|
27 | +define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages/'); |
|
28 | +define('EE_CORE', EE_PLUGIN_DIR_PATH.'core/'); |
|
29 | +define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules/'); |
|
30 | +define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public/'); |
|
31 | +define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes/'); |
|
32 | +define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets/'); |
|
33 | +define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods/'); |
|
34 | +define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated/'); |
|
35 | 35 | // core system paths |
36 | -define('EE_ADMIN', EE_CORE . 'admin/'); |
|
37 | -define('EE_CPTS', EE_CORE . 'CPTs/'); |
|
38 | -define('EE_CLASSES', EE_CORE . 'db_classes/'); |
|
39 | -define('EE_INTERFACES', EE_CORE . 'interfaces/'); |
|
40 | -define('EE_BUSINESS', EE_CORE . 'business/'); |
|
41 | -define('EE_MODELS', EE_CORE . 'db_models/'); |
|
42 | -define('EE_HELPERS', EE_CORE . 'helpers/'); |
|
43 | -define('EE_LIBRARIES', EE_CORE . 'libraries/'); |
|
44 | -define('EE_TEMPLATES', EE_CORE . 'templates/'); |
|
45 | -define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs/'); |
|
46 | -define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets/'); |
|
47 | -define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections/'); |
|
36 | +define('EE_ADMIN', EE_CORE.'admin/'); |
|
37 | +define('EE_CPTS', EE_CORE.'CPTs/'); |
|
38 | +define('EE_CLASSES', EE_CORE.'db_classes/'); |
|
39 | +define('EE_INTERFACES', EE_CORE.'interfaces/'); |
|
40 | +define('EE_BUSINESS', EE_CORE.'business/'); |
|
41 | +define('EE_MODELS', EE_CORE.'db_models/'); |
|
42 | +define('EE_HELPERS', EE_CORE.'helpers/'); |
|
43 | +define('EE_LIBRARIES', EE_CORE.'libraries/'); |
|
44 | +define('EE_TEMPLATES', EE_CORE.'templates/'); |
|
45 | +define('EE_THIRD_PARTY', EE_CORE.'third_party_libs/'); |
|
46 | +define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets/'); |
|
47 | +define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections/'); |
|
48 | 48 | // gateways |
49 | -define('EE_GATEWAYS', EE_MODULES . 'gateways/'); |
|
50 | -define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules/gateways/'); |
|
49 | +define('EE_GATEWAYS', EE_MODULES.'gateways/'); |
|
50 | +define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules/gateways/'); |
|
51 | 51 | // asset URL paths |
52 | -define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core/templates/'); |
|
53 | -define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets/'); |
|
54 | -define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images/'); |
|
55 | -define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core/third_party_libs/'); |
|
56 | -define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
57 | -define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
52 | +define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core/templates/'); |
|
53 | +define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets/'); |
|
54 | +define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images/'); |
|
55 | +define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core/third_party_libs/'); |
|
56 | +define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/'); |
|
57 | +define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/'); |
|
58 | 58 | // define upload paths |
59 | 59 | $uploads = wp_upload_dir(); |
60 | 60 | // define the uploads directory and URL |
61 | -define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . '/espresso/'); |
|
62 | -define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . '/espresso/'); |
|
61 | +define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].'/espresso/'); |
|
62 | +define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].'/espresso/'); |
|
63 | 63 | // define the templates directory and URL |
64 | -define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . '/espresso/templates/'); |
|
65 | -define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . '/espresso/templates/'); |
|
64 | +define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].'/espresso/templates/'); |
|
65 | +define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].'/espresso/templates/'); |
|
66 | 66 | // languages folder/path |
67 | -define('EE_LANGUAGES_SAFE_LOC', '../' . 'uploads/' . 'espresso/languages/'); |
|
68 | -define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/'); |
|
67 | +define('EE_LANGUAGES_SAFE_LOC', '../'.'uploads/'.'espresso/languages/'); |
|
68 | +define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages/'); |
|
69 | 69 | // check for DOMPDF fonts in uploads |
70 | -if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) { |
|
71 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
70 | +if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts/')) { |
|
71 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts/'); |
|
72 | 72 | } |
73 | 73 | // just a handy constant occasionally needed for finding values representing infinity in the DB |
74 | 74 | // you're better to use this than its straight value (currently -1) in case you ever |
75 | 75 | // want to change its default value! or find when -1 means infinity |
76 | 76 | define('EE_INF_IN_DB', -1); |
77 | 77 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
78 | -if (! defined('EE_DEBUG')) { |
|
78 | +if ( ! defined('EE_DEBUG')) { |
|
79 | 79 | define('EE_DEBUG', false); |
80 | 80 | } |
81 | 81 | // for older WP versions |
82 | -if (! defined('MONTH_IN_SECONDS')) { |
|
82 | +if ( ! defined('MONTH_IN_SECONDS')) { |
|
83 | 83 | define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
84 | 84 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public static function instance() |
50 | 50 | { |
51 | - if (! self::$_instance instanceof EE_Log) { |
|
51 | + if ( ! self::$_instance instanceof EE_Log) { |
|
52 | 52 | self::$_instance = new self(); |
53 | 53 | } |
54 | 54 | return self::$_instance; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | private function __construct() |
62 | 62 | { |
63 | 63 | |
64 | - if (! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
64 | + if ( ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | */ |
106 | 106 | private function _format_message($file = '', $function = '', $message = '', $type = '') |
107 | 107 | { |
108 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
109 | - $msg .= '[' . current_time('mysql') . '] '; |
|
108 | + $msg = '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
109 | + $msg .= '['.current_time('mysql').'] '; |
|
110 | 110 | $msg .= ! empty($file) ? basename($file) : ''; |
111 | 111 | $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
112 | - $msg .= ! empty($function) ? $function . '()' : ''; |
|
112 | + $msg .= ! empty($function) ? $function.'()' : ''; |
|
113 | 113 | $msg .= PHP_EOL; |
114 | 114 | $type = ! empty($type) ? $type : 'log message'; |
115 | - $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
115 | + $msg .= ! empty($message) ? "\t".'['.$type.'] '.$message.PHP_EOL : ''; |
|
116 | 116 | return $msg; |
117 | 117 | } |
118 | 118 | |
@@ -164,18 +164,18 @@ discard block |
||
164 | 164 | |
165 | 165 | /** @var RequestInterface $request */ |
166 | 166 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
167 | - $data = 'domain=' . $request->getServerParam('HTTP_HOST'); |
|
168 | - $data .= '&ip=' . $request->getServerParam('SERVER_ADDR'); |
|
169 | - $data .= '&server_type=' . $request->getServerParam('SERVER_SOFTWARE'); |
|
170 | - $data .= '&time=' . time(); |
|
171 | - $data .= '&remote_log=' . $this->_log; |
|
167 | + $data = 'domain='.$request->getServerParam('HTTP_HOST'); |
|
168 | + $data .= '&ip='.$request->getServerParam('SERVER_ADDR'); |
|
169 | + $data .= '&server_type='.$request->getServerParam('SERVER_SOFTWARE'); |
|
170 | + $data .= '&time='.time(); |
|
171 | + $data .= '&remote_log='.$this->_log; |
|
172 | 172 | $data .= '&action=save'; |
173 | 173 | |
174 | 174 | if (defined('EELOGGING_PASS')) { |
175 | - $data .= '&pass=' . EELOGGING_PASS; |
|
175 | + $data .= '&pass='.EELOGGING_PASS; |
|
176 | 176 | } |
177 | 177 | if (defined('EELOGGING_KEY')) { |
178 | - $data .= '&key=' . EELOGGING_KEY; |
|
178 | + $data .= '&key='.EELOGGING_KEY; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | $c = curl_init($this->_remote_logging_url); |
@@ -19,197 +19,197 @@ |
||
19 | 19 | */ |
20 | 20 | class EE_Log |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - private $_log = ''; |
|
26 | - |
|
27 | - /** |
|
28 | - * Used for remote logging |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - private $_remote_logging_url = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private $_remote_log = ''; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var EE_Log |
|
41 | - */ |
|
42 | - private static $_instance; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return EE_Log |
|
47 | - */ |
|
48 | - public static function instance() |
|
49 | - { |
|
50 | - if (! self::$_instance instanceof EE_Log) { |
|
51 | - self::$_instance = new self(); |
|
52 | - } |
|
53 | - return self::$_instance; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @access private |
|
58 | - * @return EE_Log |
|
59 | - */ |
|
60 | - private function __construct() |
|
61 | - { |
|
62 | - |
|
63 | - if (! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
64 | - return; |
|
65 | - } |
|
66 | - |
|
67 | - $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
|
68 | - $this->_remote_log = ''; |
|
69 | - |
|
70 | - if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
71 | - add_action('shutdown', array($this, 'send_log'), 9999); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * verify_filesystem |
|
78 | - * tests that the required files and folders exist and are writable |
|
79 | - * |
|
80 | - */ |
|
81 | - public function verify_filesystem() |
|
82 | - { |
|
83 | - $msg = esc_html__( |
|
84 | - 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
85 | - 'event_espresso' |
|
86 | - ); |
|
87 | - EE_Error::doing_it_wrong( |
|
88 | - __METHOD__, |
|
89 | - $msg, |
|
90 | - '4.10.1.p' |
|
91 | - ); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * _format_message |
|
97 | - * makes yer log entries look all purdy |
|
98 | - * |
|
99 | - * @param string $file |
|
100 | - * @param string $function |
|
101 | - * @param string $message |
|
102 | - * @param string $type |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - private function _format_message($file = '', $function = '', $message = '', $type = '') |
|
106 | - { |
|
107 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
108 | - $msg .= '[' . current_time('mysql') . '] '; |
|
109 | - $msg .= ! empty($file) ? basename($file) : ''; |
|
110 | - $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
111 | - $msg .= ! empty($function) ? $function . '()' : ''; |
|
112 | - $msg .= PHP_EOL; |
|
113 | - $type = ! empty($type) ? $type : 'log message'; |
|
114 | - $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
115 | - return $msg; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * log |
|
121 | - * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the |
|
122 | - * EE_Log::write_log() callback |
|
123 | - * |
|
124 | - * @param string $file |
|
125 | - * @param string $function |
|
126 | - * @param string $message |
|
127 | - * @param string $type |
|
128 | - */ |
|
129 | - public function log($file = '', $function = '', $message = '', $type = '') |
|
130 | - { |
|
131 | - $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * write_log |
|
137 | - * appends the results of the 'AHEE_log' filter to the espresso log file |
|
138 | - */ |
|
139 | - public function write_log() |
|
140 | - { |
|
141 | - $msg = esc_html__( |
|
142 | - 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
143 | - 'event_espresso' |
|
144 | - ); |
|
145 | - EE_Error::doing_it_wrong( |
|
146 | - __METHOD__, |
|
147 | - $msg, |
|
148 | - '4.10.1.p' |
|
149 | - ); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * send_log |
|
155 | - * sends the espresso log to a remote URL via a PHP cURL request |
|
156 | - */ |
|
157 | - public function send_log() |
|
158 | - { |
|
159 | - |
|
160 | - if (empty($this->_remote_logging_url)) { |
|
161 | - return; |
|
162 | - } |
|
163 | - |
|
164 | - /** @var RequestInterface $request */ |
|
165 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
166 | - $data = 'domain=' . $request->getServerParam('HTTP_HOST'); |
|
167 | - $data .= '&ip=' . $request->getServerParam('SERVER_ADDR'); |
|
168 | - $data .= '&server_type=' . $request->getServerParam('SERVER_SOFTWARE'); |
|
169 | - $data .= '&time=' . time(); |
|
170 | - $data .= '&remote_log=' . $this->_log; |
|
171 | - $data .= '&action=save'; |
|
172 | - |
|
173 | - if (defined('EELOGGING_PASS')) { |
|
174 | - $data .= '&pass=' . EELOGGING_PASS; |
|
175 | - } |
|
176 | - if (defined('EELOGGING_KEY')) { |
|
177 | - $data .= '&key=' . EELOGGING_KEY; |
|
178 | - } |
|
179 | - |
|
180 | - $c = curl_init($this->_remote_logging_url); |
|
181 | - curl_setopt($c, CURLOPT_POST, true); |
|
182 | - curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
183 | - curl_setopt($c, CURLOPT_RETURNTRANSFER, true); |
|
184 | - curl_exec($c); |
|
185 | - curl_close($c); |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * write_debug |
|
191 | - * writes the contents of the current request's data to a log file. |
|
192 | - * previous entries are overwritten |
|
193 | - */ |
|
194 | - public function write_debug() |
|
195 | - { |
|
196 | - $msg = esc_html__( |
|
197 | - 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
198 | - 'event_espresso' |
|
199 | - ); |
|
200 | - EE_Error::doing_it_wrong( |
|
201 | - __METHOD__, |
|
202 | - $msg, |
|
203 | - '4.10.1.p' |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * __clone |
|
210 | - */ |
|
211 | - public function __clone() |
|
212 | - { |
|
213 | - trigger_error(esc_html__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
214 | - } |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + private $_log = ''; |
|
26 | + |
|
27 | + /** |
|
28 | + * Used for remote logging |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + private $_remote_logging_url = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private $_remote_log = ''; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var EE_Log |
|
41 | + */ |
|
42 | + private static $_instance; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return EE_Log |
|
47 | + */ |
|
48 | + public static function instance() |
|
49 | + { |
|
50 | + if (! self::$_instance instanceof EE_Log) { |
|
51 | + self::$_instance = new self(); |
|
52 | + } |
|
53 | + return self::$_instance; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @access private |
|
58 | + * @return EE_Log |
|
59 | + */ |
|
60 | + private function __construct() |
|
61 | + { |
|
62 | + |
|
63 | + if (! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
64 | + return; |
|
65 | + } |
|
66 | + |
|
67 | + $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
|
68 | + $this->_remote_log = ''; |
|
69 | + |
|
70 | + if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
71 | + add_action('shutdown', array($this, 'send_log'), 9999); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * verify_filesystem |
|
78 | + * tests that the required files and folders exist and are writable |
|
79 | + * |
|
80 | + */ |
|
81 | + public function verify_filesystem() |
|
82 | + { |
|
83 | + $msg = esc_html__( |
|
84 | + 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
85 | + 'event_espresso' |
|
86 | + ); |
|
87 | + EE_Error::doing_it_wrong( |
|
88 | + __METHOD__, |
|
89 | + $msg, |
|
90 | + '4.10.1.p' |
|
91 | + ); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * _format_message |
|
97 | + * makes yer log entries look all purdy |
|
98 | + * |
|
99 | + * @param string $file |
|
100 | + * @param string $function |
|
101 | + * @param string $message |
|
102 | + * @param string $type |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + private function _format_message($file = '', $function = '', $message = '', $type = '') |
|
106 | + { |
|
107 | + $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
108 | + $msg .= '[' . current_time('mysql') . '] '; |
|
109 | + $msg .= ! empty($file) ? basename($file) : ''; |
|
110 | + $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
111 | + $msg .= ! empty($function) ? $function . '()' : ''; |
|
112 | + $msg .= PHP_EOL; |
|
113 | + $type = ! empty($type) ? $type : 'log message'; |
|
114 | + $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
115 | + return $msg; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * log |
|
121 | + * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the |
|
122 | + * EE_Log::write_log() callback |
|
123 | + * |
|
124 | + * @param string $file |
|
125 | + * @param string $function |
|
126 | + * @param string $message |
|
127 | + * @param string $type |
|
128 | + */ |
|
129 | + public function log($file = '', $function = '', $message = '', $type = '') |
|
130 | + { |
|
131 | + $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * write_log |
|
137 | + * appends the results of the 'AHEE_log' filter to the espresso log file |
|
138 | + */ |
|
139 | + public function write_log() |
|
140 | + { |
|
141 | + $msg = esc_html__( |
|
142 | + 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
143 | + 'event_espresso' |
|
144 | + ); |
|
145 | + EE_Error::doing_it_wrong( |
|
146 | + __METHOD__, |
|
147 | + $msg, |
|
148 | + '4.10.1.p' |
|
149 | + ); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * send_log |
|
155 | + * sends the espresso log to a remote URL via a PHP cURL request |
|
156 | + */ |
|
157 | + public function send_log() |
|
158 | + { |
|
159 | + |
|
160 | + if (empty($this->_remote_logging_url)) { |
|
161 | + return; |
|
162 | + } |
|
163 | + |
|
164 | + /** @var RequestInterface $request */ |
|
165 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
166 | + $data = 'domain=' . $request->getServerParam('HTTP_HOST'); |
|
167 | + $data .= '&ip=' . $request->getServerParam('SERVER_ADDR'); |
|
168 | + $data .= '&server_type=' . $request->getServerParam('SERVER_SOFTWARE'); |
|
169 | + $data .= '&time=' . time(); |
|
170 | + $data .= '&remote_log=' . $this->_log; |
|
171 | + $data .= '&action=save'; |
|
172 | + |
|
173 | + if (defined('EELOGGING_PASS')) { |
|
174 | + $data .= '&pass=' . EELOGGING_PASS; |
|
175 | + } |
|
176 | + if (defined('EELOGGING_KEY')) { |
|
177 | + $data .= '&key=' . EELOGGING_KEY; |
|
178 | + } |
|
179 | + |
|
180 | + $c = curl_init($this->_remote_logging_url); |
|
181 | + curl_setopt($c, CURLOPT_POST, true); |
|
182 | + curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
183 | + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); |
|
184 | + curl_exec($c); |
|
185 | + curl_close($c); |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * write_debug |
|
191 | + * writes the contents of the current request's data to a log file. |
|
192 | + * previous entries are overwritten |
|
193 | + */ |
|
194 | + public function write_debug() |
|
195 | + { |
|
196 | + $msg = esc_html__( |
|
197 | + 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
198 | + 'event_espresso' |
|
199 | + ); |
|
200 | + EE_Error::doing_it_wrong( |
|
201 | + __METHOD__, |
|
202 | + $msg, |
|
203 | + '4.10.1.p' |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * __clone |
|
210 | + */ |
|
211 | + public function __clone() |
|
212 | + { |
|
213 | + trigger_error(esc_html__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
214 | + } |
|
215 | 215 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | public function import() |
142 | 142 | { |
143 | 143 | |
144 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
144 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
145 | 145 | $this->EE_CSV = EE_CSV::instance(); |
146 | 146 | |
147 | 147 | /** @var RequestInterface $request */ |
@@ -188,18 +188,18 @@ discard block |
||
188 | 188 | break; |
189 | 189 | } |
190 | 190 | |
191 | - if (! $error_msg) { |
|
191 | + if ( ! $error_msg) { |
|
192 | 192 | $filename = $files['file']['name'][0]; |
193 | 193 | $file_ext = substr(strrchr($filename, '.'), 1); |
194 | 194 | $file_type = $files['file']['type'][0]; |
195 | 195 | $temp_file = $files['file']['tmp_name'][0]; |
196 | - $filesize = $files['file']['size'][0] / 1024;// convert from bytes to KB |
|
196 | + $filesize = $files['file']['size'][0] / 1024; // convert from bytes to KB |
|
197 | 197 | |
198 | 198 | if ($file_ext == 'csv') { |
199 | - $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
199 | + $max_upload = $this->EE_CSV->get_max_upload_size(); // max upload size in KB |
|
200 | 200 | if ($filesize < $max_upload || true) { |
201 | 201 | $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
202 | - $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
202 | + $path_to_file = $wp_upload_dir['basedir'].'/espresso/'.$filename; |
|
203 | 203 | |
204 | 204 | if (move_uploaded_file($temp_file, $path_to_file)) { |
205 | 205 | // convert csv to array |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
335 | 335 | $old_site_url = 'none-specified'; |
336 | 336 | // hanlde metadata |
337 | - if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
338 | - $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
337 | + if (isset($csv_data_array[EE_CSV::metadata_header])) { |
|
338 | + $csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]); |
|
339 | 339 | // ok so its metadata, dont try to save it to ehte db obviously... |
340 | 340 | if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
341 | 341 | EE_Error::add_attention( |
@@ -360,14 +360,14 @@ discard block |
||
360 | 360 | ) |
361 | 361 | ); |
362 | 362 | }; |
363 | - unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
363 | + unset($csv_data_array[EE_CSV::metadata_header]); |
|
364 | 364 | } |
365 | 365 | /** |
366 | 366 | * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
367 | 367 | * the value will be the newly-inserted ID. |
368 | 368 | * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
369 | 369 | */ |
370 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
370 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array()); |
|
371 | 371 | if ($old_db_to_new_db_mapping) { |
372 | 372 | EE_Error::add_attention( |
373 | 373 | sprintf( |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | ); |
388 | 388 | |
389 | 389 | // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
390 | - update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
390 | + update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
391 | 391 | |
392 | 392 | if ($this->_total_updates > 0) { |
393 | 393 | EE_Error::add_success( |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | // find the PK in the row of data (or a combined key if |
511 | 511 | // there is no primary key) |
512 | 512 | if ($model->has_primary_key_field()) { |
513 | - $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
513 | + $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
514 | 514 | } else { |
515 | 515 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
516 | 516 | } |
@@ -554,14 +554,14 @@ discard block |
||
554 | 554 | $what_to_do = self::do_update; |
555 | 555 | // and if this model has a primary key, remember its mapping |
556 | 556 | if ($model->has_primary_key_field()) { |
557 | - $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
558 | - $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
557 | + $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
|
558 | + $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
|
559 | 559 | } else { |
560 | 560 | // we want to update this conflicting item, instead of inserting a conflicting item |
561 | 561 | // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
562 | 562 | // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
563 | 563 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
564 | - $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
564 | + $model_object_data[$key_field->get_name()] = $conflicting->get( |
|
565 | 565 | $key_field->get_name() |
566 | 566 | ); |
567 | 567 | } |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | $model_name = $model->get_this_model_name(); |
622 | 622 | // if it's a site-to-site export-and-import, see if this modelobject's id |
623 | 623 | // in the old data that we know of |
624 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
624 | + if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) { |
|
625 | 625 | return self::do_update; |
626 | 626 | } else { |
627 | 627 | return self::do_insert; |
@@ -677,13 +677,13 @@ discard block |
||
677 | 677 | if ( |
678 | 678 | $model->has_primary_key_field() && |
679 | 679 | $model->get_primary_key_field()->is_auto_increment() && |
680 | - isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
680 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) && |
|
681 | 681 | isset( |
682 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
682 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]] |
|
683 | 683 | ) |
684 | 684 | ) { |
685 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
686 | - ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
685 | + $model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name( |
|
686 | + )][$model_object_data[$model->primary_key_name()]]; |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | try { |
@@ -699,10 +699,10 @@ discard block |
||
699 | 699 | $found_a_mapping = false; |
700 | 700 | foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
701 | 701 | if ($model_name_field) { |
702 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
702 | + $value_of_model_name_field = $model_object_data[$model_name_field->get_name()]; |
|
703 | 703 | if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
704 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
705 | - $model_object_data[ $field_obj->get_name() ], |
|
704 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
705 | + $model_object_data[$field_obj->get_name()], |
|
706 | 706 | $model_pointed_to_by_fk, |
707 | 707 | $old_db_to_new_db_mapping, |
708 | 708 | $export_from_site_a_to_b |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | break; |
712 | 712 | } |
713 | 713 | } else { |
714 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
715 | - $model_object_data[ $field_obj->get_name() ], |
|
714 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
715 | + $model_object_data[$field_obj->get_name()], |
|
716 | 716 | $model_pointed_to_by_fk, |
717 | 717 | $old_db_to_new_db_mapping, |
718 | 718 | $export_from_site_a_to_b |
@@ -777,8 +777,8 @@ discard block |
||
777 | 777 | */ |
778 | 778 | protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
779 | 779 | { |
780 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
781 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
780 | + if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) { |
|
781 | + return $old_db_to_new_db_mapping[$model_name][$object_id]; |
|
782 | 782 | } elseif ($object_id == '0' || $object_id == '') { |
783 | 783 | // leave as-is |
784 | 784 | return $object_id; |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | // we couldn't find a mapping for this, and it's from a different site, |
787 | 787 | // so blank it out |
788 | 788 | return null; |
789 | - } elseif (! $export_from_site_a_to_b) { |
|
789 | + } elseif ( ! $export_from_site_a_to_b) { |
|
790 | 790 | // we coudln't find a mapping for this, but it's from thsi DB anyway |
791 | 791 | // so let's just leave it as-is |
792 | 792 | return $object_id; |
@@ -806,8 +806,8 @@ discard block |
||
806 | 806 | // remove the primary key, if there is one (we don't want it for inserts OR updates) |
807 | 807 | // we'll put it back in if we need it |
808 | 808 | if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
809 | - $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
810 | - unset($model_object_data[ $model->primary_key_name() ]); |
|
809 | + $effective_id = $model_object_data[$model->primary_key_name()]; |
|
810 | + unset($model_object_data[$model->primary_key_name()]); |
|
811 | 811 | } else { |
812 | 812 | $effective_id = $model->get_index_primary_key_string($model_object_data); |
813 | 813 | } |
@@ -815,7 +815,7 @@ discard block |
||
815 | 815 | try { |
816 | 816 | $new_id = $model->insert($model_object_data); |
817 | 817 | if ($new_id) { |
818 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
818 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
|
819 | 819 | $this->_total_inserts++; |
820 | 820 | EE_Error::add_success( |
821 | 821 | sprintf( |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | $this->_total_insert_errors++; |
830 | 830 | // put the ID used back in there for the error message |
831 | 831 | if ($model->has_primary_key_field()) { |
832 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
832 | + $model_object_data[$model->primary_key_name()] = $effective_id; |
|
833 | 833 | } |
834 | 834 | EE_Error::add_error( |
835 | 835 | sprintf( |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | } catch (EE_Error $e) { |
846 | 846 | $this->_total_insert_errors++; |
847 | 847 | if ($model->has_primary_key_field()) { |
848 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
848 | + $model_object_data[$model->primary_key_name()] = $effective_id; |
|
849 | 849 | } |
850 | 850 | EE_Error::add_error( |
851 | 851 | sprintf( |
@@ -878,17 +878,17 @@ discard block |
||
878 | 878 | // one for performing an update, one for everthing else |
879 | 879 | $model_object_data_for_update = $model_object_data; |
880 | 880 | if ($model->has_primary_key_field()) { |
881 | - $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
881 | + $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
|
882 | 882 | // remove the primary key because we shouldn't use it for updating |
883 | - unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
883 | + unset($model_object_data_for_update[$model->primary_key_name()]); |
|
884 | 884 | } elseif ($model->get_combined_primary_key_fields() > 1) { |
885 | 885 | $conditions = array(); |
886 | 886 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
887 | - $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
887 | + $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
|
888 | 888 | } |
889 | 889 | } else { |
890 | 890 | $model->primary_key_name( |
891 | - );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
891 | + ); // this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | $success = $model->update($model_object_data_for_update, array($conditions)); |
@@ -906,15 +906,15 @@ discard block |
||
906 | 906 | // we would have last-minute decided to update. So we'd like to know what we updated |
907 | 907 | // and so we record what record ended up being updated using the mapping |
908 | 908 | if ($model->has_primary_key_field()) { |
909 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
909 | + $new_key_for_mapping = $model_object_data[$model->primary_key_name()]; |
|
910 | 910 | } else { |
911 | 911 | // no primary key just a combined key |
912 | 912 | $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
913 | 913 | } |
914 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
914 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping; |
|
915 | 915 | } else { |
916 | 916 | $matched_items = $model->get_all(array($conditions)); |
917 | - if (! $matched_items) { |
|
917 | + if ( ! $matched_items) { |
|
918 | 918 | // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
919 | 919 | $this->_total_update_errors++; |
920 | 920 | EE_Error::add_error( |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | implode(",", $model_object_data), |
954 | 954 | $e->getMessage() |
955 | 955 | ); |
956 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
956 | + $debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString(); |
|
957 | 957 | EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
958 | 958 | } |
959 | 959 | return $old_db_to_new_db_mapping; |
@@ -13,94 +13,94 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class EE_Import implements ResettableInterface |
15 | 15 | { |
16 | - const do_insert = 'insert'; |
|
17 | - const do_update = 'update'; |
|
18 | - const do_nothing = 'nothing'; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * instance of the EE_Import object |
|
23 | - */ |
|
24 | - private static $_instance; |
|
25 | - |
|
26 | - private static $_csv_array = array(); |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array of model names |
|
30 | - */ |
|
31 | - private static $_model_list = array(); |
|
32 | - |
|
33 | - private static $_columns_to_save = array(); |
|
34 | - |
|
35 | - protected $_total_inserts = 0; |
|
36 | - protected $_total_updates = 0; |
|
37 | - protected $_total_insert_errors = 0; |
|
38 | - protected $_total_update_errors = 0; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var EE_CSV |
|
42 | - * @since 4.10.14.p |
|
43 | - */ |
|
44 | - private $EE_CSV; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * private constructor to prevent direct creation |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - private function __construct() |
|
53 | - { |
|
54 | - $this->_total_inserts = 0; |
|
55 | - $this->_total_updates = 0; |
|
56 | - $this->_total_insert_errors = 0; |
|
57 | - $this->_total_update_errors = 0; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * singleton method used to instantiate class object |
|
63 | - * |
|
64 | - * @return EE_Import |
|
65 | - */ |
|
66 | - public static function instance() |
|
67 | - { |
|
68 | - // check if class object is instantiated |
|
69 | - if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
70 | - self::$_instance = new self(); |
|
71 | - } |
|
72 | - return self::$_instance; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Resets the importer |
|
77 | - * |
|
78 | - * @return EE_Import |
|
79 | - */ |
|
80 | - public static function reset() |
|
81 | - { |
|
82 | - self::$_instance = null; |
|
83 | - return self::instance(); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * generates HTML for a file upload input and form |
|
89 | - * |
|
90 | - * @param string $title - heading for the form |
|
91 | - * @param string $intro - additional text explaing what to do |
|
92 | - * @param string $page - EE Admin page to direct form to - in the form "espresso_{pageslug}" |
|
93 | - * @param string $action - EE Admin page route array "action" that form will direct to |
|
94 | - * @param string $type - type of file to import |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function upload_form($title, $intro, $form_url, $action, $type) |
|
98 | - { |
|
99 | - |
|
100 | - $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
101 | - |
|
102 | - ob_start(); |
|
103 | - ?> |
|
16 | + const do_insert = 'insert'; |
|
17 | + const do_update = 'update'; |
|
18 | + const do_nothing = 'nothing'; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * instance of the EE_Import object |
|
23 | + */ |
|
24 | + private static $_instance; |
|
25 | + |
|
26 | + private static $_csv_array = array(); |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array of model names |
|
30 | + */ |
|
31 | + private static $_model_list = array(); |
|
32 | + |
|
33 | + private static $_columns_to_save = array(); |
|
34 | + |
|
35 | + protected $_total_inserts = 0; |
|
36 | + protected $_total_updates = 0; |
|
37 | + protected $_total_insert_errors = 0; |
|
38 | + protected $_total_update_errors = 0; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var EE_CSV |
|
42 | + * @since 4.10.14.p |
|
43 | + */ |
|
44 | + private $EE_CSV; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * private constructor to prevent direct creation |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + private function __construct() |
|
53 | + { |
|
54 | + $this->_total_inserts = 0; |
|
55 | + $this->_total_updates = 0; |
|
56 | + $this->_total_insert_errors = 0; |
|
57 | + $this->_total_update_errors = 0; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * singleton method used to instantiate class object |
|
63 | + * |
|
64 | + * @return EE_Import |
|
65 | + */ |
|
66 | + public static function instance() |
|
67 | + { |
|
68 | + // check if class object is instantiated |
|
69 | + if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
70 | + self::$_instance = new self(); |
|
71 | + } |
|
72 | + return self::$_instance; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Resets the importer |
|
77 | + * |
|
78 | + * @return EE_Import |
|
79 | + */ |
|
80 | + public static function reset() |
|
81 | + { |
|
82 | + self::$_instance = null; |
|
83 | + return self::instance(); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * generates HTML for a file upload input and form |
|
89 | + * |
|
90 | + * @param string $title - heading for the form |
|
91 | + * @param string $intro - additional text explaing what to do |
|
92 | + * @param string $page - EE Admin page to direct form to - in the form "espresso_{pageslug}" |
|
93 | + * @param string $action - EE Admin page route array "action" that form will direct to |
|
94 | + * @param string $type - type of file to import |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function upload_form($title, $intro, $form_url, $action, $type) |
|
98 | + { |
|
99 | + |
|
100 | + $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
101 | + |
|
102 | + ob_start(); |
|
103 | + ?> |
|
104 | 104 | <div class="ee-upload-form-dv"> |
105 | 105 | <h3><?php echo esc_html($title); ?></h3> |
106 | 106 | <p><?php echo esc_html($intro); ?></p> |
@@ -116,880 +116,880 @@ discard block |
||
116 | 116 | <b><?php esc_html_e('Attention', 'event_espresso'); ?></b><br/> |
117 | 117 | <?php echo sprintf(esc_html__('Accepts .%s file types only.', 'event_espresso'), $type); ?> |
118 | 118 | <?php echo esc_html__( |
119 | - 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', |
|
120 | - 'event_espresso' |
|
121 | - ); ?> |
|
119 | + 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', |
|
120 | + 'event_espresso' |
|
121 | + ); ?> |
|
122 | 122 | </p> |
123 | 123 | |
124 | 124 | </div> |
125 | 125 | |
126 | 126 | <?php |
127 | - $uploader = ob_get_clean(); |
|
128 | - return $uploader; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * Import Event Espresso data - some code "borrowed" from event espresso csv_import.php |
|
134 | - * @return boolean success |
|
135 | - */ |
|
136 | - public function import() |
|
137 | - { |
|
138 | - |
|
139 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
140 | - $this->EE_CSV = EE_CSV::instance(); |
|
141 | - |
|
142 | - /** @var RequestInterface $request */ |
|
143 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
144 | - |
|
145 | - if ($request->requestParamIsSet('import') && $request->requestParamIsSet('csv_submitted')) { |
|
146 | - $files = $request->filesParams(); |
|
147 | - switch ($files['file']['error'][0]) { |
|
148 | - case UPLOAD_ERR_OK: |
|
149 | - $error_msg = false; |
|
150 | - break; |
|
151 | - case UPLOAD_ERR_INI_SIZE: |
|
152 | - $error_msg = esc_html__( |
|
153 | - "'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", |
|
154 | - "event_espresso" |
|
155 | - ); |
|
156 | - break; |
|
157 | - case UPLOAD_ERR_FORM_SIZE: |
|
158 | - $error_msg = esc_html__( |
|
159 | - 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', |
|
160 | - "event_espresso" |
|
161 | - ); |
|
162 | - break; |
|
163 | - case UPLOAD_ERR_PARTIAL: |
|
164 | - $error_msg = esc_html__('The uploaded file was only partially uploaded.', "event_espresso"); |
|
165 | - break; |
|
166 | - case UPLOAD_ERR_NO_FILE: |
|
167 | - $error_msg = esc_html__('No file was uploaded.', "event_espresso"); |
|
168 | - break; |
|
169 | - case UPLOAD_ERR_NO_TMP_DIR: |
|
170 | - $error_msg = esc_html__('Missing a temporary folder.', "event_espresso"); |
|
171 | - break; |
|
172 | - case UPLOAD_ERR_CANT_WRITE: |
|
173 | - $error_msg = esc_html__('Failed to write file to disk.', "event_espresso"); |
|
174 | - break; |
|
175 | - case UPLOAD_ERR_EXTENSION: |
|
176 | - $error_msg = esc_html__('File upload stopped by extension.', "event_espresso"); |
|
177 | - break; |
|
178 | - default: |
|
179 | - $error_msg = esc_html__( |
|
180 | - 'An unknown error occurred and the file could not be uploaded', |
|
181 | - "event_espresso" |
|
182 | - ); |
|
183 | - break; |
|
184 | - } |
|
185 | - |
|
186 | - if (! $error_msg) { |
|
187 | - $filename = $files['file']['name'][0]; |
|
188 | - $file_ext = substr(strrchr($filename, '.'), 1); |
|
189 | - $file_type = $files['file']['type'][0]; |
|
190 | - $temp_file = $files['file']['tmp_name'][0]; |
|
191 | - $filesize = $files['file']['size'][0] / 1024;// convert from bytes to KB |
|
192 | - |
|
193 | - if ($file_ext == 'csv') { |
|
194 | - $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
195 | - if ($filesize < $max_upload || true) { |
|
196 | - $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
|
197 | - $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
198 | - |
|
199 | - if (move_uploaded_file($temp_file, $path_to_file)) { |
|
200 | - // convert csv to array |
|
201 | - $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
202 | - |
|
203 | - $action = $request->getRequestParam('action'); |
|
204 | - |
|
205 | - // was data successfully stored in an array? |
|
206 | - if (is_array($this->csv_array)) { |
|
207 | - $import_what = str_replace('csv_import_', '', $action); |
|
208 | - $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
209 | - $processed_data = $this->csv_array; |
|
210 | - $this->columns_to_save = false; |
|
211 | - |
|
212 | - // if any imports require funky processing, we'll catch them in the switch |
|
213 | - switch ($action) { |
|
214 | - case "import_events": |
|
215 | - case "event_list": |
|
216 | - $import_what = 'Event Details'; |
|
217 | - break; |
|
218 | - |
|
219 | - case 'groupon_import_csv': |
|
220 | - $import_what = 'Groupon Codes'; |
|
221 | - $processed_data = $this->process_groupon_codes(); |
|
222 | - break; |
|
223 | - } |
|
224 | - // save processed codes to db |
|
225 | - if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
226 | - return true; |
|
227 | - } |
|
228 | - } else { |
|
229 | - // no array? must be an error |
|
230 | - EE_Error::add_error( |
|
231 | - sprintf(esc_html__("No file seems to have been uploaded", "event_espresso")), |
|
232 | - __FILE__, |
|
233 | - __FUNCTION__, |
|
234 | - __LINE__ |
|
235 | - ); |
|
236 | - return false; |
|
237 | - } |
|
238 | - } else { |
|
239 | - EE_Error::add_error( |
|
240 | - sprintf(esc_html__("%s was not successfully uploaded", "event_espresso"), $filename), |
|
241 | - __FILE__, |
|
242 | - __FUNCTION__, |
|
243 | - __LINE__ |
|
244 | - ); |
|
245 | - return false; |
|
246 | - } |
|
247 | - } else { |
|
248 | - EE_Error::add_error( |
|
249 | - sprintf( |
|
250 | - esc_html__( |
|
251 | - "%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", |
|
252 | - "event_espresso" |
|
253 | - ), |
|
254 | - $filename, |
|
255 | - $max_upload |
|
256 | - ), |
|
257 | - __FILE__, |
|
258 | - __FUNCTION__, |
|
259 | - __LINE__ |
|
260 | - ); |
|
261 | - return false; |
|
262 | - } |
|
263 | - } else { |
|
264 | - EE_Error::add_error( |
|
265 | - sprintf(esc_html__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), |
|
266 | - __FILE__, |
|
267 | - __FUNCTION__, |
|
268 | - __LINE__ |
|
269 | - ); |
|
270 | - return false; |
|
271 | - } |
|
272 | - } else { |
|
273 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
274 | - return false; |
|
275 | - } |
|
276 | - } |
|
277 | - return false; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Given an array of data (usually from a CSV import) attempts to save that data to the db. |
|
283 | - * If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names, |
|
284 | - * next level being numeric indexes adn each value representing a model object, and the last layer down |
|
285 | - * being keys of model fields and their proposed values. |
|
286 | - * If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned. |
|
287 | - * If the CSV data says (in the metadata row) that it's from the SAME database, |
|
288 | - * we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those |
|
289 | - * IDs DON'T exist in the database, they're treated as temporary IDs, |
|
290 | - * which can used elsewhere to refer to the same object. Once an item |
|
291 | - * with a temporary ID gets inserted, we record its mapping from temporary |
|
292 | - * ID to real ID, and use the real ID in place of the temporary ID |
|
293 | - * when that temporary ID was used as a foreign key. |
|
294 | - * If the CSV data says (in the metadata again) that it's from a DIFFERENT database, |
|
295 | - * we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with |
|
296 | - * ID 1, and the database already has an event with ID 1, we assume that's just a coincidence, |
|
297 | - * and insert a new event, and map it's temporary ID of 1 over to its new real ID. |
|
298 | - * An important exception are non-auto-increment primary keys. If one entry in the |
|
299 | - * CSV file has the same ID as one in the DB, we assume they are meant to be |
|
300 | - * the same item, and instead update the item in the DB with that same ID. |
|
301 | - * Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th |
|
302 | - * time you import a CSV from a different site, we remember their mappings, and |
|
303 | - * will try to update the item in the DB instead of inserting another item (eg |
|
304 | - * if we previously imported an event with temporary ID 1, and then it got a |
|
305 | - * real ID of 123, we remember that. So the next time we import an event with |
|
306 | - * temporary ID, from the same site, we know that it's real ID is 123, and will |
|
307 | - * update that event, instead of adding a new event). |
|
308 | - * |
|
309 | - * @param array $csv_data_array - the array containing the csv data produced from |
|
310 | - * EE_CSV::import_csv_to_model_data_array() |
|
311 | - * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table |
|
312 | - * fields they will be saved to |
|
313 | - * @return TRUE on success, FALSE on fail |
|
314 | - * @throws EE_Error |
|
315 | - */ |
|
316 | - public function save_csv_data_array_to_db($csv_data_array, $model_name = false) |
|
317 | - { |
|
318 | - $success = false; |
|
319 | - $error = false; |
|
320 | - // whther to treat this import as if it's data froma different database or not |
|
321 | - // ie, if it IS from a different database, ignore foreign keys whihf |
|
322 | - $export_from_site_a_to_b = true; |
|
323 | - // first level of array is not table information but a table name was passed to the function |
|
324 | - // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
|
325 | - if ($model_name) { |
|
326 | - $csv_data_array = array($csv_data_array); |
|
327 | - } |
|
328 | - // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
|
329 | - $old_site_url = 'none-specified'; |
|
330 | - // hanlde metadata |
|
331 | - if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
332 | - $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
333 | - // ok so its metadata, dont try to save it to ehte db obviously... |
|
334 | - if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
335 | - EE_Error::add_attention( |
|
336 | - sprintf( |
|
337 | - esc_html__( |
|
338 | - "CSV Data appears to be from the same database, so attempting to update data", |
|
339 | - "event_espresso" |
|
340 | - ) |
|
341 | - ) |
|
342 | - ); |
|
343 | - $export_from_site_a_to_b = false; |
|
344 | - } else { |
|
345 | - $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
346 | - EE_Error::add_attention( |
|
347 | - sprintf( |
|
348 | - esc_html__( |
|
349 | - "CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", |
|
350 | - "event_espresso" |
|
351 | - ), |
|
352 | - $old_site_url, |
|
353 | - site_url() |
|
354 | - ) |
|
355 | - ); |
|
356 | - }; |
|
357 | - unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
358 | - } |
|
359 | - /** |
|
360 | - * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
361 | - * the value will be the newly-inserted ID. |
|
362 | - * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
363 | - */ |
|
364 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
365 | - if ($old_db_to_new_db_mapping) { |
|
366 | - EE_Error::add_attention( |
|
367 | - sprintf( |
|
368 | - esc_html__( |
|
369 | - "We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", |
|
370 | - "event_espresso" |
|
371 | - ), |
|
372 | - $old_site_url, |
|
373 | - site_url() |
|
374 | - ) |
|
375 | - ); |
|
376 | - } |
|
377 | - $old_db_to_new_db_mapping = $this->save_data_rows_to_db( |
|
378 | - $csv_data_array, |
|
379 | - $export_from_site_a_to_b, |
|
380 | - $old_db_to_new_db_mapping |
|
381 | - ); |
|
382 | - |
|
383 | - // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
|
384 | - update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
385 | - |
|
386 | - if ($this->_total_updates > 0) { |
|
387 | - EE_Error::add_success( |
|
388 | - sprintf( |
|
389 | - esc_html__("%s existing records in the database were updated.", "event_espresso"), |
|
390 | - $this->_total_updates |
|
391 | - ) |
|
392 | - ); |
|
393 | - $success = true; |
|
394 | - } |
|
395 | - if ($this->_total_inserts > 0) { |
|
396 | - EE_Error::add_success( |
|
397 | - sprintf(esc_html__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts) |
|
398 | - ); |
|
399 | - $success = true; |
|
400 | - } |
|
401 | - |
|
402 | - if ($this->_total_update_errors > 0) { |
|
403 | - EE_Error::add_error( |
|
404 | - sprintf( |
|
405 | - esc_html__( |
|
406 | - "'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", |
|
407 | - "event_espresso" |
|
408 | - ), |
|
409 | - $this->_total_update_errors |
|
410 | - ), |
|
411 | - __FILE__, |
|
412 | - __FUNCTION__, |
|
413 | - __LINE__ |
|
414 | - ); |
|
415 | - $error = true; |
|
416 | - } |
|
417 | - if ($this->_total_insert_errors > 0) { |
|
418 | - EE_Error::add_error( |
|
419 | - sprintf( |
|
420 | - esc_html__( |
|
421 | - "One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", |
|
422 | - "event_espresso" |
|
423 | - ), |
|
424 | - $this->_total_insert_errors |
|
425 | - ), |
|
426 | - __FILE__, |
|
427 | - __FUNCTION__, |
|
428 | - __LINE__ |
|
429 | - ); |
|
430 | - $error = true; |
|
431 | - } |
|
432 | - |
|
433 | - // lastly, we need to update the datetime and ticket sold amounts |
|
434 | - // as those may have been affected by this |
|
435 | - EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
|
436 | - |
|
437 | - // if there was at least one success and absolutely no errors |
|
438 | - if ($success && ! $error) { |
|
439 | - return true; |
|
440 | - } else { |
|
441 | - return false; |
|
442 | - } |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * Processes the array of data, given the knowledge that it's from the same database or a different one, |
|
448 | - * and the mapping from temporary IDs to real IDs. |
|
449 | - * If the data is from a different database, we treat the primary keys and their corresponding |
|
450 | - * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys |
|
451 | - * in the real target database. As items are inserted, their temporary primary keys |
|
452 | - * are mapped to the real IDs in the target database. Also, before doing any update or |
|
453 | - * insert, we replace all the temp ID which are foreign keys with their mapped real IDs. |
|
454 | - * An exception: string primary keys are treated as real IDs, or else we'd need to |
|
455 | - * dynamically generate new string primary keys which would be very awkard for the country table etc. |
|
456 | - * Also, models with no primary key are strange too. We combine use their primar key INDEX (a |
|
457 | - * combination of fields) to create a unique string identifying the row and store |
|
458 | - * those in the mapping. |
|
459 | - * |
|
460 | - * If the data is from the same database, we usually treat primary keys as real IDs. |
|
461 | - * An exception is if there is nothing in the database for that ID. If that's the case, |
|
462 | - * we need to insert a new row for that ID, and then map from the non-existent ID |
|
463 | - * to the newly-inserted real ID. |
|
464 | - * |
|
465 | - * @param mixed $csv_data_array |
|
466 | - * @param mixed $export_from_site_a_to_b |
|
467 | - * @param mixed $old_db_to_new_db_mapping |
|
468 | - * @return array updated $old_db_to_new_db_mapping |
|
469 | - */ |
|
470 | - public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) |
|
471 | - { |
|
472 | - foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
473 | - // now check that assumption was correct. If |
|
474 | - if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
475 | - $model_name = $model_name_in_csv_data; |
|
476 | - } else { |
|
477 | - // no table info in the array and no table name passed to the function?? FAIL |
|
478 | - EE_Error::add_error( |
|
479 | - esc_html__( |
|
480 | - 'No table information was specified and/or found, therefore the import could not be completed', |
|
481 | - 'event_espresso' |
|
482 | - ), |
|
483 | - __FILE__, |
|
484 | - __FUNCTION__, |
|
485 | - __LINE__ |
|
486 | - ); |
|
487 | - return false; |
|
488 | - } |
|
489 | - /* @var $model EEM_Base */ |
|
490 | - $model = EE_Registry::instance()->load_model($model_name); |
|
491 | - |
|
492 | - // so without further ado, scanning all the data provided for primary keys and their inital values |
|
493 | - foreach ($model_data_from_import as $model_object_data) { |
|
494 | - // before we do ANYTHING, make sure the csv row wasn't just completely blank |
|
495 | - $row_is_completely_empty = true; |
|
496 | - foreach ($model_object_data as $field) { |
|
497 | - if ($field) { |
|
498 | - $row_is_completely_empty = false; |
|
499 | - } |
|
500 | - } |
|
501 | - if ($row_is_completely_empty) { |
|
502 | - continue; |
|
503 | - } |
|
504 | - // find the PK in the row of data (or a combined key if |
|
505 | - // there is no primary key) |
|
506 | - if ($model->has_primary_key_field()) { |
|
507 | - $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
508 | - } else { |
|
509 | - $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - $model_object_data = $this->_replace_temp_ids_with_mappings( |
|
514 | - $model_object_data, |
|
515 | - $model, |
|
516 | - $old_db_to_new_db_mapping, |
|
517 | - $export_from_site_a_to_b |
|
518 | - ); |
|
519 | - // now we need to decide if we're going to add a new model object given the $model_object_data, |
|
520 | - // or just update. |
|
521 | - if ($export_from_site_a_to_b) { |
|
522 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( |
|
523 | - $id_in_csv, |
|
524 | - $model_object_data, |
|
525 | - $model, |
|
526 | - $old_db_to_new_db_mapping |
|
527 | - ); |
|
528 | - } else {// this is just a re-import |
|
529 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( |
|
530 | - $id_in_csv, |
|
531 | - $model_object_data, |
|
532 | - $model, |
|
533 | - $old_db_to_new_db_mapping |
|
534 | - ); |
|
535 | - } |
|
536 | - if ($what_to_do == self::do_nothing) { |
|
537 | - continue; |
|
538 | - } |
|
539 | - |
|
540 | - // double-check we actually want to insert, if that's what we're planning |
|
541 | - // based on whether this item would be unique in the DB or not |
|
542 | - if ($what_to_do == self::do_insert) { |
|
543 | - // we're supposed to be inserting. But wait, will this thing |
|
544 | - // be acceptable if inserted? |
|
545 | - $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
546 | - if ($conflicting) { |
|
547 | - // ok, this item would conflict if inserted. Just update the item that it conflicts with. |
|
548 | - $what_to_do = self::do_update; |
|
549 | - // and if this model has a primary key, remember its mapping |
|
550 | - if ($model->has_primary_key_field()) { |
|
551 | - $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
552 | - $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
553 | - } else { |
|
554 | - // we want to update this conflicting item, instead of inserting a conflicting item |
|
555 | - // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
|
556 | - // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
|
557 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
558 | - $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
559 | - $key_field->get_name() |
|
560 | - ); |
|
561 | - } |
|
562 | - } |
|
563 | - } |
|
564 | - } |
|
565 | - if ($what_to_do == self::do_insert) { |
|
566 | - $old_db_to_new_db_mapping = $this->_insert_from_data_array( |
|
567 | - $id_in_csv, |
|
568 | - $model_object_data, |
|
569 | - $model, |
|
570 | - $old_db_to_new_db_mapping |
|
571 | - ); |
|
572 | - } elseif ($what_to_do == self::do_update) { |
|
573 | - $old_db_to_new_db_mapping = $this->_update_from_data_array( |
|
574 | - $id_in_csv, |
|
575 | - $model_object_data, |
|
576 | - $model, |
|
577 | - $old_db_to_new_db_mapping |
|
578 | - ); |
|
579 | - } else { |
|
580 | - throw new EE_Error( |
|
581 | - sprintf( |
|
582 | - esc_html__( |
|
583 | - 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', |
|
584 | - 'event_espresso' |
|
585 | - ), |
|
586 | - $what_to_do |
|
587 | - ) |
|
588 | - ); |
|
589 | - } |
|
590 | - } |
|
591 | - } |
|
592 | - return $old_db_to_new_db_mapping; |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - /** |
|
597 | - * Decides whether or not to insert, given that this data is from another database. |
|
598 | - * So, if the primary key of this $model_object_data already exists in the database, |
|
599 | - * it's just a coincidence and we should still insert. The only time we should |
|
600 | - * update is when we know what it maps to, or there's something that would |
|
601 | - * conflict (and we should instead just update that conflicting thing) |
|
602 | - * |
|
603 | - * @param string $id_in_csv |
|
604 | - * @param array $model_object_data by reference so it can be modified |
|
605 | - * @param EEM_Base $model |
|
606 | - * @param array $old_db_to_new_db_mapping by reference so it can be modified |
|
607 | - * @return string one of the consts on this class that starts with do_* |
|
608 | - */ |
|
609 | - protected function _decide_whether_to_insert_or_update_given_data_from_other_db( |
|
610 | - $id_in_csv, |
|
611 | - $model_object_data, |
|
612 | - $model, |
|
613 | - $old_db_to_new_db_mapping |
|
614 | - ) { |
|
615 | - $model_name = $model->get_this_model_name(); |
|
616 | - // if it's a site-to-site export-and-import, see if this modelobject's id |
|
617 | - // in the old data that we know of |
|
618 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
619 | - return self::do_update; |
|
620 | - } else { |
|
621 | - return self::do_insert; |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * If this thing basically already exists in the database, we want to update it; |
|
627 | - * otherwise insert it (ie, someone tweaked the CSV file, or the item was |
|
628 | - * deleted in the database so it should be re-inserted) |
|
629 | - * |
|
630 | - * @param mixed $id_in_csv |
|
631 | - * @param mixed $model_object_data |
|
632 | - * @param EEM_Base $model |
|
633 | - * @param mixed $old_db_to_new_db_mapping |
|
634 | - * @return |
|
635 | - */ |
|
636 | - protected function _decide_whether_to_insert_or_update_given_data_from_same_db( |
|
637 | - $id_in_csv, |
|
638 | - $model_object_data, |
|
639 | - $model |
|
640 | - ) { |
|
641 | - // in this case, check if this thing ACTUALLY exists in the database |
|
642 | - if ($model->get_one_conflicting($model_object_data)) { |
|
643 | - return self::do_update; |
|
644 | - } else { |
|
645 | - return self::do_insert; |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs |
|
651 | - * with their mapped real IDs. Eg, if importing from site A to B, the mapping |
|
652 | - * file may indicate that the ID "my_event_id" maps to an actual event ID of 123. |
|
653 | - * So this function searches for any event temp Ids called "my_event_id" and |
|
654 | - * replaces them with 123. |
|
655 | - * Also, if there is no temp ID for the INT foreign keys from another database, |
|
656 | - * replaces them with 0 or the field's default. |
|
657 | - * |
|
658 | - * @param mixed $model_object_data |
|
659 | - * @param EEM_Base $model |
|
660 | - * @param mixed $old_db_to_new_db_mapping |
|
661 | - * @param boolean $export_from_site_a_to_b |
|
662 | - * @return array updated model object data with temp IDs removed |
|
663 | - */ |
|
664 | - protected function _replace_temp_ids_with_mappings( |
|
665 | - $model_object_data, |
|
666 | - $model, |
|
667 | - $old_db_to_new_db_mapping, |
|
668 | - $export_from_site_a_to_b |
|
669 | - ) { |
|
670 | - // if this model object's primary key is in the mapping, replace it |
|
671 | - if ( |
|
672 | - $model->has_primary_key_field() && |
|
673 | - $model->get_primary_key_field()->is_auto_increment() && |
|
674 | - isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
675 | - isset( |
|
676 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
677 | - ) |
|
678 | - ) { |
|
679 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
680 | - ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
681 | - } |
|
682 | - |
|
683 | - try { |
|
684 | - $model_name_field = $model->get_field_containing_related_model_name(); |
|
685 | - $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
|
686 | - } catch (EE_Error $e) { |
|
687 | - $model_name_field = null; |
|
688 | - $models_pointed_to_by_model_name_field = array(); |
|
689 | - } |
|
690 | - foreach ($model->field_settings(true) as $field_obj) { |
|
691 | - if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
692 | - $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
|
693 | - $found_a_mapping = false; |
|
694 | - foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
695 | - if ($model_name_field) { |
|
696 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
697 | - if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
698 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
699 | - $model_object_data[ $field_obj->get_name() ], |
|
700 | - $model_pointed_to_by_fk, |
|
701 | - $old_db_to_new_db_mapping, |
|
702 | - $export_from_site_a_to_b |
|
703 | - ); |
|
704 | - $found_a_mapping = true; |
|
705 | - break; |
|
706 | - } |
|
707 | - } else { |
|
708 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
709 | - $model_object_data[ $field_obj->get_name() ], |
|
710 | - $model_pointed_to_by_fk, |
|
711 | - $old_db_to_new_db_mapping, |
|
712 | - $export_from_site_a_to_b |
|
713 | - ); |
|
714 | - $found_a_mapping = true; |
|
715 | - } |
|
716 | - // once we've found a mapping for this field no need to continue |
|
717 | - if ($found_a_mapping) { |
|
718 | - break; |
|
719 | - } |
|
720 | - } |
|
721 | - } else { |
|
722 | - // it's a string foreign key (which we leave alone, because those are things |
|
723 | - // like country names, which we'd really rather not make 2 USAs etc (we'd actually |
|
724 | - // prefer to just update one) |
|
725 | - // or it's just a regular value that ought to be replaced |
|
726 | - } |
|
727 | - } |
|
728 | - // |
|
729 | - if ($model instanceof EEM_Term_Taxonomy) { |
|
730 | - $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
731 | - } |
|
732 | - return $model_object_data; |
|
733 | - } |
|
734 | - |
|
735 | - /** |
|
736 | - * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id |
|
737 | - * this term-taxonomy refers to may be out-of-date so we need to update it. |
|
738 | - * @see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ |
|
739 | - * |
|
740 | - * @param mixed $model_object_data |
|
741 | - * @return array new model object data |
|
742 | - */ |
|
743 | - protected function _handle_split_term_ids($model_object_data) |
|
744 | - { |
|
745 | - if ( |
|
746 | - isset($model_object_data['term_id']) |
|
747 | - && isset($model_object_data['taxonomy']) |
|
748 | - && apply_filters( |
|
749 | - 'FHEE__EE_Import__handle_split_term_ids__function_exists', |
|
750 | - function_exists('wp_get_split_term'), |
|
751 | - $model_object_data |
|
752 | - ) |
|
753 | - ) { |
|
754 | - $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
755 | - if ($new_term_id) { |
|
756 | - $model_object_data['term_id'] = $new_term_id; |
|
757 | - } |
|
758 | - } |
|
759 | - return $model_object_data; |
|
760 | - } |
|
761 | - |
|
762 | - /** |
|
763 | - * Given the object's ID and its model's name, find it int he mapping data, |
|
764 | - * bearing in mind where it came from |
|
765 | - * |
|
766 | - * @param mixed $object_id |
|
767 | - * @param string $model_name |
|
768 | - * @param array $old_db_to_new_db_mapping |
|
769 | - * @param mixed $export_from_site_a_to_b |
|
770 | - * @return int |
|
771 | - */ |
|
772 | - protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
|
773 | - { |
|
774 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
775 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
776 | - } elseif ($object_id == '0' || $object_id == '') { |
|
777 | - // leave as-is |
|
778 | - return $object_id; |
|
779 | - } elseif ($export_from_site_a_to_b) { |
|
780 | - // we couldn't find a mapping for this, and it's from a different site, |
|
781 | - // so blank it out |
|
782 | - return null; |
|
783 | - } elseif (! $export_from_site_a_to_b) { |
|
784 | - // we coudln't find a mapping for this, but it's from thsi DB anyway |
|
785 | - // so let's just leave it as-is |
|
786 | - return $object_id; |
|
787 | - } |
|
788 | - } |
|
789 | - |
|
790 | - /** |
|
791 | - * |
|
792 | - * @param mixed $id_in_csv |
|
793 | - * @param mixed $model_object_data |
|
794 | - * @param EEM_Base $model |
|
795 | - * @param mixed $old_db_to_new_db_mapping |
|
796 | - * @return array updated $old_db_to_new_db_mapping |
|
797 | - */ |
|
798 | - protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
799 | - { |
|
800 | - // remove the primary key, if there is one (we don't want it for inserts OR updates) |
|
801 | - // we'll put it back in if we need it |
|
802 | - if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
803 | - $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
804 | - unset($model_object_data[ $model->primary_key_name() ]); |
|
805 | - } else { |
|
806 | - $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
807 | - } |
|
808 | - // the model takes care of validating the CSV's input |
|
809 | - try { |
|
810 | - $new_id = $model->insert($model_object_data); |
|
811 | - if ($new_id) { |
|
812 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
813 | - $this->_total_inserts++; |
|
814 | - EE_Error::add_success( |
|
815 | - sprintf( |
|
816 | - esc_html__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), |
|
817 | - $model->get_this_model_name(), |
|
818 | - $new_id, |
|
819 | - implode(",", $model_object_data) |
|
820 | - ) |
|
821 | - ); |
|
822 | - } else { |
|
823 | - $this->_total_insert_errors++; |
|
824 | - // put the ID used back in there for the error message |
|
825 | - if ($model->has_primary_key_field()) { |
|
826 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
827 | - } |
|
828 | - EE_Error::add_error( |
|
829 | - sprintf( |
|
830 | - esc_html__("Could not insert new %s with the csv data: %s", "event_espresso"), |
|
831 | - $model->get_this_model_name(), |
|
832 | - http_build_query($model_object_data) |
|
833 | - ), |
|
834 | - __FILE__, |
|
835 | - __FUNCTION__, |
|
836 | - __LINE__ |
|
837 | - ); |
|
838 | - } |
|
839 | - } catch (EE_Error $e) { |
|
840 | - $this->_total_insert_errors++; |
|
841 | - if ($model->has_primary_key_field()) { |
|
842 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
843 | - } |
|
844 | - EE_Error::add_error( |
|
845 | - sprintf( |
|
846 | - esc_html__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), |
|
847 | - $model->get_this_model_name(), |
|
848 | - implode(",", $model_object_data), |
|
849 | - $e->getMessage() |
|
850 | - ), |
|
851 | - __FILE__, |
|
852 | - __FUNCTION__, |
|
853 | - __LINE__ |
|
854 | - ); |
|
855 | - } |
|
856 | - return $old_db_to_new_db_mapping; |
|
857 | - } |
|
858 | - |
|
859 | - /** |
|
860 | - * Given the model object data, finds the row to update and updates it |
|
861 | - * |
|
862 | - * @param string|int $id_in_csv |
|
863 | - * @param array $model_object_data |
|
864 | - * @param EEM_Base $model |
|
865 | - * @param array $old_db_to_new_db_mapping |
|
866 | - * @return array updated $old_db_to_new_db_mapping |
|
867 | - */ |
|
868 | - protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
869 | - { |
|
870 | - try { |
|
871 | - // let's keep two copies of the model object data: |
|
872 | - // one for performing an update, one for everthing else |
|
873 | - $model_object_data_for_update = $model_object_data; |
|
874 | - if ($model->has_primary_key_field()) { |
|
875 | - $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
876 | - // remove the primary key because we shouldn't use it for updating |
|
877 | - unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
878 | - } elseif ($model->get_combined_primary_key_fields() > 1) { |
|
879 | - $conditions = array(); |
|
880 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
881 | - $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
882 | - } |
|
883 | - } else { |
|
884 | - $model->primary_key_name( |
|
885 | - );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
886 | - } |
|
887 | - |
|
888 | - $success = $model->update($model_object_data_for_update, array($conditions)); |
|
889 | - if ($success) { |
|
890 | - $this->_total_updates++; |
|
891 | - EE_Error::add_success( |
|
892 | - sprintf( |
|
893 | - esc_html__("Successfully updated %s with csv data %s", "event_espresso"), |
|
894 | - $model->get_this_model_name(), |
|
895 | - implode(",", $model_object_data_for_update) |
|
896 | - ) |
|
897 | - ); |
|
898 | - // we should still record the mapping even though it was an update |
|
899 | - // because if we were going to insert somethign but it was going to conflict |
|
900 | - // we would have last-minute decided to update. So we'd like to know what we updated |
|
901 | - // and so we record what record ended up being updated using the mapping |
|
902 | - if ($model->has_primary_key_field()) { |
|
903 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
904 | - } else { |
|
905 | - // no primary key just a combined key |
|
906 | - $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
907 | - } |
|
908 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
909 | - } else { |
|
910 | - $matched_items = $model->get_all(array($conditions)); |
|
911 | - if (! $matched_items) { |
|
912 | - // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
|
913 | - $this->_total_update_errors++; |
|
914 | - EE_Error::add_error( |
|
915 | - sprintf( |
|
916 | - esc_html__( |
|
917 | - "Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", |
|
918 | - "event_espresso" |
|
919 | - ), |
|
920 | - $model->get_this_model_name(), |
|
921 | - http_build_query($model_object_data), |
|
922 | - http_build_query($conditions) |
|
923 | - ), |
|
924 | - __FILE__, |
|
925 | - __FUNCTION__, |
|
926 | - __LINE__ |
|
927 | - ); |
|
928 | - } else { |
|
929 | - $this->_total_updates++; |
|
930 | - EE_Error::add_success( |
|
931 | - sprintf( |
|
932 | - esc_html__( |
|
933 | - "%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", |
|
934 | - "event_espresso" |
|
935 | - ), |
|
936 | - $model->get_this_model_name(), |
|
937 | - implode(",", $model_object_data) |
|
938 | - ) |
|
939 | - ); |
|
940 | - } |
|
941 | - } |
|
942 | - } catch (EE_Error $e) { |
|
943 | - $this->_total_update_errors++; |
|
944 | - $basic_message = sprintf( |
|
945 | - esc_html__("Could not update %s with the csv data: %s because %s", "event_espresso"), |
|
946 | - $model->get_this_model_name(), |
|
947 | - implode(",", $model_object_data), |
|
948 | - $e->getMessage() |
|
949 | - ); |
|
950 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
951 | - EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
952 | - } |
|
953 | - return $old_db_to_new_db_mapping; |
|
954 | - } |
|
955 | - |
|
956 | - /** |
|
957 | - * Gets the number of inserts performed since importer was instantiated or reset |
|
958 | - * |
|
959 | - * @return int |
|
960 | - */ |
|
961 | - public function get_total_inserts() |
|
962 | - { |
|
963 | - return $this->_total_inserts; |
|
964 | - } |
|
965 | - |
|
966 | - /** |
|
967 | - * Gets the number of insert errors since importer was instantiated or reset |
|
968 | - * |
|
969 | - * @return int |
|
970 | - */ |
|
971 | - public function get_total_insert_errors() |
|
972 | - { |
|
973 | - return $this->_total_insert_errors; |
|
974 | - } |
|
975 | - |
|
976 | - /** |
|
977 | - * Gets the number of updates performed since importer was instantiated or reset |
|
978 | - * |
|
979 | - * @return int |
|
980 | - */ |
|
981 | - public function get_total_updates() |
|
982 | - { |
|
983 | - return $this->_total_updates; |
|
984 | - } |
|
985 | - |
|
986 | - /** |
|
987 | - * Gets the number of update errors since importer was instantiated or reset |
|
988 | - * |
|
989 | - * @return int |
|
990 | - */ |
|
991 | - public function get_total_update_errors() |
|
992 | - { |
|
993 | - return $this->_total_update_errors; |
|
994 | - } |
|
127 | + $uploader = ob_get_clean(); |
|
128 | + return $uploader; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * Import Event Espresso data - some code "borrowed" from event espresso csv_import.php |
|
134 | + * @return boolean success |
|
135 | + */ |
|
136 | + public function import() |
|
137 | + { |
|
138 | + |
|
139 | + require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
140 | + $this->EE_CSV = EE_CSV::instance(); |
|
141 | + |
|
142 | + /** @var RequestInterface $request */ |
|
143 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
144 | + |
|
145 | + if ($request->requestParamIsSet('import') && $request->requestParamIsSet('csv_submitted')) { |
|
146 | + $files = $request->filesParams(); |
|
147 | + switch ($files['file']['error'][0]) { |
|
148 | + case UPLOAD_ERR_OK: |
|
149 | + $error_msg = false; |
|
150 | + break; |
|
151 | + case UPLOAD_ERR_INI_SIZE: |
|
152 | + $error_msg = esc_html__( |
|
153 | + "'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", |
|
154 | + "event_espresso" |
|
155 | + ); |
|
156 | + break; |
|
157 | + case UPLOAD_ERR_FORM_SIZE: |
|
158 | + $error_msg = esc_html__( |
|
159 | + 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', |
|
160 | + "event_espresso" |
|
161 | + ); |
|
162 | + break; |
|
163 | + case UPLOAD_ERR_PARTIAL: |
|
164 | + $error_msg = esc_html__('The uploaded file was only partially uploaded.', "event_espresso"); |
|
165 | + break; |
|
166 | + case UPLOAD_ERR_NO_FILE: |
|
167 | + $error_msg = esc_html__('No file was uploaded.', "event_espresso"); |
|
168 | + break; |
|
169 | + case UPLOAD_ERR_NO_TMP_DIR: |
|
170 | + $error_msg = esc_html__('Missing a temporary folder.', "event_espresso"); |
|
171 | + break; |
|
172 | + case UPLOAD_ERR_CANT_WRITE: |
|
173 | + $error_msg = esc_html__('Failed to write file to disk.', "event_espresso"); |
|
174 | + break; |
|
175 | + case UPLOAD_ERR_EXTENSION: |
|
176 | + $error_msg = esc_html__('File upload stopped by extension.', "event_espresso"); |
|
177 | + break; |
|
178 | + default: |
|
179 | + $error_msg = esc_html__( |
|
180 | + 'An unknown error occurred and the file could not be uploaded', |
|
181 | + "event_espresso" |
|
182 | + ); |
|
183 | + break; |
|
184 | + } |
|
185 | + |
|
186 | + if (! $error_msg) { |
|
187 | + $filename = $files['file']['name'][0]; |
|
188 | + $file_ext = substr(strrchr($filename, '.'), 1); |
|
189 | + $file_type = $files['file']['type'][0]; |
|
190 | + $temp_file = $files['file']['tmp_name'][0]; |
|
191 | + $filesize = $files['file']['size'][0] / 1024;// convert from bytes to KB |
|
192 | + |
|
193 | + if ($file_ext == 'csv') { |
|
194 | + $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
195 | + if ($filesize < $max_upload || true) { |
|
196 | + $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
|
197 | + $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
198 | + |
|
199 | + if (move_uploaded_file($temp_file, $path_to_file)) { |
|
200 | + // convert csv to array |
|
201 | + $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
202 | + |
|
203 | + $action = $request->getRequestParam('action'); |
|
204 | + |
|
205 | + // was data successfully stored in an array? |
|
206 | + if (is_array($this->csv_array)) { |
|
207 | + $import_what = str_replace('csv_import_', '', $action); |
|
208 | + $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
209 | + $processed_data = $this->csv_array; |
|
210 | + $this->columns_to_save = false; |
|
211 | + |
|
212 | + // if any imports require funky processing, we'll catch them in the switch |
|
213 | + switch ($action) { |
|
214 | + case "import_events": |
|
215 | + case "event_list": |
|
216 | + $import_what = 'Event Details'; |
|
217 | + break; |
|
218 | + |
|
219 | + case 'groupon_import_csv': |
|
220 | + $import_what = 'Groupon Codes'; |
|
221 | + $processed_data = $this->process_groupon_codes(); |
|
222 | + break; |
|
223 | + } |
|
224 | + // save processed codes to db |
|
225 | + if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
226 | + return true; |
|
227 | + } |
|
228 | + } else { |
|
229 | + // no array? must be an error |
|
230 | + EE_Error::add_error( |
|
231 | + sprintf(esc_html__("No file seems to have been uploaded", "event_espresso")), |
|
232 | + __FILE__, |
|
233 | + __FUNCTION__, |
|
234 | + __LINE__ |
|
235 | + ); |
|
236 | + return false; |
|
237 | + } |
|
238 | + } else { |
|
239 | + EE_Error::add_error( |
|
240 | + sprintf(esc_html__("%s was not successfully uploaded", "event_espresso"), $filename), |
|
241 | + __FILE__, |
|
242 | + __FUNCTION__, |
|
243 | + __LINE__ |
|
244 | + ); |
|
245 | + return false; |
|
246 | + } |
|
247 | + } else { |
|
248 | + EE_Error::add_error( |
|
249 | + sprintf( |
|
250 | + esc_html__( |
|
251 | + "%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", |
|
252 | + "event_espresso" |
|
253 | + ), |
|
254 | + $filename, |
|
255 | + $max_upload |
|
256 | + ), |
|
257 | + __FILE__, |
|
258 | + __FUNCTION__, |
|
259 | + __LINE__ |
|
260 | + ); |
|
261 | + return false; |
|
262 | + } |
|
263 | + } else { |
|
264 | + EE_Error::add_error( |
|
265 | + sprintf(esc_html__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), |
|
266 | + __FILE__, |
|
267 | + __FUNCTION__, |
|
268 | + __LINE__ |
|
269 | + ); |
|
270 | + return false; |
|
271 | + } |
|
272 | + } else { |
|
273 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
274 | + return false; |
|
275 | + } |
|
276 | + } |
|
277 | + return false; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Given an array of data (usually from a CSV import) attempts to save that data to the db. |
|
283 | + * If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names, |
|
284 | + * next level being numeric indexes adn each value representing a model object, and the last layer down |
|
285 | + * being keys of model fields and their proposed values. |
|
286 | + * If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned. |
|
287 | + * If the CSV data says (in the metadata row) that it's from the SAME database, |
|
288 | + * we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those |
|
289 | + * IDs DON'T exist in the database, they're treated as temporary IDs, |
|
290 | + * which can used elsewhere to refer to the same object. Once an item |
|
291 | + * with a temporary ID gets inserted, we record its mapping from temporary |
|
292 | + * ID to real ID, and use the real ID in place of the temporary ID |
|
293 | + * when that temporary ID was used as a foreign key. |
|
294 | + * If the CSV data says (in the metadata again) that it's from a DIFFERENT database, |
|
295 | + * we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with |
|
296 | + * ID 1, and the database already has an event with ID 1, we assume that's just a coincidence, |
|
297 | + * and insert a new event, and map it's temporary ID of 1 over to its new real ID. |
|
298 | + * An important exception are non-auto-increment primary keys. If one entry in the |
|
299 | + * CSV file has the same ID as one in the DB, we assume they are meant to be |
|
300 | + * the same item, and instead update the item in the DB with that same ID. |
|
301 | + * Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th |
|
302 | + * time you import a CSV from a different site, we remember their mappings, and |
|
303 | + * will try to update the item in the DB instead of inserting another item (eg |
|
304 | + * if we previously imported an event with temporary ID 1, and then it got a |
|
305 | + * real ID of 123, we remember that. So the next time we import an event with |
|
306 | + * temporary ID, from the same site, we know that it's real ID is 123, and will |
|
307 | + * update that event, instead of adding a new event). |
|
308 | + * |
|
309 | + * @param array $csv_data_array - the array containing the csv data produced from |
|
310 | + * EE_CSV::import_csv_to_model_data_array() |
|
311 | + * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table |
|
312 | + * fields they will be saved to |
|
313 | + * @return TRUE on success, FALSE on fail |
|
314 | + * @throws EE_Error |
|
315 | + */ |
|
316 | + public function save_csv_data_array_to_db($csv_data_array, $model_name = false) |
|
317 | + { |
|
318 | + $success = false; |
|
319 | + $error = false; |
|
320 | + // whther to treat this import as if it's data froma different database or not |
|
321 | + // ie, if it IS from a different database, ignore foreign keys whihf |
|
322 | + $export_from_site_a_to_b = true; |
|
323 | + // first level of array is not table information but a table name was passed to the function |
|
324 | + // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
|
325 | + if ($model_name) { |
|
326 | + $csv_data_array = array($csv_data_array); |
|
327 | + } |
|
328 | + // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
|
329 | + $old_site_url = 'none-specified'; |
|
330 | + // hanlde metadata |
|
331 | + if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
332 | + $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
333 | + // ok so its metadata, dont try to save it to ehte db obviously... |
|
334 | + if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
335 | + EE_Error::add_attention( |
|
336 | + sprintf( |
|
337 | + esc_html__( |
|
338 | + "CSV Data appears to be from the same database, so attempting to update data", |
|
339 | + "event_espresso" |
|
340 | + ) |
|
341 | + ) |
|
342 | + ); |
|
343 | + $export_from_site_a_to_b = false; |
|
344 | + } else { |
|
345 | + $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
346 | + EE_Error::add_attention( |
|
347 | + sprintf( |
|
348 | + esc_html__( |
|
349 | + "CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", |
|
350 | + "event_espresso" |
|
351 | + ), |
|
352 | + $old_site_url, |
|
353 | + site_url() |
|
354 | + ) |
|
355 | + ); |
|
356 | + }; |
|
357 | + unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
358 | + } |
|
359 | + /** |
|
360 | + * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
361 | + * the value will be the newly-inserted ID. |
|
362 | + * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
363 | + */ |
|
364 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
365 | + if ($old_db_to_new_db_mapping) { |
|
366 | + EE_Error::add_attention( |
|
367 | + sprintf( |
|
368 | + esc_html__( |
|
369 | + "We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", |
|
370 | + "event_espresso" |
|
371 | + ), |
|
372 | + $old_site_url, |
|
373 | + site_url() |
|
374 | + ) |
|
375 | + ); |
|
376 | + } |
|
377 | + $old_db_to_new_db_mapping = $this->save_data_rows_to_db( |
|
378 | + $csv_data_array, |
|
379 | + $export_from_site_a_to_b, |
|
380 | + $old_db_to_new_db_mapping |
|
381 | + ); |
|
382 | + |
|
383 | + // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
|
384 | + update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
385 | + |
|
386 | + if ($this->_total_updates > 0) { |
|
387 | + EE_Error::add_success( |
|
388 | + sprintf( |
|
389 | + esc_html__("%s existing records in the database were updated.", "event_espresso"), |
|
390 | + $this->_total_updates |
|
391 | + ) |
|
392 | + ); |
|
393 | + $success = true; |
|
394 | + } |
|
395 | + if ($this->_total_inserts > 0) { |
|
396 | + EE_Error::add_success( |
|
397 | + sprintf(esc_html__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts) |
|
398 | + ); |
|
399 | + $success = true; |
|
400 | + } |
|
401 | + |
|
402 | + if ($this->_total_update_errors > 0) { |
|
403 | + EE_Error::add_error( |
|
404 | + sprintf( |
|
405 | + esc_html__( |
|
406 | + "'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", |
|
407 | + "event_espresso" |
|
408 | + ), |
|
409 | + $this->_total_update_errors |
|
410 | + ), |
|
411 | + __FILE__, |
|
412 | + __FUNCTION__, |
|
413 | + __LINE__ |
|
414 | + ); |
|
415 | + $error = true; |
|
416 | + } |
|
417 | + if ($this->_total_insert_errors > 0) { |
|
418 | + EE_Error::add_error( |
|
419 | + sprintf( |
|
420 | + esc_html__( |
|
421 | + "One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", |
|
422 | + "event_espresso" |
|
423 | + ), |
|
424 | + $this->_total_insert_errors |
|
425 | + ), |
|
426 | + __FILE__, |
|
427 | + __FUNCTION__, |
|
428 | + __LINE__ |
|
429 | + ); |
|
430 | + $error = true; |
|
431 | + } |
|
432 | + |
|
433 | + // lastly, we need to update the datetime and ticket sold amounts |
|
434 | + // as those may have been affected by this |
|
435 | + EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
|
436 | + |
|
437 | + // if there was at least one success and absolutely no errors |
|
438 | + if ($success && ! $error) { |
|
439 | + return true; |
|
440 | + } else { |
|
441 | + return false; |
|
442 | + } |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * Processes the array of data, given the knowledge that it's from the same database or a different one, |
|
448 | + * and the mapping from temporary IDs to real IDs. |
|
449 | + * If the data is from a different database, we treat the primary keys and their corresponding |
|
450 | + * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys |
|
451 | + * in the real target database. As items are inserted, their temporary primary keys |
|
452 | + * are mapped to the real IDs in the target database. Also, before doing any update or |
|
453 | + * insert, we replace all the temp ID which are foreign keys with their mapped real IDs. |
|
454 | + * An exception: string primary keys are treated as real IDs, or else we'd need to |
|
455 | + * dynamically generate new string primary keys which would be very awkard for the country table etc. |
|
456 | + * Also, models with no primary key are strange too. We combine use their primar key INDEX (a |
|
457 | + * combination of fields) to create a unique string identifying the row and store |
|
458 | + * those in the mapping. |
|
459 | + * |
|
460 | + * If the data is from the same database, we usually treat primary keys as real IDs. |
|
461 | + * An exception is if there is nothing in the database for that ID. If that's the case, |
|
462 | + * we need to insert a new row for that ID, and then map from the non-existent ID |
|
463 | + * to the newly-inserted real ID. |
|
464 | + * |
|
465 | + * @param mixed $csv_data_array |
|
466 | + * @param mixed $export_from_site_a_to_b |
|
467 | + * @param mixed $old_db_to_new_db_mapping |
|
468 | + * @return array updated $old_db_to_new_db_mapping |
|
469 | + */ |
|
470 | + public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) |
|
471 | + { |
|
472 | + foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
473 | + // now check that assumption was correct. If |
|
474 | + if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
475 | + $model_name = $model_name_in_csv_data; |
|
476 | + } else { |
|
477 | + // no table info in the array and no table name passed to the function?? FAIL |
|
478 | + EE_Error::add_error( |
|
479 | + esc_html__( |
|
480 | + 'No table information was specified and/or found, therefore the import could not be completed', |
|
481 | + 'event_espresso' |
|
482 | + ), |
|
483 | + __FILE__, |
|
484 | + __FUNCTION__, |
|
485 | + __LINE__ |
|
486 | + ); |
|
487 | + return false; |
|
488 | + } |
|
489 | + /* @var $model EEM_Base */ |
|
490 | + $model = EE_Registry::instance()->load_model($model_name); |
|
491 | + |
|
492 | + // so without further ado, scanning all the data provided for primary keys and their inital values |
|
493 | + foreach ($model_data_from_import as $model_object_data) { |
|
494 | + // before we do ANYTHING, make sure the csv row wasn't just completely blank |
|
495 | + $row_is_completely_empty = true; |
|
496 | + foreach ($model_object_data as $field) { |
|
497 | + if ($field) { |
|
498 | + $row_is_completely_empty = false; |
|
499 | + } |
|
500 | + } |
|
501 | + if ($row_is_completely_empty) { |
|
502 | + continue; |
|
503 | + } |
|
504 | + // find the PK in the row of data (or a combined key if |
|
505 | + // there is no primary key) |
|
506 | + if ($model->has_primary_key_field()) { |
|
507 | + $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
508 | + } else { |
|
509 | + $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + $model_object_data = $this->_replace_temp_ids_with_mappings( |
|
514 | + $model_object_data, |
|
515 | + $model, |
|
516 | + $old_db_to_new_db_mapping, |
|
517 | + $export_from_site_a_to_b |
|
518 | + ); |
|
519 | + // now we need to decide if we're going to add a new model object given the $model_object_data, |
|
520 | + // or just update. |
|
521 | + if ($export_from_site_a_to_b) { |
|
522 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( |
|
523 | + $id_in_csv, |
|
524 | + $model_object_data, |
|
525 | + $model, |
|
526 | + $old_db_to_new_db_mapping |
|
527 | + ); |
|
528 | + } else {// this is just a re-import |
|
529 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( |
|
530 | + $id_in_csv, |
|
531 | + $model_object_data, |
|
532 | + $model, |
|
533 | + $old_db_to_new_db_mapping |
|
534 | + ); |
|
535 | + } |
|
536 | + if ($what_to_do == self::do_nothing) { |
|
537 | + continue; |
|
538 | + } |
|
539 | + |
|
540 | + // double-check we actually want to insert, if that's what we're planning |
|
541 | + // based on whether this item would be unique in the DB or not |
|
542 | + if ($what_to_do == self::do_insert) { |
|
543 | + // we're supposed to be inserting. But wait, will this thing |
|
544 | + // be acceptable if inserted? |
|
545 | + $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
546 | + if ($conflicting) { |
|
547 | + // ok, this item would conflict if inserted. Just update the item that it conflicts with. |
|
548 | + $what_to_do = self::do_update; |
|
549 | + // and if this model has a primary key, remember its mapping |
|
550 | + if ($model->has_primary_key_field()) { |
|
551 | + $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
552 | + $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
553 | + } else { |
|
554 | + // we want to update this conflicting item, instead of inserting a conflicting item |
|
555 | + // so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
|
556 | + // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
|
557 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
558 | + $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
559 | + $key_field->get_name() |
|
560 | + ); |
|
561 | + } |
|
562 | + } |
|
563 | + } |
|
564 | + } |
|
565 | + if ($what_to_do == self::do_insert) { |
|
566 | + $old_db_to_new_db_mapping = $this->_insert_from_data_array( |
|
567 | + $id_in_csv, |
|
568 | + $model_object_data, |
|
569 | + $model, |
|
570 | + $old_db_to_new_db_mapping |
|
571 | + ); |
|
572 | + } elseif ($what_to_do == self::do_update) { |
|
573 | + $old_db_to_new_db_mapping = $this->_update_from_data_array( |
|
574 | + $id_in_csv, |
|
575 | + $model_object_data, |
|
576 | + $model, |
|
577 | + $old_db_to_new_db_mapping |
|
578 | + ); |
|
579 | + } else { |
|
580 | + throw new EE_Error( |
|
581 | + sprintf( |
|
582 | + esc_html__( |
|
583 | + 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', |
|
584 | + 'event_espresso' |
|
585 | + ), |
|
586 | + $what_to_do |
|
587 | + ) |
|
588 | + ); |
|
589 | + } |
|
590 | + } |
|
591 | + } |
|
592 | + return $old_db_to_new_db_mapping; |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + /** |
|
597 | + * Decides whether or not to insert, given that this data is from another database. |
|
598 | + * So, if the primary key of this $model_object_data already exists in the database, |
|
599 | + * it's just a coincidence and we should still insert. The only time we should |
|
600 | + * update is when we know what it maps to, or there's something that would |
|
601 | + * conflict (and we should instead just update that conflicting thing) |
|
602 | + * |
|
603 | + * @param string $id_in_csv |
|
604 | + * @param array $model_object_data by reference so it can be modified |
|
605 | + * @param EEM_Base $model |
|
606 | + * @param array $old_db_to_new_db_mapping by reference so it can be modified |
|
607 | + * @return string one of the consts on this class that starts with do_* |
|
608 | + */ |
|
609 | + protected function _decide_whether_to_insert_or_update_given_data_from_other_db( |
|
610 | + $id_in_csv, |
|
611 | + $model_object_data, |
|
612 | + $model, |
|
613 | + $old_db_to_new_db_mapping |
|
614 | + ) { |
|
615 | + $model_name = $model->get_this_model_name(); |
|
616 | + // if it's a site-to-site export-and-import, see if this modelobject's id |
|
617 | + // in the old data that we know of |
|
618 | + if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
619 | + return self::do_update; |
|
620 | + } else { |
|
621 | + return self::do_insert; |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * If this thing basically already exists in the database, we want to update it; |
|
627 | + * otherwise insert it (ie, someone tweaked the CSV file, or the item was |
|
628 | + * deleted in the database so it should be re-inserted) |
|
629 | + * |
|
630 | + * @param mixed $id_in_csv |
|
631 | + * @param mixed $model_object_data |
|
632 | + * @param EEM_Base $model |
|
633 | + * @param mixed $old_db_to_new_db_mapping |
|
634 | + * @return |
|
635 | + */ |
|
636 | + protected function _decide_whether_to_insert_or_update_given_data_from_same_db( |
|
637 | + $id_in_csv, |
|
638 | + $model_object_data, |
|
639 | + $model |
|
640 | + ) { |
|
641 | + // in this case, check if this thing ACTUALLY exists in the database |
|
642 | + if ($model->get_one_conflicting($model_object_data)) { |
|
643 | + return self::do_update; |
|
644 | + } else { |
|
645 | + return self::do_insert; |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs |
|
651 | + * with their mapped real IDs. Eg, if importing from site A to B, the mapping |
|
652 | + * file may indicate that the ID "my_event_id" maps to an actual event ID of 123. |
|
653 | + * So this function searches for any event temp Ids called "my_event_id" and |
|
654 | + * replaces them with 123. |
|
655 | + * Also, if there is no temp ID for the INT foreign keys from another database, |
|
656 | + * replaces them with 0 or the field's default. |
|
657 | + * |
|
658 | + * @param mixed $model_object_data |
|
659 | + * @param EEM_Base $model |
|
660 | + * @param mixed $old_db_to_new_db_mapping |
|
661 | + * @param boolean $export_from_site_a_to_b |
|
662 | + * @return array updated model object data with temp IDs removed |
|
663 | + */ |
|
664 | + protected function _replace_temp_ids_with_mappings( |
|
665 | + $model_object_data, |
|
666 | + $model, |
|
667 | + $old_db_to_new_db_mapping, |
|
668 | + $export_from_site_a_to_b |
|
669 | + ) { |
|
670 | + // if this model object's primary key is in the mapping, replace it |
|
671 | + if ( |
|
672 | + $model->has_primary_key_field() && |
|
673 | + $model->get_primary_key_field()->is_auto_increment() && |
|
674 | + isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
675 | + isset( |
|
676 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
677 | + ) |
|
678 | + ) { |
|
679 | + $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
680 | + ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
681 | + } |
|
682 | + |
|
683 | + try { |
|
684 | + $model_name_field = $model->get_field_containing_related_model_name(); |
|
685 | + $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
|
686 | + } catch (EE_Error $e) { |
|
687 | + $model_name_field = null; |
|
688 | + $models_pointed_to_by_model_name_field = array(); |
|
689 | + } |
|
690 | + foreach ($model->field_settings(true) as $field_obj) { |
|
691 | + if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
692 | + $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
|
693 | + $found_a_mapping = false; |
|
694 | + foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
695 | + if ($model_name_field) { |
|
696 | + $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
697 | + if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
698 | + $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
699 | + $model_object_data[ $field_obj->get_name() ], |
|
700 | + $model_pointed_to_by_fk, |
|
701 | + $old_db_to_new_db_mapping, |
|
702 | + $export_from_site_a_to_b |
|
703 | + ); |
|
704 | + $found_a_mapping = true; |
|
705 | + break; |
|
706 | + } |
|
707 | + } else { |
|
708 | + $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
709 | + $model_object_data[ $field_obj->get_name() ], |
|
710 | + $model_pointed_to_by_fk, |
|
711 | + $old_db_to_new_db_mapping, |
|
712 | + $export_from_site_a_to_b |
|
713 | + ); |
|
714 | + $found_a_mapping = true; |
|
715 | + } |
|
716 | + // once we've found a mapping for this field no need to continue |
|
717 | + if ($found_a_mapping) { |
|
718 | + break; |
|
719 | + } |
|
720 | + } |
|
721 | + } else { |
|
722 | + // it's a string foreign key (which we leave alone, because those are things |
|
723 | + // like country names, which we'd really rather not make 2 USAs etc (we'd actually |
|
724 | + // prefer to just update one) |
|
725 | + // or it's just a regular value that ought to be replaced |
|
726 | + } |
|
727 | + } |
|
728 | + // |
|
729 | + if ($model instanceof EEM_Term_Taxonomy) { |
|
730 | + $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
731 | + } |
|
732 | + return $model_object_data; |
|
733 | + } |
|
734 | + |
|
735 | + /** |
|
736 | + * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id |
|
737 | + * this term-taxonomy refers to may be out-of-date so we need to update it. |
|
738 | + * @see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ |
|
739 | + * |
|
740 | + * @param mixed $model_object_data |
|
741 | + * @return array new model object data |
|
742 | + */ |
|
743 | + protected function _handle_split_term_ids($model_object_data) |
|
744 | + { |
|
745 | + if ( |
|
746 | + isset($model_object_data['term_id']) |
|
747 | + && isset($model_object_data['taxonomy']) |
|
748 | + && apply_filters( |
|
749 | + 'FHEE__EE_Import__handle_split_term_ids__function_exists', |
|
750 | + function_exists('wp_get_split_term'), |
|
751 | + $model_object_data |
|
752 | + ) |
|
753 | + ) { |
|
754 | + $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
755 | + if ($new_term_id) { |
|
756 | + $model_object_data['term_id'] = $new_term_id; |
|
757 | + } |
|
758 | + } |
|
759 | + return $model_object_data; |
|
760 | + } |
|
761 | + |
|
762 | + /** |
|
763 | + * Given the object's ID and its model's name, find it int he mapping data, |
|
764 | + * bearing in mind where it came from |
|
765 | + * |
|
766 | + * @param mixed $object_id |
|
767 | + * @param string $model_name |
|
768 | + * @param array $old_db_to_new_db_mapping |
|
769 | + * @param mixed $export_from_site_a_to_b |
|
770 | + * @return int |
|
771 | + */ |
|
772 | + protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
|
773 | + { |
|
774 | + if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
775 | + return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
776 | + } elseif ($object_id == '0' || $object_id == '') { |
|
777 | + // leave as-is |
|
778 | + return $object_id; |
|
779 | + } elseif ($export_from_site_a_to_b) { |
|
780 | + // we couldn't find a mapping for this, and it's from a different site, |
|
781 | + // so blank it out |
|
782 | + return null; |
|
783 | + } elseif (! $export_from_site_a_to_b) { |
|
784 | + // we coudln't find a mapping for this, but it's from thsi DB anyway |
|
785 | + // so let's just leave it as-is |
|
786 | + return $object_id; |
|
787 | + } |
|
788 | + } |
|
789 | + |
|
790 | + /** |
|
791 | + * |
|
792 | + * @param mixed $id_in_csv |
|
793 | + * @param mixed $model_object_data |
|
794 | + * @param EEM_Base $model |
|
795 | + * @param mixed $old_db_to_new_db_mapping |
|
796 | + * @return array updated $old_db_to_new_db_mapping |
|
797 | + */ |
|
798 | + protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
799 | + { |
|
800 | + // remove the primary key, if there is one (we don't want it for inserts OR updates) |
|
801 | + // we'll put it back in if we need it |
|
802 | + if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
803 | + $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
804 | + unset($model_object_data[ $model->primary_key_name() ]); |
|
805 | + } else { |
|
806 | + $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
807 | + } |
|
808 | + // the model takes care of validating the CSV's input |
|
809 | + try { |
|
810 | + $new_id = $model->insert($model_object_data); |
|
811 | + if ($new_id) { |
|
812 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
813 | + $this->_total_inserts++; |
|
814 | + EE_Error::add_success( |
|
815 | + sprintf( |
|
816 | + esc_html__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), |
|
817 | + $model->get_this_model_name(), |
|
818 | + $new_id, |
|
819 | + implode(",", $model_object_data) |
|
820 | + ) |
|
821 | + ); |
|
822 | + } else { |
|
823 | + $this->_total_insert_errors++; |
|
824 | + // put the ID used back in there for the error message |
|
825 | + if ($model->has_primary_key_field()) { |
|
826 | + $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
827 | + } |
|
828 | + EE_Error::add_error( |
|
829 | + sprintf( |
|
830 | + esc_html__("Could not insert new %s with the csv data: %s", "event_espresso"), |
|
831 | + $model->get_this_model_name(), |
|
832 | + http_build_query($model_object_data) |
|
833 | + ), |
|
834 | + __FILE__, |
|
835 | + __FUNCTION__, |
|
836 | + __LINE__ |
|
837 | + ); |
|
838 | + } |
|
839 | + } catch (EE_Error $e) { |
|
840 | + $this->_total_insert_errors++; |
|
841 | + if ($model->has_primary_key_field()) { |
|
842 | + $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
843 | + } |
|
844 | + EE_Error::add_error( |
|
845 | + sprintf( |
|
846 | + esc_html__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), |
|
847 | + $model->get_this_model_name(), |
|
848 | + implode(",", $model_object_data), |
|
849 | + $e->getMessage() |
|
850 | + ), |
|
851 | + __FILE__, |
|
852 | + __FUNCTION__, |
|
853 | + __LINE__ |
|
854 | + ); |
|
855 | + } |
|
856 | + return $old_db_to_new_db_mapping; |
|
857 | + } |
|
858 | + |
|
859 | + /** |
|
860 | + * Given the model object data, finds the row to update and updates it |
|
861 | + * |
|
862 | + * @param string|int $id_in_csv |
|
863 | + * @param array $model_object_data |
|
864 | + * @param EEM_Base $model |
|
865 | + * @param array $old_db_to_new_db_mapping |
|
866 | + * @return array updated $old_db_to_new_db_mapping |
|
867 | + */ |
|
868 | + protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
869 | + { |
|
870 | + try { |
|
871 | + // let's keep two copies of the model object data: |
|
872 | + // one for performing an update, one for everthing else |
|
873 | + $model_object_data_for_update = $model_object_data; |
|
874 | + if ($model->has_primary_key_field()) { |
|
875 | + $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
876 | + // remove the primary key because we shouldn't use it for updating |
|
877 | + unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
878 | + } elseif ($model->get_combined_primary_key_fields() > 1) { |
|
879 | + $conditions = array(); |
|
880 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
881 | + $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
882 | + } |
|
883 | + } else { |
|
884 | + $model->primary_key_name( |
|
885 | + );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
886 | + } |
|
887 | + |
|
888 | + $success = $model->update($model_object_data_for_update, array($conditions)); |
|
889 | + if ($success) { |
|
890 | + $this->_total_updates++; |
|
891 | + EE_Error::add_success( |
|
892 | + sprintf( |
|
893 | + esc_html__("Successfully updated %s with csv data %s", "event_espresso"), |
|
894 | + $model->get_this_model_name(), |
|
895 | + implode(",", $model_object_data_for_update) |
|
896 | + ) |
|
897 | + ); |
|
898 | + // we should still record the mapping even though it was an update |
|
899 | + // because if we were going to insert somethign but it was going to conflict |
|
900 | + // we would have last-minute decided to update. So we'd like to know what we updated |
|
901 | + // and so we record what record ended up being updated using the mapping |
|
902 | + if ($model->has_primary_key_field()) { |
|
903 | + $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
904 | + } else { |
|
905 | + // no primary key just a combined key |
|
906 | + $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
907 | + } |
|
908 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
909 | + } else { |
|
910 | + $matched_items = $model->get_all(array($conditions)); |
|
911 | + if (! $matched_items) { |
|
912 | + // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
|
913 | + $this->_total_update_errors++; |
|
914 | + EE_Error::add_error( |
|
915 | + sprintf( |
|
916 | + esc_html__( |
|
917 | + "Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", |
|
918 | + "event_espresso" |
|
919 | + ), |
|
920 | + $model->get_this_model_name(), |
|
921 | + http_build_query($model_object_data), |
|
922 | + http_build_query($conditions) |
|
923 | + ), |
|
924 | + __FILE__, |
|
925 | + __FUNCTION__, |
|
926 | + __LINE__ |
|
927 | + ); |
|
928 | + } else { |
|
929 | + $this->_total_updates++; |
|
930 | + EE_Error::add_success( |
|
931 | + sprintf( |
|
932 | + esc_html__( |
|
933 | + "%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", |
|
934 | + "event_espresso" |
|
935 | + ), |
|
936 | + $model->get_this_model_name(), |
|
937 | + implode(",", $model_object_data) |
|
938 | + ) |
|
939 | + ); |
|
940 | + } |
|
941 | + } |
|
942 | + } catch (EE_Error $e) { |
|
943 | + $this->_total_update_errors++; |
|
944 | + $basic_message = sprintf( |
|
945 | + esc_html__("Could not update %s with the csv data: %s because %s", "event_espresso"), |
|
946 | + $model->get_this_model_name(), |
|
947 | + implode(",", $model_object_data), |
|
948 | + $e->getMessage() |
|
949 | + ); |
|
950 | + $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
951 | + EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
952 | + } |
|
953 | + return $old_db_to_new_db_mapping; |
|
954 | + } |
|
955 | + |
|
956 | + /** |
|
957 | + * Gets the number of inserts performed since importer was instantiated or reset |
|
958 | + * |
|
959 | + * @return int |
|
960 | + */ |
|
961 | + public function get_total_inserts() |
|
962 | + { |
|
963 | + return $this->_total_inserts; |
|
964 | + } |
|
965 | + |
|
966 | + /** |
|
967 | + * Gets the number of insert errors since importer was instantiated or reset |
|
968 | + * |
|
969 | + * @return int |
|
970 | + */ |
|
971 | + public function get_total_insert_errors() |
|
972 | + { |
|
973 | + return $this->_total_insert_errors; |
|
974 | + } |
|
975 | + |
|
976 | + /** |
|
977 | + * Gets the number of updates performed since importer was instantiated or reset |
|
978 | + * |
|
979 | + * @return int |
|
980 | + */ |
|
981 | + public function get_total_updates() |
|
982 | + { |
|
983 | + return $this->_total_updates; |
|
984 | + } |
|
985 | + |
|
986 | + /** |
|
987 | + * Gets the number of update errors since importer was instantiated or reset |
|
988 | + * |
|
989 | + * @return int |
|
990 | + */ |
|
991 | + public function get_total_update_errors() |
|
992 | + { |
|
993 | + return $this->_total_update_errors; |
|
994 | + } |
|
995 | 995 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | continue; |
70 | 70 | } |
71 | 71 | if ($relation instanceof EE_Has_Many_Relation) { |
72 | - $this->nodes[ $relationName ] = new RelationNode( |
|
72 | + $this->nodes[$relationName] = new RelationNode( |
|
73 | 73 | $this->id, |
74 | 74 | $this->model, |
75 | 75 | $relation->get_other_model(), |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->dont_traverse_models |
83 | 83 | ) |
84 | 84 | ) { |
85 | - $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
85 | + $this->nodes[$relation->get_join_model()->get_this_model_name()] = new RelationNode( |
|
86 | 86 | $this->id, |
87 | 87 | $this->model, |
88 | 88 | $relation->get_join_model(), |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
131 | 131 | // related model objects. |
132 | 132 | if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
133 | - unset($this->nodes[ $model_name ]); |
|
133 | + unset($this->nodes[$model_name]); |
|
134 | 134 | } |
135 | 135 | if ($num_identified >= $model_objects_to_identify) { |
136 | 136 | // ...but admit we're wrong if the work exceeded the budget. |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $tree['rels'] = null; |
162 | 162 | } else { |
163 | 163 | foreach ($this->nodes as $relation_name => $relation_node) { |
164 | - $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
164 | + $tree['rels'][$relation_name] = $relation_node->toArray(); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | return $tree; |
@@ -23,220 +23,220 @@ |
||
23 | 23 | */ |
24 | 24 | class ModelObjNode extends BaseNode |
25 | 25 | { |
26 | - /** |
|
27 | - * @var int|string |
|
28 | - */ |
|
29 | - protected $id; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EEM_Base |
|
33 | - */ |
|
34 | - protected EEM_Base $model; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var RelationNode[]|null |
|
38 | - */ |
|
39 | - protected ?array $nodes = null; |
|
40 | - |
|
41 | - public ?string $model_name = null; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * We don't pass the model objects because this needs to serialize to something tiny for effiency. |
|
46 | - * |
|
47 | - * @param int|string $model_obj_id |
|
48 | - * @param EEM_Base $model |
|
49 | - * @param array $dont_traverse_models array of model names we DON'T want to traverse. |
|
50 | - */ |
|
51 | - public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = []) |
|
52 | - { |
|
53 | - $this->id = $model_obj_id; |
|
54 | - $this->model = $model; |
|
55 | - $this->dont_traverse_models = $dont_traverse_models; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Creates a relation node for each relation of this model's relations. |
|
61 | - * Does NOT call `discover` on them yet though. |
|
62 | - * |
|
63 | - * @throws EE_Error |
|
64 | - * @throws InvalidDataTypeException |
|
65 | - * @throws InvalidInterfaceException |
|
66 | - * @throws InvalidArgumentException |
|
67 | - * @throws ReflectionException |
|
68 | - * @since 4.10.12.p |
|
69 | - */ |
|
70 | - protected function discover() |
|
71 | - { |
|
72 | - $this->nodes = []; |
|
73 | - foreach ($this->model->relation_settings() as $relationName => $relation) { |
|
74 | - // Make sure this isn't one of the models we were told to not traverse into. |
|
75 | - if (in_array($relationName, $this->dont_traverse_models)) { |
|
76 | - continue; |
|
77 | - } |
|
78 | - if ($relation instanceof EE_Has_Many_Relation) { |
|
79 | - $this->nodes[ $relationName ] = new RelationNode( |
|
80 | - $this->id, |
|
81 | - $this->model, |
|
82 | - $relation->get_other_model(), |
|
83 | - $this->dont_traverse_models |
|
84 | - ); |
|
85 | - } elseif ( |
|
86 | - $relation instanceof EE_HABTM_Relation && |
|
87 | - ! in_array( |
|
88 | - $relation->get_join_model()->get_this_model_name(), |
|
89 | - $this->dont_traverse_models |
|
90 | - ) |
|
91 | - ) { |
|
92 | - $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
93 | - $this->id, |
|
94 | - $this->model, |
|
95 | - $relation->get_join_model(), |
|
96 | - $this->dont_traverse_models |
|
97 | - ); |
|
98 | - } |
|
99 | - } |
|
100 | - ksort($this->nodes); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Whether this item has already been initialized |
|
106 | - */ |
|
107 | - protected function isDiscovered() |
|
108 | - { |
|
109 | - return is_array($this->nodes); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @since 4.10.12.p |
|
114 | - * @return boolean |
|
115 | - */ |
|
116 | - public function isComplete() |
|
117 | - { |
|
118 | - if ($this->complete === null) { |
|
119 | - $this->complete = false; |
|
120 | - } |
|
121 | - return $this->complete; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Triggers working on each child relation node that has work to do. |
|
127 | - * |
|
128 | - * @param $model_objects_to_identify |
|
129 | - * @return int units of work done |
|
130 | - * @since 4.10.12.p |
|
131 | - */ |
|
132 | - protected function work($model_objects_to_identify) |
|
133 | - { |
|
134 | - $num_identified = 0; |
|
135 | - // Begin assuming we'll finish all the work on this node and its children... |
|
136 | - $this->complete = true; |
|
137 | - foreach ($this->nodes as $model_name => $relation_node) { |
|
138 | - $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified); |
|
139 | - // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
|
140 | - // related model objects. |
|
141 | - if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
|
142 | - unset($this->nodes[ $model_name ]); |
|
143 | - } |
|
144 | - if ($num_identified >= $model_objects_to_identify) { |
|
145 | - // ...but admit we're wrong if the work exceeded the budget. |
|
146 | - $this->complete = false; |
|
147 | - break; |
|
148 | - } |
|
149 | - } |
|
150 | - return $num_identified; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return array |
|
156 | - * @throws EE_Error |
|
157 | - * @throws InvalidDataTypeException |
|
158 | - * @throws InvalidInterfaceException |
|
159 | - * @throws InvalidArgumentException |
|
160 | - * @throws ReflectionException |
|
161 | - * @since 4.10.12.p |
|
162 | - */ |
|
163 | - public function toArray() |
|
164 | - { |
|
165 | - $tree = [ |
|
166 | - 'id' => $this->id, |
|
167 | - 'complete' => $this->isComplete(), |
|
168 | - 'rels' => [], |
|
169 | - ]; |
|
170 | - if ($this->nodes === null) { |
|
171 | - $tree['rels'] = null; |
|
172 | - } else { |
|
173 | - foreach ($this->nodes as $relation_name => $relation_node) { |
|
174 | - $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
175 | - } |
|
176 | - } |
|
177 | - return $tree; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @return array|mixed |
|
183 | - * @throws InvalidArgumentException |
|
184 | - * @throws InvalidDataTypeException |
|
185 | - * @throws InvalidInterfaceException |
|
186 | - * @throws ReflectionException |
|
187 | - * @throws EE_Error |
|
188 | - * @since 4.10.12.p |
|
189 | - */ |
|
190 | - public function getIds() |
|
191 | - { |
|
192 | - $ids = [ |
|
193 | - $this->model->get_this_model_name() => [ |
|
194 | - $this->id => $this->id, |
|
195 | - ], |
|
196 | - ]; |
|
197 | - if ($this->nodes && is_array($this->nodes)) { |
|
198 | - foreach ($this->nodes as $relation_node) { |
|
199 | - $ids = array_replace_recursive($ids, $relation_node->getIds()); |
|
200 | - } |
|
201 | - } |
|
202 | - return $ids; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * Don't serialize the models. Just record their names on some dynamic properties. |
|
208 | - * |
|
209 | - * @since 4.10.12.p |
|
210 | - */ |
|
211 | - public function __sleep() |
|
212 | - { |
|
213 | - $this->model_name = $this->model->get_this_model_name(); |
|
214 | - return array_merge( |
|
215 | - [ |
|
216 | - 'model_name', |
|
217 | - 'id', |
|
218 | - 'nodes', |
|
219 | - ], |
|
220 | - parent::__sleep() |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * Use the dynamic properties to instantiate the models we use. |
|
227 | - * |
|
228 | - * @throws EE_Error |
|
229 | - * @throws InvalidArgumentException |
|
230 | - * @throws InvalidDataTypeException |
|
231 | - * @throws InvalidInterfaceException |
|
232 | - * @throws ReflectionException |
|
233 | - * @since 4.10.12.p |
|
234 | - */ |
|
235 | - public function __wakeup() |
|
236 | - { |
|
237 | - $this->model = EE_Registry::instance()->load_model($this->model_name); |
|
238 | - parent::__wakeup(); |
|
239 | - } |
|
26 | + /** |
|
27 | + * @var int|string |
|
28 | + */ |
|
29 | + protected $id; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EEM_Base |
|
33 | + */ |
|
34 | + protected EEM_Base $model; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var RelationNode[]|null |
|
38 | + */ |
|
39 | + protected ?array $nodes = null; |
|
40 | + |
|
41 | + public ?string $model_name = null; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * We don't pass the model objects because this needs to serialize to something tiny for effiency. |
|
46 | + * |
|
47 | + * @param int|string $model_obj_id |
|
48 | + * @param EEM_Base $model |
|
49 | + * @param array $dont_traverse_models array of model names we DON'T want to traverse. |
|
50 | + */ |
|
51 | + public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = []) |
|
52 | + { |
|
53 | + $this->id = $model_obj_id; |
|
54 | + $this->model = $model; |
|
55 | + $this->dont_traverse_models = $dont_traverse_models; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Creates a relation node for each relation of this model's relations. |
|
61 | + * Does NOT call `discover` on them yet though. |
|
62 | + * |
|
63 | + * @throws EE_Error |
|
64 | + * @throws InvalidDataTypeException |
|
65 | + * @throws InvalidInterfaceException |
|
66 | + * @throws InvalidArgumentException |
|
67 | + * @throws ReflectionException |
|
68 | + * @since 4.10.12.p |
|
69 | + */ |
|
70 | + protected function discover() |
|
71 | + { |
|
72 | + $this->nodes = []; |
|
73 | + foreach ($this->model->relation_settings() as $relationName => $relation) { |
|
74 | + // Make sure this isn't one of the models we were told to not traverse into. |
|
75 | + if (in_array($relationName, $this->dont_traverse_models)) { |
|
76 | + continue; |
|
77 | + } |
|
78 | + if ($relation instanceof EE_Has_Many_Relation) { |
|
79 | + $this->nodes[ $relationName ] = new RelationNode( |
|
80 | + $this->id, |
|
81 | + $this->model, |
|
82 | + $relation->get_other_model(), |
|
83 | + $this->dont_traverse_models |
|
84 | + ); |
|
85 | + } elseif ( |
|
86 | + $relation instanceof EE_HABTM_Relation && |
|
87 | + ! in_array( |
|
88 | + $relation->get_join_model()->get_this_model_name(), |
|
89 | + $this->dont_traverse_models |
|
90 | + ) |
|
91 | + ) { |
|
92 | + $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
93 | + $this->id, |
|
94 | + $this->model, |
|
95 | + $relation->get_join_model(), |
|
96 | + $this->dont_traverse_models |
|
97 | + ); |
|
98 | + } |
|
99 | + } |
|
100 | + ksort($this->nodes); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Whether this item has already been initialized |
|
106 | + */ |
|
107 | + protected function isDiscovered() |
|
108 | + { |
|
109 | + return is_array($this->nodes); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @since 4.10.12.p |
|
114 | + * @return boolean |
|
115 | + */ |
|
116 | + public function isComplete() |
|
117 | + { |
|
118 | + if ($this->complete === null) { |
|
119 | + $this->complete = false; |
|
120 | + } |
|
121 | + return $this->complete; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Triggers working on each child relation node that has work to do. |
|
127 | + * |
|
128 | + * @param $model_objects_to_identify |
|
129 | + * @return int units of work done |
|
130 | + * @since 4.10.12.p |
|
131 | + */ |
|
132 | + protected function work($model_objects_to_identify) |
|
133 | + { |
|
134 | + $num_identified = 0; |
|
135 | + // Begin assuming we'll finish all the work on this node and its children... |
|
136 | + $this->complete = true; |
|
137 | + foreach ($this->nodes as $model_name => $relation_node) { |
|
138 | + $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified); |
|
139 | + // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
|
140 | + // related model objects. |
|
141 | + if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
|
142 | + unset($this->nodes[ $model_name ]); |
|
143 | + } |
|
144 | + if ($num_identified >= $model_objects_to_identify) { |
|
145 | + // ...but admit we're wrong if the work exceeded the budget. |
|
146 | + $this->complete = false; |
|
147 | + break; |
|
148 | + } |
|
149 | + } |
|
150 | + return $num_identified; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return array |
|
156 | + * @throws EE_Error |
|
157 | + * @throws InvalidDataTypeException |
|
158 | + * @throws InvalidInterfaceException |
|
159 | + * @throws InvalidArgumentException |
|
160 | + * @throws ReflectionException |
|
161 | + * @since 4.10.12.p |
|
162 | + */ |
|
163 | + public function toArray() |
|
164 | + { |
|
165 | + $tree = [ |
|
166 | + 'id' => $this->id, |
|
167 | + 'complete' => $this->isComplete(), |
|
168 | + 'rels' => [], |
|
169 | + ]; |
|
170 | + if ($this->nodes === null) { |
|
171 | + $tree['rels'] = null; |
|
172 | + } else { |
|
173 | + foreach ($this->nodes as $relation_name => $relation_node) { |
|
174 | + $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
175 | + } |
|
176 | + } |
|
177 | + return $tree; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @return array|mixed |
|
183 | + * @throws InvalidArgumentException |
|
184 | + * @throws InvalidDataTypeException |
|
185 | + * @throws InvalidInterfaceException |
|
186 | + * @throws ReflectionException |
|
187 | + * @throws EE_Error |
|
188 | + * @since 4.10.12.p |
|
189 | + */ |
|
190 | + public function getIds() |
|
191 | + { |
|
192 | + $ids = [ |
|
193 | + $this->model->get_this_model_name() => [ |
|
194 | + $this->id => $this->id, |
|
195 | + ], |
|
196 | + ]; |
|
197 | + if ($this->nodes && is_array($this->nodes)) { |
|
198 | + foreach ($this->nodes as $relation_node) { |
|
199 | + $ids = array_replace_recursive($ids, $relation_node->getIds()); |
|
200 | + } |
|
201 | + } |
|
202 | + return $ids; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * Don't serialize the models. Just record their names on some dynamic properties. |
|
208 | + * |
|
209 | + * @since 4.10.12.p |
|
210 | + */ |
|
211 | + public function __sleep() |
|
212 | + { |
|
213 | + $this->model_name = $this->model->get_this_model_name(); |
|
214 | + return array_merge( |
|
215 | + [ |
|
216 | + 'model_name', |
|
217 | + 'id', |
|
218 | + 'nodes', |
|
219 | + ], |
|
220 | + parent::__sleep() |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * Use the dynamic properties to instantiate the models we use. |
|
227 | + * |
|
228 | + * @throws EE_Error |
|
229 | + * @throws InvalidArgumentException |
|
230 | + * @throws InvalidDataTypeException |
|
231 | + * @throws InvalidInterfaceException |
|
232 | + * @throws ReflectionException |
|
233 | + * @since 4.10.12.p |
|
234 | + */ |
|
235 | + public function __wakeup() |
|
236 | + { |
|
237 | + $this->model = EE_Registry::instance()->load_model($this->model_name); |
|
238 | + parent::__wakeup(); |
|
239 | + } |
|
240 | 240 | } |
241 | 241 | // End of file Visitor.php |
242 | 242 | // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php |
@@ -94,16 +94,16 @@ |
||
94 | 94 | ? $this->_extra_data['template']['question_list'] |
95 | 95 | : $template; |
96 | 96 | $ans_result = ''; |
97 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
98 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
97 | + $answers = ! empty($this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs']) |
|
98 | + ? $this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs'] |
|
99 | 99 | : []; |
100 | 100 | $questions = ! empty($this->_extra_data['data']->questions) |
101 | 101 | ? $this->_extra_data['data']->questions |
102 | 102 | : []; |
103 | 103 | foreach ($answers as $answer) { |
104 | 104 | // first see if the question is in our $questions array. If not then try to get from answer object |
105 | - $question = isset($questions[ $answer->ID() ]) |
|
106 | - ? $questions[ $answer->ID() ] |
|
105 | + $question = isset($questions[$answer->ID()]) |
|
106 | + ? $questions[$answer->ID()] |
|
107 | 107 | : null; |
108 | 108 | $question = ! $question instanceof EE_Question |
109 | 109 | ? $answer->question() |
@@ -15,112 +15,112 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Question_List_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - public function __construct() |
|
19 | - { |
|
20 | - parent::__construct(); |
|
21 | - } |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | + parent::__construct(); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - protected function _init_props() |
|
25 | - { |
|
26 | - $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
27 | - $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
28 | - $this->_shortcodes = [ |
|
29 | - '[QUESTION_LIST]' => esc_html__( |
|
30 | - 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - ]; |
|
34 | - } |
|
24 | + protected function _init_props() |
|
25 | + { |
|
26 | + $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
27 | + $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
28 | + $this->_shortcodes = [ |
|
29 | + '[QUESTION_LIST]' => esc_html__( |
|
30 | + 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + ]; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @param string $shortcode |
|
39 | - * @return string |
|
40 | - * @throws EE_Error |
|
41 | - * @throws ReflectionException |
|
42 | - */ |
|
43 | - protected function _parser($shortcode) |
|
44 | - { |
|
45 | - if ($shortcode == '[QUESTION_LIST]') { |
|
46 | - return $this->_get_question_list(); |
|
47 | - } |
|
48 | - return ''; |
|
49 | - } |
|
37 | + /** |
|
38 | + * @param string $shortcode |
|
39 | + * @return string |
|
40 | + * @throws EE_Error |
|
41 | + * @throws ReflectionException |
|
42 | + */ |
|
43 | + protected function _parser($shortcode) |
|
44 | + { |
|
45 | + if ($shortcode == '[QUESTION_LIST]') { |
|
46 | + return $this->_get_question_list(); |
|
47 | + } |
|
48 | + return ''; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @return string |
|
54 | - * @throws EE_Error |
|
55 | - * @throws ReflectionException |
|
56 | - */ |
|
57 | - protected function _get_question_list() |
|
58 | - { |
|
59 | - $this->_validate_list_requirements(); |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + * @throws EE_Error |
|
55 | + * @throws ReflectionException |
|
56 | + */ |
|
57 | + protected function _get_question_list() |
|
58 | + { |
|
59 | + $this->_validate_list_requirements(); |
|
60 | 60 | |
61 | - // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
62 | - if ($this->_data['data'] instanceof EE_Registration) { |
|
63 | - return $this->_get_question_answer_list_for_attendee(); |
|
64 | - } |
|
61 | + // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
62 | + if ($this->_data['data'] instanceof EE_Registration) { |
|
63 | + return $this->_get_question_answer_list_for_attendee(); |
|
64 | + } |
|
65 | 65 | |
66 | - // for when [QUESTION_LIST] is used in the main content field. |
|
67 | - if ( |
|
68 | - $this->_data['data'] instanceof EE_Messages_Addressee |
|
69 | - && $this->_data['data']->reg_obj instanceof EE_Registration |
|
70 | - ) { |
|
71 | - return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
72 | - } |
|
73 | - return ''; |
|
74 | - } |
|
66 | + // for when [QUESTION_LIST] is used in the main content field. |
|
67 | + if ( |
|
68 | + $this->_data['data'] instanceof EE_Messages_Addressee |
|
69 | + && $this->_data['data']->reg_obj instanceof EE_Registration |
|
70 | + ) { |
|
71 | + return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
72 | + } |
|
73 | + return ''; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
79 | - * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
80 | - * |
|
81 | - * @param null $reg_obj |
|
82 | - * @return string parsed template. |
|
83 | - * @throws EE_Error |
|
84 | - * @throws ReflectionException |
|
85 | - */ |
|
86 | - private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
87 | - { |
|
88 | - $valid_shortcodes = ['question']; |
|
89 | - $reg_obj = $reg_obj instanceof EE_Registration |
|
90 | - ? $reg_obj |
|
91 | - : $this->_data['data']; |
|
92 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
93 | - ? $this->_data['template']['question_list'] |
|
94 | - : ''; |
|
95 | - $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
96 | - ? $this->_extra_data['template']['question_list'] |
|
97 | - : $template; |
|
98 | - $ans_result = ''; |
|
99 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
100 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
101 | - : []; |
|
102 | - $questions = ! empty($this->_extra_data['data']->questions) |
|
103 | - ? $this->_extra_data['data']->questions |
|
104 | - : []; |
|
105 | - foreach ($answers as $answer) { |
|
106 | - // first see if the question is in our $questions array. If not then try to get from answer object |
|
107 | - $question = isset($questions[ $answer->ID() ]) |
|
108 | - ? $questions[ $answer->ID() ] |
|
109 | - : null; |
|
110 | - $question = ! $question instanceof EE_Question |
|
111 | - ? $answer->question() |
|
112 | - : $question; |
|
113 | - if ($question instanceof EE_Question and $question->admin_only()) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
117 | - $template, |
|
118 | - $answer, |
|
119 | - $valid_shortcodes, |
|
120 | - $this->_extra_data |
|
121 | - ); |
|
122 | - } |
|
77 | + /** |
|
78 | + * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
79 | + * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
80 | + * |
|
81 | + * @param null $reg_obj |
|
82 | + * @return string parsed template. |
|
83 | + * @throws EE_Error |
|
84 | + * @throws ReflectionException |
|
85 | + */ |
|
86 | + private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
87 | + { |
|
88 | + $valid_shortcodes = ['question']; |
|
89 | + $reg_obj = $reg_obj instanceof EE_Registration |
|
90 | + ? $reg_obj |
|
91 | + : $this->_data['data']; |
|
92 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
93 | + ? $this->_data['template']['question_list'] |
|
94 | + : ''; |
|
95 | + $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
96 | + ? $this->_extra_data['template']['question_list'] |
|
97 | + : $template; |
|
98 | + $ans_result = ''; |
|
99 | + $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
100 | + ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
101 | + : []; |
|
102 | + $questions = ! empty($this->_extra_data['data']->questions) |
|
103 | + ? $this->_extra_data['data']->questions |
|
104 | + : []; |
|
105 | + foreach ($answers as $answer) { |
|
106 | + // first see if the question is in our $questions array. If not then try to get from answer object |
|
107 | + $question = isset($questions[ $answer->ID() ]) |
|
108 | + ? $questions[ $answer->ID() ] |
|
109 | + : null; |
|
110 | + $question = ! $question instanceof EE_Question |
|
111 | + ? $answer->question() |
|
112 | + : $question; |
|
113 | + if ($question instanceof EE_Question and $question->admin_only()) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
117 | + $template, |
|
118 | + $answer, |
|
119 | + $valid_shortcodes, |
|
120 | + $this->_extra_data |
|
121 | + ); |
|
122 | + } |
|
123 | 123 | |
124 | - return $ans_result; |
|
125 | - } |
|
124 | + return $ans_result; |
|
125 | + } |
|
126 | 126 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $att_result = ''; |
160 | 160 | $registrations = |
161 | 161 | isset($this->_extra_data['data']->tickets) |
162 | - ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs'] |
|
162 | + ? $this->_extra_data['data']->tickets[$ticket->ID()]['reg_objs'] |
|
163 | 163 | : []; |
164 | 164 | |
165 | 165 | // each attendee in this case should be an attendee object. |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | private function _get_registrations_from_event(EE_Event $event) |
186 | 186 | { |
187 | 187 | return isset($this->_extra_data['data']->events) |
188 | - ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs'] |
|
188 | + ? $this->_extra_data['data']->events[$event->ID()]['reg_objs'] |
|
189 | 189 | : []; |
190 | 190 | } |
191 | 191 | } |
@@ -18,166 +18,166 @@ |
||
18 | 18 | */ |
19 | 19 | class EE_Attendee_List_Shortcodes extends EE_Shortcodes |
20 | 20 | { |
21 | - protected function _init_props() |
|
22 | - { |
|
23 | - $this->label = esc_html__('Attendee List Shortcodes', 'event_espresso'); |
|
24 | - $this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso'); |
|
25 | - $this->_shortcodes = [ |
|
26 | - '[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'), |
|
27 | - ]; |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @param string $shortcode |
|
33 | - * @return string |
|
34 | - * @throws EE_Error |
|
35 | - * @throws ReflectionException |
|
36 | - */ |
|
37 | - protected function _parser($shortcode) |
|
38 | - { |
|
39 | - if ($shortcode == '[ATTENDEE_LIST]') { |
|
40 | - return $this->_get_attendee_list(); |
|
41 | - } |
|
42 | - return ''; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * figure out what the incoming data is and then return the appropriate parsed value. |
|
48 | - * |
|
49 | - * @return string |
|
50 | - * @throws EE_Error |
|
51 | - * @throws ReflectionException |
|
52 | - */ |
|
53 | - private function _get_attendee_list() |
|
54 | - { |
|
55 | - $this->_validate_list_requirements(); |
|
56 | - |
|
57 | - if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
58 | - return $this->_get_attendee_list_for_main(); |
|
59 | - } |
|
60 | - if ($this->_data['data'] instanceof EE_Event) { |
|
61 | - return $this->_get_attendee_list_for_event(); |
|
62 | - } |
|
63 | - if ($this->_data['data'] instanceof EE_Ticket) { |
|
64 | - return $this->_get_registration_list_for_ticket(); |
|
65 | - } |
|
66 | - // prevent recursive loop |
|
67 | - return ''; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * This returns the parsed attendee list for main template; |
|
73 | - */ |
|
74 | - private function _get_attendee_list_for_main() |
|
75 | - { |
|
76 | - $valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details']; |
|
77 | - $template = $this->_data['template']; |
|
78 | - $data = $this->_data['data']; |
|
79 | - $attendees = ''; |
|
80 | - |
|
81 | - |
|
82 | - // now we need to loop through the attendee list and send data to the EE_Parser helper. |
|
83 | - foreach ($data->reg_objs as $registration) { |
|
84 | - $attendees .= $this->_shortcode_helper->parse_attendee_list_template( |
|
85 | - $template, |
|
86 | - $registration, |
|
87 | - $valid_shortcodes, |
|
88 | - $this->_extra_data |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - return $attendees; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * return parsed list of attendees for an event |
|
98 | - * |
|
99 | - * @return string |
|
100 | - * @throws EE_Error |
|
101 | - * @throws ReflectionException |
|
102 | - */ |
|
103 | - private function _get_attendee_list_for_event() |
|
104 | - { |
|
105 | - $valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details']; |
|
106 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list']) |
|
107 | - ? $this->_data['template']['attendee_list'] |
|
108 | - : $this->_extra_data['template']['attendee_list']; |
|
109 | - $event = $this->_data['data']; |
|
110 | - |
|
111 | - // let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion. |
|
112 | - $template = str_replace('[EVENT_LIST]', '', $template); |
|
113 | - |
|
114 | - // here we're setting up the attendees for the attendee_list template for THIS event. |
|
115 | - $att_result = ''; |
|
116 | - $registrations = $this->_get_registrations_from_event($event); |
|
117 | - |
|
118 | - // each attendee in this case should be an attendee object. |
|
119 | - foreach ($registrations as $registration) { |
|
120 | - $att_result .= $this->_shortcode_helper->parse_attendee_list_template( |
|
121 | - $template, |
|
122 | - $registration, |
|
123 | - $valid_shortcodes, |
|
124 | - $this->_extra_data |
|
125 | - ); |
|
126 | - } |
|
127 | - |
|
128 | - return $att_result; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * return parsed list of attendees for a ticket |
|
134 | - * |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - private function _get_registration_list_for_ticket() |
|
138 | - { |
|
139 | - $valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details']; |
|
140 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list']) |
|
141 | - ? $this->_data['template']['attendee_list'] |
|
142 | - : $this->_extra_data['template']['attendee_list']; |
|
143 | - $ticket = $this->_data['data']; |
|
144 | - |
|
145 | - // let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion. |
|
146 | - $template = str_replace('[TICKET_LIST]', '', $template); |
|
147 | - $template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template); |
|
148 | - $template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template); |
|
149 | - |
|
150 | - // here we're setting up the attendees for the attendee_list template for THIS ticket. |
|
151 | - $att_result = ''; |
|
152 | - $registrations = |
|
153 | - isset($this->_extra_data['data']->tickets) |
|
154 | - ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs'] |
|
155 | - : []; |
|
156 | - |
|
157 | - // each attendee in this case should be an attendee object. |
|
158 | - foreach ($registrations as $registration) { |
|
159 | - $att_result .= $this->_shortcode_helper->parse_attendee_list_template( |
|
160 | - $template, |
|
161 | - $registration, |
|
162 | - $valid_shortcodes, |
|
163 | - $this->_extra_data |
|
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - return $att_result; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param EE_Event $event |
|
173 | - * @return array|mixed |
|
174 | - * @throws EE_Error |
|
175 | - * @throws ReflectionException |
|
176 | - */ |
|
177 | - private function _get_registrations_from_event(EE_Event $event) |
|
178 | - { |
|
179 | - return isset($this->_extra_data['data']->events) |
|
180 | - ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs'] |
|
181 | - : []; |
|
182 | - } |
|
21 | + protected function _init_props() |
|
22 | + { |
|
23 | + $this->label = esc_html__('Attendee List Shortcodes', 'event_espresso'); |
|
24 | + $this->description = esc_html__('All shortcodes specific to attendee lists', 'event_espresso'); |
|
25 | + $this->_shortcodes = [ |
|
26 | + '[ATTENDEE_LIST]' => esc_html__('Will output a list of attendees', 'event_espresso'), |
|
27 | + ]; |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @param string $shortcode |
|
33 | + * @return string |
|
34 | + * @throws EE_Error |
|
35 | + * @throws ReflectionException |
|
36 | + */ |
|
37 | + protected function _parser($shortcode) |
|
38 | + { |
|
39 | + if ($shortcode == '[ATTENDEE_LIST]') { |
|
40 | + return $this->_get_attendee_list(); |
|
41 | + } |
|
42 | + return ''; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * figure out what the incoming data is and then return the appropriate parsed value. |
|
48 | + * |
|
49 | + * @return string |
|
50 | + * @throws EE_Error |
|
51 | + * @throws ReflectionException |
|
52 | + */ |
|
53 | + private function _get_attendee_list() |
|
54 | + { |
|
55 | + $this->_validate_list_requirements(); |
|
56 | + |
|
57 | + if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
58 | + return $this->_get_attendee_list_for_main(); |
|
59 | + } |
|
60 | + if ($this->_data['data'] instanceof EE_Event) { |
|
61 | + return $this->_get_attendee_list_for_event(); |
|
62 | + } |
|
63 | + if ($this->_data['data'] instanceof EE_Ticket) { |
|
64 | + return $this->_get_registration_list_for_ticket(); |
|
65 | + } |
|
66 | + // prevent recursive loop |
|
67 | + return ''; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * This returns the parsed attendee list for main template; |
|
73 | + */ |
|
74 | + private function _get_attendee_list_for_main() |
|
75 | + { |
|
76 | + $valid_shortcodes = ['attendee', 'event_list', 'ticket_list', 'question_list', 'recipient_details']; |
|
77 | + $template = $this->_data['template']; |
|
78 | + $data = $this->_data['data']; |
|
79 | + $attendees = ''; |
|
80 | + |
|
81 | + |
|
82 | + // now we need to loop through the attendee list and send data to the EE_Parser helper. |
|
83 | + foreach ($data->reg_objs as $registration) { |
|
84 | + $attendees .= $this->_shortcode_helper->parse_attendee_list_template( |
|
85 | + $template, |
|
86 | + $registration, |
|
87 | + $valid_shortcodes, |
|
88 | + $this->_extra_data |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + return $attendees; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * return parsed list of attendees for an event |
|
98 | + * |
|
99 | + * @return string |
|
100 | + * @throws EE_Error |
|
101 | + * @throws ReflectionException |
|
102 | + */ |
|
103 | + private function _get_attendee_list_for_event() |
|
104 | + { |
|
105 | + $valid_shortcodes = ['attendee', 'ticket_list', 'question_list', 'recipient_details']; |
|
106 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list']) |
|
107 | + ? $this->_data['template']['attendee_list'] |
|
108 | + : $this->_extra_data['template']['attendee_list']; |
|
109 | + $event = $this->_data['data']; |
|
110 | + |
|
111 | + // let's remove any existing [EVENT_LIST] shortcode from the attendee list template so that we don't get recursion. |
|
112 | + $template = str_replace('[EVENT_LIST]', '', $template); |
|
113 | + |
|
114 | + // here we're setting up the attendees for the attendee_list template for THIS event. |
|
115 | + $att_result = ''; |
|
116 | + $registrations = $this->_get_registrations_from_event($event); |
|
117 | + |
|
118 | + // each attendee in this case should be an attendee object. |
|
119 | + foreach ($registrations as $registration) { |
|
120 | + $att_result .= $this->_shortcode_helper->parse_attendee_list_template( |
|
121 | + $template, |
|
122 | + $registration, |
|
123 | + $valid_shortcodes, |
|
124 | + $this->_extra_data |
|
125 | + ); |
|
126 | + } |
|
127 | + |
|
128 | + return $att_result; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * return parsed list of attendees for a ticket |
|
134 | + * |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + private function _get_registration_list_for_ticket() |
|
138 | + { |
|
139 | + $valid_shortcodes = ['attendee', 'event_list', 'question_list', 'recipient_details']; |
|
140 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['attendee_list']) |
|
141 | + ? $this->_data['template']['attendee_list'] |
|
142 | + : $this->_extra_data['template']['attendee_list']; |
|
143 | + $ticket = $this->_data['data']; |
|
144 | + |
|
145 | + // let's remove any existing [TICKET_LIST] (or related) shortcode from the attendee list template so that we don't get recursion. |
|
146 | + $template = str_replace('[TICKET_LIST]', '', $template); |
|
147 | + $template = str_replace('[RECIPIENT_TICKET_LIST]', '', $template); |
|
148 | + $template = str_replace('[PRIMARY_REGISTRANT_TICKET_LIST]', '', $template); |
|
149 | + |
|
150 | + // here we're setting up the attendees for the attendee_list template for THIS ticket. |
|
151 | + $att_result = ''; |
|
152 | + $registrations = |
|
153 | + isset($this->_extra_data['data']->tickets) |
|
154 | + ? $this->_extra_data['data']->tickets[ $ticket->ID() ]['reg_objs'] |
|
155 | + : []; |
|
156 | + |
|
157 | + // each attendee in this case should be an attendee object. |
|
158 | + foreach ($registrations as $registration) { |
|
159 | + $att_result .= $this->_shortcode_helper->parse_attendee_list_template( |
|
160 | + $template, |
|
161 | + $registration, |
|
162 | + $valid_shortcodes, |
|
163 | + $this->_extra_data |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + return $att_result; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param EE_Event $event |
|
173 | + * @return array|mixed |
|
174 | + * @throws EE_Error |
|
175 | + * @throws ReflectionException |
|
176 | + */ |
|
177 | + private function _get_registrations_from_event(EE_Event $event) |
|
178 | + { |
|
179 | + return isset($this->_extra_data['data']->events) |
|
180 | + ? $this->_extra_data['data']->events[ $event->ID() ]['reg_objs'] |
|
181 | + : []; |
|
182 | + } |
|
183 | 183 | } |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | ?> |
8 | 8 | <h2><?php esc_html_e('Event Registration Data', 'event_espresso'); ?></h2> |
9 | 9 | <p><?php |
10 | - esc_html_e( |
|
11 | - 'We collect information about you during event registration. This information may include but is not limited to:', |
|
12 | - 'event_espresso' |
|
13 | - ); ?></p> |
|
10 | + esc_html_e( |
|
11 | + 'We collect information about you during event registration. This information may include but is not limited to:', |
|
12 | + 'event_espresso' |
|
13 | + ); ?></p> |
|
14 | 14 | <ul> |
15 | 15 | <li><?php esc_html_e('Your names', 'event_espresso'); ?></li> |
16 | 16 | <li><?php esc_html_e('Billing address', 'event_espresso'); ?></li> |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | <li><?php esc_html_e('Email address', 'event_espresso'); ?></li> |
19 | 19 | <li><?php esc_html_e('Phone number', 'event_espresso'); ?></li> |
20 | 20 | <li><?php |
21 | - esc_html_e( |
|
22 | - 'Location and traffic data (including partial IP address and browser type)', |
|
23 | - 'event_espresso' |
|
24 | - ); ?> |
|
21 | + esc_html_e( |
|
22 | + 'Location and traffic data (including partial IP address and browser type)', |
|
23 | + 'event_espresso' |
|
24 | + ); ?> |
|
25 | 25 | </li> |
26 | 26 | <li><?php |
27 | - esc_html_e( |
|
28 | - 'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase', |
|
29 | - 'event_espresso' |
|
30 | - ); ?> |
|
27 | + esc_html_e( |
|
28 | + 'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase', |
|
29 | + 'event_espresso' |
|
30 | + ); ?> |
|
31 | 31 | </li> |
32 | 32 | </ul> |
33 | 33 | |
@@ -36,101 +36,101 @@ discard block |
||
36 | 36 | <li><?php esc_html_e('Send you important account/purchase/service information.', 'event_espresso'); ?></li> |
37 | 37 | <li><?php esc_html_e('Respond to your queries, refund requests, or complaints.', 'event_espresso'); ?></li> |
38 | 38 | <li><?php |
39 | - esc_html_e( |
|
40 | - 'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', |
|
41 | - 'event_espresso' |
|
42 | - ); ?></li> |
|
39 | + esc_html_e( |
|
40 | + 'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', |
|
41 | + 'event_espresso' |
|
42 | + ); ?></li> |
|
43 | 43 | <li><?php |
44 | - esc_html_e( |
|
45 | - 'Set up and administer your account, provide technical and customer support, and to verify your identity.', |
|
46 | - 'event_espresso' |
|
47 | - ); ?></li> |
|
44 | + esc_html_e( |
|
45 | + 'Set up and administer your account, provide technical and customer support, and to verify your identity.', |
|
46 | + 'event_espresso' |
|
47 | + ); ?></li> |
|
48 | 48 | </ul> |
49 | 49 | |
50 | 50 | <?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
51 | 51 | <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2> |
52 | 52 | <?php |
53 | - // if onsite or offsite payment methods are active |
|
54 | - if (! empty($active_onsite_payment_methods)) { ?> |
|
53 | + // if onsite or offsite payment methods are active |
|
54 | + if (! empty($active_onsite_payment_methods)) { ?> |
|
55 | 55 | <p><?php |
56 | - esc_html_e( |
|
57 | - 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
|
58 | - 'event_espresso' |
|
59 | - ); ?></p> |
|
56 | + esc_html_e( |
|
57 | + 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
|
58 | + 'event_espresso' |
|
59 | + ); ?></p> |
|
60 | 60 | <p><?php |
61 | - printf( |
|
62 | - esc_html_x( |
|
63 | - 'Please see the privacy policy of %1$s.', |
|
64 | - 'Please see the privacy policy of PayPal Pro', |
|
65 | - 'event_espresso' |
|
66 | - ), |
|
67 | - implode( |
|
68 | - ', ', |
|
69 | - array_merge( |
|
70 | - $active_onsite_payment_methods, |
|
71 | - $active_offsite_payment_methods |
|
72 | - ) |
|
73 | - ) |
|
74 | - ); ?></p> |
|
61 | + printf( |
|
62 | + esc_html_x( |
|
63 | + 'Please see the privacy policy of %1$s.', |
|
64 | + 'Please see the privacy policy of PayPal Pro', |
|
65 | + 'event_espresso' |
|
66 | + ), |
|
67 | + implode( |
|
68 | + ', ', |
|
69 | + array_merge( |
|
70 | + $active_onsite_payment_methods, |
|
71 | + $active_offsite_payment_methods |
|
72 | + ) |
|
73 | + ) |
|
74 | + ); ?></p> |
|
75 | 75 | <p><?php |
76 | - esc_html_e( |
|
77 | - 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
|
78 | - 'event_espresso' |
|
79 | - ); ?></p> |
|
76 | + esc_html_e( |
|
77 | + 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
|
78 | + 'event_espresso' |
|
79 | + ); ?></p> |
|
80 | 80 | <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
81 | 81 | <p><?php |
82 | - printf( |
|
83 | - esc_html_x( |
|
84 | - 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.', |
|
85 | - 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.', |
|
86 | - 'event_espresso' |
|
87 | - ), |
|
88 | - implode(', ', $active_offsite_payment_methods) |
|
89 | - ); ?></p> |
|
82 | + printf( |
|
83 | + esc_html_x( |
|
84 | + 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.', |
|
85 | + 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.', |
|
86 | + 'event_espresso' |
|
87 | + ), |
|
88 | + implode(', ', $active_offsite_payment_methods) |
|
89 | + ); ?></p> |
|
90 | 90 | <?php } ?> |
91 | 91 | <h2><?php esc_html_e('Payment Logging', 'event_espresso'); ?></h2> |
92 | 92 | <p><?php |
93 | - esc_html_e( |
|
94 | - 'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.', |
|
95 | - 'event_espresso' |
|
96 | - ); ?></p> |
|
93 | + esc_html_e( |
|
94 | + 'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.', |
|
95 | + 'event_espresso' |
|
96 | + ); ?></p> |
|
97 | 97 | <?php } ?> |
98 | 98 | |
99 | 99 | <h2><?php esc_html_e('Event Registration Cookies', 'event_espresso'); ?></h2> |
100 | 100 | <p><?php |
101 | - printf( |
|
102 | - esc_html_x( |
|
103 | - 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.', |
|
104 | - 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.', |
|
105 | - 'event_espresso' |
|
106 | - ), |
|
107 | - $session_lifespan |
|
108 | - ); ?></p> |
|
101 | + printf( |
|
102 | + esc_html_x( |
|
103 | + 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.', |
|
104 | + 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.', |
|
105 | + 'event_espresso' |
|
106 | + ), |
|
107 | + $session_lifespan |
|
108 | + ); ?></p> |
|
109 | 109 | |
110 | 110 | <h2><?php esc_html_e('Email History Data', 'event_espresso'); ?></h2> |
111 | 111 | <p><?php |
112 | - esc_html_e( |
|
113 | - 'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.', |
|
114 | - 'event_espresso' |
|
115 | - ); ?></p> |
|
112 | + esc_html_e( |
|
113 | + 'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.', |
|
114 | + 'event_espresso' |
|
115 | + ); ?></p> |
|
116 | 116 | |
117 | 117 | <h2><?php esc_html_e('Event Check-In Record', 'event_espresso'); ?></h2> |
118 | 118 | <p><?php |
119 | - esc_html_e( |
|
120 | - 'When you attend an event, an event manager may record the time you check in or out of the event.', |
|
121 | - 'event_espresso' |
|
122 | - ); ?></p> |
|
119 | + esc_html_e( |
|
120 | + 'When you attend an event, an event manager may record the time you check in or out of the event.', |
|
121 | + 'event_espresso' |
|
122 | + ); ?></p> |
|
123 | 123 | |
124 | 124 | <h2><?php esc_html_e('Event Registration Data Retention', 'event_espresso'); ?></h2> |
125 | 125 | <p><?php |
126 | - esc_html_e( |
|
127 | - 'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.', |
|
128 | - 'event_espresso' |
|
129 | - ); ?></p> |
|
126 | + esc_html_e( |
|
127 | + 'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.', |
|
128 | + 'event_espresso' |
|
129 | + ); ?></p> |
|
130 | 130 | |
131 | 131 | <h2><?php esc_html_e('Event Registration Data Erasure and Export', 'event_espresso'); ?></h2> |
132 | 132 | <p><?php |
133 | - esc_html_e( |
|
134 | - 'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.', |
|
135 | - 'event_espresso' |
|
136 | - ); ?></p> |
|
133 | + esc_html_e( |
|
134 | + 'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.', |
|
135 | + 'event_espresso' |
|
136 | + ); ?></p> |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | ); ?></li> |
48 | 48 | </ul> |
49 | 49 | |
50 | -<?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
|
50 | +<?php if ( ! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
|
51 | 51 | <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2> |
52 | 52 | <?php |
53 | 53 | // if onsite or offsite payment methods are active |
54 | - if (! empty($active_onsite_payment_methods)) { ?> |
|
54 | + if ( ! empty($active_onsite_payment_methods)) { ?> |
|
55 | 55 | <p><?php |
56 | 56 | esc_html_e( |
57 | 57 | 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
78 | 78 | 'event_espresso' |
79 | 79 | ); ?></p> |
80 | - <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
|
80 | + <?php } elseif ( ! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
|
81 | 81 | <p><?php |
82 | 82 | printf( |
83 | 83 | esc_html_x( |