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:
@@ -6,98 +6,63 @@ 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;
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
return $repo->getVersions();
|
||||
}
|
||||
|
||||
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]
|
||||
);
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->promote($version);
|
||||
}
|
||||
|
||||
public static function demote(string $version): void
|
||||
{
|
||||
global $mdb;
|
||||
$mdb->update('pp_update_versions',
|
||||
['channel' => 'beta', 'promoted_at' => null],
|
||||
['version' => $version]
|
||||
);
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->demote($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;
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
return $repo->discoverVersions();
|
||||
}
|
||||
|
||||
public static function get_licenses(): array
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb->select('pp_update_licenses', '*', ['ORDER' => ['domain' => 'ASC']]) ?: [];
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
return $repo->getLicenses();
|
||||
}
|
||||
|
||||
public static function get_license(int $id): array
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb->get('pp_update_licenses', '*', ['id' => $id]) ?: [];
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
return $repo->getLicense($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);
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->saveLicense($data);
|
||||
}
|
||||
|
||||
public static function delete_license(int $id): void
|
||||
{
|
||||
global $mdb;
|
||||
$mdb->delete('pp_update_licenses', ['id' => $id]);
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->deleteLicense($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';
|
||||
$repo = new \Domain\Releases\ReleasesRepository($mdb);
|
||||
$repo->toggleBeta($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,51 +5,21 @@ class SeoAdditional
|
||||
public static function element_delete( $element_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_seo_additional', [ 'id' => (int)$element_id ] );
|
||||
$repo = new \Domain\SeoAdditional\SeoAdditionalRepository($mdb);
|
||||
return $repo->elementDelete($element_id);
|
||||
}
|
||||
|
||||
|
||||
public static function element_save( $id, $url, $status, $title, $keywords, $description, $text )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$id )
|
||||
{
|
||||
if ( $mdb -> insert( 'pp_seo_additional', [
|
||||
'url' => $url,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'title' => $title,
|
||||
'keywords' => $keywords,
|
||||
'description' => $description,
|
||||
'text' => $text
|
||||
] ) )
|
||||
{
|
||||
\S::delete_cache();
|
||||
return $mdb -> id();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_seo_additional', [
|
||||
'url' => $url,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'title' => $title,
|
||||
'keywords' => $keywords,
|
||||
'description' => $description,
|
||||
'text' => $text
|
||||
$repo = new \Domain\SeoAdditional\SeoAdditionalRepository($mdb);
|
||||
return $repo->elementSave($id, $url, $status, $title, $keywords, $description, $text);
|
||||
}
|
||||
|
||||
], [
|
||||
'id' => (int)$id
|
||||
] );
|
||||
|
||||
\S::delete_cache();
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function element_details( $element_id )
|
||||
{
|
||||
global $mdb;
|
||||
$result = $mdb -> get ( 'pp_seo_additional', '*', [ 'id' => (int)$element_id ] );
|
||||
return $result;
|
||||
global $mdb;
|
||||
$repo = new \Domain\SeoAdditional\SeoAdditionalRepository($mdb);
|
||||
return $repo->elementDetails($element_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,151 +6,7 @@ class Update
|
||||
public static function update()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
\S::delete_session( 'new-version' );
|
||||
|
||||
$versions = file_get_contents( 'http://www.cmspro.project-dc.pl/updates/versions.php?key=' . $settings['update_key'] );
|
||||
$versions = explode( PHP_EOL, $versions );
|
||||
|
||||
foreach ( $versions as $ver )
|
||||
{
|
||||
$ver = trim( $ver );
|
||||
if ( (float)$ver > (float)\S::get_version() )
|
||||
{
|
||||
if ( strlen( $ver ) == 5 )
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 2 ) . 0;
|
||||
else
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 1 ) . 0;
|
||||
|
||||
$baseUrl = 'http://www.cmspro.project-dc.pl/updates/' . $dir;
|
||||
|
||||
/* pobranie paczki ZIP */
|
||||
$file = file_get_contents( $baseUrl . '/ver_' . $ver . '.zip' );
|
||||
|
||||
$dlHandler = fopen( 'update.zip' , 'w' );
|
||||
if ( !fwrite( $dlHandler, $file ) )
|
||||
return false;
|
||||
fclose( $dlHandler );
|
||||
|
||||
if ( !file_exists( 'update.zip' ) )
|
||||
return false;
|
||||
|
||||
/* pobranie manifestu JSON (nowy system) lub fallback na legacy _sql.txt / _files.txt */
|
||||
$manifest = null;
|
||||
$manifestJson = @file_get_contents( $baseUrl . '/ver_' . $ver . '_manifest.json' );
|
||||
if ( $manifestJson )
|
||||
{
|
||||
if ( substr( $manifestJson, 0, 3 ) === "\xEF\xBB\xBF" )
|
||||
$manifestJson = substr( $manifestJson, 3 );
|
||||
$manifest = @json_decode( $manifestJson, true );
|
||||
}
|
||||
|
||||
if ( is_array( $manifest ) )
|
||||
{
|
||||
/* weryfikacja checksum SHA256 */
|
||||
if ( !empty( $manifest['checksum_zip'] ) )
|
||||
{
|
||||
$expectedHash = str_replace( 'sha256:', '', $manifest['checksum_zip'] );
|
||||
$actualHash = hash_file( 'sha256', 'update.zip' );
|
||||
if ( $expectedHash !== $actualHash )
|
||||
{
|
||||
unlink( 'update.zip' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* aktualizacja bazy danych z manifestu */
|
||||
if ( !empty( $manifest['sql'] ) && is_array( $manifest['sql'] ) )
|
||||
{
|
||||
foreach ( $manifest['sql'] as $query )
|
||||
{
|
||||
$query = trim( $query );
|
||||
if ( $query )
|
||||
$mdb -> query( $query );
|
||||
}
|
||||
}
|
||||
|
||||
/* usuwanie plikow z manifestu */
|
||||
if ( !empty( $manifest['files']['deleted'] ) && is_array( $manifest['files']['deleted'] ) )
|
||||
{
|
||||
foreach ( $manifest['files']['deleted'] as $filePath )
|
||||
{
|
||||
$fullPath = '../' . $filePath;
|
||||
if ( file_exists( $fullPath ) )
|
||||
unlink( $fullPath );
|
||||
}
|
||||
}
|
||||
|
||||
/* usuwanie katalogow z manifestu */
|
||||
if ( !empty( $manifest['directories_deleted'] ) && is_array( $manifest['directories_deleted'] ) )
|
||||
{
|
||||
foreach ( $manifest['directories_deleted'] as $dirPath )
|
||||
{
|
||||
$fullPath = '../' . $dirPath;
|
||||
if ( is_dir( $fullPath ) )
|
||||
\S::delete_dir( $fullPath );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* legacy: aktualizacja bazy danych z _sql.txt */
|
||||
$sql = @file_get_contents( $baseUrl . '/ver_' . $ver . '_sql.txt' );
|
||||
if ( $sql )
|
||||
{
|
||||
$sql = explode( PHP_EOL, $sql );
|
||||
if ( is_array( $sql ) ) foreach ( $sql as $query )
|
||||
{
|
||||
$query = trim( $query );
|
||||
if ( $query )
|
||||
$mdb -> query( $query );
|
||||
}
|
||||
}
|
||||
|
||||
/* legacy: usuwanie zbednych plikow z _files.txt */
|
||||
$lines = @file_get_contents( $baseUrl . '/ver_' . $ver . '_files.txt' );
|
||||
if ( $lines )
|
||||
{
|
||||
$lines = explode( PHP_EOL, $lines );
|
||||
if ( is_array( $lines ) ) foreach ( $lines as $line )
|
||||
{
|
||||
if ( strpos( $line, 'F: ' ) !== false )
|
||||
{
|
||||
$delFile = substr( $line, 3, strlen( $line ) );
|
||||
if ( file_exists( $delFile ) )
|
||||
unlink( $delFile );
|
||||
}
|
||||
|
||||
if ( strpos( $line, 'D: ' ) !== false )
|
||||
{
|
||||
$delDir = substr( $line, 3, strlen( $line ) );
|
||||
if ( is_dir( $delDir ) )
|
||||
\S::delete_dir( $delDir );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* wgrywanie nowych plikow */
|
||||
$file_name = 'update.zip';
|
||||
|
||||
$path = pathinfo( realpath( $file_name ), PATHINFO_DIRNAME );
|
||||
$path = substr( $path, 0, strlen( $path ) - 5 );
|
||||
$zip = new \ZipArchive;
|
||||
$res = $zip -> open( $file_name );
|
||||
if ( $res === TRUE )
|
||||
{
|
||||
$zip -> extractTo( $path );
|
||||
$zip -> close();
|
||||
unlink( $file_name );
|
||||
}
|
||||
|
||||
$updateThis = fopen( '../libraries/version.ini', 'w' );
|
||||
fwrite( $updateThis, $ver );
|
||||
fclose( $updateThis );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$repo = new \Domain\Releases\UpdateRepository($mdb, $settings);
|
||||
return $repo->update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user