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 _get(kls, site, totouch=[]): results = [] for path, uid in totouch: path = str(path) obj = safeTraverse(site, path.lstrip('/')) results.append(ContentTouchMigrator._get(obj)) return results
def _get(kls, site, paths=[], attributes=[]): results = {} for path in paths: path = str(path).lstrip('/') obj = safeTraverse(site, path) results[path] = ContentObjectMigrator._get(obj, attributes=attributes) return results
def __call__(self): field = self.request.get('field') context = safeTraverse(self.context, self.request.get('path')) field = context.getField(field) filename = field.getFilename(context) if not filename: filename = context.getId() resp = self.request.response resp.setHeader('filename', filename) resp.setHeader('Content-type', field.getContentType(context)) return field.download(context)
def _touchPath(self, path): # have data for request but no object created yet? # need to assemble obj first then obj = safeTraverse(self.site, path, None) if obj: return obj resp = requests.post(self.source, data={ 'migrator': ContentTouchMigrator.title, 'path': path }) content = json.loads(resp.content) migr = ContentTouchMigrator(self.site, path) return migr.set(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
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 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))