connection->getQueryBuilder(); $cardsWithTranslatedCategory = $query->select(['id', 'card']) ->from('recent_contact') ->where($query->expr()->notLike( 'card', $query->createNamedParameter('%CATEGORIES:Recently contacted%') )) ->setMaxResults(self::CARDS_PER_BATCH) ->executeQuery(); $rowCount = $cardsWithTranslatedCategory->rowCount(); $output->startProgress($rowCount); $this->connection->beginTransaction(); $updateQuery = $query->update('recent_contact') ->set('card', $query->createParameter('card')) ->where($query->expr()->eq('id', $query->createParameter('id'))); while ($card = $cardsWithTranslatedCategory->fetch()) { $output->advance(1); try { $vcard = Reader::read($card['card']); } catch (ParseException $e) { $output->info('Could not parse vcard with id ' . $card['id']); continue; } $vcard->remove('CATEGORIES'); $vcard->add('CATEGORIES', 'Recently contacted'); $updateQuery->setParameter('id', $card['id']); $updateQuery->setParameter('card', $vcard->serialize()); $updateQuery->executeStatement(); } $this->connection->commit(); $cardsWithTranslatedCategory->closeCursor(); $output->finishProgress(); if ($rowCount === self::CARDS_PER_BATCH) { $this->jobList->add(BackgroundRepair::class, [ 'app' => Application::APP_ID, 'step' => FixVcardCategory::class, 'reschedule' => time(), // Use a different argument to reschedule the job ]); } } }