Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Orchard CMS Custom Data Importer

I have custom code that reads a bunch of xml documents and creates a custom data import recipe that I upload using the Import/Export module in Orchard. The imported documents are of a content type "Api Documentation" that I created using the Orchard admin UI. Now, I would like to make this recipe file generation code part of a custom Orchard module (if that is the right approach, I am not sure) and let the admin user do the following:

  1. Use a form in the admin Dashboard section to upload the xml documents that need to be run through the recipe file generator

  2. That form submits the recipe file to the Import/Export module, so that it can perform its import process as usual

What would be the best approach to handle this? I am not even sure that creating a custom module is the right approach. If there are other extensibility options that I should take advantage of, that would be great to know.

like image 886
user1888320 Avatar asked Oct 22 '22 22:10

user1888320


1 Answers

The IImportExportService interface has a member called Import:

void Import(string recipeText);

Once you've generated your recipe you can call this method and it will execute the recipe and update the shell.

If you are just importing data then if I'm not mistaken you can get away without updating the shell (which you only need to do if features have been enabled or disabled) - in which case you can make a couple of calls to the IRecipeParser and IRecipeManager interfaces instead:

var recipe = _recipeParser.ParseRecipe(recipeText);
_recipeManager.Execute(recipe);

I've written something similar which does some importing/exporting so you can move pieces of content between sites; it also does some encryption so the details are hidden from prying eyes. A great place to start if is to read the source for the ImportExportService as it isn't all that complicated.

like image 176
mdm Avatar answered Dec 19 '22 16:12

mdm