Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parent containers always created as Folder rather than the related @type as defined in parent #139

Open
zopyx opened this issue Jun 16, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@zopyx
Copy link
Contributor

zopyx commented Jun 16, 2022

Situation:

  • fresh Plone 6.0.0a4 site
  • importing a File.json
  • some FIle objects have parents that are not Folder instances but more specialized DX container classes
  • these parent folders are being created as Folder independent of @type value of the parent item:

https://github.com/collective/collective.exportimport/blob/main/src/collective/exportimport/import_content.py#L831

@zopyx
Copy link
Contributor Author

zopyx commented Jun 16, 2022

The basic assumption that every parent is a Folder of this code

https://github.com/collective/collective.exportimport/blob/main/src/collective/exportimport/import_content.py#L816

is wrong. Parent containers can be arbitrary containerish types. This must be taken into account.

It also does not help (as a workaround) to import some container type before the other container type because there parents might be mixed in any arbitrary combination.

@zopyx zopyx added the bug Something isn't working label Jun 16, 2022
@zopyx
Copy link
Contributor Author

zopyx commented Jun 16, 2022

There is perhaps another flaw in the parent handling. Our File.json contains an item https://nohost/eteaching/praxis/digital-learning-map-2020/180202_CfP_pdf.pdf with this parent:

 'parent': {'@id': 'https://nohost/eteaching/praxis/digital-learning-map-2020',
            '@type': 'eteaching.policy.projectsite',
            'description': 'Was macht Lernen mit digitalen Medien an '
                           'Hochschulen erfolgreich? Das untersuchte das vom '
                           'BMBF geförderte Projekt Digital Learning Map 2020 '
                           '(LearnMap). Das dreijährige Projekt lief von 2017 '
                           'bis Anfang 2020 am Leibniz-Institut für '
                           'Wissensmedien (IWM) in Tübingen und betrachtete '
                           'das Thema Digitalisierung von Hochschulen aus '
                           'unterschiedlichen Perspektiven.',
            'review_state': 'published',
            'title': 'Digital Learning Map 2020'},

With the current implementation, both parent folders praxis/digital-learning-map-2020 would be created as Folder which is wrong as discussed above. The container type for digital-learning-map-2020 could be created correctly with the information given from parent. However, there is no information about praxis which could a non-Folder too.

I think, we need

  • the full parents information on the export side rather than only parent
  • collective.exportimport would have to deal with multiple parents and arbitrary @type information for each parent rather than assuming Folder

@zopyx
Copy link
Contributor Author

zopyx commented Jun 26, 2022

I implemented the @parents export through a customer export hook like

        def global_dict_hook(self, item, obj):
            """Use this to modify or skip the serialized data by type.
            Return the modified dict (item) or None if you want to skip this particular object.
            """

            def getAcquisitionChain(object):
                inner = object.aq_inner
                iter = inner
                while iter is not None:
                    yield iter
                    if ISiteRoot.providedBy(iter):
                       break
                    if not hasattr(iter, "aq_parent"):
                        raise RuntimeError("Parent traversing interrupted by object: " + str(parent))
                    iter = iter.aq_parent


            parents = list()

            p_chain = reversed(list(getAcquisitionChain(obj)))
            for p in p_chain:

                try:
                    state = get_state(p)
                except:
                    state = ""

                if p.portal_type != 'Plone Site' and p != obj:
                    parents.append({
                        "@id": p.absolute_url(),
                        "@type": p.portal_type,
                        "description": p.Description(),
                        "title": p.Title(),
                        "review_state": state
                        })

            item["parents"] = parents

@zopyx
Copy link
Contributor Author

zopyx commented Jun 26, 2022

The following (ugly) code recreates the folderish objects with the correct portal_type and workflow state:

https://github.com/collective/collective.exportimport/blob/eteaching-fixes/src/collective/exportimport/import_content.py#L833-L862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant