eventDispatcher = $eventDispatcher; } public function getImport(): ?Import { return $this->import; } public function disableSiteConfigurationImport(): void { $this->importSiteConfigurations = false; } /** * Import a T3D file directly * * @param string $file The full absolute path to the file * @param int $pid The pid under which the t3d file should be imported * @throws \ErrorException * @return int ID of first created page */ public function importT3DFile(string $file, int $pid): int { $this->import = GeneralUtility::makeInstance(Import::class); $this->import->setPid($pid); if (!$this->importSiteConfigurations) { $this->import->disableSiteConfigurationImport(); } $this->eventDispatcher->dispatch(new BeforeImportEvent($this->import, $file)); try { $this->import->loadFile($file); $this->import->importData(); } catch (\Exception $e) { $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); $logger->warning( $e->getMessage() . PHP_EOL . implode(PHP_EOL, $this->import->getErrorLog()) ); } // Get id of first created page: $importResponse = 0; $importMapId = $this->import->getImportMapId(); if (isset($importMapId['pages'])) { $newPages = $importMapId['pages']; $importResponse = (int)reset($newPages); } // Check for errors during the import process: if ($this->import->hasErrors()) { if (!$importResponse) { throw new \ErrorException('No page records imported', 1377625537); } } return $importResponse; } }