TYPO3  7.6
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 
18 
25 {
35  public function importT3DFile($file, $pid)
36  {
37  if (!is_string($file)) {
38  throw new \InvalidArgumentException('Input parameter $file has to be of type string', 1377625645);
39  }
40  if (!is_int($pid)) {
41  throw new \InvalidArgumentException('Input parameter $int has to be of type integer', 1377625646);
42  }
44  $import = GeneralUtility::makeInstance(\TYPO3\CMS\Impexp\ImportExport::class);
45  $import->init(0, 'import');
46 
48 
49  $importResponse = 0;
50  if ($file && @is_file($file)) {
51  if ($import->loadFile($file, 1)) {
52  // Import to root page:
53  $import->importData($pid);
54  // Get id of first created page:
55  $newPages = $import->import_mapId['pages'];
56  $importResponse = (int)reset($newPages);
57  }
58  }
59 
60  // Check for errors during the import process:
61  $errors = $import->printErrorLog();
62  if ($errors !== '') {
64  $logger = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
65  $logger->warning($errors);
66 
67  if (!$importResponse) {
68  throw new \ErrorException('No page records imported', 1377625537);
69  }
70  }
71  return $importResponse;
72  }
73 
79  protected function getSignalSlotDispatcher()
80  {
81  return GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
82  }
83 
91  protected function emitAfterImportExportInitialisationSignal(\TYPO3\CMS\Impexp\ImportExport $import)
92  {
93  $this->getSignalSlotDispatcher()->dispatch(__CLASS__, 'afterImportExportInitialisation', array($import));
94  }
95 }