Archives: added the option with_archive to export web services (defaults to 0)

SVN:trunk[4711]
This commit is contained in:
Romain Quetiez
2017-04-27 15:03:24 +00:00
parent c66728e478
commit ea2681e08c
3 changed files with 46 additions and 9 deletions

View File

@@ -153,8 +153,11 @@ class utils
{
$iDefault = 0;
}
$iCurrent = self::ReadParam('with-archive', $iDefault, true);
// Read and record the value for switching the archive mode
$iCurrent = self::ReadParam('with-archive', $iDefault);
$_SESSION['archive_mode'] = $iCurrent;
// Read and use the value for the current page (web services)
$iCurrent = self::ReadParam('with_archive', $iCurrent, true);
self::$bPageMode = ($iCurrent == 1);
}

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2015-2016 Combodo SARL
// Copyright (C) 2015-2017 Combodo SARL
//
// This file is part of iTop.
//
@@ -19,7 +19,7 @@
/**
* Export data specified by an OQL or a query phrasebook entry
*
* @copyright Copyright (C) 2015-2016 Combodo SARL
* @copyright Copyright (C) 2015-2017 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -90,6 +90,14 @@ function Usage(Page $oP)
}
$oP->p(" * expression: an OQL expression (e.g. SELECT Contact WHERE name LIKE 'm%')");
$oP->p(" * query: (alternative to 'expression') the id of an entry from the query phrasebook");
if (Utils::IsModeCLI())
{
$oP->p(" * with_archive: (optional, defaults to 0) if set to 1 then the result set will include archived objects");
}
else
{
$oP->p(" * with_archive: (optional, defaults to the current mode) if set to 1 then the result set will include archived objects");
}
$oP->p(" * arg_xxx: (needed if the query has parameters) the value of the parameter 'xxx'");
$aSupportedFormats = BulkExport::FindSupportedFormats();
$oP->p(" * format: (optional, default is html) the desired output format. Can be one of '".implode("', '", array_keys($aSupportedFormats))."'");
@@ -430,13 +438,19 @@ EOF
* @param string $sExpression The OQL query to export or null
* @param string $sQueryId The entry in the query phrasebook if $sExpression is null
* @param string $sFormat The code of export format: csv, pdf, html, xlsx
* @param boolean $bWithArchive
* @throws MissingQueryArgument
* @return Ambigous <iBulkExport, NULL>
*/
function CheckParameters($sExpression, $sQueryId, $sFormat)
{
$oExporter = null;
$oExporter = null;
if (utils::IsArchiveMode() && !UserRights::CanBrowseArchive())
{
ReportErrorAndExit("The user account is not authorized to access the archives");
}
if (($sExpression === null) && ($sQueryId === null))
{
ReportErrorAndUsage("Missing parameter. The parameter 'expression' or 'query' must be specified.");
@@ -485,7 +499,7 @@ function CheckParameters($sExpression, $sQueryId, $sFormat)
}
}
$oSearch->SetInternalParams($aArgs);
$sFormat = utils::ReadParam('format', 'html', true /* Allow CLI */, 'raw_data');
$oExporter = BulkExport::FindExporter($sFormat, $oSearch);
if ($oExporter == null)
@@ -588,7 +602,11 @@ if (utils::IsModeCLI())
$sExpression = utils::ReadParam('expression', null, true /* Allow CLI */, 'raw_data');
$sQueryId = utils::ReadParam('query', null, true /* Allow CLI */, 'raw_data');
$bLocalize = (utils::ReadParam('no_localize', 0) != 1);
if (utils::IsArchiveMode() && !UserRights::CanBrowseArchive())
{
ReportErrorAndExit("The user account is not authorized to access the archives");
}
if (($sExpression == null) && ($sQueryId == null))
{
ReportErrorAndUsage("Missing parameter. At least one of '--expression' or '--query' must be specified.");

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2010-2012 Combodo SARL
// Copyright (C) 2010-2017 Combodo SARL
//
// This file is part of iTop.
//
@@ -20,7 +20,7 @@
/**
* Export data specified by an OQL
*
* @copyright Copyright (C) 2010-2012 Combodo SARL
* @copyright Copyright (C) 2010-2017 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -76,6 +76,14 @@ $oAppContext = new ApplicationContext();
$iActiveNodeId = utils::ReadParam('menu', -1);
$currentOrganization = utils::ReadParam('org_id', '');
if (utils::IsArchiveMode() && !UserRights::CanBrowseArchive())
{
$oP = new CLIPage("iTop - Export");
$oP->p("The user account is not authorized to access the archives");
$oP->output();
exit -1;
}
$bLocalize = (utils::ReadParam('no_localize', 0) != 1);
$sFileName = utils::ReadParam('filename', '', true, 'string');
@@ -336,6 +344,14 @@ if (!$oP)
$oP->p("Parameters:");
$oP->p(" * expression: an OQL expression (URL encoded if needed)");
$oP->p(" * query: (alternative to 'expression') the id of an entry from the query phrasebook");
if (Utils::IsModeCLI())
{
$oP->p(" * with_archive: (optional, defaults to 0) if set to 1 then the result set will include archived objects");
}
else
{
$oP->p(" * with_archive: (optional, defaults to the current mode) if set to 1 then the result set will include archived objects");
}
$oP->p(" * arg_xxx: (needed if the query has parameters) the value of the parameter 'xxx'");
$oP->p(" * format: (optional, default is html) the desired output format. Can be one of 'html', 'spreadsheet', 'csv', 'xlsx' or 'xml'");
$oP->p(" * fields: (optional, no effect on XML format) list of fields (attribute codes, or alias.attcode) separated by a coma");