Skip to content

Commit

Permalink
Create Table\TriggersController
Browse files Browse the repository at this point in the history
Moves database|table triggers entry point logic to
Database|Table\TriggersController and removes the entry point file.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Dec 11, 2019
1 parent 8a80007 commit fa6fc40
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 85 deletions.
46 changes: 46 additions & 0 deletions libraries/classes/Controllers/Database/TriggersController.php
Expand Up @@ -9,6 +9,7 @@
namespace PhpMyAdmin\Controllers\Database;

use PhpMyAdmin\Rte\Triggers;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;

/**
Expand All @@ -23,8 +24,53 @@ class TriggersController extends AbstractController
*/
public function index(): void
{
global $_PMA_RTE, $db, $table, $tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats;
global $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos, $url_query;
global $errors, $titles;

$_PMA_RTE = 'TRI';

if (! $this->response->isAjax()) {
/**
* Displays the header and tabs
*/
if (! empty($table) && in_array($table, $this->dbi->getTables($db))) {
include_once ROOT_PATH . 'libraries/tbl_common.inc.php';
} else {
$table = '';
include_once ROOT_PATH . 'libraries/db_common.inc.php';

list(
$tables,
$num_tables,
$total_num_tables,
$sub_part,
$is_show_stats,
$db_is_system_schema,
$tooltip_truename,
$tooltip_aliasname,
$pos
) = Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
}
} else {
/**
* Since we did not include some libraries, we need
* to manually select the required database and
* create the missing $url_query variable
*/
if (strlen($db) > 0) {
$this->dbi->selectDb($db);
if (! isset($url_query)) {
$url_query = Url::getCommon(
[
'db' => $db,
'table' => $table,
]
);
}
}
}

/**
* Create labels for the list
*/
Expand Down
85 changes: 85 additions & 0 deletions libraries/classes/Controllers/Table/TriggersController.php
@@ -0,0 +1,85 @@
<?php
/**
* @package PhpMyAdmin\Controllers\Table
*/
declare(strict_types=1);

namespace PhpMyAdmin\Controllers\Table;

use PhpMyAdmin\Rte\Triggers;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;

/**
* Triggers management.
* @package PhpMyAdmin\Controllers\Table
*/
class TriggersController extends AbstractController
{
/**
* @return void
*/
public function index(): void
{
global $_PMA_RTE, $db, $table, $tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats;
global $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos, $url_query;
global $errors, $titles;

$_PMA_RTE = 'TRI';

if (! $this->response->isAjax()) {
/**
* Displays the header and tabs
*/
if (! empty($table) && in_array($table, $this->dbi->getTables($db))) {
include_once ROOT_PATH . 'libraries/tbl_common.inc.php';
} else {
$table = '';
include_once ROOT_PATH . 'libraries/db_common.inc.php';

list(
$tables,
$num_tables,
$total_num_tables,
$sub_part,
$is_show_stats,
$db_is_system_schema,
$tooltip_truename,
$tooltip_aliasname,
$pos
) = Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
}
} else {
/**
* Since we did not include some libraries, we need
* to manually select the required database and
* create the missing $url_query variable
*/
if (strlen($db) > 0) {
$this->dbi->selectDb($db);
if (! isset($url_query)) {
$url_query = Url::getCommon(
[
'db' => $db,
'table' => $table,
]
);
}
}
}

/**
* Create labels for the list
*/
$titles = Util::buildActionTitles();

/**
* Keep a list of errors that occurred while
* processing an 'Add' or 'Edit' operation.
*/
$errors = [];

$triggers = new Triggers($this->dbi);
$triggers->main();
}
}
80 changes: 0 additions & 80 deletions libraries/entry_points/database/triggers.php

This file was deleted.

16 changes: 11 additions & 5 deletions libraries/routes.php
Expand Up @@ -19,6 +19,7 @@
use PhpMyAdmin\Controllers\Database\RoutinesController;
use PhpMyAdmin\Controllers\Database\SearchController;
use PhpMyAdmin\Controllers\Database\StructureController;
use PhpMyAdmin\Controllers\Database\TriggersController;
use PhpMyAdmin\Controllers\ErrorReportController;
use PhpMyAdmin\Controllers\GisDataEditorController;
use PhpMyAdmin\Controllers\HomeController;
Expand All @@ -40,6 +41,7 @@
use PhpMyAdmin\Controllers\Server\Status\StatusController;
use PhpMyAdmin\Controllers\Server\Status\VariablesController as StatusVariables;
use PhpMyAdmin\Controllers\Server\VariablesController;
use PhpMyAdmin\Controllers\Table\TriggersController as TableTriggersController;
use PhpMyAdmin\Controllers\ThemesController;
use PhpMyAdmin\Controllers\TransformationOverviewController;
use PhpMyAdmin\Controllers\TransformationWrapperController;
Expand Down Expand Up @@ -237,8 +239,10 @@
$routes->addRoute(['GET', 'POST'], '/tracking', function () {
require_once ROOT_PATH . 'libraries/entry_points/database/tracking.php';
});
$routes->addRoute(['GET', 'POST'], '/triggers', function () {
require_once ROOT_PATH . 'libraries/entry_points/database/triggers.php';
$routes->addRoute(['GET', 'POST'], '/triggers', function () use ($containerBuilder) {
/** @var TriggersController $controller */
$controller = $containerBuilder->get(TriggersController::class);
$controller->index();
});
});
$routes->addRoute(['GET', 'POST'], '/error-report', function () use ($containerBuilder) {
Expand Down Expand Up @@ -497,7 +501,7 @@
$routes->addRoute(['GET', 'POST'], '/sql', function () {
require_once ROOT_PATH . 'libraries/entry_points/sql.php';
});
$routes->addGroup('/table', function (RouteCollector $routes) {
$routes->addGroup('/table', function (RouteCollector $routes) use ($containerBuilder) {
$routes->addRoute(['GET', 'POST'], '/addfield', function () {
require_once ROOT_PATH . 'libraries/entry_points/table/addfield.php';
});
Expand Down Expand Up @@ -555,8 +559,10 @@
$routes->addRoute(['GET', 'POST'], '/tracking', function () {
require_once ROOT_PATH . 'libraries/entry_points/table/tracking.php';
});
$routes->addRoute(['GET', 'POST'], '/triggers', function () {
require_once ROOT_PATH . 'libraries/entry_points/database/triggers.php';
$routes->addRoute(['GET', 'POST'], '/triggers', function () use ($containerBuilder) {
/** @var TableTriggersController $controller */
$controller = $containerBuilder->get(TableTriggersController::class);
$controller->index();
});
$routes->addRoute(['GET', 'POST'], '/zoom_select', function () {
require_once ROOT_PATH . 'libraries/entry_points/table/zoom_select.php';
Expand Down
9 changes: 9 additions & 0 deletions services_controllers.yml
Expand Up @@ -411,6 +411,15 @@ services:
transformations: '@transformations'
create_add_field: '@create_add_field'

PhpMyAdmin\Controllers\Table\TriggersController:
class: 'PhpMyAdmin\Controllers\Table\TriggersController'
arguments:
response: '@response'
dbi: '@dbi'
template: '@template'
db: '%db%'
table: '%table%'

PhpMyAdmin\Controllers\ThemesController:
class: 'PhpMyAdmin\Controllers\ThemesController'
arguments:
Expand Down

0 comments on commit fa6fc40

Please sign in to comment.