‪TYPO3CMS  9.5
ImportExportUtility.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
28 {
38  public function ‪importT3DFile($file, $pid)
39  {
40  if (!is_string($file)) {
41  throw new \InvalidArgumentException('Input parameter $file has to be of type string', 1377625645);
42  }
43  if (!is_int($pid)) {
44  throw new \InvalidArgumentException('Input parameter $int has to be of type integer', 1377625646);
45  }
47  $import = GeneralUtility::makeInstance(Import::class);
48  $import->init();
49 
51 
52  $importResponse = 0;
53  if ($file && @is_file($file)) {
54  if ($import->loadFile($file, 1)) {
55  // Import to root page:
56  $import->importData($pid);
57  // Get id of first created page:
58  $newPages = $import->import_mapId['pages'];
59  $importResponse = (int)reset($newPages);
60  }
61  }
62 
63  // Check for errors during the import process:
64  ‪$errors = $import->printErrorLog();
65  if (‪$errors !== '') {
66  $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
67  $logger->warning(‪$errors);
68 
69  if (!$importResponse) {
70  throw new \ErrorException('No page records imported', 1377625537);
71  }
72  }
73  return $importResponse;
74  }
75 
81  protected function ‪getSignalSlotDispatcher()
82  {
83  return GeneralUtility::makeInstance(Dispatcher::class);
84  }
85 
94  {
95  $this->‪getSignalSlotDispatcher()->‪dispatch(__CLASS__, 'afterImportExportInitialisation', [$import]);
96  }
97 }
‪TYPO3\CMS\Impexp\Utility\ImportExportUtility\importT3DFile
‪int importT3DFile($file, $pid)
Definition: ImportExportUtility.php:38
‪TYPO3\CMS\Impexp\Utility\ImportExportUtility\getSignalSlotDispatcher
‪Dispatcher getSignalSlotDispatcher()
Definition: ImportExportUtility.php:81
‪TYPO3\CMS\Impexp\Utility\ImportExportUtility
Definition: ImportExportUtility.php:28
‪TYPO3\CMS\Impexp\Import
Definition: Import.php:40
‪TYPO3\CMS\Impexp\Utility
Definition: ImportExportUtility.php:2
‪TYPO3\CMS\Extbase\SignalSlot\Dispatcher\dispatch
‪mixed dispatch($signalClassName, $signalName, array $signalArguments=[])
Definition: Dispatcher.php:115
‪TYPO3\CMS\Impexp\Utility\ImportExportUtility\emitAfterImportExportInitialisationSignal
‪emitAfterImportExportInitialisationSignal(Import $import)
Definition: ImportExportUtility.php:93
‪$errors
‪$errors
Definition: annotationChecker.php:115
‪TYPO3\CMS\Core\Log\LogManager
Definition: LogManager.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\SignalSlot\Dispatcher
Definition: Dispatcher.php:28