- admin\factory\Releases: logika biznesowa (wersje, licencje, toggle beta) - admin\controls\Releases: handlery HTTP (promote, demote, save/delete/toggle licencji) - admin\view\Releases: renderowanie przez \Tpl - admin/templates/releases/main-view.php: dwa taby (Wersje + Licencje), tabela wersji z przyciskami promocji, CRUD licencji z formularzem inline - templates/additional-menu.php: link "Releases & Licencje" w menu dewelopera - updates/versions.php: przebudowa — czyta z DB (pp_update_licenses, pp_update_versions), auto-discovery nowych ZIPow jako beta - config.php: dodano host_remote dla polaczen zdalnych Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
82 lines
2.3 KiB
PHP
82 lines
2.3 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 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';
|
|
}
|
|
}
|