From 43a10e6944a48c4222da76e1778dd9c1ed71c49d Mon Sep 17 00:00:00 2001 From: jf-cbd Date: Tue, 22 Apr 2025 09:37:54 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20"N=C2=B08259=20-=20Problem=20with=20Ge?= =?UTF-8?q?tMaxSize=20on=20AttributeText"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 29c75f626b1ae9a6000c6123d80b56658d658a9b. --- core/attributedef.class.inc.php | 2 +- core/dbobject.class.php | 26 +++--------------- .../core/AttributeDefinitionTest.php | 27 ------------------- .../core/DBObject/DBObjectTest.php | 19 ------------- 4 files changed, 5 insertions(+), 69 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index aceae7bdf..45e715776 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -4440,7 +4440,7 @@ class AttributeText extends AttributeString { // Is there a way to know the current limitation for mysql? // See mysql_field_len() - return 16383; // number of characters (that can be 1-4 bytes long), not of bytes + return 65535; } public static function RenderWikiHtml($sText, $bWikiOnly = false) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 4068819e8..fec3d472a 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -760,10 +760,10 @@ abstract class DBObject implements iDisplay */ public function SetTrim($sAttCode, $sValue) { - if (!$this->StringFitsInField($sAttCode, $sValue)) { - $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); - $iMaxSize = $oAttDef->GetMaxSize(); - $sLength = mb_strlen($sValue); + $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); + $iMaxSize = $oAttDef->GetMaxSize(); + $sLength = mb_strlen($sValue); + if ($iMaxSize && ($sLength > $iMaxSize)) { $sMessage = " -truncated ($sLength chars)"; $sValue = mb_substr($sValue, 0, $iMaxSize - mb_strlen($sMessage)).$sMessage; } @@ -818,24 +818,6 @@ abstract class DBObject implements iDisplay $oKPI->ComputeStatsForExtension($this, 'AfterDelete'); } - /** - * @param string $sAttCode - * @param string $sValue - * - * @return bool - * @throws \Exception - * - * @Since 3.2.2 - */ - public function StringFitsInField(string $sAttCode, string $sValue): bool - { - $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); - $iMaxSize = $oAttDef->GetMaxSize(); - $sLength = mb_strlen($sValue); - - return !($iMaxSize && ($sLength > $iMaxSize)); - } - /** * Compute (and optionally start) the StopWatches deadlines * diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php index 58881762e..047f39462 100644 --- a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php +++ b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php @@ -2,19 +2,11 @@ namespace Combodo\iTop\Test\UnitTest\Core; -use ArchivedObjectException; use AttributeDate; use AttributeDateTime; use Change; use Combodo\iTop\Test\UnitTest\ItopDataTestCase; -use CoreCannotSaveObjectException; -use CoreException; -use CoreUnexpectedValue; -use CoreWarning; -use EventRestService; use MetaModel; -use MySQLException; -use OQLException; use UserRequest; class AttributeDefinitionTest extends ItopDataTestCase { @@ -351,23 +343,4 @@ PHP return $oAttribute; } - /** - * @throws CoreException - * @throws CoreUnexpectedValue - * @throws OQLException - * @throws ArchivedObjectException - * @throws CoreCannotSaveObjectException - * @throws CoreWarning - * @throws MySQLException - */ - public function testTrimLogOnAttributeText() - { - // will throw MySQLException if GetMaxSize() of AttributeText is incorrect (should be number of bytes, not of characters) - $oLog = new EventRestService(); - $sLongString = json_encode(array_fill(0, 5000, 'é😃 '), - JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); - $oLog->SetTrim('json_input', $sLongString); - static::assertNotEquals($oLog->Get('json_input'), $sLongString); - static::assertStringContainsString('truncated', $oLog->Get('json_input')); - } } \ No newline at end of file diff --git a/tests/php-unit-tests/unitary-tests/core/DBObject/DBObjectTest.php b/tests/php-unit-tests/unitary-tests/core/DBObject/DBObjectTest.php index 92ac10703..7c97e4044 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObject/DBObjectTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBObject/DBObjectTest.php @@ -22,7 +22,6 @@ namespace Combodo\iTop\Test\UnitTest\Core; use Attachment; use AttributeDateTime; use Combodo\iTop\Service\Events\EventData; -use EventRestService; use Combodo\iTop\Test\UnitTest\ItopDataTestCase; use CoreException; use DateTime; @@ -1416,22 +1415,4 @@ class DBObjectTest extends ItopDataTestCase $this->assertEquals("2024-01-15 09:45:00", $oObject->Get('end_date'), 'SetComputedDate +2 weeks on a WorkOrder DateTimeAttribute'); } - - public function testStringFitsInField() - { - //🎁 character is 4 bytes long - $sTooLongText = str_repeat('🎁', 17000); - $oLog = new EventRestService(); - $this->assertFalse($oLog->StringFitsInField('json_output', $sTooLongText)); - - $sCorrectLengthText = str_repeat('🎁', 16383); - $this->assertTrue($oLog->StringFitsInField('json_output', $sCorrectLengthText)); - - - $sCorrectLengthString = str_repeat('🎁', 255); - $this->assertTrue($oLog->StringFitsInField('operation', $sCorrectLengthString)); - - $sTooLongString = str_repeat('🎁', 256); - $this->assertFalse($oLog->StringFitsInField('operation', $sTooLongString)); - } }