N°4173 Fix memory_limit error when saving an object pointing to a big AttributeBlob

Check of pointed object was loading the whole object instead of just doing a count
This commit is contained in:
Pierre Goiffon
2021-07-27 15:14:59 +02:00
parent 714294e1b4
commit a66830de17
2 changed files with 12 additions and 8 deletions

View File

@@ -1859,9 +1859,7 @@ abstract class DBObject implements iDisplay
{
/** @var \AttributeExternalKey $oAtt */
$sTargetClass = $oAtt->GetTargetClass();
$oTargetObj = MetaModel::GetObject($sTargetClass, $toCheck, false /*must be found*/, true /*allow all data*/);
if (is_null($oTargetObj))
{
if (false === MetaModel::IsObjectExistsInDb($sTargetClass, $toCheck)) {
return "Target object not found ($sTargetClass::$toCheck)";
}
}

View File

@@ -6976,12 +6976,9 @@ abstract class MetaModel
if (!utils::IsArchiveMode() && $oObject->IsArchived())
{
if ($bMustBeFound)
{
if ($bMustBeFound) {
throw new ArchivedObjectException("The object $sClass::$iKey is archived");
}
else
{
} else {
return null;
}
}
@@ -6989,6 +6986,15 @@ abstract class MetaModel
return $oObject;
}
public static function IsObjectExistsInDb(string $sClass, int $iKey): bool
{
$oFilter = DBObjectSearch::FromOQL('SELECT '.$sClass.' WHERE id = :id', ['id' => $iKey,]);
$oSet = new DBObjectSet($oFilter);
$iCount = $oSet->Count();
return ($iCount > 0);
}
/**
* Search for the specified class and id. If the object is archived it will be returned anyway (this is for pre-2.4
* module compatibility, see N.1108)