devilbox/.devilbox/www/htdocs/vendor/phpmyadmin-4.9.3/db_tracking.php

155 lines
4.3 KiB
PHP
Raw Normal View History

2016-10-22 14:57:10 +00:00
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tracking configuration for database
*
* @package PhpMyAdmin
*/
2018-04-14 09:18:00 +00:00
use PhpMyAdmin\Display\CreateTable;
use PhpMyAdmin\Message;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\Tracker;
use PhpMyAdmin\Tracking;
use PhpMyAdmin\Util;
2016-10-22 14:57:10 +00:00
/**
* Run common work
*/
require_once 'libraries/common.inc.php';
//Get some js files needed for Ajax requests
$response = Response::getInstance();
2016-10-22 14:57:10 +00:00
$header = $response->getHeader();
$scripts = $header->getScripts();
2018-04-14 09:18:00 +00:00
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
2016-10-22 14:57:10 +00:00
$scripts->addFile('db_tracking.js');
/**
* If we are not in an Ajax request, then do the common work and show the links etc.
*/
require 'libraries/db_common.inc.php';
$url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
2018-12-16 14:31:03 +00:00
$url_params['goto'] = 'tbl_tracking.php';
$url_params['back'] = 'db_tracking.php';
2016-10-22 14:57:10 +00:00
// Get the database structure
$sub_part = '_structure';
list(
$tables,
$num_tables,
$total_num_tables,
$sub_part,
$is_show_stats,
$db_is_system_schema,
$tooltip_truename,
$tooltip_aliasname,
$pos
2018-04-14 09:18:00 +00:00
) = Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
2016-10-22 14:57:10 +00:00
2018-12-16 14:31:03 +00:00
if (isset($_POST['delete_tracking']) && isset($_POST['table'])) {
2016-10-22 14:57:10 +00:00
2018-12-16 14:31:03 +00:00
Tracker::deleteTracking($GLOBALS['db'], $_POST['table']);
2018-04-14 09:18:00 +00:00
Message::success(
2016-10-22 14:57:10 +00:00
__('Tracking data deleted successfully.')
)->display();
2018-12-16 14:31:03 +00:00
} elseif (isset($_POST['submit_create_version'])) {
2016-10-22 14:57:10 +00:00
2018-12-16 14:31:03 +00:00
Tracking::createTrackingForMultipleTables($_POST['selected']);
2018-04-14 09:18:00 +00:00
Message::success(
2016-10-22 14:57:10 +00:00
sprintf(
__(
'Version %1$s was created for selected tables,'
. ' tracking is active for them.'
),
2018-12-16 14:31:03 +00:00
htmlspecialchars($_POST['version'])
2016-10-22 14:57:10 +00:00
)
)->display();
2018-12-16 14:31:03 +00:00
} elseif (isset($_POST['submit_mult'])) {
2016-10-22 14:57:10 +00:00
2018-12-16 14:31:03 +00:00
if (! empty($_POST['selected_tbl'])) {
if ($_POST['submit_mult'] == 'delete_tracking') {
2016-10-22 14:57:10 +00:00
2018-12-16 14:31:03 +00:00
foreach ($_POST['selected_tbl'] as $table) {
2016-10-22 14:57:10 +00:00
Tracker::deleteTracking($GLOBALS['db'], $table);
}
2018-04-14 09:18:00 +00:00
Message::success(
2016-10-22 14:57:10 +00:00
__('Tracking data deleted successfully.')
)->display();
2018-12-16 14:31:03 +00:00
} elseif ($_POST['submit_mult'] == 'track') {
2016-10-22 14:57:10 +00:00
2018-04-14 09:18:00 +00:00
echo Tracking::getHtmlForDataDefinitionAndManipulationStatements(
2016-10-22 14:57:10 +00:00
'db_tracking.php' . $url_query,
0,
$GLOBALS['db'],
2018-12-16 14:31:03 +00:00
$_POST['selected_tbl']
2016-10-22 14:57:10 +00:00
);
exit;
}
} else {
2018-04-14 09:18:00 +00:00
Message::notice(
2016-10-22 14:57:10 +00:00
__('No tables selected.')
)->display();
}
}
// Get tracked data about the database
2018-12-16 14:31:03 +00:00
$data = Tracker::getTrackedData($GLOBALS['db'], '', '1');
2016-10-22 14:57:10 +00:00
// No tables present and no log exist
if ($num_tables == 0 && count($data['ddlog']) == 0) {
echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
if (empty($db_is_system_schema)) {
2018-04-14 09:18:00 +00:00
echo CreateTable::getHtml($db);
2016-10-22 14:57:10 +00:00
}
exit;
}
// ---------------------------------------------------------------------------
2018-04-14 09:18:00 +00:00
$relation = new Relation();
$cfgRelation = $relation->getRelationsParam();
2016-10-22 14:57:10 +00:00
// Prepare statement to get HEAD version
$all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
2018-04-14 09:18:00 +00:00
Util::backquote($cfgRelation['db']) . '.' .
Util::backquote($cfgRelation['tracking']) .
2018-12-16 14:31:03 +00:00
' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($GLOBALS['db']) .
2016-10-22 14:57:10 +00:00
'\' ' .
' GROUP BY table_name' .
' ORDER BY table_name ASC';
2018-04-14 09:18:00 +00:00
$all_tables_result = $relation->queryAsControlUser($all_tables_query);
2016-10-22 14:57:10 +00:00
// If a HEAD version exists
if (is_object($all_tables_result)
&& $GLOBALS['dbi']->numRows($all_tables_result) > 0
) {
2018-04-14 09:18:00 +00:00
echo Tracking::getHtmlForTrackedTables(
2016-10-22 14:57:10 +00:00
$GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage,
$text_dir, $cfgRelation
);
}
2018-04-14 09:18:00 +00:00
$untracked_tables = Tracking::getUntrackedTables($GLOBALS['db']);
2016-10-22 14:57:10 +00:00
// If untracked tables exist
if (count($untracked_tables) > 0) {
2018-04-14 09:18:00 +00:00
echo Tracking::getHtmlForUntrackedTables(
2016-10-22 14:57:10 +00:00
$GLOBALS['db'], $untracked_tables, $url_query, $pmaThemeImage, $text_dir
);
}
// If available print out database log
if (count($data['ddlog']) > 0) {
$log = '';
foreach ($data['ddlog'] as $entry) {
$log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
. $entry['statement'] . "\n";
}
2018-04-14 09:18:00 +00:00
echo Util::getMessage(__('Database Log'), $log);
2016-10-22 14:57:10 +00:00
}