MigrationBundle/Migrations/Version20170307181737.php
protected function updateTinyMCEInContent(Database $db)
    {
        $this->write('  + Updating medias in tinyMce attributes');

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

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

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

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

                if (updated) {
                    db.content.update({_id: content._id}, content);
                }
            });
        '));
    }
protected function updateTinyMCEInContent(Database $db)
    {
        $this->write('  + Updating medias in tinyMce attributes');

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

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

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

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

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

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

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

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

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

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