/**
  * Checks if a previous version was installed and if the feeds need migrating to the framework structure.
  *
  * @param string $previous_version The version number of the previously installed version.
  */
 public function upgrade($previous_version)
 {
     if (empty($previous_version)) {
         $previous_version = get_option('gf_paypalpaymentspro_version');
     }
     $previous_is_pre_addon_framework = !empty($previous_version) && version_compare($previous_version, '2.0.dev1', '<');
     if ($previous_is_pre_addon_framework) {
         $this->log_debug(__METHOD__ . '(): Copying over data to new table structure.');
         $old_feeds = $this->get_old_feeds();
         if (!$old_feeds) {
             $this->log_debug(__METHOD__ . '(): No old feeds found to copy.');
             return;
         }
         $counter = 1;
         foreach ($old_feeds as $old_feed) {
             $feed_name = 'Feed ' . $counter;
             $form_id = $old_feed['form_id'];
             $is_active = $old_feed['is_active'];
             $customer_fields = rgar($old_feed['meta'], 'customer_fields');
             $new_meta = array('feedName' => $feed_name, 'transactionType' => rgar($old_feed['meta'], 'type'), 'change_post_status' => rgar($old_feed['meta'], 'update_post_action') ? '1' : '0', 'update_post_action' => rgar($old_feed['meta'], 'update_post_action'), 'recurringAmount' => rgar($old_feed['meta'], 'recurring_amount_field') == 'all' ? 'form_total' : rgar($old_feed['meta'], 'recurring_amount_field'), 'recurringTimes' => rgar($old_feed['meta'], 'recurring_times'), 'payPeriod' => rgar($old_feed['meta'], 'pay_period'), 'paymentAmount' => 'form_total', 'setupFee_enabled' => rgar($old_feed['meta'], 'setup_fee_enabled'), 'setupFee_product' => rgar($old_feed['meta'], 'setup_fee_amount_field'), 'billingInformation_firstName' => rgar($customer_fields, 'first_name'), 'billingInformation_lastName' => rgar($customer_fields, 'last_name'), 'billingInformation_email' => rgar($customer_fields, 'email'), 'billingInformation_address' => rgar($customer_fields, 'address1'), 'billingInformation_address2' => rgar($customer_fields, 'address2'), 'billingInformation_city' => rgar($customer_fields, 'city'), 'billingInformation_state' => rgar($customer_fields, 'state'), 'billingInformation_zip' => rgar($customer_fields, 'zip'), 'billingInformation_country' => rgar($customer_fields, 'country'), 'apiSettingsEnabled' => rgar($old_feed['meta'], 'api_settings_enabled'), 'overrideMode' => rgar($old_feed['meta'], 'api_mode'), 'overrideUsername' => rgar($old_feed['meta'], 'api_username'), 'overridePassword' => rgar($old_feed['meta'], 'api_password'), 'overrideVendor' => rgar($old_feed['meta'], 'api_vendor'), 'overridePartner' => rgar($old_feed['meta'], 'api_partner'));
             $optin_enabled = rgar($old_feed['meta'], 'paypalpaymentspro_conditional_enabled');
             if ($optin_enabled) {
                 $new_meta['feed_condition_conditional_logic'] = 1;
                 $new_meta['feed_condition_conditional_logic_object'] = array('conditionalLogic' => array('actionType' => 'show', 'logicType' => 'all', 'rules' => array(array('fieldId' => $old_feed['meta']['paypalpaymentspro_conditional_field_id'], 'operator' => $old_feed['meta']['paypalpaymentspro_conditional_operator'], 'value' => $old_feed['meta']['paypalpaymentspro_conditional_value']))));
             } else {
                 $new_meta['feed_condition_conditional_logic'] = 0;
             }
             $this->insert_feed($form_id, $is_active, $new_meta);
             $counter++;
         }
         $old_settings = get_option('gf_paypalpaymentspro_settings');
         if (!empty($old_settings)) {
             $this->log_debug(__METHOD__ . '(): Copying plugin settings.');
             $new_settings = array('mode' => rgar($old_settings, 'mode'), 'username' => rgar($old_settings, 'username'), 'password' => rgar($old_settings, 'password'), 'vendor' => rgar($old_settings, 'vendor'), 'partner' => rgar($old_settings, 'partner'));
             parent::update_plugin_settings($new_settings);
         }
         //copy existing transactions to new table
         $this->copy_transactions();
     }
 }
 public function upgrade($previous_version)
 {
     if (empty($previous_version)) {
         $previous_version = get_option('gf_authorizenet_version');
     }
     $previous_is_pre_addon_framework = !empty($previous_version) && version_compare($previous_version, '2.0.dev1', '<');
     if ($previous_is_pre_addon_framework) {
         $this->log_debug(__METHOD__ . '(): Copying over data to new table structure.');
         $old_feeds = $this->get_old_feeds();
         if ($old_feeds) {
             $this->log_debug(__METHOD__ . '(): Migrating feeds.');
             $counter = 1;
             foreach ($old_feeds as $old_feed) {
                 $feed_name = 'Feed ' . $counter;
                 $form_id = $old_feed['form_id'];
                 $is_active = $old_feed['is_active'];
                 $customer_fields = rgar($old_feed['meta'], 'customer_fields');
                 $new_meta = array('feedName' => $feed_name, 'transactionType' => rgar($old_feed['meta'], 'type'), 'enableReceipt' => rgar($old_feed['meta'], 'enable_receipt'), 'change_post_status' => rgar($old_feed['meta'], 'update_post_action') ? '1' : '0', 'update_post_action' => rgar($old_feed['meta'], 'update_post_action'), 'recurringAmount' => rgar($old_feed['meta'], 'recurring_amount_field') == 'all' ? 'form_total' : rgar($old_feed['meta'], 'recurring_amount_field'), 'recurringTimes' => rgar($old_feed['meta'], 'recurring_times'), 'paymentAmount' => 'form_total', 'billingCycle_length' => rgar($old_feed['meta'], 'billing_cycle_number'), 'billingCycle_unit' => $this->convert_interval(rgar($old_feed['meta'], 'billing_cycle_type'), 'text'), 'setupFee_enabled' => rgar($old_feed['meta'], 'setup_fee_enabled'), 'setupFee_product' => rgar($old_feed['meta'], 'setup_fee_amount_field'), 'trial_enabled' => rgar($old_feed['meta'], 'trial_period_enabled'), 'trial_product' => 'enter_amount', 'trial_amount' => rgar($old_feed['meta'], 'trial_amount'), 'billingInformation_firstName' => rgar($customer_fields, 'first_name'), 'billingInformation_lastName' => rgar($customer_fields, 'last_name'), 'billingInformation_email' => rgar($customer_fields, 'email'), 'billingInformation_address' => rgar($customer_fields, 'address1'), 'billingInformation_address2' => rgar($customer_fields, 'address2'), 'billingInformation_city' => rgar($customer_fields, 'city'), 'billingInformation_state' => rgar($customer_fields, 'state'), 'billingInformation_zip' => rgar($customer_fields, 'zip'), 'billingInformation_country' => rgar($customer_fields, 'country'), 'apiSettingsEnabled' => rgar($old_feed['meta'], 'api_settings_enabled'), 'overrideMode' => rgar($old_feed['meta'], 'api_mode'), 'overrideLogin' => rgar($old_feed['meta'], 'api_login'), 'overrideKey' => rgar($old_feed['meta'], 'api_key'));
                 $optin_enabled = rgar($old_feed['meta'], 'authorizenet_conditional_enabled');
                 if ($optin_enabled) {
                     $new_meta['feed_condition_conditional_logic'] = 1;
                     $new_meta['feed_condition_conditional_logic_object'] = array('conditionalLogic' => array('actionType' => 'show', 'logicType' => 'all', 'rules' => array(array('fieldId' => $old_feed['meta']['authorizenet_conditional_field_id'], 'operator' => $old_feed['meta']['authorizenet_conditional_operator'], 'value' => $old_feed['meta']['authorizenet_conditional_value']))));
                 } else {
                     $new_meta['feed_condition_conditional_logic'] = 0;
                 }
                 $this->insert_feed($form_id, $is_active, $new_meta);
                 $counter++;
             }
         }
         $old_settings = get_option('gf_authorizenet_settings');
         if (!empty($old_settings)) {
             $this->log_debug(__METHOD__ . '(): Copying plugin settings.');
             $new_settings = array('mode' => rgar($old_settings, 'mode'), 'loginId' => rgar($old_settings, 'login_id'), 'transactionKey' => rgar($old_settings, 'transaction_key'), 'arb' => rgar($old_settings, 'arb_configured') == 'on' ? '1' : '0');
             parent::update_plugin_settings($new_settings);
         }
         //copy existing authorize.net transactions to new table
         $this->copy_transactions();
     }
 }