Files
proton/framework/Console/Commands/CoreSyncCommand.php
T
rsgrinko c96150b48a Обновление проектов на ядре: точки расширения, версия, Core\Updater и core:* команды
Событие http.responded и слоты каркаса (layout.head/layout.topbar) — чтобы
частым нуждам проекта не приходилось патчить framework/ напрямую. Версия
ядра (framework/VERSION, мажор.минор.патч) и core:bump — вручную, не хуком
на каждый коммит: версия размечает точку для синхронизации, а не сами
коммиты. Core\Updater поверх контрольных сумм (framework/.checksums.json)
вместо археологии по git log: core:check/diff/sync — что взять безопасно,
что мержить руками, что ядро удалило и не сломает ли это app/config/routes/
resources/views. core:latest и --remote у diff/sync — версия, changelog и
файлы ядра прямо с GitHub/Gitea через HttpClient, без git clone.

На живой симуляции переноса поймал и починил два реальных бага: markSynced()
не давал недомерженному патчу тихо стать новой доверенной базой, а
brokenReferences() не путает магическую ::class и унаследованные от Model
методы с настоящей поломкой.
2026-09-18 20:13:20 +03:00

122 lines
3.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace Rsgrinko\Proton\Console\Commands;
use Rsgrinko\Proton\Console\Command;
use Rsgrinko\Proton\Core\Updater;
use Rsgrinko\Proton\Support\Config;
use Rsgrinko\Proton\Support\ProtonException;
/**
* копирует из ядра то, что безопасно копировать. Без --apply — тот же план,
* что у core:diff, ничего не пишется: цена ошибки здесь выше, чем у migrate.
*/
final class CoreSyncCommand extends Command
{
public function name(): string
{
return 'core:sync';
}
public function description(): string
{
return 'копирует безопасную часть обновления ядра; без --apply — только план (--path=<каталог> или --remote)';
}
public function usage(): string
{
return 'core:sync --path=<каталог с ядром рядом> | --remote [--apply]';
}
public function run(): int
{
$updater = new Updater(APP_ROOT);
if ($updater->storedBaseline() === []) {
$this->fail('Доверенного состояния ещё нет — сначала: php bin/proton core:check --baseline');
return 1;
}
$path = $this->option('path', '');
$temporary = null;
if ($path === null || $path === '') {
if (!$this->hasOption('remote')) {
$this->fail('Нужен --path=<каталог> или --remote');
return 1;
}
try {
$path = $temporary = $updater->downloadRemote(
(string) Config::get('core.repo'),
(string) Config::get('core.branch')
);
} catch (ProtonException $e) {
$this->fail($e->getMessage());
return 1;
}
}
$report = $updater->diff($path);
$apply = $this->hasOption('apply');
if (!$apply) {
$this->line('Только план — для записи добавьте --apply. Что было бы скопировано:');
$this->printList($report['safe']);
} else {
$copied = $updater->copyFiles($path, $report['safe']);
$updater->markSynced($copied);
$this->ok('Скопировано файлов: ' . count($copied));
$this->printList($copied);
}
if ($report['manual'] !== []) {
$this->line();
$this->line('Требуют ручного слияния (не тронуты):');
$this->printList($report['manual']);
}
if ($report['broken'] !== []) {
$this->line();
$this->line('Возможно сломается в вашем коде — проверьте после слияния:');
foreach (array_keys($report['broken']) as $symbol) {
$this->line(' ' . $symbol);
}
}
if ($temporary !== null) {
$updater->cleanupRemote($temporary);
}
if ($apply) {
$this->line();
$this->line('Дальше: php bin/proton test, затем php bin/proton core:bump, когда список ручного слияния разобран.');
}
return 0;
}
/**
* @param array<int, string> $items
*/
private function printList(array $items): void
{
if ($items === []) {
$this->line(' — (пусто)');
return;
}
foreach ($items as $item) {
$this->line(' ' . $item);
}
}
}