-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken assignment of features and categories
We migrated the part of the import to use DataHandler. We didn't invest too much time as budgets are low. Still the bugs are covered with tests and fixed. Relates: #10782
- Loading branch information
1 parent
0784945
commit d92fffd
Showing
12 changed files
with
274 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Classes/Service/DestinationDataImportService/DataHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
namespace Wrm\Events\Service\DestinationDataImportService; | ||
|
||
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler; | ||
use TYPO3\CMS\Core\Log\Logger; | ||
use TYPO3\CMS\Core\Log\LogManager; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use Wrm\Events\Service\DestinationDataImportService\DataHandler\Assignment; | ||
|
||
final class DataHandler | ||
{ | ||
/** | ||
* @var Logger | ||
*/ | ||
private $logger; | ||
|
||
public function __construct( | ||
LogManager $logManager | ||
) { | ||
$this->logger = $logManager->getLogger(__CLASS__); | ||
} | ||
|
||
public function storeAssignments( | ||
Assignment $assignment | ||
): void { | ||
$data = [ | ||
'tx_events_domain_model_event' => [ | ||
$assignment->getUid() => [ | ||
$assignment->getColumnName() => implode(',', $assignment->getUids()), | ||
], | ||
], | ||
]; | ||
|
||
$this->logger->debug('Import assignment.', $data); | ||
$dataHandler = GeneralUtility::makeInstance(Typo3DataHandler::class); | ||
$dataHandler->start($data, []); | ||
$dataHandler->process_datamap(); | ||
|
||
if ($dataHandler->errorLog !== []) { | ||
$this->logger->error('Error during import of assignments.', [ | ||
'assignment' => $assignment, | ||
'errors' => $dataHandler->errorLog, | ||
]); | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
Classes/Service/DestinationDataImportService/DataHandler/Assignment.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
namespace Wrm\Events\Service\DestinationDataImportService\DataHandler; | ||
|
||
use InvalidArgumentException; | ||
use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject; | ||
|
||
final class Assignment | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $uid; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $columnName; | ||
|
||
/** | ||
* @var int[] | ||
*/ | ||
private $uids; | ||
|
||
/** | ||
* @param AbstractDomainObject[] $assignments | ||
*/ | ||
public function __construct( | ||
int $uid, | ||
string $columnName, | ||
array $assignments | ||
) { | ||
$this->uid = $uid; | ||
$this->columnName = $columnName; | ||
$this->uids = array_map(static function (AbstractDomainObject $model): int { | ||
$uid = $model->getUid(); | ||
if (is_int($uid) === false) { | ||
throw new InvalidArgumentException('Only object with uid supported.', 1698936965); | ||
} | ||
return $uid; | ||
}, $assignments); | ||
} | ||
|
||
public function getUid(): int | ||
{ | ||
return $this->uid; | ||
} | ||
|
||
public function getColumnName(): string | ||
{ | ||
return $this->columnName; | ||
} | ||
|
||
/** | ||
* @return int[] | ||
*/ | ||
public function getUids(): array | ||
{ | ||
return $this->uids; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
Tests/Functional/Import/DestinationDataTest/Assertions/ImportsFeaturesAddsNewFeatures.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.