'/markets', 'title' => 'Market Check', 'slug' => '/markets/market-check', 'header' => 'Market Content Check', 'scope' => 'markets'], ['parentSlug' => '/solutions', 'title' => 'Solution Check', 'slug' => '/solutions/solution-check', 'header' => 'Solution Content Check', 'scope' => 'solutions'], ]; protected function configure(): void { $this->addOption('apply', null, InputOption::VALUE_NONE, 'Create the pages (default: dry run)'); } protected function execute(InputInterface $input, OutputInterface $output): int { Bootstrap::initializeBackendAuthentication(); $apply = (bool)$input->getOption('apply'); $db = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages'); $template = $db->fetchAssociative( 'SELECT uid, doktype, backend_layout, backend_layout_next_level, no_index, no_follow, nav_hide, no_search, seo_title, description FROM pages WHERE deleted = 0 AND slug = ?', [self::TEMPLATE_SLUG] ); if ($template === false) { $output->writeln('Template page ' . self::TEMPLATE_SLUG . ' not found.'); return Command::FAILURE; } $output->writeln(sprintf( 'Template %s (uid %d): doktype %d, layout "%s", no_index %d, nav_hide %d, no_search %d', self::TEMPLATE_SLUG, $template['uid'], $template['doktype'], $template['backend_layout'], $template['no_index'], $template['nav_hide'], $template['no_search'] )); $output->writeln($apply ? 'APPLY' : 'DRY RUN - nothing is written (--apply to create)'); $created = 0; foreach (self::PAGES as $def) { $existing = $db->fetchAssociative('SELECT uid FROM pages WHERE deleted = 0 AND slug = ?', [$def['slug']]); if ($existing !== false) { $output->writeln(sprintf(' %s exists (uid %d) - skipped', $def['slug'], $existing['uid'])); continue; } $parent = $db->fetchAssociative('SELECT uid FROM pages WHERE deleted = 0 AND sys_language_uid = 0 AND slug = ?', [$def['parentSlug']]); if ($parent === false) { $output->writeln(sprintf(' parent %s not found - %s skipped', $def['parentSlug'], $def['slug'])); continue; } $output->writeln(sprintf(' create %s "%s" under %s (pid %d) + vitec_pagecheck "%s" (scope %s)', $def['slug'], $def['title'], $def['parentSlug'], $parent['uid'], $def['header'], $def['scope'])); $created++; if (!$apply) { continue; } $pageId = 'NEWpage' . $def['scope']; $datamap = [ 'pages' => [ $pageId => [ 'pid' => -(int)$this->lastChild((int)$parent['uid'], (int)$parent['uid']), 'title' => $def['title'], 'slug' => $def['slug'], 'doktype' => (int)$template['doktype'], 'backend_layout' => (string)$template['backend_layout'], 'backend_layout_next_level' => (string)$template['backend_layout_next_level'], 'no_index' => (int)$template['no_index'], 'no_follow' => (int)$template['no_follow'], 'nav_hide' => (int)$template['nav_hide'], 'no_search' => (int)$template['no_search'], 'hidden' => 0, ], ], 'tt_content' => [ 'NEWce' . $def['scope'] => [ 'pid' => $pageId, 'colPos' => 0, 'sys_language_uid' => 0, 'CType' => 'vitec_pagecheck', 'header' => $def['header'], 'pi_flexform' => ['data' => ['sDEF' => ['lDEF' => ['settings.scope' => ['vDEF' => $def['scope']]]]]], ], ], ]; $dataHandler = GeneralUtility::makeInstance(DataHandler::class); $dataHandler->start($datamap, []); $dataHandler->process_datamap(); if ($dataHandler->errorLog !== []) { $output->writeln(' DataHandler: ' . implode(' | ', $dataHandler->errorLog) . ''); return Command::FAILURE; } foreach ($dataHandler->substNEWwithIDs as $new => $uid) { $output->writeln(sprintf(' written: %s -> #%d', $new, $uid)); } } $output->writeln(sprintf('%s: %d page(s).', $apply ? 'DONE' : 'DRY RUN - would create', $created)); if ($apply && $created > 0) { $output->writeln('Afterwards: vendor/bin/typo3 cache:flush'); } return Command::SUCCESS; } /** uid of the last live child page (to append after it), or the parent itself when there is none */ private function lastChild(int $parentUid, int $fallback): int { $uid = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages')->fetchOne( 'SELECT uid FROM pages WHERE deleted = 0 AND sys_language_uid = 0 AND pid = ? ORDER BY sorting DESC LIMIT 1', [$parentUid] ); return $uid === false ? $fallback : (int)$uid; } }