Files
cmsPRO/autoload/admin/factory/class.Releases.php
Jacek Pyziak dd31c062ad 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>
2026-02-28 01:46:32 +01:00

104 lines
2.9 KiB
PHP

<?php
namespace admin\factory;
class Releases
{
public static function get_versions(): array
{
global $mdb;
$rows = $mdb->select('pp_update_versions', '*', ['ORDER' => ['version' => 'DESC']]);
if (!$rows) return [];
foreach ($rows as &$row)
$row['zip_exists'] = file_exists('../updates/' . self::zip_dir($row['version']) . '/ver_' . $row['version'] . '.zip');
return $rows;
}
public static function promote(string $version): void
{
global $mdb;
$mdb->update('pp_update_versions',
['channel' => 'stable', 'promoted_at' => date('Y-m-d H:i:s')],
['version' => $version]
);
}
public static function demote(string $version): void
{
global $mdb;
$mdb->update('pp_update_versions',
['channel' => 'beta', 'promoted_at' => null],
['version' => $version]
);
}
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;
return $mdb->select('pp_update_licenses', '*', ['ORDER' => ['domain' => 'ASC']]) ?: [];
}
public static function get_license(int $id): array
{
global $mdb;
return $mdb->get('pp_update_licenses', '*', ['id' => $id]) ?: [];
}
public static function save_license(array $data): void
{
global $mdb;
$row = [
'key' => trim($data['key'] ?? ''),
'domain' => trim($data['domain'] ?? ''),
'valid_to_date' => $data['valid_to_date'] ?: null,
'valid_to_version' => $data['valid_to_version'] ?: null,
'beta' => (int)(bool)($data['beta'] ?? 0),
'note' => trim($data['note'] ?? ''),
];
if (!empty($data['id']))
$mdb->update('pp_update_licenses', $row, ['id' => (int)$data['id']]);
else
$mdb->insert('pp_update_licenses', $row);
}
public static function delete_license(int $id): void
{
global $mdb;
$mdb->delete('pp_update_licenses', ['id' => $id]);
}
public static function toggle_beta(int $id): void
{
global $mdb;
$license = $mdb->get('pp_update_licenses', ['id', 'beta'], ['id' => $id]);
if ($license)
$mdb->update('pp_update_licenses', ['beta' => $license['beta'] ? 0 : 1], ['id' => $id]);
}
private static function zip_dir(string $version): string
{
return substr($version, 0, strlen($version) - (strlen($version) == 5 ? 2 : 1)) . '0';
}
}