55
66declare (strict_types=1 );
77
8- namespace PhpMyAdmin ;
8+ namespace PhpMyAdmin \ Tracking ;
99
1010use DateTimeImmutable ;
1111use PhpMyAdmin \ConfigStorage \Relation ;
12+ use PhpMyAdmin \Core ;
13+ use PhpMyAdmin \DatabaseInterface ;
1214use PhpMyAdmin \Dbal \ResultInterface ;
1315use PhpMyAdmin \Html \Generator ;
16+ use PhpMyAdmin \Message ;
17+ use PhpMyAdmin \SqlQueryForm ;
18+ use PhpMyAdmin \Template ;
19+ use PhpMyAdmin \Url ;
20+ use PhpMyAdmin \Util ;
1421
1522use function __ ;
16- use function array_key_exists ;
1723use function array_merge ;
1824use function array_multisort ;
1925use function count ;
2026use function date ;
2127use function htmlspecialchars ;
2228use function in_array ;
2329use function ini_set ;
24- use function is_array ;
2530use function json_encode ;
2631use function mb_strstr ;
2732use function preg_replace ;
3237use const SORT_ASC ;
3338
3439/**
35- * PhpMyAdmin\Tracking class
40+ * PhpMyAdmin\Tracking\Tracking class
3641 */
3742class Tracking
3843{
@@ -41,6 +46,7 @@ public function __construct(
4146 public Template $ template ,
4247 protected Relation $ relation ,
4348 private DatabaseInterface $ dbi ,
49+ private TrackingChecker $ trackingChecker ,
4450 ) {
4551 }
4652
@@ -117,18 +123,6 @@ public function getHtmlForMainPage(
117123 string $ textDir ,
118124 int |null $ lastVersion = null ,
119125 ): string {
120- $ selectableTablesSqlResult = $ this ->getSqlResultForSelectableTables ($ db );
121- $ selectableTablesEntries = [];
122- $ selectableTablesNumRows = 0 ;
123- if ($ selectableTablesSqlResult !== false ) {
124- foreach ($ selectableTablesSqlResult as $ entry ) {
125- $ entry ['is_tracked ' ] = Tracker::isTracked ($ entry ['db_name ' ], $ entry ['table_name ' ]);
126- $ selectableTablesEntries [] = $ entry ;
127- }
128-
129- $ selectableTablesNumRows = $ selectableTablesSqlResult ->numRows ();
130- }
131-
132126 $ versionSqlResult = $ this ->getListOfVersionsOfTable ($ db , $ table );
133127 if ($ lastVersion === null && $ versionSqlResult !== false ) {
134128 $ lastVersion = $ this ->getTableLastVersionNumber ($ versionSqlResult );
@@ -145,8 +139,7 @@ public function getHtmlForMainPage(
145139 'url_params ' => $ urlParams ,
146140 'db ' => $ db ,
147141 'table ' => $ table ,
148- 'selectable_tables_num_rows ' => $ selectableTablesNumRows ,
149- 'selectable_tables_entries ' => $ selectableTablesEntries ,
142+ 'selectable_tables_entries ' => $ this ->trackingChecker ->getTrackedTables ($ db ),
150143 'selected_table ' => $ _POST ['table ' ] ?? null ,
151144 'last_version ' => $ lastVersion ,
152145 'versions ' => $ versions ,
@@ -164,24 +157,6 @@ public function getTableLastVersionNumber(ResultInterface $result): int
164157 return (int ) $ result ->fetchValue ('version ' );
165158 }
166159
167- /**
168- * Function to get sql results for selectable tables
169- */
170- public function getSqlResultForSelectableTables (string $ db ): ResultInterface |false
171- {
172- $ trackingFeature = $ this ->relation ->getRelationParameters ()->trackingFeature ;
173- if ($ trackingFeature === null ) {
174- return false ;
175- }
176-
177- $ sql_query = ' SELECT DISTINCT db_name, table_name FROM '
178- . Util::backquote ($ trackingFeature ->database ) . '. ' . Util::backquote ($ trackingFeature ->tracking )
179- . " WHERE db_name = ' " . $ this ->dbi ->escapeString ($ db ) . "' "
180- . ' ORDER BY db_name, table_name ' ;
181-
182- return $ this ->dbi ->queryAsControlUser ($ sql_query );
183- }
184-
185160 /**
186161 * Function to get html for tracking report and tracking report export
187162 *
@@ -774,7 +749,7 @@ public function deleteFromTrackingReportLog(
774749 *
775750 * @return string HTML SQL query form
776751 */
777- public function exportAsSqlDump (string $ db , string $ table , array $ entries ): string
752+ public function exportAsSqlDump (array $ entries ): string
778753 {
779754 $ html = '' ;
780755 $ new_query = '# '
@@ -1082,7 +1057,7 @@ public function getHtmlForDbTrackingTables(
10821057 . '\' GROUP BY table_name ORDER BY table_name ASC ' ;
10831058
10841059 $ allTablesResult = $ this ->dbi ->queryAsControlUser ($ allTablesQuery );
1085- $ untrackedTables = $ this ->getUntrackedTables ($ db );
1060+ $ untrackedTables = $ this ->trackingChecker -> getUntrackedTableNames ($ db );
10861061
10871062 // If a HEAD version exists
10881063 $ versions = [];
@@ -1107,44 +1082,4 @@ public function getHtmlForDbTrackingTables(
11071082 'untracked_tables ' => $ untrackedTables ,
11081083 ]);
11091084 }
1110-
1111- /**
1112- * Helper function: Recursive function for getting table names from $table_list
1113- *
1114- * @param array $table_list Table list
1115- * @param string $db Current database
1116- *
1117- * @return array
1118- */
1119- public function extractTableNames (array $ table_list , string $ db ): array
1120- {
1121- $ untracked_tables = [];
1122- $ sep = $ GLOBALS ['cfg ' ]['NavigationTreeTableSeparator ' ];
1123-
1124- foreach ($ table_list as $ value ) {
1125- if (is_array ($ value ) && array_key_exists ('is ' . $ sep . 'group ' , $ value ) && $ value ['is ' . $ sep . 'group ' ]) {
1126- // Recursion step
1127- $ untracked_tables = array_merge ($ this ->extractTableNames ($ value , $ db ), $ untracked_tables );
1128- } elseif (is_array ($ value ) && (Tracker::getVersion ($ db , $ value ['Name ' ]) == -1 )) {
1129- $ untracked_tables [] = $ value ['Name ' ];
1130- }
1131- }
1132-
1133- return $ untracked_tables ;
1134- }
1135-
1136- /**
1137- * Get untracked tables
1138- *
1139- * @param string $db current database
1140- *
1141- * @return array
1142- */
1143- public function getUntrackedTables (string $ db ): array
1144- {
1145- $ table_list = Util::getTableList ($ db );
1146-
1147- //Use helper function to get table list recursively.
1148- return $ this ->extractTableNames ($ table_list , $ db );
1149- }
11501085}
0 commit comments