From a2cdf214f043b3354f31376de654f766facf600f Mon Sep 17 00:00:00 2001 From: Anne-Catherine <57360138+accognet@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:02:16 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B03715=20-=20Export=20above=201000=20entri?= =?UTF-8?q?es=20ignore=20obsolete=20data=20from=20user=20preference=20(#46?= =?UTF-8?q?8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * N°3715 - Export above 10000 entries ignore obsolete data from user preference --- core/bulkexport.class.inc.php | 11 +- .../unitary-tests/core/BulkExportTest.php | 162 ++++++++++++++++++ 2 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 tests/php-unit-tests/unitary-tests/core/BulkExportTest.php diff --git a/core/bulkexport.class.inc.php b/core/bulkexport.class.inc.php index dec6973e9..92878aba7 100644 --- a/core/bulkexport.class.inc.php +++ b/core/bulkexport.class.inc.php @@ -149,7 +149,9 @@ abstract class BulkExport $this->oSearch = null; $this->iChunkSize = 0; $this->sFormatCode = null; - $this->aStatusInfo = array(); + $this->aStatusInfo = [ + 'show_obsolete_data' => utils::ShowObsoleteData(), + ]; $this->oBulkExportResult = null; $this->sTmpFile = ''; $this->bLocalizeOutput = false; @@ -203,15 +205,17 @@ abstract class BulkExport if ($oInfo && ($oInfo->Get('user_id') == UserRights::GetUserId())) { $sFormatCode = $oInfo->Get('format'); - $oSearch = DBObjectSearch::unserialize($oInfo->Get('search')); + $aStatusInfo = json_decode($oInfo->Get('status_info'),true); + $oSearch = DBObjectSearch::unserialize($oInfo->Get('search')); + $oSearch->SetShowObsoleteData($aStatusInfo['show_obsolete_data']); $oBulkExporter = self::FindExporter($sFormatCode, $oSearch); if ($oBulkExporter) { $oBulkExporter->SetFormat($sFormatCode); $oBulkExporter->SetObjectList($oSearch); $oBulkExporter->SetChunkSize($oInfo->Get('chunk_size')); - $oBulkExporter->SetStatusInfo(json_decode($oInfo->Get('status_info'), true)); + $oBulkExporter->SetStatusInfo($aStatusInfo); $oBulkExporter->SetLocalizeOutput($oInfo->Get('localize_output')); @@ -289,6 +293,7 @@ abstract class BulkExport */ public function SetObjectList(DBSearch $oSearch) { + $oSearch->SetShowObsoleteData($this->aStatusInfo['show_obsolete_data']); $this->oSearch = $oSearch; } diff --git a/tests/php-unit-tests/unitary-tests/core/BulkExportTest.php b/tests/php-unit-tests/unitary-tests/core/BulkExportTest.php new file mode 100644 index 000000000..189232700 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/BulkExportTest.php @@ -0,0 +1,162 @@ +[ + 'list_org' => [ + ['org1', true], + ['org2', true], + ['org3', false], + ['org4', true], + ['org5', true], + ['org6', false], + ['org7', true], + ['org8', true], + ['org9', false], + ['org11', true], + ['org12', false], + ['org13', true], + ['org14', true], + ], + 'export_org' => $sExportResultPage1, + 'nb_pages' => 1, + 'expected_status' =>'run' + ], + 'Page2'=>[ + 'list_org' => [ + ['org1', true], + ['org2', true], + ['org3', false], + ['org4', true], + ['org5', true], + ['org6', false], + ['org7', true], + ['org8', true], + ['org9', false], + ['org11', true], + ['org12', false], + ['org13', true], + ['org14', true], + ], + 'export_org' => $sExportResultPage2, + 'nb_pages' => 2, + 'expected_status' =>'done' + ] + ]; + } + + /** + * @dataProvider OrganizationsForExportProvider + * + * @param $aListOrg + * @param $sExpectedValue + * @param $iNbPage + * @param $sExpectedStatus + * + * @throws \OQLException + * @throws \ReflectionException + */ + public function testExportWithShowObsoleteParam($aListOrg, + $sExpectedValue, $iNbPage, $sExpectedStatus) + { + // Create tests organizations to have enough data (some obsolete) + $iFirstOrg = 0; + foreach ($aListOrg as $aOrg) { + $oObj = $this->CreateOrganization($aOrg[0]); + if ($aOrg[1] === false) { + $oObj->Set('status', 'inactive'); + $oObj->DBUpdate(); + } + if($iFirstOrg === 0){ + $iFirstOrg = $oObj->GetKey(); + } + } + + $aResult = [ + // Fallback error, just in case + 'code' => 'error', + 'percentage' => 100, + 'message' => "Export not found for token", + ]; + + // Prepare status info and for obsolete data to `false` in order to check that we have less organizations + // in the export result than we have in DB + $aStatusInfo = [ + "fields" => [ + [ + "sFieldSpec" => "name", + "sAlias" => "Organization", + "sClass" => "Organization", + "sAttCode" => "name", + "sLabel" => "Name", + "sColLabel" => "Name" + ] + ], + "text_qualifier" => "\"", + "charset" => "ISO-8859-1", + "separator" => ",", + "date_format" => "Y-m-d H:i:s", + "formatted_text" => false, + "show_obsolete_data" => false + ]; + + $oSearch = DBObjectSearch::FromOQL('SELECT Organization WHERE id >= '.$iFirstOrg); + $oExporter = BulkExport::FindExporter('csv', $oSearch); + $oExporter->SetStatusInfo($aStatusInfo); + $oExporter->SetObjectList($oSearch); + $oExporter->SetChunkSize(5); + + $data = $oExporter->GetHeader(); + + for ($i = 0; $i < $iNbPage; $i++) { + $data .= $oExporter->GetNextChunk($aResult); + } + $this->assertEquals($sExpectedStatus,$aResult['code']); + $this->assertEquals($sExpectedValue, $data); + } + +}