AddonService.php
147 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\App\Service\Addons; |
| 4 | |
| 5 | |
| 6 | class AddonService |
| 7 | { |
| 8 | public function isUserAddonActive() { |
| 9 | return defined('PMUE_EDITION'); |
| 10 | } |
| 11 | |
| 12 | public function isWooCommerceAddonActive() { |
| 13 | return defined('PMWE_EDITION'); |
| 14 | } |
| 15 | |
| 16 | public function isAcfAddonActive() { |
| 17 | return defined('PMAE_EDITION'); |
| 18 | } |
| 19 | |
| 20 | public function isWooCommerceOrderAddonActive() { |
| 21 | return defined('PMWOE_EDITION'); |
| 22 | } |
| 23 | |
| 24 | public function isWooCommerceProductAddonActive() { |
| 25 | return defined('PMWPE_EDITION'); |
| 26 | } |
| 27 | |
| 28 | public function isWoocommerceAddonActiveAndIsWooCommerceExport() |
| 29 | { |
| 30 | return $this->isWooCommerceAddonActive() && \XmlExportWooCommerce::$is_active; |
| 31 | } |
| 32 | |
| 33 | public function isUserAddonActiveAndIsUserExport() |
| 34 | { |
| 35 | return $this->isUserAddonActive() && \XmlExportUser::$is_active; |
| 36 | } |
| 37 | |
| 38 | public function userExportsExistAndAddonNotInstalled() |
| 39 | { |
| 40 | if($this->isUserAddonActive()) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | $exports = new \PMXE_Export_List(); |
| 45 | $exports->getBy('parent_id', 0)->convertRecords(); |
| 46 | |
| 47 | foreach ($exports as $item) { |
| 48 | |
| 49 | if(!isset($item['options']['cpt'])) { |
| 50 | continue; |
| 51 | } |
| 52 | |
| 53 | if(!is_array($item['options']['cpt'])) { |
| 54 | $item['options']['cpt'] = array($item['options']['cpt']); |
| 55 | } |
| 56 | |
| 57 | if ( |
| 58 | ((in_array('users', $item['options']['cpt']) || in_array('shop_customer', $item['options']['cpt']))) || |
| 59 | ($item['options']['export_type'] == 'advanced' && $item['options']['wp_query_selector'] == 'wp_user_query') |
| 60 | ) { |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | } |
| 65 | |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | public function wooCommerceExportsExistAndAddonNotInstalled() |
| 70 | { |
| 71 | |
| 72 | if($this->isWooCommerceAddonActive()) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | $exports = new \PMXE_Export_List(); |
| 77 | $exports->getBy('parent_id', 0)->convertRecords(); |
| 78 | |
| 79 | foreach ($exports as $item) { |
| 80 | |
| 81 | if(!isset($item['options']['cpt'])) { |
| 82 | continue; |
| 83 | } |
| 84 | |
| 85 | if(!is_array($item['options']['cpt'])) { |
| 86 | $item['options']['cpt'] = array($item['options']['cpt']); |
| 87 | } |
| 88 | |
| 89 | if ( |
| 90 | ( |
| 91 | ( |
| 92 | (in_array('product', $item['options']['cpt']) && \class_exists('WooCommerce') && !$this->isWooCommerceProductAddonActive()) || |
| 93 | in_array('product_variation', $item['options']['cpt']) || |
| 94 | in_array('shop_order', $item['options']['cpt']) || |
| 95 | in_array('shop_review', $item['options']['cpt']) || |
| 96 | in_array('shop_coupon', $item['options']['cpt']) |
| 97 | )) |
| 98 | ) { |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | } |
| 103 | |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | public function acfExportsExistAndNotInstalled() |
| 108 | { |
| 109 | if($this->isAcfAddonActive()) { |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | $exports = new \PMXE_Export_List(); |
| 114 | $exports->getBy('parent_id', 0)->convertRecords(); |
| 115 | |
| 116 | foreach ($exports as $item) { |
| 117 | |
| 118 | if(is_array($item->options['cc_type']) && in_array('acf', $item->options['cc_type'])) { |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | } |
| 123 | |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | public function hasExportAtOlderVersionThan($version) |
| 128 | { |
| 129 | $exports = new \PMXE_Export_List(); |
| 130 | $exports->getBy('parent_id', 0)->convertRecords(); |
| 131 | |
| 132 | foreach ($exports as $item) { |
| 133 | |
| 134 | if (!isset($item['options']['created_at_version'])) { |
| 135 | continue; |
| 136 | } |
| 137 | |
| 138 | if(version_compare($item['options']['created_at_version'], $version) < 0) { |
| 139 | return true; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | } |