public function ReloadState()
 {
     if ($this->sToken == null) {
         throw new Exception('ExcelExporter not initialized with a token, cannot reload state');
     }
     if (!file_exists($this->GetStateFile())) {
         throw new Exception("ExcelExporter: missing status file '" . $this->GetStateFile() . "', cannot reload state.");
     }
     $sJson = file_get_contents($this->GetStateFile());
     $aState = json_decode($sJson, true);
     if ($aState === null) {
         throw new Exception("ExcelExporter:corrupted status file '" . $this->GetStateFile() . "', not a JSON, cannot reload state.");
     }
     $this->sState = $aState['state'];
     $this->aStatistics = $aState['statistics'];
     $this->oSearch = DBObjectSearch::unserialize($aState['filter']);
     $this->iPosition = $aState['position'];
     $this->iChunkSize = $aState['chunk_size'];
     $this->aObjectsIDs = $aState['object_ids'];
     $this->sOutputFilePath = $aState['output_file_path'];
     $this->bAdvancedMode = $aState['advanced_mode'];
 }
예제 #2
0
     // ui.linkswidget
 ////////////////////////////////////////////////////
 // ui.linkswidget
 case 'doAddObjects':
     $oPage->SetContentType('text/html');
     $sAttCode = utils::ReadParam('sAttCode', '');
     $iInputId = utils::ReadParam('iInputId', '');
     $sSuffix = utils::ReadParam('sSuffix', '');
     $sRemoteClass = utils::ReadParam('sRemoteClass', $sClass, false, 'class');
     $bDuplicates = utils::ReadParam('bDuplicates', 'false') == 'false' ? false : true;
     $sJson = utils::ReadParam('json', '', false, 'raw_data');
     $oWizardHelper = WizardHelper::FromJSON($sJson);
     $oObj = $oWizardHelper->GetTargetObject();
     $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
     if ($sFilter != '') {
         $oFullSetFilter = DBObjectSearch::unserialize($sFilter);
     } else {
         $oFullSetFilter = new DBObjectSearch($sRemoteClass);
     }
     $oWidget->DoAddObjects($oPage, $oFullSetFilter, $oObj);
     break;
     ////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////
 case 'wizard_helper_preview':
     $oPage->SetContentType('text/html');
     $sJson = utils::ReadParam('json_obj', '', false, 'raw_data');
     $oWizardHelper = WizardHelper::FromJSON($sJson);
     $oObj = $oWizardHelper->GetTargetObject();
     $oObj->DisplayBareProperties($oPage);
     break;
 case 'wizard_helper':
