Skip to content

Commit

Permalink
[BUGFIX] Allow import module to also access distributions
Browse files Browse the repository at this point in the history
This patch streamlines the import module with the import command.
While the CLI commands can import data from extensions, the interface
has no option to perform this action. We are now listing available
datasets from distributions in the import module.

Resolves: #101256
Releases: main, 12.4
Change-Id: I6fac0d22bbb42a6ff8b682b6c3415a3d7e4982d6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79863
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
benjaminkott authored and bmack committed Jul 7, 2023
1 parent 060500a commit 76d868d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
28 changes: 27 additions & 1 deletion typo3/sysext/impexp/Classes/Controller/ImportController.php
Expand Up @@ -27,6 +27,7 @@
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter;
Expand All @@ -36,6 +37,7 @@
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Impexp\Import;

/**
Expand Down Expand Up @@ -176,7 +178,11 @@ protected function configureImportFromFormDataAndImportIfRequested(ModuleTemplat
$import->setShowDiff(!(bool)($inputData['notShowDiff'] ?? false));
$import->setSoftrefInputValues((array)($inputData['softrefInputValues'] ?? null));
if (!empty($inputData['file'])) {
$filePath = $this->getFilePathWithinFileMountBoundaries((string)$inputData['file']);
if (PathUtility::isExtensionPath($inputData['file'])) {
$filePath = $inputData['file'];
} else {
$filePath = $this->getFilePathWithinFileMountBoundaries((string)$inputData['file']);
}
try {
$import->loadFile($filePath, true);
$import->checkImportPrerequisites();
Expand Down Expand Up @@ -204,6 +210,8 @@ protected function getFilePathWithinFileMountBoundaries(string $filePath): strin
protected function getSelectableFileList(Import $import): array
{
$exportFiles = [];

// Fileadmin
$folder = $import->getOrCreateDefaultImportExportFolder();
if ($folder !== null) {
$filter = GeneralUtility::makeInstance(FileExtensionFilter::class);
Expand All @@ -215,6 +223,24 @@ protected function getSelectableFileList(Import $import): array
foreach ($exportFiles as $file) {
$selectableFiles[$file->getCombinedIdentifier()] = $file->getPublicUrl();
}

// Extension Distribution
if ($this->getBackendUser()->isAdmin()) {
$possibleImportFiles = [
'Initialisation/data.t3d',
'Initialisation/data.xml',
];
$activePackages = GeneralUtility::makeInstance(PackageManager::class)->getActivePackages();
foreach ($activePackages as $package) {
foreach ($possibleImportFiles as $possibleImportFile) {
if (!file_exists($package->getPackagePath() . $possibleImportFile)) {
continue;
}
$selectableFiles['EXT:' . $package->getPackageKey() . '/' . $possibleImportFile] = 'EXT:' . $package->getPackageKey() . '/' . $possibleImportFile;
}
}
}

return $selectableFiles;
}

Expand Down
5 changes: 4 additions & 1 deletion typo3/sysext/impexp/Classes/ImportExport.php
Expand Up @@ -597,8 +597,11 @@ protected function addRecord(string $table, int $uid, array &$lines, int $indent
$databaseRecord = $this->getRecordFromDatabase($table, $newUid, '*');
BackendUtility::workspaceOL($table, $databaseRecord);
}
/** @var array|null $importRecord */
$importRecord = $this->dat['records'][$table . ':' . $uid]['data'] ?? null;
if (is_array($databaseRecord) && is_array($importRecord)) {
if ($databaseRecord === null) {
$line['showDiffContent'] = '';
} elseif (is_array($databaseRecord) && is_array($importRecord)) {
$line['showDiffContent'] = $this->compareRecords($databaseRecord, $importRecord, $table, $diffInverse);
} else {
$line['showDiffContent'] = 'ERROR: One of the inputs were not an array!';
Expand Down
Expand Up @@ -33,7 +33,7 @@
'active' => 'active',
'updatePath' => '<strong>NEW!</strong>',
'updateMode' => sprintf('<select class="form-select form-select-sm" name="tx_impexp[import_mode][pages:0]" style="width: 100px"><option value="0">Insert</option><option value="%s">Force UID [0] (Admin)</option><option value="%s">Exclude</option></select>', \TYPO3\CMS\Impexp\Import::IMPORT_MODE_FORCE_UID, \TYPO3\CMS\Impexp\Import::IMPORT_MODE_EXCLUDE),
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -310,7 +310,7 @@
'active' => 'active',
'updatePath' => '<strong>NEW!</strong>',
'updateMode' => sprintf('<select class="form-select form-select-sm" name="tx_impexp[import_mode][tt_content:3]" style="width: 100px"><option value="0">Insert</option><option value="%s">Force UID [3] (Admin)</option><option value="%s">Exclude</option></select>', \TYPO3\CMS\Impexp\Import::IMPORT_MODE_FORCE_UID, \TYPO3\CMS\Impexp\Import::IMPORT_MODE_EXCLUDE),
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -374,7 +374,7 @@
'active' => 'active',
'updatePath' => '<strong>NEW!</strong>',
'updateMode' => sprintf('<select class="form-select form-select-sm" name="tx_impexp[import_mode][sys_file_reference:1]" style="width: 100px"><option value="0">Insert</option><option value="%s">Force UID [1] (Admin)</option><option value="%s">Exclude</option></select>', \TYPO3\CMS\Impexp\Import::IMPORT_MODE_FORCE_UID, \TYPO3\CMS\Impexp\Import::IMPORT_MODE_EXCLUDE),
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -423,7 +423,7 @@
'active' => 'active',
'updatePath' => '<strong>NEW!</strong>',
'updateMode' => sprintf('<select class="form-select form-select-sm" name="tx_impexp[import_mode][sys_file_reference:2]" style="width: 100px"><option value="0">Insert</option><option value="%s">Force UID [2] (Admin)</option><option value="%s">Exclude</option></select>', \TYPO3\CMS\Impexp\Import::IMPORT_MODE_FORCE_UID, \TYPO3\CMS\Impexp\Import::IMPORT_MODE_EXCLUDE),
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -472,7 +472,7 @@
'active' => 'active',
'updatePath' => '<strong>NEW!</strong>',
'updateMode' => sprintf('<select class="form-select form-select-sm" name="tx_impexp[import_mode][sys_file_reference:3]" style="width: 100px"><option value="0">Insert</option><option value="%s">Force UID [3] (Admin)</option><option value="%s">Exclude</option></select>', \TYPO3\CMS\Impexp\Import::IMPORT_MODE_FORCE_UID, \TYPO3\CMS\Impexp\Import::IMPORT_MODE_EXCLUDE),
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down
Expand Up @@ -31,7 +31,7 @@
</span>',
'title' => '',
'active' => 'active',
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand All @@ -48,7 +48,7 @@
</span>',
'title' => 'used-1.jpg',
'active' => 'active',
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -118,7 +118,7 @@
</span>',
'title' => 'fileadmin',
'active' => 'active',
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -269,7 +269,7 @@
</span>',
'title' => 'CE 3 second image',
'active' => 'active',
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -331,7 +331,7 @@
</span>',
'title' => 'used-1.jpg',
'active' => 'active',
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -378,7 +378,7 @@
</span>',
'title' => 'used-2.jpg',
'active' => 'active',
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down Expand Up @@ -425,7 +425,7 @@
</span>',
'title' => 'used-2.jpg',
'active' => 'active',
'showDiffContent' => 'ERROR: One of the inputs were not an array!',
'showDiffContent' => '',
'controls' => '',
'message' => '',
],
Expand Down

0 comments on commit 76d868d

Please sign in to comment.