mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°4342 - Improve generic bulk deletion function with memory limit handling (#321)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user