Skip to content

Commit

Permalink
Merge pull request #15903 from eileenmcnaughton/except
Browse files Browse the repository at this point in the history
Convert a few fatals to exceptions.
  • Loading branch information
eileenmcnaughton authored Nov 21, 2019
2 parents bd4c91f + 7c58994 commit 6e143a8
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ protected function assignTestFK($fieldName, $fieldDef, $params) {
* @param array $fieldDef
* @param int $counter
* The globally-unique ID of the test object.
*
* @throws \CRM_Core_Exception
*/
protected function assignTestValue($fieldName, &$fieldDef, $counter) {
$dbName = $fieldDef['name'];
Expand Down Expand Up @@ -304,9 +306,8 @@ protected function assignTestValue($fieldName, &$fieldDef, $counter) {
break;

case CRM_Utils_Type::T_TIME:
CRM_Core_Error::fatal("T_TIME shouldn't be used.");
//$object->$dbName='000000';
//break;
throw new CRM_Core_Exception('T_TIME shouldn\'t be used.');

case CRM_Utils_Type::T_CCNUM:
$this->$dbName = '4111 1111 1111 1111';
break;
Expand Down Expand Up @@ -913,6 +914,8 @@ public static function getDatabaseName() {
*
* @return bool
* true if constraint exists, false otherwise
*
* @throws \CRM_Core_Exception
*/
public static function checkConstraintExists($tableName, $constraint) {
static $show = [];
Expand All @@ -922,7 +925,7 @@ public static function checkConstraintExists($tableName, $constraint) {
$dao = CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE);

if (!$dao->fetch()) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('query failed');
}

$show[$tableName] = $dao->Create_Table;
Expand All @@ -936,7 +939,7 @@ public static function checkConstraintExists($tableName, $constraint) {
*
* @param array $tables
*
* @throws Exception
* @throws CRM_Core_Exception
*
* @return bool
* true if CONSTRAINT keyword exists, false otherwise
Expand All @@ -949,7 +952,7 @@ public static function schemaRequiresRebuilding($tables = ["civicrm_contact"]) {
$dao = CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE);

if (!$dao->fetch()) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Show create table failed.');
}

$show[$tableName] = $dao->Create_Table;
Expand All @@ -975,6 +978,8 @@ public static function schemaRequiresRebuilding($tables = ["civicrm_contact"]) {
*
* @return bool
* true if in format, false otherwise
*
* @throws \CRM_Core_Exception
*/
public static function checkFKConstraintInFormat($tableName, $columnName) {
static $show = [];
Expand All @@ -984,7 +989,7 @@ public static function checkFKConstraintInFormat($tableName, $columnName) {
$dao = CRM_Core_DAO::executeQuery($query);

if (!$dao->fetch()) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('query failed');
}

$show[$tableName] = $dao->Create_Table;
Expand Down Expand Up @@ -1179,6 +1184,8 @@ public function fetchMap($keyColumn, $valueColumn) {
*
* @return string|null
* Value of $returnColumn in the retrieved record
*
* @throws \CRM_Core_Exception
*/
public static function getFieldValue($daoName, $searchValue, $returnColumn = 'name', $searchColumn = 'id', $force = FALSE) {
if (
Expand All @@ -1188,7 +1195,7 @@ public static function getFieldValue($daoName, $searchValue, $returnColumn = 'na
// adding this here since developers forget to check for an id
// or for the 'null' (which is a bad DAO kludge)
// and hence we get the first value in the db
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('getFieldValue failed');
}

self::$_dbColumnValueCache = self::$_dbColumnValueCache ?? [];
Expand Down

0 comments on commit 6e143a8

Please sign in to comment.