diff --git a/core/bulkexport.class.inc.php b/core/bulkexport.class.inc.php index 95e75f8c5..9aa624b15 100644 --- a/core/bulkexport.class.inc.php +++ b/core/bulkexport.class.inc.php @@ -74,7 +74,11 @@ class BulkExportResult extends DBObject MetaModel::Init_AddAttribute(new AttributeLongText("search", array("allowed_values"=>null, "sql"=>"search", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); MetaModel::Init_AddAttribute(new AttributeLongText("status_info", array("allowed_values"=>null, "sql"=>"status_info", "default_value"=>'', "is_null_allowed"=>false, "depends_on"=>array()))); } - + + /** + * @throws CoreUnexpectedValue + * @throws Exception + */ public function ComputeValues() { $this->Set('user_id', UserRights::GetUserId()); @@ -150,9 +154,9 @@ abstract class BulkExport /** * Find the first class capable of exporting the data in the given format - * @param string $sFormat The lowercase format (e.g. html, csv, spreadsheet, xlsx, xml, json, pdf...) + * @param string $sFormatCode The lowercase format (e.g. html, csv, spreadsheet, xlsx, xml, json, pdf...) * @param DBSearch $oSearch The search/filter defining the set of objects to export or null when listing the supported formats - * @return iBulkExport|NULL + * @return BulkExport|NULL */ static public function FindExporter($sFormatCode, $oSearch = null) { @@ -202,7 +206,11 @@ abstract class BulkExport } return $oBulkExporter; } - + + /** + * @param $data + * @throws Exception + */ public function AppendToTmpFile($data) { if ($this->sTmpFile == '') @@ -221,10 +229,10 @@ abstract class BulkExport { return $this->sTmpFile; } - + /** * Lists all possible export formats. The output is a hash array in the form: 'format_code' => 'localized format label' - * @return multitype:string + * @return array :string */ static public function FindSupportedFormats() { @@ -288,13 +296,21 @@ abstract class BulkExport { } + /** + * @return string + */ public function GetHeader() { + return ''; } abstract public function GetNextChunk(&$aStatus); + + /** + * @return string + */ public function GetFooter() { - + return ''; } public function SaveState() @@ -355,13 +371,21 @@ abstract class BulkExport { } + + /** + * @return string + */ public function GetMimeType() { - + return ''; } + + /** + * @return string + */ public function GetFileExtension() { - + return ''; } public function GetCharacterSet() { @@ -388,6 +412,11 @@ abstract class BulkExport return $this->aStatusInfo; } + /** + * @param $sExtension + * @return string + * @throws Exception + */ protected function MakeTmpFile($sExtension) { if(!is_dir(APPROOT."data/bulk_export")) @@ -401,7 +430,6 @@ abstract class BulkExport } $iNum = rand(); - $sFileName = ''; do { $iNum++; diff --git a/webservices/export-v2.php b/webservices/export-v2.php index 157eec5ab..26a30a50c 100644 --- a/webservices/export-v2.php +++ b/webservices/export-v2.php @@ -37,6 +37,7 @@ require_once(APPROOT.'/core/bulkexport.class.inc.php'); require_once(APPROOT.'/application/startup.inc.php'); + function ReportErrorAndExit($sErrorMessage) { if (utils::IsModeCLI()) @@ -44,14 +45,14 @@ function ReportErrorAndExit($sErrorMessage) $oP = new CLIPage("iTop - Export"); $oP->p('ERROR: '.$sErrorMessage); $oP->output(); - exit -1; + exit(-1); } else { $oP = new WebPage("iTop - Export"); $oP->p('ERROR: '.$sErrorMessage); $oP->output(); - exit -1; + exit(-1); } } @@ -63,7 +64,7 @@ function ReportErrorAndUsage($sErrorMessage) $oP->p('ERROR: '.$sErrorMessage); Usage($oP); $oP->output(); - exit -1; + exit(-1); } else { @@ -71,7 +72,7 @@ function ReportErrorAndUsage($sErrorMessage) $oP->p('ERROR: '.$sErrorMessage); Usage($oP); $oP->output(); - exit -1; + exit(-1); } } @@ -117,10 +118,10 @@ function Usage(Page $oP) } } } - if (!Utils::IsModeCLI()) - { - //$oP->add(''); - } + //if (!Utils::IsModeCLI()) + //{ + // $oP->add(''); + //} } function DisplayExpressionForm(WebPage $oP, $sAction, $sExpression = '', $sExceptionMessage = '') @@ -399,7 +400,7 @@ EOF { if (utils::IsModeCLI()) { - Usage(); + Usage($oP); ReportErrorAndExit("No expression or query phrasebook identifier supplied."); } else @@ -442,9 +443,7 @@ 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 + * @return BulkExport */ function CheckParameters($sExpression, $sQueryId, $sFormat) { @@ -511,14 +510,17 @@ function CheckParameters($sExpression, $sQueryId, $sFormat) } catch(MissingQueryArgument $e) { + $oSearch = null; ReportErrorAndUsage("Invalid OQL query: '$sExpression'.\n".$e->getMessage()); } catch(OQLException $e) { + $oSearch = null; ReportErrorAndExit("Invalid OQL query: '$sExpression'.\n".$e->getMessage()); } catch(Exception $e) { + $oSearch = null; ReportErrorAndExit($e->getMessage()); } @@ -577,7 +579,7 @@ if (utils::IsModeCLI()) catch(Exception $e) { echo "Error: ".$e->GetMessage()."
\n"; - exit -2; + exit(-2); } $sAuthUser = utils::ReadParam('auth_user', null, true /* Allow CLI */, 'raw_data');