{* file to handle db changes in 4.7.19 during upgrade *}
+-- CRM-19715
+SELECT @option_group_id_act := max(id) from civicrm_option_group where name = 'activity_type';
+SELECT @close_acc_period_act_val := `value` FROM civicrm_option_value WHERE option_group_id = @option_group_id_act AND name = 'Close Accounting Period';
+SELECT @close_accounting_period_activity_count := count(id) FROM `civicrm_activity` WHERE `activity_type_id` = @close_acc_period_act_val;
+
+-- Delete Close Accounting Period activity type
+DELETE FROM civicrm_option_value
+ WHERE option_group_id = @option_group_id_act AND name = 'Close Accounting Period' AND @close_accounting_period_activity_count = 0;
('Deferred Revenue - Event Fee', @domainContactId, @opLiability, 'Event revenue to be recognized in future months when the events occur', '2730', 'OCLIAB', 0, 1, 0, 0),
('Deferred Revenue - Member Dues', @domainContactId, @opLiability, 'Membership revenue to be recognized in future months', '2740', 'OCLIAB', 0, 1, 0, 0);
--- CRM-16189 Financial account relationship
-SELECT @option_group_id_act := max(id) from civicrm_option_group where name = 'activity_type';
-SELECT @option_group_id_act_wt := MAX(weight) FROM civicrm_option_value WHERE option_group_id = @option_group_id_act;
-SELECT @option_group_id_act_val := MAX(CAST( `value` AS UNSIGNED )) FROM civicrm_option_value WHERE option_group_id = @option_group_id_act;
-INSERT INTO
- `civicrm_option_value` (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, {localize field='description'}`description`{/localize}, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`)
-VALUES
-(@option_group_id_act, {localize}'{ts escape="sql"}Close Accounting Period{/ts}'{/localize}, @option_group_id_act_val+1, 'Close Accounting Period', NULL, 0, 0, @option_group_id_act_wt+1, {localize}'Close Accounting Period'{/localize}, 0, 1, 1, 2, NULL);
-- Activity Type for failed payment
(@option_group_id_act, 'Failed Payment', 53, 'Failed Payment', NULL, 1, 0, 53, 'Failed Payment', 0, 1, 1, @contributeCompId, NULL, NULL),
- -- Activity Type for Close Accounting Period
- (@option_group_id_act, '{ts escape="sql"}Close Accounting Period{/ts}', 54, 'Close Accounting Period', NULL, 1, 0, 54, '{ts escape="sql"}Close Accounting Period{/ts}', 0, 1, 1, @contributeCompId, NULL, NULL),
-
(@option_group_id_gender, '{ts escape="sql"}Female{/ts}', 1, 'Female', NULL, 0, NULL, 1, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_gender, '{ts escape="sql"}Male{/ts}', 2, 'Male', NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_gender, '{ts escape="sql"}Other{/ts}', 3, 'Other', NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL, NULL),