3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Do not limit constraint field reference search.

This commit is contained in:
Michael Stenta 2019-07-02 10:29:45 -04:00
parent 766454b0b7
commit 2d5b5eb28d

View file

@ -11,10 +11,7 @@
function farm_constraint_farm_constraint($type, $bundle, $id) {
// Check to see if there are any field references to this entity.
// Limit to 1 because we don't need a full list of references, we only want
// to know if ANY references exist.
$limit = 1;
$references = farm_constraint_field_references($type, $id, $limit);
$references = farm_constraint_field_references($type, $id);
// If references were found, a constraint was detected! Return TRUE.
if (!empty($references)) {
@ -41,16 +38,11 @@ function farm_constraint_farm_constraint($type, $bundle, $id) {
* The entity type.
* @param $id
* The entity id.
* @param $limit
* An optional limit to the number of references to return. This is disabled
* by default, which means all references will be returned. Setting this to
* 1 is a good way to check if ANY references exist without loading all of
* them. It will stop looking as soon as the limit is reached.
*
* @return array
* Returns an array of references to the entity.
*/
function farm_constraint_field_references($type, $id, $limit = FALSE) {
function farm_constraint_field_references($type, $id) {
// Start an empty references array.
$references = array();
@ -120,11 +112,9 @@ function farm_constraint_field_references($type, $id, $limit = FALSE) {
// entity.
$result = db_query('SELECT entity_type, entity_id FROM {' . $table . '} WHERE ' . $column . ' = :id AND deleted != 1', array(':id' => $id));
// Iterate through the results.
// Iterate through the results and add the reference to the array.
foreach ($result as $row) {
if (!empty($row)) {
// Add the reference to the array.
$references[] = array(
'entity_type' => $row->entity_type,
'entity_id' => $row->entity_id,
@ -132,11 +122,6 @@ function farm_constraint_field_references($type, $id, $limit = FALSE) {
'table' => $table,
'column' => $column,
);
// If we are at or over our limit, return now.
if (!empty($limit) && count($references) >= $limit) {
return $references;
}
}
}
}