wagtail-wordpress-import icon indicating copy to clipboard operation
wagtail-wordpress-import copied to clipboard

Add a command to run hooks without full import

Open fabienheureux opened this issue 3 years ago • 1 comments

While developping some import hooks, it could be useful to have a management command allowing to run hooks without running a full import again.

In my case, import attempts take several minutes because of lots of not found images that raise ConnectionError exceptions. This could be better handled, however, having a way of running only hooks without a full import could really make developping hooks faster.

I started working on this, and would be happy to submit a PR, however I would like to hear some feedback about whether it could be a bad idea before going too far.

What I have in mind is the following: split WordpressImporter.run method into several methods

  • prepare_run
  • run_hooks

prepare_run

Everything needed to run both hooks and the main import run https://github.com/torchbox/wagtail-wordpress-import/blob/main/wagtail_wordpress_import/importers/wordpress.py#L61-L72

run_hooks

This code block could live in a single method and be called at the bottom of WordpressImporter.run method https://github.com/torchbox/wagtail-wordpress-import/blob/main/wagtail_wordpress_import/importers/wordpress.py#L198-L222

Thoughts

It might require a "dry run" in order to set the imported_pages variables.
Also, another way of doing things could be through a command line argument --hooks_only.

fabienheureux avatar Jan 22 '22 10:01 fabienheureux

Developing import_hooks can be a challenge especially if you are doing it on a live import. I noticed on some of your PR's/Issues you use a cut down version of the xml file which is a great idea and something I do too.

I light of that I built this: https://github.com/nickmoreton/wwi-docker-develop so I can run up a complete developing setup that includes both WordPress and Wagtail and you just run ./setup.sh after cloning it and in a couple of minutes you have Wagtail with a small import completed.

I'd love to hear what you think about it! Potentially you could create your own commands in the Wagtail part.

nickmoreton avatar Jan 27 '22 15:01 nickmoreton