Skip to content

Commit

Permalink
[BUGFIX] Fix issue #13 : remove join condition in update request
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian RIVAL committed Oct 22, 2024
1 parent 93ceb22 commit db9f731
Showing 1 changed file with 48 additions and 19 deletions.
67 changes: 48 additions & 19 deletions Classes/Updates/v76/MigrateMediaToAssetsForTextMediaCe.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,54 @@ public function getPrerequisites(): array
*
* @return bool
*/
public function executeUpdate(): bool
{
public function executeUpdate(): bool
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_file_reference');
$queryBuilder = $connection->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$result = $queryBuilder
->select('uid_local', 'uid_foreign')
->from('sys_file_reference')
->leftJoin(
'sys_file_reference','tt_content','tt_content',
$queryBuilder->expr()->eq('sys_file_reference.uid_foreign', $queryBuilder->quoteIdentifier('tt_content.uid'))
)
->where(
$updateQueryBuilder->expr()->and(
$updateQueryBuilder->expr()->eq(
'tt_content.CType', $updateQueryBuilder->createNamedParameter('textmedia', \PDO::PARAM_STR)
),
$updateQueryBuilder->expr()->gt('tt_content.media', $updateQueryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$updateQueryBuilder->expr()->eq('sys_file_reference.tablenames', $updateQueryBuilder->createNamedParameter('tt_content', \PDO::PARAM_STR)),
)
)
->executeQuery();

$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_file_reference');
$updateQueryBuilder = $connection->createQueryBuilder();
$updateQueryBuilder->update('sys_file_reference')
->leftJoin('sys_file_reference','tt_content','tt_content')
->where(
$updateQueryBuilder->expr()->and(
$updateQueryBuilder->expr()->eq(
'tt_content.CType', $updateQueryBuilder->createNamedParameter('textmedia', \PDO::PARAM_STR)
),
$updateQueryBuilder->expr()->gt('media', $updateQueryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
)
)->set('tt_content.assets', 'tt_content.media', false)
->set('sys_file_reference.fieldname', 'assets')
->set('tt_content.media', 0)
->executeStatement();
$ttContentUids = [];
$updateQueryBuilder = $connection->createQueryBuilder();
while ($row = $result->fetchAssociative()) {
$ttContentUids[] = $row['uid_foreign'];
$updateQueryBuilder->update('sys_file_reference')
->set('fieldname', 'assets')
->where(
$updateQueryBuilder->expr()->and(
$updateQueryBuilder->expr()->eq('tablenames', $updateQueryBuilder->createNamedParameter('tt_content', \PDO::PARAM_STR)),
$updateQueryBuilder->expr()->eq('uid_local', $updateQueryBuilder->createNamedParameter($row['uid_local'], \PDO::PARAM_INT)),
$updateQueryBuilder->expr()->eq('uid_foreign', $updateQueryBuilder->createNamedParameter($row['uid_foreign'], \PDO::PARAM_INT)),
)
)
->executeStatement();
}

return true;
}
if (!empty($ttContentUids)) {
$updateQueryBuilder->resetQueryPart();
$updateQueryBuilder->update('tt_content')
->set('assets', 'media', false)
->set('media', 0)
->where($updateQueryBuilder->expr()->in('uid', $ttContentUids))
->executeStatement();
}

return true;
}
}

0 comments on commit db9f731

Please sign in to comment.