getCountOfRowsWhichNeedUpdate(); return sprintf('Update %d records to set the default value of the fields imagewidth & imageheight to NULL instead of 0.', $fieldsThatNeedUpdate); } protected function getCountOfRowsWhichNeedUpdate(): int { $qb = $this->connectionPool->getQueryBuilderForTable('tt_content'); $qb->getRestrictions()->removeAll(); return (int)$qb ->count('*') ->from('tt_content') ->where( $qb->expr()->or( $qb->expr()->eq('imagewidth', $qb->createNamedParameter(0, Connection::PARAM_INT)), $qb->expr()->eq('imageheight', $qb->createNamedParameter(0, Connection::PARAM_INT)), ) ) ->executeQuery() ->fetchOne(); } public function updateNecessary(): bool { return $this->getCountOfRowsWhichNeedUpdate() > 0; } /** * @return string[] All new fields and tables must exist */ public function getPrerequisites(): array { return [ DatabaseUpdatedPrerequisite::class, ]; } public function executeUpdate(): bool { foreach (['imagewidth', 'imageheight'] as $fieldName) { $qb = $this->connectionPool->getQueryBuilderForTable('tt_content'); $qb ->update('tt_content') ->set($fieldName, null) ->where($qb->expr()->eq($fieldName, $qb->createNamedParameter(0, Connection::PARAM_INT))) ->executeStatement(); } return true; } }