getConnectionForTable('tt_content'); $tableColumns = $connection->getSchemaManager()->listTableColumns('tt_content'); // Only proceed if section_frame field still exists if (!isset($tableColumns['section_frame'])) { return false; } $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content'); $queryBuilder->getRestrictions()->removeAll(); $elementCount = $queryBuilder->count('uid') ->from('tt_content') ->where( $queryBuilder->expr()->gt('section_frame', 0) ) ->execute() ->fetchColumn(0); return (bool)$elementCount; } /** * @return string[] All new fields and tables must exist */ public function getPrerequisites(): array { return [ DatabaseUpdatedPrerequisite::class ]; } /** * Performs the database update * * @return bool */ public function executeUpdate(): bool { $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content'); $queryBuilder = $connection->createQueryBuilder(); $queryBuilder->getRestrictions()->removeAll(); $statement = $queryBuilder->select('uid', 'section_frame') ->from('tt_content') ->where( $queryBuilder->expr()->gt('section_frame', 0) ) ->execute(); while ($record = $statement->fetch()) { $queryBuilder = $connection->createQueryBuilder(); $queryBuilder->update('tt_content') ->where( $queryBuilder->expr()->eq( 'uid', $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT) ) ) ->set('section_frame', 0, false) ->set('frame_class', $this->mapSectionFrame($record['section_frame'])); $queryBuilder->execute(); } return true; } /** * Map the old to the new values * * @param int $sectionFrame The content of the FlexForm * @return string The equivalent value frame_class */ protected function mapSectionFrame($sectionFrame) { $mapping = [ 0 => 'default', 5 => 'ruler-before', 6 => 'ruler-after', 10 => 'indent', 11 => 'indent-left', 12 => 'indent-right', 66 => 'none' ]; if (array_key_exists($sectionFrame, $mapping)) { return $mapping[$sectionFrame]; } return 'custom-' . (int)$sectionFrame; } }