Пример #1
0
 def update(self):
     assert self.manager.ghost is not None
     if IGhostFolder.providedBy(self.manager.ghost):
         self.manager.ghost.set_haunted(
             self.target, auto_delete=self.manager.auto_delete)
     else:
         self.recreate()
 def upgrade_to_ghost(self, content):
     container = content.get_container()
     if not IGhostFolder.providedBy(container):
         return None
     if container.get_link_status() is not None:
         logger.warning(
             u"Invalid Ghost Folder, not transforming: %s.",
             content_path(content))
         return None
     content_id = content.getId()
     container_haunted = container.get_haunted()
     content_haunted = container_haunted._getOb(content_id, None)
     if not IImage.providedBy(content_haunted):
         logger.warning(
             u"Original found for %s, but is not an image, not transforming it.",
             content_path(content))
         return None
     # Prevent quota system to fail if the image is an old one.
     # XXX Quota will be out of sync after the upgrade.
     if (content.hires_image is not None and
         content.hires_image.meta_type != 'Silva File'):
         content.hires_image = None
     ghost = get_factory(content_haunted)(
                 ghost=content,
                 container=container,
                 auto_delete=True,
                 auto_publish=True).modify(
         content_haunted, content_id).verify()
     logger.info(
         u"Image converted to ghost asset: %s.",
         content_path(content))
     return ghost
    def test_convert_to_folder(self):
        """Test Ghost Folder convertion to a regular Folder.
        """
        factory = self.root.target.manage_addProduct['Silva']
        factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder)

        ghost = self.root.target.ghost
        self.assertTrue(verifyObject(IGhostFolder, ghost))
        self.assertEqual(self.root.target.objectValues('Silva Ghost Folder'),
                         [ghost])
        self.assertEqual(self.root.target.objectValues('Silva Folder'), [])

        ghost.to_folder()

        ghost = self.root.target.ghost
        self.assertTrue(verifyObject(IFolder, ghost))
        self.assertFalse(IGhostFolder.providedBy(ghost))
        self.assertEqual(self.root.target.objectValues('Silva Ghost Folder'),
                         [])
        self.assertEqual(self.root.target.objectValues('Silva Folder'),
                         [ghost])

        # Content is still there
        self.assertEqual(ghost.objectIds(),
                         ['document', 'folder', 'index', 'publication'])

        # And there are still ghosts
        self.assertTrue(verifyObject(IGhostFolder, ghost.folder))
        self.assertTrue(verifyObject(IGhostFolder, ghost.publication))
        self.assertTrue(verifyObject(IGhost, ghost.index))
        self.assertTrue(verifyObject(IGhost, ghost.document))
 def upgrade(self, ghost):
     target_path = ghost._content_path
     if target_path:
         try:
             target = ghost.get_root().unrestrictedTraverse(target_path)
         except (AttributeError, KeyError, NotFound, TypeError):
             logger.error(
                 u'Unexisting target for Ghost %s: %s.',
                 content_path(ghost), "/".join(target_path))
             return ghost
         target = aq_inner(target)
         if not ISilvaObject.providedBy(target):
             logger.error(
                 u'Ghost target is not a Silva object for: %s.',
                 content_path(ghost))
             return ghost
         try:
             [o for o in aq_iter(target, error=RuntimeError)]
         except RuntimeError:
             logger.error(
                 u'Invalid target for Ghost %s: %s.',
                 content_path(ghost), '/'.join(target_path))
             return ghost
         if target is not None and ISilvaObject.providedBy(target):
             logger.info(
                 u'Upgrading Ghost target for: %s.',
                 "/".join(ghost.getPhysicalPath()))
             container = aq_parent(ghost).get_container()
             ghost.set_haunted(
                 target,
                 auto_delete=IGhostFolder.providedBy(container))
         del ghost._content_path
     return ghost
 def upgrade_to_ghost(self, content):
     container = content.get_container()
     if not IGhostFolder.providedBy(container):
         return None
     if container.get_link_status() is not None:
         logger.warning(
             u"Invalid Ghost Folder, not transforming: %s.",
             content_path(content))
         return None
     file_id = content.getId()
     container_haunted = container.get_haunted()
     file_haunted = container_haunted._getOb(file_id, None)
     if not IFile.providedBy(file_haunted):
         logger.warning(
             u"Original found for %s, but is not an file, not transforming it.",
             content_path(content))
         return None
     ghost = get_factory(file_haunted)(
                 ghost=content,
                 container=container,
                 auto_delete=True,
                 auto_publish=True).modify(file_haunted, file_id).verify()
     logger.info(
         u"File converted to ghost asset: %s.",
         content_path(content))
     return ghost
