<?php

namespace Oro\Bundle\TranslationBundle\Migration;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Types\Type;

use Psr\Log\LoggerInterface;

use Oro\Bundle\MigrationBundle\Migration\ParametrizedMigrationQuery;

class DeleteTranslationKeysQuery extends ParametrizedMigrationQuery
{
    /** @var string */
    private $domain;

    /** @var array */
    private $translationKeys;

    /**
     * @param string $domain
     * @param array $translationKeys
     */
    public function __construct($domain, array $translationKeys)
    {
        $this->domain = $domain;
        $this->translationKeys = $translationKeys;
    }

    /**
     * {@inheritdoc}
     */
    public function getDescription()
    {
        return 'Remove unused translation keys for RFQ status field';
    }

    /**
     * {@inheritdoc}
     */
    public function execute(LoggerInterface $logger)
    {
        $this->deleteTranslationKeys($logger, $this->domain, $this->translationKeys);
    }

    /**
     * @param LoggerInterface $logger
     * @param string $domain
     * @param array $translationKeys
     */
    protected function deleteTranslationKeys(LoggerInterface $logger, $domain, array $translationKeys)
    {
        // Delete unused translation keys.
        $params = [
            'translation_keys' => $translationKeys,
            'domain' => $domain
        ];

        $keyField = $this->connection->getDatabasePlatform() instanceof MySqlPlatform ? '`key`' : 'key';

        $types  = [
            'translation_keys'   => Connection::PARAM_STR_ARRAY,
            'domain' => Type::STRING
        ];

        $sql = "DELETE FROM oro_translation_key" .
            " WHERE " . $keyField . " IN (:translation_keys)" .
            " AND domain = :domain ";

        $this->logQuery($logger, $sql, $params, $types);
        $this->connection->executeUpdate($sql, $params, $types);
    }
}

Add migration to delete translation keys with values from DB - created common query to delete unused translation keys
BB-6489: Add migration to delete translation keys with values from DB
- created common query  to delete unused translation keys
