Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
7d61e75f | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
7d61e75f TO |
7 | | This work is published under the GNU AGPLv3 license with some | |
8 | | permitted exceptions and without any warranty. For full license | | |
9 | | and copyright information, see https://civicrm.org/licensing | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | */ |
18 | ||
19b53e5b C |
19 | namespace api\v4\Traits; |
20 | ||
21 | trait OptionCleanupTrait { | |
22 | ||
380f3545 TO |
23 | /** |
24 | * @var int | |
25 | */ | |
19b53e5b | 26 | protected $optionGroupMaxId; |
380f3545 TO |
27 | |
28 | /** | |
29 | * @var int | |
30 | */ | |
19b53e5b C |
31 | protected $optionValueMaxId; |
32 | ||
0b49aa04 | 33 | public function setUp(): void { |
19b53e5b C |
34 | $this->optionGroupMaxId = \CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_option_group'); |
35 | $this->optionValueMaxId = \CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_option_value'); | |
36 | } | |
37 | ||
cacd9d67 | 38 | public function tearDown(): void { |
19b53e5b C |
39 | if ($this->optionValueMaxId) { |
40 | \CRM_Core_DAO::executeQuery('DELETE FROM civicrm_option_value WHERE id > ' . $this->optionValueMaxId); | |
41 | } | |
42 | if ($this->optionGroupMaxId) { | |
43 | \CRM_Core_DAO::executeQuery('DELETE FROM civicrm_option_group WHERE id > ' . $this->optionGroupMaxId); | |
44 | } | |
45 | } | |
46 | ||
47 | } |