pageSettings->init('Export'); $pageSettingsErrorHtml = $this->pageSettings->getErrorHTML(); $pageSettingsHtml = $this->pageSettings->getHTML(); $this->response->addScriptFiles(['export.js']); $isRawQuery = $request->has('raw_query'); if (Current::$database === '' && ! $isRawQuery) { return $this->response->missingParameterError('db'); } if (Current::$table === '' && ! $isRawQuery) { return $this->response->missingParameterError('table'); } UrlParams::$params = ['db' => Current::$database, 'table' => Current::$table]; UrlParams::$params['goto'] = Url::getFromRoute('/table/export'); UrlParams::$params['back'] = Url::getFromRoute('/table/export'); // When we have some query, we need to remove LIMIT from that and possibly // generate WHERE clause (if we are asked to export specific rows) if (Current::$sqlQuery !== '') { $parser = new Parser(Current::$sqlQuery); if (! empty($parser->statements[0]) && $parser->statements[0] instanceof SelectStatement) { // Checking if the WHERE clause has to be replaced. $replaces = []; if (is_array(Current::$whereClause) && Current::$whereClause !== []) { $replaces[] = ['WHERE', 'WHERE (' . implode(') OR (', Current::$whereClause) . ')']; } // Preparing to remove the LIMIT clause. $replaces[] = ['LIMIT', '']; // Replacing the clauses. Current::$sqlQuery = Query::replaceClauses($parser->statements[0], $parser->list, $replaces); } } if ($request->has('single_table')) { Export::$singleTable = (bool) $request->getParam('single_table'); } $exportList = Plugins::getExport(ExportType::Table, Export::$singleTable); if ($exportList === []) { $this->response->addHTML(Message::error( __('Could not load export plugins, please check your installation!'), )->getDisplay()); return $this->response->response(); } $exportType = ExportType::Table; $isReturnBackFromRawExport = $request->getParsedBodyParam('export_type') === 'raw'; if ($request->hasBodyParam('raw_query') || $isReturnBackFromRawExport) { $exportType = ExportType::Raw; } $options = $this->export->getOptions( $exportType, Current::$database, Current::$table, Current::$sqlQuery, Current::$numTables, 0, $exportList, $request->getParam('format'), $request->getParam('what'), ); $this->response->render('table/export/index', array_merge($options, [ 'export_type' => $exportType->value, 'page_settings_error_html' => $pageSettingsErrorHtml, 'page_settings_html' => $pageSettingsHtml, ])); return $this->response->response(); } }