fix: ep:migrate-gridelements stops cleanly when the report cannot be written
An unwritable --report path ended in a TypeError from fputcsv() after the counts were printed. The command now says so and exits with an error before anything is migrated. Page titles in the report include hidden pages (Connection::select() applied the frontend restrictions). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
119364dcaa
commit
d86efd72e3
1 file changed
+11
-5
@@ -161,7 +161,10 @@ class MigrateGridelementsCommand extends Command
|
||||
$output->writeln(sprintf('%6d other rows with grid values, cleared', $leftovers));
|
||||
}
|
||||
if ($input->getOption('report')) {
|
||||
$this->writeReport((string)$input->getOption('report'), $report);
|
||||
if (!$this->writeReport((string)$input->getOption('report'), $report)) {
|
||||
$output->writeln(sprintf('<error>Cannot write the report to %s, nothing migrated.</error>', $input->getOption('report')));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
$output->writeln(sprintf('Report: %d rows in %s', count($report), $input->getOption('report')));
|
||||
}
|
||||
if ($updates === [] && $leftovers === 0) {
|
||||
@@ -194,19 +197,22 @@ class MigrateGridelementsCommand extends Command
|
||||
/**
|
||||
* @param list<array{0: array<string, mixed>, 1: string, 2: string, 3: string}> $rows
|
||||
*/
|
||||
private function writeReport(string $file, array $rows): void
|
||||
private function writeReport(string $file, array $rows): bool
|
||||
{
|
||||
$handle = @fopen($file, 'wb');
|
||||
if ($handle === false) {
|
||||
return false;
|
||||
}
|
||||
$titles = [];
|
||||
foreach ($this->connectionPool->getConnectionForTable('pages')->select(['uid', 'title'], 'pages', ['sys_language_uid' => 0])->iterateAssociative() as $page) {
|
||||
foreach ($this->connectionPool->getConnectionForTable('pages')->executeQuery('SELECT uid, title FROM pages WHERE sys_language_uid = 0')->iterateAssociative() as $page) {
|
||||
$titles[(int)$page['uid']] = $page['title'];
|
||||
}
|
||||
$handle = fopen($file, 'wb');
|
||||
fputcsv($handle, ['uid', 'pid', 'page', 'CType', 'header', 'hidden', 'group', 'reason', 'action'], escape: '');
|
||||
foreach ($rows as [$row, $group, $reason, $action]) {
|
||||
fputcsv($handle, [
|
||||
$row['uid'], $row['pid'], $titles[(int)$row['pid']] ?? '', $row['CType'], $row['header'], $row['hidden'], $group, $reason, $action,
|
||||
], escape: '');
|
||||
}
|
||||
fclose($handle);
|
||||
return fclose($handle);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user