X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FDAO.php;h=e5971188cba74adbc09a1854777bf18a5d9bd3db;hb=f299f7db79fed6f3598c84302966bda087e7cac3;hp=d1b7668fee2e305b21841274695a09f8caaf3d4d;hpb=6974b5bc0980883e2d2ae056195f22fd27d41a1f;p=civicrm-core.git diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index d1b7668fee..e5971188cb 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 5 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2019 | + | Copyright CiviCRM LLC (c) 2004-2020 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -31,7 +31,7 @@ * All DAO classes should inherit from this class. * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2019 + * @copyright CiviCRM LLC (c) 2004-2020 */ if (!defined('DB_DSN_MODE')) { @@ -1063,6 +1063,18 @@ LIKE %1 return $result; } + /** + * Check if a given table has data. + * + * @param string $tableName + * @return bool + * TRUE if $tableName has at least one record. + */ + public static function checkTableHasData($tableName) { + $c = CRM_Core_DAO::singleValueQuery(sprintf('SELECT count(*) c FROM `%s`', $tableName)); + return $c > 0; + } + /** * @param $version * @@ -1550,7 +1562,7 @@ FROM civicrm_domain $tr['%' . $key] = $item[0]; } elseif ($abort) { - CRM_Core_Error::fatal("{$item[0]} is not of type {$item[1]}"); + throw new CRM_Core_Exception("{$item[0]} is not of type {$item[1]}"); } } } @@ -1858,7 +1870,7 @@ SELECT contact_id /** * Drop all CiviCRM tables. * - * @throws \CRM_Exception + * @throws \CRM_Core_Exception */ public static function dropAllTables() {