Пример #6
0
 def update(self):
     assert self.manager.ghost is not None
     if IGhostFolder.providedBy(self.manager.ghost):
         self.manager.ghost.set_haunted(
             self.target, auto_delete=self.manager.auto_delete)
     else:
         self.recreate()
Пример #7
0
 def description(self):
     if IGhostFolder.providedBy(self.context):
         return _(u'This Ghost Folder can be converted '
                  u'to a normal Publication or Folder. All ghosted content '
                  u'will be duplicated and can then be edited.')
     elif IPublication.providedBy(self.context):
         if self.manager.is_site():
             return _(u"This Silva Publication is a local site. You need to "
                      u"remove any local service, and the local site before "
                      u"you can convert it to a Silva Folder.")
         return _(u'This Silva Publication can be converted '
                  u'to a Silva Folder, or can become a local site.')
     return _(u'This Silva Folder can be converted '
              u'to a Publication.')
Пример #8
0
    def test_convert_to_publication(self):
        """Test convertion of a Ghost Folder to a Publication.
        """
        factory = self.root.target.manage_addProduct['Silva']
        factory.manage_addGhostFolder('ghost', None, haunted=self.root.folder)

        ghost = self.root.target.ghost
        self.assertFalse(IPublication.providedBy(ghost))
        self.assertTrue(verifyObject(IGhostFolder, ghost))
        self.assertEqual(
            self.root.target.objectValues('Silva Ghost Folder'),
            [ghost])
        self.assertEqual(
            self.root.target.objectValues('Silva Publication'),
            [])

        ghost.to_publication()

        ghost = self.root.target.ghost
        self.assertTrue(verifyObject(IPublication, ghost))
        self.assertFalse(IGhostFolder.providedBy(ghost))
        self.assertEqual(
            self.root.target.objectValues('Silva Ghost Folder'),
            [])
        self.assertEqual(
            self.root.target.objectValues('Silva Publication'),
            [ghost])

        # Content is still there
        self.assertEqual(
            ghost.objectIds(),
            ['document', 'folder', 'index', 'publication'])

        # And there are still ghosts
        self.assertTrue(verifyObject(IGhostFolder, ghost.folder))
        self.assertTrue(verifyObject(IGhostFolder, ghost.publication))
        self.assertTrue(verifyObject(IGhost, ghost.index))
        self.assertTrue(verifyObject(IGhost, ghost.document))
Пример #9
0
 def need_update(self):
     if IGhostFolder.providedBy(self.manager.ghost):
         return self.target != self.manager.ghost.get_haunted()
     # Only update if the invalid ghost is an asset.
     return IContainer.providedBy(self.manager.ghost)
Пример #10
0
 def available(self, form):
     return (IGhostFolder.providedBy(form.context) or
             (IPublication.providedBy(form.context) and
              not form.manager.is_site()))
Пример #11
0
 def need_update(self):
     if IGhostFolder.providedBy(self.manager.ghost):
         return self.target != self.manager.ghost.get_haunted()
     # Only update if the invalid ghost is an asset.
     return IContainer.providedBy(self.manager.ghost)