TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ImportExportUtility.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Impexp\Utility;
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(0, 'import');
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 !== '') {
67  $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
68  $logger->warning($errors);
69 
70  if (!$importResponse) {
71  throw new \ErrorException('No page records imported', 1377625537);
72  }
73  }
74  return $importResponse;
75  }
76 
82  protected function getSignalSlotDispatcher()
83  {
84  return GeneralUtility::makeInstance(Dispatcher::class);
85  }
86 
95  {
96  $this->getSignalSlotDispatcher()->dispatch(__CLASS__, 'afterImportExportInitialisation', [$import]);
97  }
98 }
static makeInstance($className,...$constructorArguments)