Update website

This commit is contained in:
Guilhem Lavaux 2025-02-11 21:30:02 +01:00
parent 0a686aeb9a
commit c4ffa0f6ee
4360 changed files with 1727 additions and 718385 deletions

View file

@ -1,109 +0,0 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Import;
use PhpMyAdmin\Core;
use function function_exists;
use function ini_get;
use function json_encode;
use function ucwords;
use function uniqid;
/**
* Handles plugins that show the upload progress.
*/
final class Ajax
{
/**
* Sets up some variables for upload progress
*/
public static function uploadProgressSetup(): array
{
/**
* constant for differentiating array in $_SESSION variable
*/
$SESSION_KEY = '__upload_status';
/**
* sets default plugin for handling the import process
*/
$_SESSION[$SESSION_KEY]['handler'] = '';
/**
* unique ID for each upload
*/
$upload_id = uniqid('');
/**
* list of available plugins
*/
$plugins = [
// in PHP 5.4 session-based upload progress was problematic, see closed bug 3964
//"session",
'progress',
'noplugin',
];
// select available plugin
foreach ($plugins as $plugin) {
$check = $plugin . 'Check';
if (self::$check()) {
$upload_class = 'PhpMyAdmin\Plugins\Import\Upload\Upload' . ucwords($plugin);
$_SESSION[$SESSION_KEY]['handler'] = $upload_class;
break;
}
}
return [
$SESSION_KEY,
$upload_id,
$plugins,
];
}
/**
* Checks if PhpMyAdmin\Plugins\Import\Upload\UploadProgress bar extension is
* available.
*/
public static function progressCheck(): bool
{
return function_exists('uploadprogress_get_info');
}
/**
* Checks if PHP 5.4 session upload-progress feature is available.
*/
public static function sessionCheck(): bool
{
return ini_get('session.upload_progress.enabled') === '1';
}
/**
* Default plugin for handling import.
* If no other plugin is available, noplugin is used.
*
* @return true
*/
public static function nopluginCheck(): bool
{
return true;
}
/**
* The function outputs json encoded status of uploaded.
* It uses PMA_getUploadStatus, which is defined in plugin's file.
*
* @param string $id ID of transfer, usually $upload_id
*/
public static function status($id): void
{
Core::headerJSON();
echo json_encode(
$_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getUploadStatus($id)
);
}
}

View file

@ -1,160 +0,0 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Import;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Statement;
use PhpMyAdmin\SqlParser\Statements\DeleteStatement;
use PhpMyAdmin\SqlParser\Statements\UpdateStatement;
use PhpMyAdmin\SqlParser\Utils\Query;
use PhpMyAdmin\Url;
use function implode;
use function strtoupper;
final class SimulateDml
{
/** @var DatabaseInterface */
private $dbi;
public function __construct(DatabaseInterface $dbi)
{
$this->dbi = $dbi;
}
public function getError(): string
{
return $this->dbi->getError();
}
/**
* Find the matching rows for UPDATE/DELETE query.
*
* @param DeleteStatement|UpdateStatement|Statement $statement
*
* @return array<string, int|string>
* @psalm-return array{
* sql_query: string,
* matched_rows: (int|numeric-string),
* matched_rows_url: string
* }
*/
public function getMatchedRows(string $query, Parser $parser, $statement): array
{
$matchedRowQuery = '';
if ($statement instanceof DeleteStatement) {
$matchedRowQuery = $this->getSimulatedDeleteQuery($parser, $statement);
} elseif ($statement instanceof UpdateStatement) {
$matchedRowQuery = $this->getSimulatedUpdateQuery($parser, $statement);
}
// Execute the query and get the number of matched rows.
$matchedRows = $this->executeMatchedRowQuery($matchedRowQuery);
$matchedRowsUrl = Url::getFromRoute('/sql', [
'db' => $GLOBALS['db'],
'sql_query' => $matchedRowQuery,
'sql_signature' => Core::signSqlQuery($matchedRowQuery),
]);
return [
'sql_query' => Html\Generator::formatSql($query),
'matched_rows' => $matchedRows,
'matched_rows_url' => $matchedRowsUrl,
];
}
/**
* Executes the matched_row_query and returns the resultant row count.
*
* @param string $matchedRowQuery SQL query
*
* @return int|string
* @psalm-return int|numeric-string
*/
private function executeMatchedRowQuery(string $matchedRowQuery)
{
$this->dbi->selectDb($GLOBALS['db']);
// Execute the query.
$result = $this->dbi->tryQuery($matchedRowQuery);
if (! $result) {
return 0;
}
// Count the number of rows in the result set.
return $result->numRows();
}
/**
* Transforms a DELETE query into SELECT statement.
*
* @return string SQL query
*/
private function getSimulatedDeleteQuery(Parser $parser, DeleteStatement $statement): string
{
$tableReferences = Query::getTables($statement);
$where = Query::getClause($statement, $parser->list, 'WHERE');
if (empty($where)) {
$where = '1';
}
$orderAndLimit = '';
if (! empty($statement->order)) {
$orderAndLimit .= ' ORDER BY ' . Query::getClause($statement, $parser->list, 'ORDER BY');
}
if (! empty($statement->limit)) {
$orderAndLimit .= ' LIMIT ' . Query::getClause($statement, $parser->list, 'LIMIT');
}
return 'SELECT * FROM ' . implode(', ', $tableReferences) .
' WHERE ' . $where . $orderAndLimit;
}
/**
* Transforms a UPDATE query into SELECT statement.
*
* @return string SQL query
*/
private function getSimulatedUpdateQuery(Parser $parser, UpdateStatement $statement): string
{
$tableReferences = Query::getTables($statement);
$where = Query::getClause($statement, $parser->list, 'WHERE');
if (empty($where)) {
$where = '1';
}
$columns = [];
$diff = [];
foreach ($statement->set as $set) {
$columns[] = $set->column;
$notEqualOperator = ' <> ';
if (strtoupper($set->value) === 'NULL') {
$notEqualOperator = ' IS NOT ';
}
$diff[] = $set->column . $notEqualOperator . $set->value;
}
if (! empty($diff)) {
$where .= ' AND (' . implode(' OR ', $diff) . ')';
}
$orderAndLimit = '';
if (! empty($statement->order)) {
$orderAndLimit .= ' ORDER BY ' . Query::getClause($statement, $parser->list, 'ORDER BY');
}
if (! empty($statement->limit)) {
$orderAndLimit .= ' LIMIT ' . Query::getClause($statement, $parser->list, 'LIMIT');
}
return 'SELECT ' . implode(', ', $columns) .
' FROM ' . implode(', ', $tableReferences) .
' WHERE ' . $where . $orderAndLimit;
}
}