public function ReadParameters() { parent::ReadParameters(); $sQueryId = utils::ReadParam('query', null, true); $sFields = utils::ReadParam('fields', null, true, 'raw_data'); if (($sFields === null || $sFields === '') && $sQueryId === null) { throw new BulkExportMissingParameterException('fields'); } else { if ($sQueryId !== null && $sQueryId !== null) { $oSearch = DBObjectSearch::FromOQL('SELECT QueryOQL WHERE id = :query_id', array('query_id' => $sQueryId)); $oQueries = new DBObjectSet($oSearch); if ($oQueries->Count() > 0) { $oQuery = $oQueries->Fetch(); if ($sFields === null || $sFields === '') { // 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)); } } } $aFields = explode(',', $sFields); $this->aStatusInfo['fields'] = array(); foreach ($aFields as $sField) { // Trim the values since it's too temping to write: fields=name, first_name, org_name instead of fields=name,first_name,org_name $this->aStatusInfo['fields'][] = trim($sField); } }
function DoExport(Page $oP, BulkExport $oExporter, $bInteractive = false) { $exportResult = $oExporter->GetHeader(); $aStatus = array(); do { $exportResult .= $oExporter->GetNextChunk($aStatus); } while ($aStatus['code'] != 'done' && $aStatus['code'] != 'error'); if ($aStatus['code'] == 'error') { $oExporter->Cleanup(); ReportErrorAndExit("Export failed: '{$aStatus['message']}'"); } else { $exportResult .= $oExporter->GetFooter(); $oP->SetContentType($oExporter->GetMimeType()); $oP->add($exportResult); $oExporter->Cleanup(); } }
public function ReadParameters() { parent::ReadParameters(); $sQueryId = utils::ReadParam('query', null, true); $sFields = utils::ReadParam('fields', null, true, 'raw_data'); if (($sFields === null || $sFields === '') && $sQueryId === null) { throw new BulkExportMissingParameterException('fields'); } else { if ($sQueryId !== null && $sQueryId !== null) { $oSearch = DBObjectSearch::FromOQL('SELECT QueryOQL WHERE id = :query_id', array('query_id' => $sQueryId)); $oQueries = new DBObjectSet($oSearch); if ($oQueries->Count() > 0) { $oQuery = $oQueries->Fetch(); if ($sFields === null || $sFields === '') { // 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)); } } } // Interpret (and check) the list of fields // $aSelectedClasses = $this->oSearch->GetSelectedClasses(); $aAliases = array_keys($aSelectedClasses); $aAuthorizedClasses = array(); foreach ($aSelectedClasses as $sAlias => $sClassName) { if (UserRights::IsActionAllowed($sClassName, UR_ACTION_BULK_READ) == UR_ALLOWED_YES) { $aAuthorizedClasses[$sAlias] = $sClassName; } } $aFields = explode(',', $sFields); $this->aStatusInfo['fields'] = array(); foreach ($aFields as $sFieldSpec) { // Trim the values since it's natural to write: fields=name, first_name, org_name instead of fields=name,first_name,org_name $sExtendedAttCode = trim($sFieldSpec); if (preg_match('/^([^\\.]+)\\.(.+)$/', $sExtendedAttCode, $aMatches)) { $sAlias = $aMatches[1]; $sAttCode = $aMatches[2]; } else { $sAlias = reset($aAliases); $sAttCode = $sExtendedAttCode; } if (!array_key_exists($sAlias, $aSelectedClasses)) { throw new Exception("Invalid alias '{$sAlias}' for the column '{$sExtendedAttCode}'. Availables aliases: '" . implode("', '", $aAliases) . "'"); } $sClass = $aSelectedClasses[$sAlias]; if (!array_key_exists($sAlias, $aAuthorizedClasses)) { throw new Exception("You do not have enough permissions to bulk read data of class '{$sClass}' (alias: {$sAlias})"); } if ($this->bLocalizeOutput) { try { $sLabel = MetaModel::GetLabel($sClass, $sAttCode); } catch (Exception $e) { throw new Exception("Wrong field specification '{$sFieldSpec}': " . $e->getMessage()); } } else { $sLabel = $sAttCode; } if (count($aAuthorizedClasses) > 1) { $sColLabel = $sAlias . '.' . $sLabel; } else { $sColLabel = $sLabel; } $this->aStatusInfo['fields'][] = array('sFieldSpec' => $sExtendedAttCode, 'sAlias' => $sAlias, 'sClass' => $sClass, 'sAttCode' => $sAttCode, 'sLabel' => $sLabel, 'sColLabel' => $sColLabel); } }
$oExporter = BulkExport::FindExporterFromToken($token); if ($oExporter) { $sMimeType = $oExporter->GetMimeType(); if (substr($sMimeType, 0, 5) == 'text/') { $sMimeType .= ';charset=' . strtolower($oExporter->GetCharacterSet()); } $oPage->SetContentType($sMimeType); $oPage->SetContentDisposition('attachment', $oExporter->GetDownloadFileName()); $oPage->add(file_get_contents($oExporter->GetTmpFilePath())); } } break; case 'export_cancel': $token = utils::ReadParam('token', null); if ($token !== null) { $oExporter = BulkExport::FindExporterFromToken($token); if ($oExporter) { $oExporter->Cleanup(); } } $aResult = array('code' => 'error', 'percentage' => 100, 'message' => Dict::S('Core:BulkExport:ExportCancelledByUser')); $oPage->add(json_encode($aResult)); break; case 'extend_lock': $sObjClass = utils::ReadParam('obj_class', '', false, 'class'); $iObjKey = (int) utils::ReadParam('obj_key', 0, false, 'integer'); $sToken = utils::ReadParam('token', 0, false, 'raw_data'); $aResult = iTopOwnershipLock::ExtendLock($sObjClass, $iObjKey, $sToken); if (!$aResult['status']) { if ($aResult['operation'] == 'lost') { $sName = $aResult['owner']->GetName();
function DoExport(WebPage $oP, BulkExport $oExporter, $bInteractive = false) { $oExporter->SetHttpHeaders($oP); $exportResult = $oExporter->GetHeader(); $aStatus = array(); do { $exportResult .= $oExporter->GetNextChunk($aStatus); } while ($aStatus['code'] != 'done' && $aStatus['code'] != 'error'); if ($aStatus['code'] == 'error') { $oExporter->Cleanup(); ReportErrorAndExit("Export failed: '{$aStatus['message']}'"); } else { $exportResult .= $oExporter->GetFooter(); $sMimeType = $oExporter->GetMimeType(); if (substr($sMimeType, 0, 5) == 'text/') { $sMimeType .= ';charset=' . strtolower($oExporter->GetCharacterSet()); } $oP->SetContentType($sMimeType); $oP->SetContentDisposition('attachment', $oExporter->GetDownloadFileName()); $oP->add($exportResult); $oExporter->Cleanup(); } }
public function ReadParameters() { parent::ReadParameters(); $this->aStatusInfo['localize'] = utils::ReadParam('no_localize', 0) != 1; }
public function ReadParameters() { parent::ReadParameters(); $this->aStatusInfo['linksets'] = utils::ReadParam('linksets', 0) == 1; }