Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract actions from controllers to new controllers
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
- Loading branch information
1 parent
a73e26c
commit e355487
Showing
35 changed files
with
2,667 additions
and
1,447 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
libraries/classes/Controllers/Database/Operations/CollationController.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,112 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Database\Operations; | ||
|
||
use PhpMyAdmin\Controllers\Database\AbstractController; | ||
use PhpMyAdmin\DatabaseInterface; | ||
use PhpMyAdmin\Message; | ||
use PhpMyAdmin\Operations; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Template; | ||
use PhpMyAdmin\Url; | ||
use PhpMyAdmin\Util; | ||
|
||
use function __; | ||
|
||
final class CollationController extends AbstractController | ||
{ | ||
/** @var Operations */ | ||
private $operations; | ||
|
||
/** @var DatabaseInterface */ | ||
private $dbi; | ||
|
||
/** | ||
* @param ResponseRenderer $response | ||
* @param string $db Database name | ||
* @param DatabaseInterface $dbi | ||
*/ | ||
public function __construct( | ||
$response, | ||
Template $template, | ||
$db, | ||
Operations $operations, | ||
$dbi | ||
) { | ||
parent::__construct($response, $template, $db); | ||
$this->operations = $operations; | ||
$this->dbi = $dbi; | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
global $db, $cfg, $errorUrl; | ||
|
||
if (! $this->response->isAjax()) { | ||
return; | ||
} | ||
|
||
if (empty($_POST['db_collation'])) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON('message', Message::error(__('No collation provided.'))); | ||
|
||
return; | ||
} | ||
|
||
Util::checkParameters(['db']); | ||
|
||
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database'); | ||
$errorUrl .= Url::getCommon(['db' => $db], '&'); | ||
|
||
if (! $this->hasDatabase()) { | ||
return; | ||
} | ||
|
||
$sql_query = 'ALTER DATABASE ' . Util::backquote($db) | ||
. ' DEFAULT' . Util::getCharsetQueryPart($_POST['db_collation'] ?? ''); | ||
$this->dbi->query($sql_query); | ||
$message = Message::success(); | ||
|
||
/** | ||
* Changes tables charset if requested by the user | ||
*/ | ||
if ( | ||
isset($_POST['change_all_tables_collations']) && | ||
$_POST['change_all_tables_collations'] === 'on' | ||
) { | ||
[$tables] = Util::getDbInfo($db, null); | ||
foreach ($tables as $tableName => $data) { | ||
if ($this->dbi->getTable($db, $tableName)->isView()) { | ||
// Skip views, we can not change the collation of a view. | ||
// issue #15283 | ||
continue; | ||
} | ||
|
||
$sql_query = 'ALTER TABLE ' | ||
. Util::backquote($db) | ||
. '.' | ||
. Util::backquote($tableName) | ||
. ' DEFAULT ' | ||
. Util::getCharsetQueryPart($_POST['db_collation'] ?? ''); | ||
$this->dbi->query($sql_query); | ||
|
||
/** | ||
* Changes columns charset if requested by the user | ||
*/ | ||
if ( | ||
! isset($_POST['change_all_tables_columns_collations']) || | ||
$_POST['change_all_tables_columns_collations'] !== 'on' | ||
) { | ||
continue; | ||
} | ||
|
||
$this->operations->changeAllColumnsCollation($db, $tableName, $_POST['db_collation']); | ||
} | ||
} | ||
|
||
$this->response->setRequestStatus($message->isSuccess()); | ||
$this->response->addJSON('message', $message); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
libraries/classes/Controllers/Database/Structure/AddPrefixController.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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Database\Structure; | ||
|
||
use PhpMyAdmin\Controllers\Database\AbstractController; | ||
|
||
use function __; | ||
|
||
final class AddPrefixController extends AbstractController | ||
{ | ||
public function __invoke(): void | ||
{ | ||
global $db; | ||
|
||
$selected = $_POST['selected_tbl'] ?? []; | ||
|
||
if (empty($selected)) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON('message', __('No table selected.')); | ||
|
||
return; | ||
} | ||
|
||
$params = ['db' => $db]; | ||
foreach ($selected as $selectedValue) { | ||
$params['selected'][] = $selectedValue; | ||
} | ||
|
||
$this->response->disable(); | ||
$this->render('database/structure/add_prefix', ['url_params' => $params]); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
libraries/classes/Controllers/Database/Structure/AddPrefixTableController.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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Database\Structure; | ||
|
||
use PhpMyAdmin\Controllers\Database\AbstractController; | ||
use PhpMyAdmin\Controllers\Database\StructureController; | ||
use PhpMyAdmin\DatabaseInterface; | ||
use PhpMyAdmin\Message; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Template; | ||
use PhpMyAdmin\Util; | ||
|
||
use function count; | ||
|
||
final class AddPrefixTableController extends AbstractController | ||
{ | ||
/** @var DatabaseInterface */ | ||
private $dbi; | ||
|
||
/** @var StructureController */ | ||
private $structureController; | ||
|
||
/** | ||
* @param ResponseRenderer $response | ||
* @param string $db | ||
* @param DatabaseInterface $dbi | ||
*/ | ||
public function __construct($response, Template $template, $db, $dbi, StructureController $structureController) | ||
{ | ||
parent::__construct($response, $template, $db); | ||
$this->dbi = $dbi; | ||
$this->structureController = $structureController; | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
global $db, $message, $sql_query; | ||
|
||
$selected = $_POST['selected'] ?? []; | ||
|
||
$sql_query = ''; | ||
$selectedCount = count($selected); | ||
|
||
for ($i = 0; $i < $selectedCount; $i++) { | ||
$newTableName = $_POST['add_prefix'] . $selected[$i]; | ||
$aQuery = 'ALTER TABLE ' . Util::backquote($selected[$i]) | ||
. ' RENAME ' . Util::backquote($newTableName); | ||
|
||
$sql_query .= $aQuery . ';' . "\n"; | ||
$this->dbi->selectDb($db); | ||
$this->dbi->query($aQuery); | ||
} | ||
|
||
$message = Message::success(); | ||
|
||
if (empty($_POST['message'])) { | ||
$_POST['message'] = $message; | ||
} | ||
|
||
($this->structureController)(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
libraries/classes/Controllers/Database/Structure/CentralColumns/AddController.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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Database\Structure\CentralColumns; | ||
|
||
use PhpMyAdmin\Controllers\Database\AbstractController; | ||
use PhpMyAdmin\Controllers\Database\StructureController; | ||
use PhpMyAdmin\Database\CentralColumns; | ||
use PhpMyAdmin\DatabaseInterface; | ||
use PhpMyAdmin\Message; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Template; | ||
|
||
use function __; | ||
|
||
final class AddController extends AbstractController | ||
{ | ||
/** @var DatabaseInterface */ | ||
private $dbi; | ||
|
||
/** @var StructureController */ | ||
private $structureController; | ||
|
||
/** | ||
* @param ResponseRenderer $response | ||
* @param string $db | ||
* @param DatabaseInterface $dbi | ||
*/ | ||
public function __construct($response, Template $template, $db, $dbi, StructureController $structureController) | ||
{ | ||
parent::__construct($response, $template, $db); | ||
$this->dbi = $dbi; | ||
$this->structureController = $structureController; | ||
} | ||
|
||
public function __invoke(): void | ||
{ | ||
global $message; | ||
|
||
$selected = $_POST['selected_tbl'] ?? []; | ||
|
||
if (empty($selected)) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON('message', __('No table selected.')); | ||
|
||
return; | ||
} | ||
|
||
$centralColumns = new CentralColumns($this->dbi); | ||
$error = $centralColumns->syncUniqueColumns($selected); | ||
|
||
$message = $error instanceof Message ? $error : Message::success(__('Success!')); | ||
|
||
unset($_POST['submit_mult']); | ||
|
||
($this->structureController)(); | ||
} | ||
} |
Oops, something went wrong.