diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 823cfa93c..40797d270 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -8599,7 +8599,7 @@ class AttributeBlob extends AttributeDefinition public function RecordAttChange(DBObject $oObject, $original, $value): void { // N°6502 Don't record history if only the download count has changed - if ($original->EqualsExceptDownloadsCount($value)) { + if ((null !== $original) && (null !== $value) && $original->EqualsExceptDownloadsCount($value)) { return; } diff --git a/sources/Service/Base/ObjectRepository.php b/sources/Service/Base/ObjectRepository.php index f8ada588a..77eac98e5 100644 --- a/sources/Service/Base/ObjectRepository.php +++ b/sources/Service/Base/ObjectRepository.php @@ -38,7 +38,7 @@ class ObjectRepository * * @return array|null */ - static public function Search(string $sObjectClass, array $aFieldsToLoad, string $sSearch): ?array + public static function Search(string $sObjectClass, array $aFieldsToLoad, string $sSearch): ?array { try { @@ -82,7 +82,7 @@ class ObjectRepository * * @return array|null */ - static public function SearchFromOql(string $sObjectClass, array $aFieldsToLoad, string $sOql, string $sSearch, DBObject $oThisObject = null): ?array + public static function SearchFromOql(string $sObjectClass, array $aFieldsToLoad, string $sOql, string $sSearch, DBObject $oThisObject = null): ?array { try { @@ -117,7 +117,7 @@ class ObjectRepository * @throws \CoreException * @throws \DictExceptionMissingString */ - static private function DBSetToObjectArray(iDBObjectSetIterator $oDbObjectSet, string $sObjectClass, array $aFieldsToLoad): array + private static function DBSetToObjectArray(iDBObjectSetIterator $oDbObjectSet, string $sObjectClass, array $aFieldsToLoad): array { // Retrieve friendly name complementary specification $aComplementAttributeSpec = MetaModel::GetNameSpec($sObjectClass, FriendlyNameType::COMPLEMENTARY); @@ -158,7 +158,7 @@ class ObjectRepository * * @return mixed */ - static public function GetDefaultFieldsToLoad(array $aComplementAttributeSpec, string $sObjectImageAttCode) + public static function GetDefaultFieldsToLoad(array $aComplementAttributeSpec, string $sObjectImageAttCode) { // Friendly name complementary fields $aFieldsToLoad = $aComplementAttributeSpec[1]; @@ -185,7 +185,7 @@ class ObjectRepository * * @return array */ - static public function ComputeOthersData(DBObject $oDbObject, string $sClass, array $aData, array $aComplementAttributeSpec, string $sObjectImageAttCode): array + public static function ComputeOthersData(DBObject $oDbObject, string $sClass, array $aData, array $aComplementAttributeSpec, string $sObjectImageAttCode): array { try { @@ -196,6 +196,7 @@ class ObjectRepository $aData['obsolescence_flag'] = $oDbObject->IsObsolete(); // Additional fields + $sFriendlynameForHtml = utils::EscapeHtml($aData['friendlyname']); if (count($aComplementAttributeSpec[1]) > 0) { $aData['has_additional_field'] = true; $aArguments = []; @@ -203,9 +204,10 @@ class ObjectRepository $aArguments[] = $oDbObject->Get($sAdditionalField); } $aData['additional_field'] = vsprintf($aComplementAttributeSpec[0], $aArguments); - $aData['full_description'] = "{$aData['friendlyname']}
{$aData['additional_field']}"; + $sAdditionalFieldForHtml = utils::EscapeHtml($aData['additional_field']); + $aData['full_description'] = "{$sFriendlynameForHtml}
{$sAdditionalFieldForHtml}"; } else { - $aData['full_description'] = $aData['friendlyname']; + $aData['full_description'] = $sFriendlynameForHtml; } // Image @@ -308,7 +310,7 @@ class ObjectRepository * * @return bool */ - static public function DeleteFromOql(string $sOql): bool + public static function DeleteFromOql(string $sOql): bool { try { diff --git a/tests/php-unit-tests/unitary-tests/core/ormDocumentTest.php b/tests/php-unit-tests/unitary-tests/core/ormDocumentTest.php new file mode 100644 index 000000000..e9d33871c --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/ormDocumentTest.php @@ -0,0 +1,142 @@ +RequireOnceItopFile('core/ormdocument.class.inc.php'); + } + + + /** + * @param array $aDocAData + * @param array $aDocBData + * @param bool $bExpectedResult + * + * @dataProvider EqualsExceptDownloadsCountProvider + */ + public function testEqualsExceptDownloadsCount(array $aDocAData, array $aDocBData, bool $bExpectedResult) + { + $oDocA = new ormDocument(base64_decode($aDocAData[0]), $aDocAData[1], $aDocAData[2], $aDocAData[3]); + $oDocB = new ormDocument(base64_decode($aDocBData[0]), $aDocBData[1], $aDocBData[2], $aDocBData[3]); + + $bTestedResult = $oDocA->EqualsExceptDownloadsCount($oDocB); + $this->assertSame($bExpectedResult, $bTestedResult); + } + + public function EqualsExceptDownloadsCountProvider(): array + { + $sFirstDummyTextFileContentBase64 = "Rmlyc3Q="; + $sSecondDummyTextFileContentBase64 = "U2Vjb25k"; + + return [ + 'Total different files' => [ + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "a.txt", + 0 + ], + [ + $sSecondDummyTextFileContentBase64, + "image/png", + "b.png", + 1 + ], + false, + ], + 'Different data only' => [ + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "a.txt", + 0 + ], + [ + $sSecondDummyTextFileContentBase64, + "text/plain", + "a.txt", + 0 + ], + false, + ], + 'Different mime types only' => [ + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "a.txt", + 0 + ], + [ + $sFirstDummyTextFileContentBase64, + "image/png", + "a.txt", + 0 + ], + false, + ], + 'Different file names only' => [ + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "a.txt", + 0 + ], + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "b.txt", + 0 + ], + false, + ], + 'Different download counts only' => [ + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "a.txt", + 0 + ], + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "a.txt", + 1 + ], + true, + ], + 'Identical files, different object instances' => [ + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "a.txt", + 0 + ], + [ + $sFirstDummyTextFileContentBase64, + "text/plain", + "a.txt", + 0 + ], + false, + ], + ]; + } +}