/**
  * 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_campaignmonitor_version');
     }
     $previous_is_pre_addon_framework = !empty($previous_version) && version_compare($previous_version, '3.0.dev1', '<');
     if ($previous_is_pre_addon_framework) {
         $this->copy_feeds();
         $old_settings = get_option('gf_campaignmonitor_settings');
         $new_settings = array('apiKey' => $old_settings['api_key'], 'apiClientId' => $old_settings['client_id']);
         parent::update_plugin_settings($new_settings);
         //set paypal delay setting
         $this->update_paypal_delay_settings('delay_campaignmonitor_subscription');
     }
 }
 public function upgrade($previous_version)
 {
     if (empty($previous_version)) {
         $previous_version = get_option('gf_freshbooks_version');
     }
     $previous_is_pre_addon_framework = !empty($previous_version) && version_compare($previous_version, '2.0.dev1', '<');
     if ($previous_is_pre_addon_framework) {
         $old_feeds = $this->get_old_feeds();
         if (!$old_feeds) {
             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'];
             $line_items = '';
             switch (rgar($old_feed['meta'], 'is_fixed_cost')) {
                 case "1":
                     $line_items = 'fixed';
                 case "2":
                     $line_items = 'pricing';
                 case "0":
                     $line_items = 'dynamic';
             }
             $new_meta = array('feedName' => $feed_name, 'email' => rgar($old_feed['meta'], 'email'), 'firstName' => rgar($old_feed['meta'], 'first_name'), 'lastName' => rgar($old_feed['meta'], 'last_name'), 'organization' => rgar($old_feed['meta'], 'organization'), 'address' => rgar($old_feed['meta'], 'address'), 'phone' => rgar($old_feed['meta'], 'phone'), 'fax' => rgar($old_feed['meta'], 'fax'), 'notes' => rgar($old_feed['meta'], 'notes'), 'alsoCreate' => rgar($old_feed['meta'], 'alsocreate'), 'poNumber' => rgar($old_feed['meta'], 'ponumber'), 'discount' => rgar($old_feed['meta'], 'discount'), 'notes2' => rgar($old_feed['meta'], 'notes2'), 'terms' => rgar($old_feed['meta'], 'terms'), 'updateClient' => rgar($old_feed['meta'], 'update_client'), 'lineItems' => $line_items);
             $i = 0;
             foreach ($old_feed['meta']['items'] as $item) {
                 $new_meta['item'][] = $item['item_id'];
                 $new_meta['description'][] = $item['description'];
                 $new_meta['cost'][] = $item['cost'];
                 $new_meta['quantity'][] = $item['quantity'];
             }
             $optin_enabled = rgar($old_feed['meta'], 'optin_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']['optin_field_id'], 'operator' => $old_feed['meta']['optin_operator'], 'value' => $old_feed['meta']['optin_value']))));
             } else {
                 $new_meta['feed_condition_conditional_logic'] = 0;
             }
             $this->insert_feed($form_id, $is_active, $new_meta);
             $counter++;
         }
         $new_settings = array('siteName' => get_option('gf_freshbooks_site_name'), 'authToken' => get_option('gf_freshbooks_auth_token'));
         parent::update_plugin_settings($new_settings);
     }
 }