예제 #3
0
        $oP->EndCollapsibleSection();
    }
}
$sOperation = utils::ReadParam('operation', 'menu');
$oAppContext = new ApplicationContext();
$oP = new iTopWebPage(Dict::S('UI:RunQuery:Title'));
// Main program
$sExpression = utils::ReadParam('expression', '', false, 'raw_data');
$sEncoding = utils::ReadParam('encoding', 'oql');
ShowExamples($oP, $sExpression);
try {
    if ($sEncoding == 'crypted') {
        // Translate $sExpression into a oql expression
        $sClearText = base64_decode($sExpression);
        echo "<strong>FYI: '{$sClearText}'</strong><br/>\n";
        $oFilter = DBObjectSearch::unserialize($sExpression);
        $sExpression = $oFilter->ToOQL();
    } else {
        // leave $sExpression as is
    }
    $oFilter = null;
    $aArgs = array();
    $sSyntaxError = null;
    if (!empty($sExpression)) {
        try {
            $oFilter = DBObjectSearch::FromOQL($sExpression);
        } catch (Exception $e) {
            if ($e instanceof OqlException) {
                $sSyntaxError = $e->getHtmlDesc();
            } else {
                $sSyntaxError = $e->getMessage();
예제 #4
0
 protected function CheckQuery($sQuery, $bIsCorrectQuery)
 {
     if ($bIsCorrectQuery) {
         echo "<h4 style=\"color:green;\">{$sQuery}</h4>\n";
     } else {
         echo "<h4 style=\"color:red;\">{$sQuery}</h3>\n";
     }
     try {
         //$oOql = new OqlInterpreter($sQuery);
         //$oTrash = $oOql->ParseQuery();
         //self::DumpVariable($oTrash, true);
         $oMyFilter = DBObjectSearch::FromOQL($sQuery);
     } catch (OQLException $oOqlException) {
         if ($bIsCorrectQuery) {
             echo "<p>More info on this unexpected failure:<br/>" . $oOqlException->getHtmlDesc() . "</p>\n";
             throw $oOqlException;
             return false;
         } else {
             // Everything is fine :-)
             echo "<p>More info on this expected failure:\n";
             echo "<ul>\n";
             echo "<li>" . get_class($oOqlException) . "</li>\n";
             echo "<li>" . $oOqlException->getMessage() . "</li>\n";
             echo "<li>" . $oOqlException->getHtmlDesc() . "</li>\n";
             echo "</ul>\n";
             echo "</p>\n";
             return true;
         }
     }
     // The query was correctly parsed, was it expected to be correct ?
     if (!$bIsCorrectQuery) {
         throw new UnitTestException("The query '{$sQuery}' was parsed with success, while it shouldn't (?)");
         return false;
     }
     echo "<p>To OQL: " . $oMyFilter->ToOQL() . "</p>";
     $this->search_and_show_list($oMyFilter);
     //echo "<p>first pass<p>\n";
     //self::DumpVariable($oMyFilter, true);
     $sQuery1 = $oMyFilter->MakeSelectQuery();
     //echo "<p>second pass<p>\n";
     //self::DumpVariable($oMyFilter, true);
     //$sQuery1 = $oMyFilter->MakeSelectQuery();
     $sSerialize = $oMyFilter->serialize();
     echo "<p>Serialized:{$sSerialize}</p>\n";
     $oFilter2 = DBObjectSearch::unserialize($sSerialize);
     try {
         $sQuery2 = $oMyFilter2->MakeSelectQuery();
     } catch (Exception $e) {
         echo "<p>Could not compute the query after unserialize</p>\n";
         echo "<p>Query 1: {$sQuery1}</p>\n";
         MyHelpers::var_cmp_html($oMyFilter, $oFilter2);
         throw $e;
     }
     //if ($oFilter2 != $oMyFilter) no, they may differ while the resulting query is the same!
     if ($sQuery1 != $sQuery2) {
         echo "<p>serialize/unserialize mismatch :-(</p>\n";
         MyHelpers::var_cmp_html($sQuery1, $sQuery2);
         MyHelpers::var_cmp_html($oMyFilter, $oFilter2);
         return false;
     }
     return true;
 }
예제 #5
0
     $oPage->add('<p style="font-size:10pt;margin-left:2em;margin-top:-0.5em;padding-bottom:1em;">' . Dict::S('UI:CSVImport:AdvancedMode+') . '</p>');
     $oPage->add('<p><input type="checkbox" id="export-auto-download" checked="checked"/>&nbsp;<label for="export-auto-download">' . Dict::S('ExcelExport:AutoDownload') . '</label></p>');
     $oPage->add('</div>');
     $oPage->add('<div class="progress"><p class="status-message">' . Dict::S('ExcelExport:PreparingExport') . '</p><div class="progress-bar"><div class="progress-label"></div></div></div>');
     $oPage->add('<div class="statistics"><div class="stats-toggle closed">' . Dict::S('ExcelExport:Statistics') . '<div class="stats-data"></div></div></div>');
     $oPage->add('</div>');
     $aLabels = array('dialog_title' => Dict::S('ExcelExporter:ExportDialogTitle'), 'cancel_button' => Dict::S('UI:Button:Cancel'), 'export_button' => Dict::S('ExcelExporter:ExportButton'), 'download_button' => Dict::Format('ExcelExporter:DownloadButton', 'export.xlsx'));
     $sJSLabels = json_encode($aLabels);
     $sFilter = addslashes($sFilter);
     $sJSPageUrl = addslashes(utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.render.php');
     $oPage->add_ready_script("\$('#XlsxExportDlg').xlsxexporter({filter: '{$sFilter}', labels: {$sJSLabels}, ajax_page_url: '{$sJSPageUrl}'});");
     break;
 case 'xlsx_start':
     $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
     $bAdvanced = utils::ReadParam('advanced', 'false') == 'true';
     $oSearch = DBObjectSearch::unserialize($sFilter);
     $oExcelExporter = new ExcelExporter();
     $oExcelExporter->SetObjectList($oSearch);
     //$oExcelExporter->SetChunkSize(10); //Only for testing
     $oExcelExporter->SetAdvancedMode($bAdvanced);
     $sToken = $oExcelExporter->SaveState();
     $oPage->add(json_encode(array('status' => 'ok', 'token' => $sToken)));
     break;
 case 'xlsx_run':
     $sMemoryLimit = MetaModel::GetConfig()->Get('xlsx_exporter_memory_limit');
     ini_set('memory_limit', $sMemoryLimit);
     ini_set('max_execution_time', max(300, ini_get('max_execution_time')));
     // At least 5 minutes
     $sToken = utils::ReadParam('token', '', false, 'raw_data');
     $oExcelExporter = new ExcelExporter($sToken);
     $aStatus = $oExcelExporter->Run();
예제 #6
0
 /**
  * Find the exporter corresponding to the given persistent token
  * @param int $iPersistentToken The identifier of the BulkExportResult object storing the information
  * @return iBulkExport|NULL
  */
 public static function FindExporterFromToken($iPersistentToken = null)
 {
     $oBulkExporter = null;
     $oInfo = MetaModel::GetObject('BulkExportResult', $iPersistentToken, false);
     if ($oInfo && $oInfo->Get('user_id') == UserRights::GetUserId()) {
         $sFormatCode = $oInfo->Get('format');
         $oSearch = DBObjectSearch::unserialize($oInfo->Get('search'));
         $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->sTmpFile = $oInfo->Get('temp_file_path');
             $oBulkExporter->oBulkExportResult = $oInfo;
         }
     }
     return $oBulkExporter;
 }