IsImportAllowed.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\App\Specification; |
| 4 | |
| 5 | |
| 6 | class IsImportAllowed |
| 7 | { |
| 8 | public function isSatisfied($item) |
| 9 | { |
| 10 | $is_re_import_allowed = true; |
| 11 | if ( ! empty($item['options']['ids']) ) |
| 12 | { |
| 13 | if (in_array('shop_order', $item['options']['cpt']) and class_exists('WooCommerce')) { |
| 14 | $required_fields = array('woo_order' => 'id'); |
| 15 | } |
| 16 | else { |
| 17 | $required_fields = array('id' => 'id'); |
| 18 | } |
| 19 | // re-import products |
| 20 | if ((in_array('product', $item['options']['cpt']) or $item['options']['export_type'] == 'advanced') and class_exists('WooCommerce') and (empty($item['options']['wp_query_selector']) or $item['options']['wp_query_selector'] == 'wp_query')) { |
| 21 | $required_fields['woo'] = '_sku'; |
| 22 | $required_fields['cats'] = 'product_type'; |
| 23 | $required_fields['parent'] = 'parent'; |
| 24 | } |
| 25 | if ((in_array('users', $item['options']['cpt']) or $item['options']['export_type'] == 'advanced') and (!empty($item['options']['wp_query_selector']) and $item['options']['wp_query_selector'] == 'wp_user_query')) { |
| 26 | $required_fields['user_email'] = 'user_email'; |
| 27 | $required_fields['user_login'] = 'user_login'; |
| 28 | } |
| 29 | if ($item['options']['export_type'] == 'advanced' and (empty($item['options']['wp_query_selector']) or $item['options']['wp_query_selector'] == 'wp_query')){ |
| 30 | $required_fields['post_type'] = 'post_type'; |
| 31 | } |
| 32 | $defined_fields = array(); |
| 33 | foreach ($item['options']['ids'] as $ID => $value) |
| 34 | { |
| 35 | foreach ($required_fields as $type => $field) |
| 36 | { |
| 37 | if (strtolower($item['options']['cc_type'][$ID]) == $type && strtolower($item['options']['cc_label'][$ID]) == strtolower($field)){ |
| 38 | $defined_fields[] = $field; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | foreach ($required_fields as $type => $field) { |
| 44 | if ( ! in_array($field, $defined_fields) ){ |
| 45 | $is_re_import_allowed = false; |
| 46 | break; |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return $is_re_import_allowed; |
| 52 | } |
| 53 | } |