From d86efd72e3fc26f88ef344d798d7e1888e5992f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 23 Oct 2026 18:07:05 +0200 Subject: [PATCH] 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 --- .../Command/MigrateGridelementsCommand.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/ep_theme/Classes/Command/MigrateGridelementsCommand.php b/packages/ep_theme/Classes/Command/MigrateGridelementsCommand.php index ee7d9b4..4781b46 100644 --- a/packages/ep_theme/Classes/Command/MigrateGridelementsCommand.php +++ b/packages/ep_theme/Classes/Command/MigrateGridelementsCommand.php @@ -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('Cannot write the report to %s, nothing migrated.', $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, 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); } }