feat(releases): powrót do zakładki Licencje po zapisie + wykrywanie wersji z dysku

- Redirecty save_license/delete_license/toggle_beta kierują teraz na #licenses
- Dodano akcję discover_versions: skanuje updates/*/ver_*.zip przez glob(),
  rejestruje nieznane wersje jako beta w pp_update_versions
- Przycisk "Wykryj wersje z dysku" w zakładce Wersje
- Tpl::__isset() dla poprawnej obsługi isset() na właściwościach szablonu
- Usunięto tymczasowy plik diagnostyczny _diag_licenses.php

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 01:46:32 +01:00
parent 869f25d6db
commit dd31c062ad
5 changed files with 47 additions and 52 deletions

View File

@@ -1,49 +0,0 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
chdir(__DIR__ . '/admin');
require_once '../config.php';
require_once '../libraries/medoo/medoo.php';
require_once '../libraries/grid/config.php';
$mdb = new medoo([
'database_type' => 'mysql',
'database_name' => $database['name'],
'server' => $database['host'],
'username' => $database['user'],
'password' => $database['password'],
'charset' => 'utf8'
]);
spl_autoload_register(function($classname) {
$q = explode('\\', $classname);
$c = array_pop($q);
$f = '../autoload/' . implode('/', $q) . '/class.' . $c . '.php';
if (file_exists($f)) { require_once($f); return; }
$f = '../autoload/' . implode('/', $q) . '/' . $c . '.php';
if (file_exists($f)) require_once($f);
});
// Render view (exactly like admin does)
$html = \admin\view\Releases::main_view();
// Find licenses table section in rendered HTML
$start = strpos($html, 'tab-licenses');
$end = strpos($html, '</table>', $start) + 8;
$section = substr($html, $start - 50, $end - $start + 50 + 100);
header('Content-Type: text/plain');
echo "=== FULL HTML SIZE: " . strlen($html) . " bytes ===\n\n";
echo "=== LICENSES SECTION ===\n";
echo $section . "\n\n";
// Count <tr> in licenses part
$lic_start = strpos($html, 'id="tab-licenses"');
$lic_end = strpos($html, '</div>', $lic_start + 100);
$lic_html = substr($html, $lic_start, $lic_end - $lic_start);
$tr_count = substr_count($lic_html, '<tr>');
echo "=== TR COUNT in #tab-licenses: $tr_count ===\n";
echo "=== TAB-LICENSES SNIPPET (first 500 chars) ===\n";
echo substr($lic_html, 0, 500) . "\n";

View File

@@ -26,6 +26,14 @@ ob_start();
<!-- TAB: Wersje -->
<div class="releases-tab-pane active" id="tab-versions">
<div style="margin-bottom: 12px;">
<form method="post" action="/admin/releases/discover_versions/" style="display:inline"
onsubmit="return confirm('Wykryć wersje z dysku i zarejestrować jako stable?')">
<button type="submit" class="btn btn-info btn-sm">
<i class="fa fa-search"></i> Wykryj wersje z dysku
</button>
</form>
</div>
<table class="table table-bordered table-striped table-hover table-condensed">
<thead>
<tr>
@@ -298,6 +306,7 @@ $grid->gdb_opt = $gdb;
$grid->include_plugins = true;
$grid->title = 'Releases &amp; Licencje';
$grid->default_buttons = false;
$grid->form = false;
$grid->external_code = $out;
echo $grid->draw();
?>

View File

@@ -68,6 +68,11 @@ class Tpl
$this->vars[ $name ] = $value;
}
public function __isset( $name )
{
return isset( $this->vars[ $name ] );
}
public function __get( $name )
{
return $this->vars[ $name ];

View File

@@ -26,11 +26,19 @@ class Releases
exit;
}
public static function discover_versions(): void
{
$added = \admin\factory\Releases::discover_versions();
\S::set_message("Wykryto i dodano {$added} nowych wersji jako stable.");
header('Location: /admin/releases/main_view/');
exit;
}
public static function save_license(): void
{
\admin\factory\Releases::save_license($_POST);
\S::set_message('Licencja została zapisana.');
header('Location: /admin/releases/main_view/');
header('Location: /admin/releases/main_view/#licenses');
exit;
}
@@ -39,7 +47,7 @@ class Releases
$id = (int)\S::get('id');
if ($id)
\admin\factory\Releases::delete_license($id);
header('Location: /admin/releases/main_view/');
header('Location: /admin/releases/main_view/#licenses');
exit;
}
@@ -48,7 +56,7 @@ class Releases
$id = (int)\S::get('id');
if ($id)
\admin\factory\Releases::toggle_beta($id);
header('Location: /admin/releases/main_view/');
header('Location: /admin/releases/main_view/#licenses');
exit;
}
}

View File

@@ -31,6 +31,28 @@ class Releases
);
}
public static function discover_versions(): int
{
global $mdb;
$known = array_flip($mdb->select('pp_update_versions', 'version', []) ?: []);
$zips = glob('../updates/*/ver_*.zip') ?: [];
$added = 0;
foreach ($zips as $path) {
preg_match('/ver_([0-9.]+)\.zip$/', $path, $m);
if (!$m) continue;
$ver = $m[1];
if (isset($known[$ver])) continue;
$mdb->insert('pp_update_versions', [
'version' => $ver,
'channel' => 'beta',
'created_at' => date('Y-m-d H:i:s'),
]);
$known[$ver] = true;
$added++;
}
return $added;
}
public static function get_licenses(): array
{
global $mdb;