N°4342 - Improve generic bulk deletion function with memory limit handling (#321)

This commit is contained in:
Anne-Catherine
2024-02-28 09:55:04 +01:00
committed by GitHub
parent e7b493dafa
commit baa05ba8d4
3 changed files with 82 additions and 34 deletions

View File

@@ -5,6 +5,7 @@ namespace Combodo\iTop\Test\UnitTest\Core;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use CoreException;
use DBObjectSearch;
use MetaModel;
/**
@@ -456,6 +457,31 @@ class MetaModelTest extends ItopDataTestCase
'Non existing person' => [10, false],
];
}
/**
* @return void
* @throws CoreException
* @throws \OQLException
*/
public function testPurgeData(){
// Set max_chunk_size to 2 (default 1000) to test chunk deletion with only 10 items
$oConfig = MetaModel::GetConfig();
$oConfig->Set('purge_data.max_chunk_size', 2);
MetaModel::SetConfig($oConfig);
$aPkPerson = [];
for ($i=0; $i < 10; $i++) {
$oPerson = $this->CreatePerson($i, 1);
$sClass = get_class($oPerson);
$aPkPerson[] = $oPerson->GetKey();
}
$sDeleteOQL = 'SELECT '.$sClass.' WHERE id IN ('.implode(',', $aPkPerson).')';
$oFilter = DBObjectSearch::FromOQL($sDeleteOQL);
$iNbDelete = MetaModel::PurgeData($oFilter);
$this->assertEquals($iNbDelete, 10, 'MetaModel::PurgeData must delete 10 objects per batch of 2 items');
}
}
abstract class Wizzard