def migrateObjects(self, objects):
        paths = []
        for obj in objects:
            objpath = self.getRelativePath(obj)
            if objpath not in self.imported and not \
                (self.onlyNew and objpath in self.site._import_results):
                paths.append(objpath)
        if paths:  # only if there are ones to migrate
            migr = MultiContentObjectMigrator(self.site, self.site,
                paths, self.attributes)
            response = requests.post(self.source, data={
                'migrator': migr.title,
                'args': json.dumps({
                        'attributes': self.attributes,
                        'paths': paths})
                })
            objectsData = json.loads(response.content)
            for path, content in objectsData.items():
                path = str(path)
                object = safeTraverse(self.site, path)
                self._migrateObject(object, path, content=content)

        for obj in objects:
            # then need to check if any are folders...
            if IBaseFolder.providedBy(obj):
                migr = FolderContentsMigrator(self.site, obj)
                folderdata = requests.post(self.source, data={
                    'migrator': FolderContentsMigrator.title,
                    'path': '/'.join(obj.getPhysicalPath()
                        )[len(self.sitepath) + 1:]
                })
                self(migr, json.loads(folderdata.content))
    def _migrateObject(self, obj, objpath, content=None):
        if content is None:
            response = requests.post(self.source,
                                     data={
                                         'migrator':
                                         ContentObjectMigrator.title,
                                         'path':
                                         objpath,
                                         'args':
                                         json.dumps(
                                             {'attributes': self.attributes})
                                     })
            content = json.loads(response.content)
        totouch = []
        for uid, path in content['uids']:
            if uid not in self.convertedUids:
                path = str(path).lstrip('/')
                uidObj = None
                if path in self.stubs or path in self.imported:
                    # might be imported but we don't know the uid conversion...
                    uidObj = safeTraverse(self.site, path, None)
                    if uidObj:
                        self.convertedUids[uid] = uidObj.UID()
                if uidObj is None:
                    # create stub object if they aren't there
                    # this is so we can convert uids
                    totouch.append((path, uid))
                    #self.touchPath(path, uid)
        if totouch:
            self.touchPaths(totouch)

        self.convertUids(content)
        logger.info('apply data migrations on %s' % (objpath))
        migr = ContentObjectMigrator(self.site, obj)
        error = True
        while error:
            error = False
            try:
                migr.set(content)
                self.handleDeferred(obj, objpath, content)
            except MissingObjectException, ex:
                logger.info('oops, could not find %s - touching' % ex.path)
                path = ex.path
                try:
                    self._touchPath(path)
                except ValueError:
                    # error in response. must not be valid object
                    if path not in self.site._touch_errors:
                        self.site._touch_errors.append(path)
                error = True
