[BUGFIX] Fix wrong type hint for emitAfterExtensionT3DImportSignal()
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / Utility / ImportExportUtility.php
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
17 /**
18 * Utility for import / export
19 * Can be used for API access for simple importing of files
20 *
21 */
22 class ImportExportUtility {
23
24 /**
25 * Import a T3D file directly
26 *
27 * @param string $file The full absolute path to the file
28 * @param int $pid The pid under which the t3d file should be imported
29 * @throws \ErrorException
30 * @throws \InvalidArgumentException
31 * @return int
32 */
33 public function importT3DFile($file, $pid) {
34 $importResponse = array();
35 if (!is_string($file)) {
36 throw new \InvalidArgumentException('Input parameter $file has to be of type string', 1377625645);
37 }
38 if (!is_int($pid)) {
39 throw new \InvalidArgumentException('Input parameter $int has to be of type integer', 1377625646);
40 }
41 /** @var $import \TYPO3\CMS\Impexp\ImportExport */
42 $import = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
43 $import->init(0, 'import');
44
45 if ($file && @is_file($file)) {
46 if ($import->loadFile($file, 1)) {
47 // Import to root page:
48 $import->importData($pid);
49 // Get id of container page:
50 $newPages = $import->import_mapId['pages'];
51 reset($newPages);
52 $importResponse = current($newPages);
53 }
54 }
55
56 // Check for errors during the import process:
57 if (empty($importResponse) && $errors = $import->printErrorLog()) {
58 throw new \ErrorException($errors, 1377625537);
59 } else {
60 return $importResponse;
61 }
62 }
63 }