From f72b7c0ae44270a6f9990a78cb315546e37f26d5 Mon Sep 17 00:00:00 2001 From: Nicole Cordes Date: Thu, 3 Sep 2015 12:10:46 +0200 Subject: [PATCH] [BUGFIX] Check if EXT:filemetadata is loaded The field sys_file_metadata.caption is added as select field but this field only exists in the database table if the extension filemetadata is active. The patch adds a check if the extension is loaded before inserting the field into the SQL statement. --- Classes/Service/MigrateRelationsService.php | 58 ++++++++++++--------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/Classes/Service/MigrateRelationsService.php b/Classes/Service/MigrateRelationsService.php index 86748bd..cc8078e 100644 --- a/Classes/Service/MigrateRelationsService.php +++ b/Classes/Service/MigrateRelationsService.php @@ -27,6 +27,7 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ use TYPO3\CMS\Core\Messaging\FlashMessage; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -313,38 +314,42 @@ protected function getPidOfForeignRecord(array $damRelation) { return $record['pid'] ?: 0; } - /** - * After a migration of tx_dam -> sys_file the col _migrateddamuid is - * filled with dam uid Now we can search in dam relations for dam records - * which have already been migrated to sys_file - * - * @return \mysqli_result - */ - protected function execSelectDamReferencesWhereSysFileExists() { - $where = 'tx_dam_mm_ref.tablenames <> ""'; - if ($this->tablename !== '') { - $where = 'tx_dam_mm_ref.tablenames = "' . $this->tablename . '"'; - } - - return $this->database->exec_SELECTquery( - 'tx_dam_mm_ref.*, + /** + * After a migration of tx_dam -> sys_file the col _migrateddamuid is + * filled with dam uid Now we can search in dam relations for dam records + * which have already been migrated to sys_file + * + * @return \mysqli_result + */ + protected function execSelectDamReferencesWhereSysFileExists() { + $where = 'tx_dam_mm_ref.tablenames <> ""'; + if ($this->tablename !== '') { + $where = 'tx_dam_mm_ref.tablenames = "' . $this->tablename . '"'; + } + + $selectFields = 'tx_dam_mm_ref.*, sys_file_metadata.title, sys_file_metadata.description, sys_file_metadata.alternative, - sys_file_metadata.caption, - sys_file.uid as sys_file_uid', - 'tx_dam_mm_ref + sys_file.uid as sys_file_uid'; + if (ExtensionManagementUtility::isLoaded('filemetadata')) { + $selectFields .= ', sys_file_metadata.caption'; + } + + return $this->database->exec_SELECTquery( + $selectFields, + '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 ', - $where, - '', - 'tx_dam_mm_ref.sorting ASC,tx_dam_mm_ref.sorting_foreign ASC', - (int)$this->getRecordLimit() - ); - } + $where, + '', + 'tx_dam_mm_ref.sorting ASC,tx_dam_mm_ref.sorting_foreign ASC', + (int)$this->getRecordLimit() + ); + } /** * col for fieldname was saved in col "ident" @@ -426,9 +431,12 @@ protected function compileChainFieldArray($damRelation, $ttContentFields, $conte // assign DAM meta data fields // fields are actually coming from migrated sys_file_metadata $out[self::CHAIN_META_ALT] = $damRelation['alternative']; - $out[self::CHAIN_META_CAPTION] = $damRelation['caption']; $out[self::CHAIN_META_DESCRIPTION] = $damRelation['description']; $out[self::CHAIN_META_TITLE] = $damRelation['title']; + $out[self::CHAIN_META_CAPTION] = ''; + if (ExtensionManagementUtility::isLoaded('filemetadata')) { + $out[self::CHAIN_META_CAPTION] = $damRelation['caption']; + } return $out; }