Esempio n. 3
0
    def __call__(self):

        # give admin privs no matter what
        # XXX remember, this is not safe to have on a
        # production site!
        sm = getSecurityManager()
        tmp_user = UnrestrictedUser(sm.getUser().getId(), '', ['Manager'], '')
        acl = getToolByName(self.context, 'acl_users')
        tmp_user = tmp_user.__of__(acl)
        newSecurityManager(None, tmp_user)
        migrator = getMigratorFromRequest(self.request)

        self.request.response.setHeader('Content-Type', 'application/json')
        logger.info('Running %s for %s' % (migrator.title, repr(migrator.obj)))
        data = migrator.get()
        return json.dumps(data)
    def _migrateObject(self, obj, objpath, content=None):
        if content is None:
            response = requests.post(self.source, data={
                'migrator': ContentObjectMigrator.title,
                'path': objpath,
                'args': json.dumps({
                    'attributes': self.attributes})
            })
            content = json.loads(response.content)
        totouch = []
        for uid, path in content['uids']:
            if uid not in self.convertedUids:
                path = str(path).lstrip('/')
                uidObj = None
                if path in self.stubs or path in self.imported:
                    # might be imported but we don't know the uid conversion...
                    uidObj = safeTraverse(self.site, path, None)
                    if uidObj:
                        self.convertedUids[uid] = uidObj.UID()
                if uidObj is None:
                    # create stub object if they aren't there
                    # this is so we can convert uids
                    totouch.append((path, uid))
                    #self.touchPath(path, uid)
        if totouch:
            self.touchPaths(totouch)

        self.convertUids(content)
        logger.info('apply data migrations on %s' % (objpath))
        migr = ContentObjectMigrator(self.site, obj)
        error = True
        while error:
            error = False
            try:
                migr.set(content)
                self.handleDeferred(obj, objpath, content)
            except MissingObjectException, ex:
                logger.info(
                    'oops, could not find %s - touching' % ex.path)
                path = ex.path
                try:
                    self._touchPath(path)
                except ValueError:
                    # error in response. must not be valid object
                    if path not in self.site._touch_errors:
                        self.site._touch_errors.append(path)
                error = True
    def __call__(self):

        # give admin privs no matter what
        # XXX remember, this is not safe to have on a
        # production site!
        sm = getSecurityManager()
        tmp_user = UnrestrictedUser(sm.getUser().getId(), '', ['Manager'],
            '')
        acl = getToolByName(self.context, 'acl_users')
        tmp_user = tmp_user.__of__(acl)
        newSecurityManager(None, tmp_user)
        migrator = getMigratorFromRequest(self.request)

        self.request.response.setHeader('Content-Type', 'application/json')
        logger.info('Running %s for %s' % (migrator.title, repr(migrator.obj)))
        data = migrator.get()
        return json.dumps(data)
 def touchPaths(self, uids):
     totouch = []
     for path, uid in uids:
         obj = safeTraverse(self.site, path, None)
         if not obj:
             totouch.append((path, uid))
         else:
             self.convertedUids[uid] = obj.UID()
     resp = requests.post(self.source, data={
         'migrator': MultiContentTouchMigrator.title,
         'args': json.dumps({'totouch': totouch})
     })
     content = json.loads(resp.content)
     migr = MultiContentTouchMigrator(self.site)
     for touched, olduid in migr.set(content):
         path = '/'.join(touched.getPhysicalPath())[len(self.sitepath) + 1:]
         self.stubs.append(path.lstrip('/'))
         realuid = touched.UID()
         self.convertedUids[olduid] = realuid
 def touchPaths(self, uids):
     totouch = []
     for path, uid in uids:
         obj = safeTraverse(self.site, path, None)
         if not obj:
             totouch.append((path, uid))
         else:
             self.convertedUids[uid] = obj.UID()
     resp = requests.post(self.source,
                          data={
                              'migrator': MultiContentTouchMigrator.title,
                              'args': json.dumps({'totouch': totouch})
                          })
     content = json.loads(resp.content)
     migr = MultiContentTouchMigrator(self.site)
     for touched, olduid in migr.set(content):
         path = '/'.join(touched.getPhysicalPath())[len(self.sitepath) + 1:]
         self.stubs.append(path.lstrip('/'))
         realuid = touched.UID()
         self.convertedUids[olduid] = realuid
    def migrateObjects(self, objects):
        paths = []
        for obj in objects:
            objpath = self.getRelativePath(obj)
            if objpath not in self.imported and not \
                (self.onlyNew and objpath in self.site._import_results):
                paths.append(objpath)
        if paths:  # only if there are ones to migrate
            migr = MultiContentObjectMigrator(self.site, self.site, paths,
                                              self.attributes)
            response = requests.post(self.source,
                                     data={
                                         'migrator':
                                         migr.title,
                                         'args':
                                         json.dumps({
                                             'attributes': self.attributes,
                                             'paths': paths
                                         })
                                     })
            objectsData = json.loads(response.content)
            for path, content in objectsData.items():
                path = str(path)
                object = safeTraverse(self.site, path)
                self._migrateObject(object, path, content=content)

        for obj in objects:
            # then need to check if any are folders...
            if IBaseFolder.providedBy(obj):
                migr = FolderContentsMigrator(self.site, obj)
                folderdata = requests.post(
                    self.source,
                    data={
                        'migrator':
                        FolderContentsMigrator.title,
                        'path':
                        '/'.join(obj.getPhysicalPath())[len(self.sitepath) +
                                                        1:]
                    })
                self(migr, json.loads(folderdata.content))