MigrationBundle/Migrations/Version20170307181737.php
protected function updateBlocks(Database $db)
    {
        $this->write(' + Updating block documents');

        $this->write(' + updating medias in tinyMce attributes');

        $this->checkExecute($db->execute(
            $this->getJSFunctions() . '

            db.block.find({}).snapshot().forEach(function(block) {
                var updated = false;

                for (var attributeName in block.attributes) {
                    if (block.attributes.hasOwnProperty(attributeName) && (typeof block.attributes[attributeName] == "string")) {
                        var pattern = /\[media=([^\]\{]+)\]([^\]]+)\[\/media\]|\[media=\{"format":"([^"]+)"\}\]([^\]]+)\[\/media\]/g;
                        var matches = pattern.execAll(block.attributes[attributeName]);

                        for (var i = 0; i < matches.length; i++) {
                            var mediaId = getMediaIdFromMatch(matches[i]);
                            var format = getMediaFormatFromMatch(matches[i]);
                            block.attributes[attributeName] = updateAttribute(block.attributes[attributeName], mediaId, format, getMediaAlt(mediaId, block.language));
                            updated = true;
                        }
                    }
                }

                if (updated) {
                    db.block.update({_id: block._id}, block);
                }
            });
        '));

        $this->write(' + updating medias in block attributes');

        $configMediaFieldType = $this->container->getParameter('open_orchestra_migration.media_configuration');

        $this->checkExecute($db->execute(
            $this->getJSFunctions() . '

            var blockMediaFieldAttribute = '.json_encode($configMediaFieldType['block_media_field_attribute']).';
            db.block.find({}).snapshot().forEach(function(block) {
                var updated = false;
                for (var attributeName in block.attributes) {
                    if (
                        block.attributes.hasOwnProperty(attributeName) &&
                        blockMediaFieldAttribute.indexOf(attributeName) > -1
                    ) {
                        var alt = "";
                        if (
                            null !== block.attributes[attributeName].id &
                            "" !== block.attributes[attributeName].id
                        ) {
                           alt = getMediaAlt(block.attributes[attributeName].id, block.language);
                        }
                        block.attributes[attributeName].alt = alt;
                        block.attributes[attributeName].legend = "";
                        updated = true;
                    }
                }

                if (updated) {
                    db.block.update({_id: block._id}, block);
                }
            });
        '));
    }
protected function updateBlocks(Database $db)
    {
        $this->write(' + Updating block documents');

        $this->write(' + updating medias in tinyMce attributes');

        $this->checkExecute($db->execute(
            $this->getJSFunctions() . '

            db.block.find({}).snapshot().forEach(function(block) {
                var updated = false;

                for (var attributeName in block.attributes) {
                    if (block.attributes.hasOwnProperty(attributeName) && (typeof block.attributes[attributeName] == "string")) {
                        var pattern = /\[media=([^\]\{]+)\]([^\]]+)\[\/media\]|\[media=\{"format":"([^"]+)"\}\]([^\]]+)\[\/media\]/g;
                        var matches = pattern.execAll(block.attributes[attributeName]);

                        for (var i = 0; i < matches.length; i++) {
                            var mediaId = getMediaIdFromMatch(matches[i]);
                            var format = getMediaFormatFromMatch(matches[i]);
                            block.attributes[attributeName] = updateAttribute(block.attributes[attributeName], mediaId, format, getMediaAlt(mediaId, block.language));
                            updated = true;
                        }
                    }
                }

                if (updated) {
                    db.block.update({_id: block._id}, block);
                }
            });
        '));

        $this->write(' + updating medias in block attributes');

        $configMediaFieldType = $this->container->getParameter('open_orchestra_migration.media_configuration');

        $this->checkExecute($db->execute(
            $this->getJSFunctions() . '

            var blockMediaFieldAttribute = '.json_encode($configMediaFieldType['block_media_field_attribute']).';
            db.block.find({}).snapshot().forEach(function(block) {
                var updated = false;
                for (var attributeName in block.attributes) {
                    if (
                        block.attributes.hasOwnProperty(attributeName) &&
                        blockMediaFieldAttribute.indexOf(attributeName) > -1
                    ) {
                        var alt = "";
                        if (
                            null !== block.attributes[attributeName].id &
                            "" !== block.attributes[attributeName].id
                        ) {
                           alt = getMediaAlt(block.attributes[attributeName].id, block.language);
                        }
                        block.attributes[attributeName].alt = alt;
                        block.attributes[attributeName].legend = "";
                        updated = true;
                    }
                }

                if (updated) {
                    db.block.update({_id: block._id}, block);
                }
            });
        '));
    }
protected function updateBlocks ( Database $ db ) { $ this -> write ( ' + Updating block documents' ) ; $ this -> write ( ' + updating medias in tinyMce attributes' ) ; $ this -> checkExecute ( $ db -> execute ( $ this -> getJSFunctions ( ) . '

            db.block.find({}).snapshot().forEach(function(block) {
                var updated = false;

                for (var attributeName in block.attributes) {
                    if (block.attributes.hasOwnProperty(attributeName) && (typeof block.attributes[attributeName] == "string")) {
                        var pattern = /\[media=([^\]\{]+)\]([^\]]+)\[\/media\]|\[media=\{"format":"([^"]+)"\}\]([^\]]+)\[\/media\]/g;
                        var matches = pattern.execAll(block.attributes[attributeName]);

                        for (var i = 0; i < matches.length; i++) {
                            var mediaId = getMediaIdFromMatch(matches[i]);
                            var format = getMediaFormatFromMatch(matches[i]);
                            block.attributes[attributeName] = updateAttribute(block.attributes[attributeName], mediaId, format, getMediaAlt(mediaId, block.language));
                            updated = true;
                        }
                    }
                }

                if (updated) {
                    db.block.update({_id: block._id}, block);
                }
            });
        ' ) ) ; $ this -> write ( ' + updating medias in block attributes' ) ; $ configMediaFieldType = $ this -> container -> getParameter ( 'open_orchestra_migration.media_configuration' ) ; $ this -> checkExecute ( $ db -> execute ( $ this -> getJSFunctions ( ) . '

            var blockMediaFieldAttribute = ' . json_encode ( $ configMediaFieldType [ 'block_media_field_attribute' ] ) . ';
            db.block.find({}).snapshot().forEach(function(block) {
                var updated = false;
                for (var attributeName in block.attributes) {
                    if (
                        block.attributes.hasOwnProperty(attributeName) &&
                        blockMediaFieldAttribute.indexOf(attributeName) > -1
                    ) {
                        var alt = "";
                        if (
                            null !== block.attributes[attributeName].id &
                            "" !== block.attributes[attributeName].id
                        ) {
                           alt = getMediaAlt(block.attributes[attributeName].id, block.language);
                        }
                        block.attributes[attributeName].alt = alt;
                        block.attributes[attributeName].legend = "";
                        updated = true;
                    }
                }

                if (updated) {
                    db.block.update({_id: block._id}, block);
                }
            });
        ' ) ) ; }
Add alt+legend to tinyMce attributes in blocks
alt is taken from the media document

@param Database $db
Add alt + legend to tinyMce attributes in blocks alt is taken from the media document