"Fossies" - the Fresh Open Source Software Archive 
Member "phpMyAdmin-5.1.0-all-languages/libraries/classes/Controllers/Database/TrackingController.php" (24 Feb 2021, 5195 Bytes) of package /linux/www/phpMyAdmin-5.1.0-all-languages.zip:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 <?php
2
3 declare(strict_types=1);
4
5 namespace PhpMyAdmin\Controllers\Database;
6
7 use PhpMyAdmin\CheckUserPrivileges;
8 use PhpMyAdmin\DatabaseInterface;
9 use PhpMyAdmin\Html\Generator;
10 use PhpMyAdmin\Message;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\Template;
13 use PhpMyAdmin\Tracker;
14 use PhpMyAdmin\Tracking;
15 use PhpMyAdmin\Url;
16 use PhpMyAdmin\Util;
17 use function count;
18 use function htmlspecialchars;
19 use function sprintf;
20
21 /**
22 * Tracking configuration for database.
23 */
24 class TrackingController extends AbstractController
25 {
26 /** @var Tracking */
27 private $tracking;
28
29 /** @var DatabaseInterface */
30 private $dbi;
31
32 /**
33 * @param Response $response
34 * @param string $db Database name.
35 * @param DatabaseInterface $dbi
36 */
37 public function __construct($response, Template $template, $db, Tracking $tracking, $dbi)
38 {
39 parent::__construct($response, $template, $db);
40 $this->tracking = $tracking;
41 $this->dbi = $dbi;
42 }
43
44 public function index(): void
45 {
46 global $db, $text_dir, $url_params, $tables, $num_tables, $PMA_Theme;
47 global $total_num_tables, $sub_part, $pos, $data, $cfg;
48 global $tooltip_truename, $tooltip_aliasname, $err_url;
49
50 $this->addScriptFiles(['vendor/jquery/jquery.tablesorter.js', 'database/tracking.js']);
51
52 Util::checkParameters(['db']);
53
54 $err_url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
55 $err_url .= Url::getCommon(['db' => $db], '&');
56
57 if (! $this->hasDatabase()) {
58 return;
59 }
60
61 $url_params['goto'] = Url::getFromRoute('/table/tracking');
62 $url_params['back'] = Url::getFromRoute('/database/tracking');
63
64 // Get the database structure
65 $sub_part = '_structure';
66
67 [
68 $tables,
69 $num_tables,
70 $total_num_tables,
71 $sub_part,,
72 $isSystemSchema,
73 $tooltip_truename,
74 $tooltip_aliasname,
75 $pos,
76 ] = Util::getDbInfo($db, $sub_part ?? '');
77
78 if (isset($_POST['delete_tracking'], $_POST['table'])) {
79 Tracker::deleteTracking($db, $_POST['table']);
80 echo Message::success(
81 __('Tracking data deleted successfully.')
82 )->getDisplay();
83 } elseif (isset($_POST['submit_create_version'])) {
84 $this->tracking->createTrackingForMultipleTables($_POST['selected']);
85 echo Message::success(
86 sprintf(
87 __(
88 'Version %1$s was created for selected tables,'
89 . ' tracking is active for them.'
90 ),
91 htmlspecialchars($_POST['version'])
92 )
93 )->getDisplay();
94 } elseif (isset($_POST['submit_mult'])) {
95 if (! empty($_POST['selected_tbl'])) {
96 if ($_POST['submit_mult'] === 'delete_tracking') {
97 foreach ($_POST['selected_tbl'] as $table) {
98 Tracker::deleteTracking($db, $table);
99 }
100 echo Message::success(
101 __('Tracking data deleted successfully.')
102 )->getDisplay();
103 } elseif ($_POST['submit_mult'] === 'track') {
104 echo $this->template->render('create_tracking_version', [
105 'route' => '/database/tracking',
106 'url_params' => $url_params,
107 'last_version' => 0,
108 'db' => $db,
109 'selected' => $_POST['selected_tbl'],
110 'type' => 'both',
111 'default_statements' => $cfg['Server']['tracking_default_statements'],
112 ]);
113
114 return;
115 }
116 } else {
117 echo Message::notice(
118 __('No tables selected.')
119 )->getDisplay();
120 }
121 }
122
123 // Get tracked data about the database
124 $data = Tracker::getTrackedData($db, '', '1');
125
126 // No tables present and no log exist
127 if ($num_tables == 0 && count($data['ddlog']) === 0) {
128 echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
129
130 if (empty($isSystemSchema)) {
131 $checkUserPrivileges = new CheckUserPrivileges($this->dbi);
132 $checkUserPrivileges->getPrivileges();
133
134 echo $this->template->render('database/create_table', ['db' => $db]);
135 }
136
137 return;
138 }
139
140 echo $this->tracking->getHtmlForDbTrackingTables(
141 $db,
142 $url_params,
143 $PMA_Theme->getImgPath(),
144 $text_dir
145 );
146
147 // If available print out database log
148 if (count($data['ddlog']) <= 0) {
149 return;
150 }
151
152 $log = '';
153 foreach ($data['ddlog'] as $entry) {
154 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
155 . $entry['statement'] . "\n";
156 }
157 echo Generator::getMessage(__('Database Log'), $log);
158 }
159 }