PMA\libraries\Table::saveUiPrefsToDb PHP Method

saveUiPrefsToDb() protected method

Save this table's UI preferences into phpMyAdmin database.
protected saveUiPrefsToDb ( ) : true | Message
return true | Message
    protected function saveUiPrefsToDb()
    {
        $cfgRelation = PMA_getRelationsParam();
        $pma_table = Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['table_uiprefs']);
        $secureDbName = $GLOBALS['dbi']->escapeString($this->_db_name);
        $username = $GLOBALS['cfg']['Server']['user'];
        $sql_query = " REPLACE INTO " . $pma_table . " (username, db_name, table_name, prefs) VALUES ('" . $GLOBALS['dbi']->escapeString($username) . "', '" . $secureDbName . "', '" . $GLOBALS['dbi']->escapeString($this->_name) . "', '" . $GLOBALS['dbi']->escapeString(json_encode($this->uiprefs)) . "')";
        $success = $this->_dbi->tryQuery($sql_query, $GLOBALS['controllink']);
        if (!$success) {
            $message = Message::error(__('Could not save table UI preferences!'));
            $message->addMessage(Message::rawError($this->_dbi->getError($GLOBALS['controllink'])), '<br /><br />');
            return $message;
        }
        // Remove some old rows in table_uiprefs if it exceeds the configured
        // maximum rows
        $sql_query = 'SELECT COUNT(*) FROM ' . $pma_table;
        $rows_count = $this->_dbi->fetchValue($sql_query);
        $max_rows = $GLOBALS['cfg']['Server']['MaxTableUiprefs'];
        if ($rows_count > $max_rows) {
            $num_rows_to_delete = $rows_count - $max_rows;
            $sql_query = ' DELETE FROM ' . $pma_table . ' ORDER BY last_update ASC' . ' LIMIT ' . $num_rows_to_delete;
            $success = $this->_dbi->tryQuery($sql_query, $GLOBALS['controllink']);
            if (!$success) {
                $message = Message::error(sprintf(__('Failed to cleanup table UI preferences (see ' . '$cfg[\'Servers\'][$i][\'MaxTableUiprefs\'] %s)'), Util::showDocu('config', 'cfg_Servers_MaxTableUiprefs')));
                $message->addMessage(Message::rawError($this->_dbi->getError($GLOBALS['controllink'])), '<br /><br />');
                return $message;
            }
        }
        return true;
    }