From fead96c4ca7b491257fd33ed62da76abe18de1e8 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Thu, 25 Oct 2018 11:10:29 +0300 Subject: [PATCH] Add delete options on delete plugin --- src/include/class-wc-retailcrm-base.php | 3 ++- src/include/class-wc-retailcrm-plugin.php | 17 ++++++++++------- src/uninstall.php | 2 ++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 9d35209..8f0bfa2 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -950,6 +950,7 @@ if (!class_exists('WC_Retailcrm_Base')) { $api_client = $this->getApiClient(); $clientId = get_option('retailcrm_client_id'); WC_Retailcrm_Plugin::integration_module($api_client, $clientId, false); + delete_option('retailcrm_active_in_crm'); } /** @@ -962,7 +963,7 @@ if (!class_exists('WC_Retailcrm_Base')) { $client_id = get_option('retailcrm_client_id'); if (!$client_id) { - $client_id = hash('md5', date('Y-m-d H:i:s')); + $client_id = uniqid(); } if ($settings['api_url'] && $settings['api_key'] && $settings['api_version']) { diff --git a/src/include/class-wc-retailcrm-plugin.php b/src/include/class-wc-retailcrm-plugin.php index 1310d62..f000ed0 100644 --- a/src/include/class-wc-retailcrm-plugin.php +++ b/src/include/class-wc-retailcrm-plugin.php @@ -3,9 +3,13 @@ class WC_Retailcrm_Plugin { public $file; + public static $history_run = false; private static $instance = null; + const MARKETPLACE_LOGO = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b69ce4bda663-woocommercesvg2.svg'; + const INTEGRATION_CODE = 'woocommerce'; + public static function getInstance($file) { if (self::$instance === null) { self::$instance = new self($file); @@ -81,24 +85,23 @@ class WC_Retailcrm_Plugin { * Edit configuration in CRM * * @param WC_Retailcrm_Proxy $api_client - * @param string $cliend_id + * @param string $client_id * @param bool $active * * @return boolean */ - public static function integration_module($api_client, $cliend_id, $active = true) - { + public static function integration_module($api_client, $client_id, $active = true) { if (!$api_client) { return false; } $configuration = array( - 'clientId' => $cliend_id, - 'code' => 'woocommerce', - 'integrationCode' => 'woocommerce', + 'clientId' => $client_id, + 'code' => self::INTEGRATION_CODE . '-' . $client_id, + 'integrationCode' => self::INTEGRATION_CODE, 'active' => $active, 'name' => 'WooCommerce', - 'logo' => 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b69ce4bda663-woocommercesvg2.svg' + 'logo' => self::MARKETPLACE_LOGO ); $response = $api_client->integrationModulesEdit($configuration); diff --git a/src/uninstall.php b/src/uninstall.php index 913fbcc..5e9c27f 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -39,6 +39,8 @@ wp_clear_scheduled_hook('retailcrm_inventories'); $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'woocommerce_integration-retailcrm_settings';"); $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_customers_history_since_id';"); $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_orders_history_since_id';"); +$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_active_in_crm';"); +$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_client_id';"); // Clear any cached data that has been removed wp_cache_flush();