diff options
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Traits/TableDropperTrait.php')
-rw-r--r-- | www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Traits/TableDropperTrait.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Traits/TableDropperTrait.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Traits/TableDropperTrait.php new file mode 100644 index 00000000..6e543473 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Traits/TableDropperTrait.php @@ -0,0 +1,23 @@ +<?php + +namespace Civi\Test\Api4\Traits; + +trait TableDropperTrait { + /** + * @param $prefix + */ + protected function dropByPrefix($prefix) { + $sql = "SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) " . + "AS statement FROM information_schema.tables " . + "WHERE table_name LIKE '%s%%' AND table_schema = DATABASE();"; + $sql = sprintf($sql, $prefix); + $dropTableQuery = \CRM_Core_DAO::executeQuery($sql); + $dropTableQuery->fetch(); + $dropTableQuery = $dropTableQuery->statement; + + if ($dropTableQuery) { + \CRM_Core_DAO::executeQuery($dropTableQuery); + } + } + +} |