diff --git a/CRM/TwingleCampaign/Upgrader.php b/CRM/TwingleCampaign/Upgrader.php index dcbb82f..13c9f75 100644 --- a/CRM/TwingleCampaign/Upgrader.php +++ b/CRM/TwingleCampaign/Upgrader.php @@ -1,120 +1,102 @@ error("Could not read json file"); - throw new Exception('Could not read json file'); - } + $campaign_info = ExtensionCache::getInstance()->getCampaigns(); // Create campaign types foreach ($campaign_info['campaign_types'] as $campaign_type) { - new BAO\CampaignType($campaign_type); + new CampaignType($campaign_type); } - foreach (BAO\CampaignType::getCampaignTypes() as $campaign_type) { + foreach (CampaignType::getCampaignTypes() as $campaign_type) { $campaign_type->create(); } // Create custom groups foreach ($campaign_info['custom_groups'] as $custom_group) { - foreach (BAO\CampaignType::getCampaignTypes() as $campaign_type) { + foreach (CampaignType::getCampaignTypes() as $campaign_type) { if ($campaign_type->getName() == $custom_group['campaign_type']) { $custom_group['extends_entity_column_value'] = $campaign_type->getValue(); } } - $cg = new BAO\CustomGroup($custom_group); + $cg = new CustomGroup($custom_group); $cg->create(); } // Create custom fields foreach ($campaign_info['custom_fields'] as $custom_field) { - $cf = new BAO\CustomField($custom_field); + $cf = new CustomField($custom_field); $cf->create(); } } /** - * Example: Run a simple query when a module is disabled. - * * @throws \CiviCRM_API3_Exception * @throws \Exception */ + public function uninstall() { + + $campaign_info = ExtensionCache::getInstance()->getCampaigns(); + + // Delete campaign types + foreach ($campaign_info['campaign_types'] as $campaign_type) { + $result = CampaignType::fetch($campaign_type['name']); + if ($result) { + $result->delete(); + } + } + + // Delete custom groups + foreach ($campaign_info['custom_groups'] as $custom_group) { + $result = CustomGroup::fetch($custom_group['name']); + if ($result) { + $result->delete(); + } + } + + // Delete all settings for this extension + Configuration::deleteAll(); + + } + + /** + * @throws \Exception + */ + public function enable() { + + } + + /** + * @throws \Exception + */ public function disable() { - $json_file = file_get_contents(E::path() . '/CRM/TwingleCampaign/resources/campaigns.json'); - $campaign_info = json_decode($json_file, TRUE); - - if (!$campaign_info) { - \Civi::log()->error("Could not read json file"); - throw new Exception('Could not read json file'); - } - - // Delete campaign types - foreach ($campaign_info['campaign_types'] as $campaign_type) { - $result = BAO\CampaignType::fetch($campaign_type['name']); - if ($result) { - $result->delete(); - } - } - - // Delete custom groups - foreach ($campaign_info['custom_groups'] as $custom_group) { - $result = BAO\CustomGroup::fetch($custom_group['name']); - if ($result) { - $result->delete(); - } - } - // Delete all settings for this extension - Configuration::deleteAll(); } /**