From 5b0414371158ff4397f6ac2545da6d3b10f13539 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 21 Jul 2020 16:39:55 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B03111=20-=20Fix=20Portal=20export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/bulkexport.class.inc.php | 7 +++- core/excelbulkexport.class.inc.php | 3 +- core/tabularbulkexport.class.inc.php | 36 +++++++++++-------- .../portal/public/js/export.js | 4 +-- .../src/Controller/ManageBrickController.php | 12 +++++-- .../manage/popup-export-excel.html.twig | 3 +- pages/ajax.render.php | 9 +++++ 7 files changed, 52 insertions(+), 22 deletions(-) diff --git a/core/bulkexport.class.inc.php b/core/bulkexport.class.inc.php index bc6f9031e..dec6973e9 100644 --- a/core/bulkexport.class.inc.php +++ b/core/bulkexport.class.inc.php @@ -345,10 +345,10 @@ abstract class BulkExport $this->oBulkExportResult->Set('format', $this->sFormatCode); $this->oBulkExportResult->Set('search', $this->oSearch->serialize()); $this->oBulkExportResult->Set('chunk_size', $this->iChunkSize); - $this->oBulkExportResult->Set('temp_file_path', $this->sTmpFile); $this->oBulkExportResult->Set('localize_output', $this->bLocalizeOutput); } $this->oBulkExportResult->Set('status_info', json_encode($this->GetStatusInfo())); + $this->oBulkExportResult->Set('temp_file_path', $this->sTmpFile); utils::PushArchiveMode(false); $ret = $this->oBulkExportResult->DBWrite(); utils::PopArchiveMode(); @@ -420,6 +420,11 @@ abstract class BulkExport public function GetStatistics() { + } + + public function SetFields($sFields) + { + } public function GetDownloadFileName() diff --git a/core/excelbulkexport.class.inc.php b/core/excelbulkexport.class.inc.php index 6717adfbb..1d4569397 100644 --- a/core/excelbulkexport.class.inc.php +++ b/core/excelbulkexport.class.inc.php @@ -353,7 +353,8 @@ EOF $fStartExcel = microtime(true); $writer = new XLSXWriter(); - $oDateTimeFormat = new DateTimeFormat($this->aStatusInfo['date_format']); + $sDateFormat = isset($this->aStatusInfo['date_format']) ? $this->aStatusInfo['date_format'] : (string)AttributeDateTime::GetFormat(); + $oDateTimeFormat = new DateTimeFormat($sDateFormat); $writer->setDateTimeFormat($oDateTimeFormat->ToExcel()); $oDateFormat = new DateTimeFormat($oDateTimeFormat->ToDateFormat()); $writer->setDateFormat($oDateFormat->ToExcel()); diff --git a/core/tabularbulkexport.class.inc.php b/core/tabularbulkexport.class.inc.php index 1013474f0..0ec74c594 100644 --- a/core/tabularbulkexport.class.inc.php +++ b/core/tabularbulkexport.class.inc.php @@ -365,29 +365,37 @@ EOF { throw new BulkExportMissingParameterException('fields'); } - else if(($sQueryId !== null) && ($sQueryId !== null)) + else { - $oSearch = DBObjectSearch::FromOQL('SELECT QueryOQL WHERE id = :query_id', array('query_id' => $sQueryId)); - $oQueries = new DBObjectSet($oSearch); - if ($oQueries->Count() > 0) + if (($sQueryId !== null) && ($sQueryId !== null)) { - $oQuery = $oQueries->Fetch(); - if (($sFields === null) || ($sFields === '')) + $oSearch = DBObjectSearch::FromOQL('SELECT QueryOQL WHERE id = :query_id', array('query_id' => $sQueryId)); + $oQueries = new DBObjectSet($oSearch); + if ($oQueries->Count() > 0) { - // No 'fields' parameter supplied, take the fields from the query phrasebook definition - $sFields = trim($oQuery->Get('fields')); - if ($sFields === '') + $oQuery = $oQueries->Fetch(); + if (($sFields === null) || ($sFields === '')) { - throw new BulkExportMissingParameterException('fields'); + // No 'fields' parameter supplied, take the fields from the query phrasebook definition + $sFields = trim($oQuery->Get('fields')); + if ($sFields === '') + { + throw new BulkExportMissingParameterException('fields'); + } } } - } - else - { - throw BulkExportException('Invalid value for the parameter: query. There is no Query Phrasebook with id = '.$sQueryId, Dict::Format('Core:BulkExport:InvalidParameter_Query', $sQueryId)); + else + { + throw BulkExportException('Invalid value for the parameter: query. There is no Query Phrasebook with id = '.$sQueryId, Dict::Format('Core:BulkExport:InvalidParameter_Query', $sQueryId)); + } } } + $this->SetFields($sFields); + } + + public function SetFields($sFields) + { // Interpret (and check) the list of fields // $aSelectedClasses = $this->oSearch->GetSelectedClasses(); diff --git a/datamodels/2.x/itop-portal-base/portal/public/js/export.js b/datamodels/2.x/itop-portal-base/portal/public/js/export.js index d08762600..5334ac363 100644 --- a/datamodels/2.x/itop-portal-base/portal/public/js/export.js +++ b/datamodels/2.x/itop-portal-base/portal/public/js/export.js @@ -20,8 +20,8 @@ function ExportStartExport() { var oParams = {}; oParams.operation = 'export_build'; oParams.format = sFormat; - oParams.expression = sOQL; - oParams.fields = sFields; + oParams.token = sToken; + oParams.start = 1; $.post(GetAbsoluteUrlAppRoot() + 'pages/ajax.render.php', oParams, function (data) { if (data == null) { ExportError('Export failed (no data provided), please contact your administrator'); diff --git a/datamodels/2.x/itop-portal-base/portal/src/Controller/ManageBrickController.php b/datamodels/2.x/itop-portal-base/portal/src/Controller/ManageBrickController.php index ab8921327..3786612b3 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Controller/ManageBrickController.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Controller/ManageBrickController.php @@ -28,6 +28,7 @@ use AttributeImage; use AttributeSet; use AttributeTagSet; use BinaryExpression; +use BulkExport; use CMDBSource; use Combodo\iTop\Portal\Brick\AbstractBrick; use Combodo\iTop\Portal\Brick\ManageBrick; @@ -245,11 +246,18 @@ class ManageBrickController extends BrickController } $sFields = implode(',', $aFields); + $sFormat = 'xlsx'; + $oSearch->UpdateContextFromUser(); + $oExporter = BulkExport::FindExporter($sFormat, $oSearch); + $oExporter->SetObjectList($oSearch); + $oExporter->SetFormat($sFormat); + $oExporter->SetChunkSize(EXPORTER_DEFAULT_CHUNK_SIZE); + $oExporter->SetFields($sFields); + $aData = array( 'oBrick' => $oBrick, 'sBrickId' => $sBrickId, - 'sFields' => $sFields, - 'sOQL' => $oSearch->ToOQL(), + 'sToken' => $oExporter->SaveState(), ); return $this->render(static::EXCEL_EXPORT_TEMPLATE_PATH, $aData); diff --git a/datamodels/2.x/itop-portal-base/portal/templates/bricks/manage/popup-export-excel.html.twig b/datamodels/2.x/itop-portal-base/portal/templates/bricks/manage/popup-export-excel.html.twig index 4194af16c..32417e391 100644 --- a/datamodels/2.x/itop-portal-base/portal/templates/bricks/manage/popup-export-excel.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/templates/bricks/manage/popup-export-excel.html.twig @@ -27,9 +27,8 @@