/**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $db->execute('
         db.status.update({}, {$unset: {"outOfWorkflow":1}} , {"multi": true});;
         db.content_type.update({}, {$unset: {"definingStatusable":1}} , {"multi": true});;
     ');
 }
 /**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $db->execute('
         db.status.remove({"name": "outOfWorkflow"});
         db.status.update({}, {$unset: {"blockedEdition":1}} , {"multi": true});;
     ');
 }
 /**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $db->execute('
         db.users_group.find({ \'modelRoles\' : { $exists:1 }}).forEach(function(item) {
             for (i = 0; i != item.modelRoles.length; ++i) {
                 if (item.modelRoles[i].type == \'node\') {
                     delete item.modelRoles[i].type;
                     item.modelRoles[i].nodeId = item.modelRoles[i].id;
                     delete item.modelRoles[i].id;
                 }
             }
             db.users_group.update({ _id: item._id }, item);
         });
     ');
     $db->execute('db.users_group.update({}, { $rename : { \'modelRoles\':\'nodeRoles\' }}, { multi: true });');
 }
 /**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $this->getKeywordableCollection();
     $this->loadConfiguration();
     foreach ($this->collections as $collection) {
         $db->execute('
             db.' . $collection . '.find().forEach(function(item) {
                 if (typeof item.keywords != \'undefined\') {
                     keywords = item.keywords;
                     item.keywords = [];
                     for (var i in keywords) {
                         keyword = {};
                         keyword._id = keywords[i].$id
                         db.keyword.find({"_id" : keywords[i].$id}).forEach(function(record) {
                             for (property in record) {
                                 keyword[property] = record[property];
                             }
                         });
                         item.keywords.push(keyword);
                     }
                     db.' . $collection . '.update({ _id: item._id }, item);
                 }
             });
         ');
     }
     $this->parseNode('down');
 }
 /**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $db->execute('
         db.users_group.find({ roles: \'ROLE_ACCESS_MOVE_TREE\' }).forEach(function(item) {
             db.users_group.update({ _id: item._id}, { $pull: { roles : \'ROLE_ACCESS_MOVE_TREE\' }});
             db.users_group.update({ _id: item._id}, { $push: { roles : \'ROLE_ACCESS_MOVE_NODE\' }});
         });
         db.users_group.find({ \'modelRoles\' : { $exists:1 }}).forEach(function(item) {
                 var currentNodeId = [];
                 var length = item.modelRoles.length;
                 for (i = 0; i != length; ++i) {
                    if (currentNodeId.indexOf(item.modelRoles[i].id) == -1 && item.modelRoles[i].type == \'node\') {
                       currentNodeId.push(item.modelRoles[i].id);
                       var nodeRole = {};
                       nodeRole[\'id\'] = item.modelRoles[i].id;
                       nodeRole[\'accessType\'] = \'denied\';
                       nodeRole[\'granted\'] = 0;
                       nodeRole[\'type\'] = \'node\';
                       nodeRole[\'role\'] = \'ROLE_ACCESS_MOVE_NODE\';
                       item.modelRoles.push(nodeRole);
                    }
                 }
                 db.users_group.update({ _id: item._id }, item);
             }
         );
     ');
 }
 /**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $db->execute('
         db.site.find().forEach(function(item) {
             aliases = item.aliases;
             item.aliases = [];
             for (i in aliases) {
                 item.aliases.push(aliases[i]);
             }
             db.site.update({_id: item._id}, item);
         });
     ');
 }
 /**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $db->execute('
         db.node.find().forEach(function(item) {
             delete item.currentlyPublished;
             db.node.update({_id: item._id}, item);
         });
         db.content.find().forEach(function(item) {
             delete item.currentlyPublished;
             db.content.update({_id: item._id}, item);
         });
     ');
 }
 /**
  * Downgrade db
  *
  * @param Database $db
  */
 public function down(Database $db)
 {
     $db->execute('
         db.users_group.find().forEach(function(item) {
             var modelRoles = [];
             for (var i in item.modelRoles) {
                 var modelRole = item.modelRoles[i];
                 modelRoles.push(modelRole);
             };
             item.modelRoles = modelRoles;
             db.users_group.update({_id: item._id}, item);
         })
     ');
 }
    /**
     * @param Database $db
     */
    public function down(Database $db)
    {
        $db->execute($this->getCleanRowAreasFunction() . '

            db.template.find().forEach(function(item) {
                 if (typeof item.rootArea != \'undefined\') {
                     var rowAreas = item.rootArea.subAreas;
                     areas = []
                     areas = cleanRowAreas(rowAreas);
                     item.areas = areas;
                     delete item.rootArea;
                     db.template.update({ _id: item._id }, item);
                 }
            });
        ');
    }
    /**
     * @param Database $db
     * @param string $collection
     * @param string $property
     */
    protected function downStorageTranslatedValue(Database $db, $collection, $property)
    {
        $db->execute('
            db.' . $collection . '.find({"' . $property . '":{$exists:1}}).forEach(function(item) {
                 var property = item.' . $property . ';
                 var newProperty = {};
                 for (var language in property) {
                    var value = property[language];

                    var element = {};
                    element.language = language;
                    element.value = value;
                    newProperty[language] = element;
                 }
                 item.' . $property . ' = newProperty;

                 db.' . $collection . '.update({_id: item._id}, item);
            });
        ');
    }
    /**
     * @param Database $db
     */
    public function down(Database $db)
    {
        $db->execute('
            db.workflow_function.find({"names":{$exists:1}}).forEach(function(item) {
                 var property = item.names;
                 var newProperty = {};
                 for (var language in property) {
                    var value = property[language];

                    var element = {};
                    element.language = language;
                    element.value = value;
                    newProperty[language] = element;
                 }
                 item.names = newProperty;

                 db.workflow_function.update({_id: item._id}, item);
            });
        ');
    }
    /**
     * @param Database $db
     */
    public function down(Database $db)
    {
        $db->execute('
            var deleteBlockPrivateInArea = function(area, node) {
                if (typeof area.blocks != \'undefined\') {
                    var blocks = area.blocks;
                    for (var i in blocks) {
                        var block = blocks[i];
                        delete block.blockPrivate;
                    }
                }
                if (typeof area.subAreas != \'undefined\') {
                    var areas = area.subAreas;
                    for (var i in areas) {
                        var subAreas = areas[i];
                        deleteBlockPrivateInArea(subAreas, node);
                    }
                }
            }

            db.node.find().forEach(function(item) {
                 var rootArea = item.rootArea;
                 if (typeof rootArea != \'undefined\') {
                     deleteBlockPrivateInArea(rootArea, item);
                 }

                 db.node.update({ _id: item._id }, item);
            });
        ');
    }
Example #13
0
 /**
  * @see Database::execute()
  */
 public function execute($code, array $args = [])
 {
     $this->log(['execute' => true, 'code' => $code, 'args' => $args]);
     return parent::execute($code, $args);
 }
 /**
  * Revert media documents
  *
  * @param Database $db
  */
 protected function revertMedias(Database $db)
 {
     $db->execute($this->getRevertAlternativesRequest());
     $db->execute($this->getRevertAudioThumbnailRequest());
     $db->execute($this->getRevertImageThumbnailRequest());
     $db->execute($this->getRevertMediaTypeRequest());
 }
 /**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $languages = $this->container->getParameter('open_orchestra_backoffice.orchestra_choice.front_language');
     $languages = array_keys($languages);
     $language = $languages[0];
     $revertRequest = '
         db.site.find().forEach(function(item) {
             var itemHasChanged = false;
             if ("object" == typeof item.metaKeywords) {
                 item.metaKeywords = item.metaKeywords.' . $language . ';
                 itemHasChanged = true;
             }
             if ("object" == typeof item.metaDescriptions) {
                 item.metaDescription = item.metaDescriptions.' . $language . ';
                 delete item.metaDescriptions;
                 itemHasChanged = true;
             }
             if (itemHasChanged) {
                 db.site.update({_id: item._id}, item);
             }
         });
     ';
     $db->execute($revertRequest);
 }
 public function down(Database $db)
 {
     $db->execute('db.node.update({}, {$unset : {\'boLabel\':\'\'}}, false, true);');
 }
 /**
  * @param Database $db
  */
 public function down(Database $db)
 {
     $db->execute('
         db.trash_item.update({}, {$unset: {"siteId":1}} , {"multi": true});;
     ');
 }