Skip to content

vtws_recordExists($recordId) returns true when $recordId is empty or it doesn't exist as crmid in vtiger_crmentity

vtws_recordExists returns true when vtiger_crmentity.deleted = 0 which is what you would expect, because that means that the record has not been deleted.

The problem is when there is no record in the vtiger_crmentity table. In that case, the function also returns true which is terribly wrong and an unexpected behavior of the function.

This is what the function looks like:

function vtws_recordExists($recordId) {
	$ids = vtws_getIdComponents($recordId);
	return !Vtiger_Util_Helper::CheckRecordExi1stance($ids[1]);
}

This is what Vtiger_Util_Helper::CheckRecordExi1stance() looks like:

public static function checkRecordExistance($recordId){
	global $adb;
	$query = 'Select deleted from vtiger_crmentity where crmid=?';
	$result = $adb->pquery($query, array($recordId));
	return $adb->query_result($result, 'deleted');
}

If the query returns no result, then this line return !Vtiger_Util_Helper::CheckRecordExi1stance($ids[1]); in vtws_recordExists converts it to true

Edited by Prasad