Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAM localized meta-data migration #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions Classes/Service/MigrateMetadataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MigrateMetadataService extends AbstractService {
'hpixels' => 'width',
'title' => 'title',
'vpixels' => 'height',
'sys_language_uid' => 'sys_language_uid',
);

/**
Expand Down Expand Up @@ -136,11 +137,18 @@ public function execute() {
$this->isInstalledMedia = ExtensionManagementUtility::isLoaded('media');

while ($record = $this->database->sql_fetch_assoc($res)) {
$fileMetaData = $this->createArrayForUpdateSysFileMetadataRecord($record);
$this->database->exec_UPDATEquery(
'sys_file_metadata',
'uid = ' . $record['metadata_uid'],
$this->createArrayForUpdateSysFileMetadataRecord($record)
'uid = ' . $record['metadata_uid'] . ' AND sys_language_uid = ' . $record['sys_language_uid'],
$fileMetaData
);
// if no SQL error and still no record has been updated, then it means that
// the record does not exist and must be created e.g. localized DAM record.
if (($this->database->sql_error() == '') && $this->database->sql_affected_rows() == 0) {
$this->updateArrayForInsertSysFileRecord($fileMetaData, $record);
$this->database->exec_INSERTquery('sys_file_metadata', $fileMetaData);
}

$this->database->exec_UPDATEquery(
'sys_file',
Expand All @@ -165,7 +173,7 @@ protected function execSelectMigratedSysFilesQuery() {
return $this->database->exec_SELECTquery(
'DISTINCT m.uid AS metadata_uid, f.uid as file_uid, f._migrateddamuid AS dam_uid, d.*',
'sys_file f, sys_file_metadata m, tx_dam d',
'm.file=f.uid AND f._migrateddamuid=d.uid AND f._migrateddamuid > 0'
'm.file=f.uid AND ((f._migrateddamuid = d.uid OR f._migrateddamuid = d.l18n_parent)) AND f._migrateddamuid > 0'
);
}

Expand All @@ -191,6 +199,8 @@ protected function createArrayForUpdateSysFileMetadataRecord(array $damRecord) {
}
}

$updateData['tstamp'] = $_SERVER['REQUEST_TIME'];

return $updateData;
}

Expand All @@ -215,4 +225,24 @@ protected function createArrayForUpdateSysFileRecord(array $damRecord) {

return $updateData;
}

/**
* Update provided array with necessary fields required to create a new `sys_file_metadata` record.
*
* @param array $fileMetaData File meta data.
* @param array $damRecord DAM record file with UIDs for corresponding
* `sys_file` and `sys_file_metadata` records.
*
* @return void
*/
protected function updateArrayForInsertSysFileRecord(array &$fileMetaData, array $damRecord) {
$fileMetaData['file'] = $damRecord['file_uid'];
$fileMetaData['categories'] = 0;
$fileMetaData['l10n_parent'] = (intval($damRecord['sys_language_uid']) > 0) ? $damRecord['metadata_uid'] : 0;

if ($this->isInstalledFileMetadata) {
$fileMetaData['note'] = $fileMetaData['note'] ? $fileMetaData['note'] : '';
$fileMetaData['caption'] = $fileMetaData['caption'] ? $fileMetaData['caption'] : '';
}
}
}
21 changes: 12 additions & 9 deletions Classes/Service/MigrateRelationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,19 @@ protected function execSelectDamReferencesWhereSysFileExists() {

return $this->database->exec_SELECTquery(
'tx_dam_mm_ref.*,
sys_file_metadata.title,
sys_file_metadata.description,
sys_file_metadata.alternative,
sys_file.uid as sys_file_uid',
sys_file_metadata.title,
sys_file_metadata.description,
sys_file_metadata.alternative,
sys_file.uid as sys_file_uid',
'tx_dam_mm_ref
JOIN sys_file ON
sys_file._migrateddamuid = tx_dam_mm_ref.uid_local
JOIN sys_file_metadata ON
sys_file.uid = sys_file_metadata.file
',
JOIN tx_dam ON
tx_dam_mm_ref.uid_local = tx_dam.uid
JOIN sys_file ON
sys_file._migrateddamuid = tx_dam_mm_ref.uid_local
JOIN sys_file_metadata ON
(tx_dam.sys_language_uid = sys_file_metadata.sys_language_uid AND sys_file.uid = sys_file_metadata.file)
JOIN tt_content ON tx_dam_mm_ref.uid_foreign = tt_content.uid
',
$where,
'',
'tx_dam_mm_ref.sorting ASC,tx_dam_mm_ref.sorting_foreign ASC',
Expand Down
1 change: 1 addition & 0 deletions Classes/Service/MigrateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MigrateService extends AbstractService {
'description' => 'description',
'alt_text' => 'alternative',
'categories' => 'categories',
'sys_language_uid' => 'sys_language_uid',
);

/**
Expand Down