Sync/StorageManager/MysqlStorageManager.php
private function deductionForDeletion($connection, $tableName, $documentType, $documentId, $shopId)
    {
        $sql = sprintf(
            "SELECT `id` FROM {$tableName}
            WHERE
                `type` != 'D'
                AND `document_type` = :documentType
                AND `document_id` = :documentId
                AND `status` = :status
                AND `id` < :id"
        );

        $statement = $connection->prepare($sql);
        $statement->execute(
            [
                'documentType' => $documentType,
                'documentId' => $documentId,
                'status' => self::STATUS_NEW,
                'id' => $connection->lastInsertId(),
            ]
        );

        $entries = $statement->fetchAll();

        foreach ($entries as $entry) {
            $this->removeRecord($entry['id'], [$shopId]);
        }
    }
private function deductionForDeletion($connection, $tableName, $documentType, $documentId, $shopId)
    {
        $sql = sprintf(
            "SELECT `id` FROM {$tableName}
            WHERE
                `type` != 'D'
                AND `document_type` = :documentType
                AND `document_id` = :documentId
                AND `status` = :status
                AND `id` < :id"
        );

        $statement = $connection->prepare($sql);
        $statement->execute(
            [
                'documentType' => $documentType,
                'documentId' => $documentId,
                'status' => self::STATUS_NEW,
                'id' => $connection->lastInsertId(),
            ]
        );

        $entries = $statement->fetchAll();

        foreach ($entries as $entry) {
            $this->removeRecord($entry['id'], [$shopId]);
        }
    }
private function deductionForDeletion ( $ connection , $ tableName , $ documentType , $ documentId , $ shopId ) { $ sql = sprintf ( "SELECT `id` FROM {$tableName}
            WHERE
                `type` != 'D'
                AND `document_type` = :documentType
                AND `document_id` = :documentId
                AND `status` = :status
                AND `id` < :id" ) ; $ statement = $ connection -> prepare ( $ sql ) ; $ statement -> execute ( [ 'documentType' => $ documentType , 'documentId' => $ documentId , 'status' => self :: STATUS_NEW , 'id' => $ connection -> lastInsertId ( ) , ] ) ; $ entries = $ statement -> fetchAll ( ) ; foreach ( $ entries as $ entry ) { $ this -> removeRecord ( $ entry [ 'id' ] , [ $ shopId ] ) ; } }
Find meaningless operations and remove them.

When user creates product|category|content, makes some updates and then deletes that product|category|content,
then leave only the last operation - deletion.

@param Connection $connection
@param string     $tableName
@param string     $documentType
@param int        $documentId
@param int        $shopId
Find meaningless operations and remove them .