Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
- Loading branch information
1 parent
00cb1b3
commit bfaf16f
Showing
39 changed files
with
2,069 additions
and
1,127 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
libraries/classes/Controllers/Sql/ColumnPreferencesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Sql; | ||
|
||
use PhpMyAdmin\CheckUserPrivileges; | ||
use PhpMyAdmin\Controllers\AbstractController; | ||
use PhpMyAdmin\DatabaseInterface; | ||
use PhpMyAdmin\Message; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Sql; | ||
use PhpMyAdmin\Template; | ||
|
||
final class ColumnPreferencesController extends AbstractController | ||
{ | ||
/** @var Sql */ | ||
private $sql; | ||
|
||
/** @var CheckUserPrivileges */ | ||
private $checkUserPrivileges; | ||
|
||
/** @var DatabaseInterface */ | ||
private $dbi; | ||
|
||
/** | ||
* @param ResponseRenderer $response | ||
* @param DatabaseInterface $dbi | ||
*/ | ||
public function __construct( | ||
$response, | ||
Template $template, | ||
Sql $sql, | ||
CheckUserPrivileges $checkUserPrivileges, | ||
$dbi | ||
) { | ||
parent::__construct($response, $template); | ||
$this->sql = $sql; | ||
$this->checkUserPrivileges = $checkUserPrivileges; | ||
$this->dbi = $dbi; | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
global $db, $table; | ||
|
||
$this->checkUserPrivileges->getPrivileges(); | ||
|
||
$tableObject = $this->dbi->getTable($db, $table); | ||
$status = false; | ||
|
||
// set column order | ||
if (isset($_POST['col_order'])) { | ||
$status = $this->sql->setColumnProperty($tableObject, 'col_order'); | ||
} | ||
|
||
// set column visibility | ||
if ($status === true && isset($_POST['col_visib'])) { | ||
$status = $this->sql->setColumnProperty($tableObject, 'col_visib'); | ||
} | ||
|
||
if ($status instanceof Message) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON('message', $status->getString()); | ||
|
||
return; | ||
} | ||
|
||
$this->response->setRequestStatus($status === true); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
libraries/classes/Controllers/Sql/DefaultForeignKeyCheckValueController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Sql; | ||
|
||
use PhpMyAdmin\CheckUserPrivileges; | ||
use PhpMyAdmin\Controllers\AbstractController; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Template; | ||
use PhpMyAdmin\Utils\ForeignKey; | ||
|
||
final class DefaultForeignKeyCheckValueController extends AbstractController | ||
{ | ||
/** @var CheckUserPrivileges */ | ||
private $checkUserPrivileges; | ||
|
||
/** | ||
* @param ResponseRenderer $response | ||
*/ | ||
public function __construct($response, Template $template, CheckUserPrivileges $checkUserPrivileges) | ||
{ | ||
parent::__construct($response, $template); | ||
$this->checkUserPrivileges = $checkUserPrivileges; | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
$this->checkUserPrivileges->getPrivileges(); | ||
$this->response->addJSON('default_fk_check_value', ForeignKey::isCheckEnabled()); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
libraries/classes/Controllers/Sql/EnumValuesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Sql; | ||
|
||
use PhpMyAdmin\CheckUserPrivileges; | ||
use PhpMyAdmin\Controllers\AbstractController; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Sql; | ||
use PhpMyAdmin\Template; | ||
|
||
use function __; | ||
use function htmlentities; | ||
|
||
use const ENT_COMPAT; | ||
|
||
final class EnumValuesController extends AbstractController | ||
{ | ||
/** @var Sql */ | ||
private $sql; | ||
|
||
/** @var CheckUserPrivileges */ | ||
private $checkUserPrivileges; | ||
|
||
/** | ||
* @param ResponseRenderer $response | ||
*/ | ||
public function __construct( | ||
$response, | ||
Template $template, | ||
Sql $sql, | ||
CheckUserPrivileges $checkUserPrivileges | ||
) { | ||
parent::__construct($response, $template); | ||
$this->sql = $sql; | ||
$this->checkUserPrivileges = $checkUserPrivileges; | ||
} | ||
|
||
/** | ||
* Get possible values for enum fields during grid edit. | ||
*/ | ||
public function __invoke(): void | ||
{ | ||
global $db, $table; | ||
|
||
$this->checkUserPrivileges->getPrivileges(); | ||
|
||
$column = $_POST['column']; | ||
$curr_value = $_POST['curr_value']; | ||
$values = $this->sql->getValuesForColumn($db, $table, $column); | ||
|
||
if ($values === null) { | ||
$this->response->addJSON('message', __('Error in processing request')); | ||
$this->response->setRequestStatus(false); | ||
|
||
return; | ||
} | ||
|
||
// Converts characters of $curr_value to HTML entities. | ||
$convertedCurrentValue = htmlentities($curr_value, ENT_COMPAT, 'UTF-8'); | ||
|
||
$dropdown = $this->template->render('sql/enum_column_dropdown', [ | ||
'values' => $values, | ||
'selected_values' => [$convertedCurrentValue], | ||
]); | ||
|
||
$this->response->addJSON('dropdown', $dropdown); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
libraries/classes/Controllers/Sql/RelationalValuesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Sql; | ||
|
||
use PhpMyAdmin\CheckUserPrivileges; | ||
use PhpMyAdmin\Controllers\AbstractController; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Sql; | ||
use PhpMyAdmin\Template; | ||
|
||
final class RelationalValuesController extends AbstractController | ||
{ | ||
/** @var Sql */ | ||
private $sql; | ||
|
||
/** @var CheckUserPrivileges */ | ||
private $checkUserPrivileges; | ||
|
||
/** | ||
* @param ResponseRenderer $response | ||
*/ | ||
public function __construct( | ||
$response, | ||
Template $template, | ||
Sql $sql, | ||
CheckUserPrivileges $checkUserPrivileges | ||
) { | ||
parent::__construct($response, $template); | ||
$this->sql = $sql; | ||
$this->checkUserPrivileges = $checkUserPrivileges; | ||
} | ||
|
||
/** | ||
* Get values for the relational columns | ||
* | ||
* During grid edit, if we have a relational field, show the dropdown for it. | ||
*/ | ||
public function __invoke(): void | ||
{ | ||
global $db, $table; | ||
|
||
$this->checkUserPrivileges->getPrivileges(); | ||
|
||
$column = $_POST['column']; | ||
if ( | ||
$_SESSION['tmpval']['relational_display'] === 'D' | ||
&& isset($_POST['relation_key_or_display_column']) | ||
&& $_POST['relation_key_or_display_column'] | ||
) { | ||
$curr_value = $_POST['relation_key_or_display_column']; | ||
} else { | ||
$curr_value = $_POST['curr_value']; | ||
} | ||
|
||
$dropdown = $this->sql->getHtmlForRelationalColumnDropdown( | ||
$db, | ||
$table, | ||
$column, | ||
$curr_value | ||
); | ||
$this->response->addJSON('dropdown', $dropdown); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Sql; | ||
|
||
use PhpMyAdmin\CheckUserPrivileges; | ||
use PhpMyAdmin\Controllers\AbstractController; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Sql; | ||
use PhpMyAdmin\Template; | ||
|
||
use function __; | ||
use function htmlentities; | ||
|
||
use const ENT_COMPAT; | ||
|
||
final class SetValuesController extends AbstractController | ||
{ | ||
/** @var Sql */ | ||
private $sql; | ||
|
||
/** @var CheckUserPrivileges */ | ||
private $checkUserPrivileges; | ||
|
||
/** | ||
* @param ResponseRenderer $response | ||
*/ | ||
public function __construct( | ||
$response, | ||
Template $template, | ||
Sql $sql, | ||
CheckUserPrivileges $checkUserPrivileges | ||
) { | ||
parent::__construct($response, $template); | ||
$this->sql = $sql; | ||
$this->checkUserPrivileges = $checkUserPrivileges; | ||
} | ||
|
||
/** | ||
* Get possible values for SET fields during grid edit. | ||
*/ | ||
public function __invoke(): void | ||
{ | ||
global $db, $table; | ||
|
||
$this->checkUserPrivileges->getPrivileges(); | ||
|
||
$column = $_POST['column']; | ||
$currentValue = $_POST['curr_value']; | ||
$fullValues = $_POST['get_full_values'] ?? false; | ||
$whereClause = $_POST['where_clause'] ?? null; | ||
|
||
$values = $this->sql->getValuesForColumn($db, $table, $column); | ||
|
||
if ($values === null) { | ||
$this->response->addJSON('message', __('Error in processing request')); | ||
$this->response->setRequestStatus(false); | ||
|
||
return; | ||
} | ||
|
||
// If the $currentValue was truncated, we should fetch the correct full values from the table. | ||
if ($fullValues && ! empty($whereClause)) { | ||
$currentValue = $this->sql->getFullValuesForSetColumn( | ||
$db, | ||
$table, | ||
$column, | ||
$whereClause | ||
); | ||
} | ||
|
||
// Converts characters of $currentValue to HTML entities. | ||
$convertedCurrentValue = htmlentities($currentValue, ENT_COMPAT, 'UTF-8'); | ||
|
||
$select = $this->template->render('sql/set_column', [ | ||
'values' => $values, | ||
'current_values' => $convertedCurrentValue, | ||
]); | ||
|
||
$this->response->addJSON('select', $select); | ||
} | ||
} |
Oops, something went wrong.