TYPO3 CMS  TYPO3_8-7
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 
27 {
37  public function importT3DFile($file, $pid)
38  {
39  if (!is_string($file)) {
40  throw new \InvalidArgumentException('Input parameter $file has to be of type string', 1377625645);
41  }
42  if (!is_int($pid)) {
43  throw new \InvalidArgumentException('Input parameter $int has to be of type integer', 1377625646);
44  }
46  $import = GeneralUtility::makeInstance(Import::class);
47  $import->init(0, 'import');
48 
50 
51  $importResponse = 0;
52  if ($file && @is_file($file)) {
53  if ($import->loadFile($file, 1)) {
54  // Import to root page:
55  $import->importData($pid);
56  // Get id of first created page:
57  $newPages = $import->import_mapId['pages'];
58  $importResponse = (int)reset($newPages);
59  }
60  }
61 
62  // Check for errors during the import process:
63  $errors = $import->printErrorLog();
64  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 }
static makeInstance($className,... $constructorArguments)