feat(05-domain-seoadditional-cron-releases): Domain layer kompletny — SeoAdditional + Cron + Releases
Phase 5 complete: - Domain\SeoAdditional\SeoAdditionalRepository (elementDelete, elementSave, elementDetails) - Domain\Cron\CronRepository (3 pub + 12 private helper methods) - Domain\Releases\ReleasesRepository (9 metod: wersje, licencje, discover) - Domain\Releases\UpdateRepository (auto-update, konstruktor($db, $settings)) - 4 legacy factory wrappers zaktualizowane do wrapper delegation Domain layer: 13/13 repozytoriów kompletnych. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
101
autoload/Domain/Releases/ReleasesRepository.php
Normal file
101
autoload/Domain/Releases/ReleasesRepository.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace Domain\Releases;
|
||||
|
||||
class ReleasesRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function getVersions(): array
|
||||
{
|
||||
$rows = $this->db->select('pp_update_versions', '*', ['ORDER' => ['version' => 'DESC']]);
|
||||
if (!$rows) return [];
|
||||
foreach ($rows as &$row)
|
||||
$row['zip_exists'] = file_exists('../updates/' . $this->zipDir($row['version']) . '/ver_' . $row['version'] . '.zip');
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function promote(string $version): void
|
||||
{
|
||||
$this->db->update('pp_update_versions',
|
||||
['channel' => 'stable', 'promoted_at' => date('Y-m-d H:i:s')],
|
||||
['version' => $version]
|
||||
);
|
||||
}
|
||||
|
||||
public function demote(string $version): void
|
||||
{
|
||||
$this->db->update('pp_update_versions',
|
||||
['channel' => 'beta', 'promoted_at' => null],
|
||||
['version' => $version]
|
||||
);
|
||||
}
|
||||
|
||||
public function discoverVersions(): int
|
||||
{
|
||||
$known = array_flip($this->db->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;
|
||||
$this->db->insert('pp_update_versions', [
|
||||
'version' => $ver,
|
||||
'channel' => 'beta',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
$known[$ver] = true;
|
||||
$added++;
|
||||
}
|
||||
return $added;
|
||||
}
|
||||
|
||||
public function getLicenses(): array
|
||||
{
|
||||
return $this->db->select('pp_update_licenses', '*', ['ORDER' => ['domain' => 'ASC']]) ?: [];
|
||||
}
|
||||
|
||||
public function getLicense(int $id): array
|
||||
{
|
||||
return $this->db->get('pp_update_licenses', '*', ['id' => $id]) ?: [];
|
||||
}
|
||||
|
||||
public function saveLicense(array $data): void
|
||||
{
|
||||
$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']))
|
||||
$this->db->update('pp_update_licenses', $row, ['id' => (int)$data['id']]);
|
||||
else
|
||||
$this->db->insert('pp_update_licenses', $row);
|
||||
}
|
||||
|
||||
public function deleteLicense(int $id): void
|
||||
{
|
||||
$this->db->delete('pp_update_licenses', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function toggleBeta(int $id): void
|
||||
{
|
||||
$license = $this->db->get('pp_update_licenses', ['id', 'beta'], ['id' => $id]);
|
||||
if ($license)
|
||||
$this->db->update('pp_update_licenses', ['beta' => $license['beta'] ? 0 : 1], ['id' => $id]);
|
||||
}
|
||||
|
||||
private function zipDir(string $version): string
|
||||
{
|
||||
return substr($version, 0, strlen($version) - (strlen($version) == 5 ? 2 : 1)) . '0';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user