phpmyadmin/libraries/classes/Controllers/Table/Structure/AbstractIndexController.php
Maurício Meneghini Fauth 613678f8f5
Replace assignments with null coalesce equal operator
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2023-02-20 17:03:05 -03:00

55 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Table\Structure;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Controllers\Table\StructureController;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Query\Generator;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Table\Indexes;
use PhpMyAdmin\Template;
use function __;
use function is_array;
abstract class AbstractIndexController extends AbstractController
{
protected StructureController $structureController;
protected Indexes $indexes;
public function __construct(
ResponseRenderer $response,
Template $template,
StructureController $structureController,
Indexes $indexes
) {
parent::__construct($response, $template);
$this->structureController = $structureController;
$this->indexes = $indexes;
}
public function handleIndexCreation(ServerRequest $request, string $indexType): void
{
$GLOBALS['message'] ??= null;
$selected = $request->getParsedBodyParam('selected_fld', []);
if (! is_array($selected) || $selected === []) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', __('No column selected.'));
return;
}
$GLOBALS['sql_query'] = Generator::getAddIndexSql($indexType, $GLOBALS['table'], $selected);
$GLOBALS['message'] = $this->indexes->executeAddIndexSql($GLOBALS['db'], $GLOBALS['sql_query']);
($this->structureController)($request);
}
}