Remove Tracking Twig extension (#18250)

* Remove get_tracker_version extension

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove test seam and fix test

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

---------

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2023-03-13 15:44:19 +00:00 committed by GitHub
parent 6264b7c71c
commit 0e600bb1f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 61 deletions

View File

@ -12,7 +12,6 @@ use PhpMyAdmin\Twig\I18nExtension;
use PhpMyAdmin\Twig\MessageExtension;
use PhpMyAdmin\Twig\SanitizeExtension;
use PhpMyAdmin\Twig\TableExtension;
use PhpMyAdmin\Twig\TrackerExtension;
use PhpMyAdmin\Twig\TransformationsExtension;
use PhpMyAdmin\Twig\UrlExtension;
use PhpMyAdmin\Twig\UtilExtension;
@ -90,7 +89,6 @@ class Template
$twig->addExtension(new MessageExtension());
$twig->addExtension(new SanitizeExtension());
$twig->addExtension(new TableExtension());
$twig->addExtension(new TrackerExtension());
$twig->addExtension(new TransformationsExtension());
$twig->addExtension(new UrlExtension());
$twig->addExtension(new UtilExtension());

View File

@ -1100,7 +1100,7 @@ class Tracking
return $this->template->render('database/tracking/tables', [
'db' => $db,
'head_version_exists' => $versions !== [],
'untracked_tables_exists' => count($untrackedTables) > 0,
'untracked_tables_exists' => $untrackedTables !== [],
'versions' => $versions,
'url_params' => $urlParams,
'text_dir' => $textDir,
@ -1113,11 +1113,10 @@ class Tracking
*
* @param array $table_list Table list
* @param string $db Current database
* @param bool $testing Testing
*
* @return array
*/
public function extractTableNames(array $table_list, $db, $testing = false): array
public function extractTableNames(array $table_list, $db): array
{
$untracked_tables = [];
$sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
@ -1125,8 +1124,8 @@ class Tracking
foreach ($table_list as $value) {
if (is_array($value) && array_key_exists('is' . $sep . 'group', $value) && $value['is' . $sep . 'group']) {
// Recursion step
$untracked_tables = array_merge($this->extractTableNames($value, $db, $testing), $untracked_tables);
} elseif (is_array($value) && ($testing || Tracker::getVersion($db, $value['Name']) == -1)) {
$untracked_tables = array_merge($this->extractTableNames($value, $db), $untracked_tables);
} elseif (is_array($value) && (Tracker::getVersion($db, $value['Name']) == -1)) {
$untracked_tables[] = $value['Name'];
}
}

View File

@ -1,27 +0,0 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Twig;
use PhpMyAdmin\Tracker;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class TrackerExtension extends AbstractExtension
{
/**
* Returns a list of functions to add to the existing list.
*
* @return TwigFunction[]
*/
public function getFunctions(): array
{
return [
new TwigFunction(
'get_tracker_version',
Tracker::getVersion(...),
),
];
}
}

View File

@ -155,29 +155,27 @@
</tr>
</thead>
<tbody>
{% for table_name in untracked_tables %}
{% if get_tracker_version(db, table_name) == -1 %}
<tr>
<td class="text-center">
<input type="checkbox" name="selected_tbl[]"
class="checkall" id="selected_tbl_{{ table_name }}"
value="{{ table_name }}">
</td>
<th>
<label for="selected_tbl_{{ table_name }}">
{{ table_name }}
</label>
</th>
<td>
<a href="{{ url('/table/tracking', url_params|merge({
'db': db,
'table': table_name
})) }}">
{{ get_icon('eye', 'Track table'|trans) }}
</a>
</td>
</tr>
{% endif %}
{% for table_name in untracked_tables %}
<tr>
<td class="text-center">
<input type="checkbox" name="selected_tbl[]"
class="checkall" id="selected_tbl_{{ table_name }}"
value="{{ table_name }}">
</td>
<th>
<label for="selected_tbl_{{ table_name }}">
{{ table_name }}
</label>
</th>
<td>
<a href="{{ url('/table/tracking', url_params|merge({
'db': db,
'table': table_name
})) }}">
{{ get_icon('eye', 'Track table'|trans) }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -2325,13 +2325,13 @@ class DbiDummy implements DbiExtension
'query' => 'SELECT MAX(version) FROM `pmadb`.`tracking` WHERE `db_name` = \'db\''
. ' AND `table_name` = \'hello_world\'',
'columns' => ['version'],
'result' => [['10']],
'result' => [],
],
[
'query' => 'SELECT MAX(version) FROM `pmadb`.`tracking` WHERE `db_name` = \'db\''
. ' AND `table_name` = \'hello_lovely_world\'',
'columns' => ['version'],
'result' => [['10']],
'result' => [],
],
[
'query' => 'SELECT MAX(version) FROM `pmadb`.`tracking` WHERE `db_name` = \'db\''

View File

@ -110,10 +110,10 @@ class TrackingTest extends AbstractTestCase
'hello_world' => ['Name' => 'hello_world'],
],
];
$untracked_tables = $this->tracking->extractTableNames($table_list, 'db', true);
$untracked_tables = $this->tracking->extractTableNames($table_list, 'db');
$this->assertContains('hello_world', $untracked_tables);
$this->assertContains('hello_lovely_world', $untracked_tables);
$this->assertContains('hello_lovely_world2', $untracked_tables);
$this->assertNotContains('hello_lovely_world2', $untracked_tables);
}
public function testGetHtmlForMain(): void