PMA\libraries\plugins\export\ExportSql::_exportMetadata PHP Method

_exportMetadata() private method

Exports metadata from Configuration Storage
private _exportMetadata ( string $db, string $table, array $metadataTypes ) : boolean
$db string database being exported
$table string table being exported
$metadataTypes array types of metadata to export
return boolean Whether it succeeded
    private function _exportMetadata($db, $table, $metadataTypes)
    {
        $cfgRelation = PMA_getRelationsParam();
        if (isset($table)) {
            $types = array('column_info' => 'db_name', 'table_uiprefs' => 'db_name', 'tracking' => 'db_name');
        } else {
            $types = array('bookmark' => 'dbase', 'relation' => 'master_db', 'pdf_pages' => 'db_name', 'savedsearches' => 'db_name', 'central_columns' => 'db_name');
        }
        $aliases = array();
        $comment = $this->_possibleCRLF() . $this->_exportComment();
        if (isset($table)) {
            $comment .= $this->_exportComment(sprintf(__('Metadata for table %s'), $table));
        } else {
            $comment .= $this->_exportComment(sprintf(__('Metadata for database %s'), $db));
        }
        $comment .= $this->_exportComment();
        if (!PMA_exportOutputHandler($comment)) {
            return false;
        }
        foreach ($types as $type => $dbNameColumn) {
            if (in_array($type, $metadataTypes) && isset($cfgRelation[$type])) {
                // special case, designer pages and their coordinates
                if ($type == 'pdf_pages') {
                    $sql_query = "SELECT `page_nr`, `page_descr` FROM " . Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation[$type]) . " WHERE " . Util::backquote($dbNameColumn) . " = '" . $GLOBALS['dbi']->escapeString($db) . "'";
                    $result = $GLOBALS['dbi']->fetchResult($sql_query, 'page_nr', 'page_descr');
                    foreach ($result as $page => $name) {
                        // insert row for pdf_page
                        $sql_query_row = "SELECT `db_name`, `page_descr` FROM " . Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation[$type]) . " WHERE " . Util::backquote($dbNameColumn) . " = '" . $GLOBALS['dbi']->escapeString($db) . "'" . " AND `page_nr` = '" . intval($page) . "'";
                        if (!$this->exportData($cfgRelation['db'], $cfgRelation[$type], $GLOBALS['crlf'], '', $sql_query_row, $aliases)) {
                            return false;
                        }
                        $lastPage = $GLOBALS['crlf'] . "SET @LAST_PAGE = LAST_INSERT_ID();" . $GLOBALS['crlf'];
                        if (!PMA_exportOutputHandler($lastPage)) {
                            return false;
                        }
                        $sql_query_coords = "SELECT `db_name`, `table_name`, " . "'@LAST_PAGE' AS `pdf_page_number`, `x`, `y` FROM " . Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['table_coords']) . " WHERE `pdf_page_number` = '" . $page . "'";
                        $GLOBALS['exporting_metadata'] = true;
                        if (!$this->exportData($cfgRelation['db'], $cfgRelation['table_coords'], $GLOBALS['crlf'], '', $sql_query_coords, $aliases)) {
                            $GLOBALS['exporting_metadata'] = false;
                            return false;
                        }
                        $GLOBALS['exporting_metadata'] = false;
                    }
                    continue;
                }
                // remove auto_incrementing id field for some tables
                if ($type == 'bookmark') {
                    $sql_query = "SELECT `dbase`, `user`, `label`, `query` FROM ";
                } elseif ($type == 'column_info') {
                    $sql_query = "SELECT `db_name`, `table_name`, `column_name`," . " `comment`, `mimetype`, `transformation`," . " `transformation_options`, `input_transformation`," . " `input_transformation_options` FROM";
                } elseif ($type == 'savedsearches') {
                    $sql_query = "SELECT `username`, `db_name`, `search_name`," . " `search_data` FROM";
                } else {
                    $sql_query = "SELECT * FROM ";
                }
                $sql_query .= Util::backquote($cfgRelation['db']) . '.' . Util::backquote($cfgRelation[$type]) . " WHERE " . Util::backquote($dbNameColumn) . " = '" . $GLOBALS['dbi']->escapeString($db) . "'";
                if (isset($table)) {
                    $sql_query .= " AND `table_name` = '" . $GLOBALS['dbi']->escapeString($table) . "'";
                }
                if (!$this->exportData($cfgRelation['db'], $cfgRelation[$type], $GLOBALS['crlf'], '', $sql_query, $aliases)) {
                    return false;
                }
            }
        }
        return true;
    }