One of my last tasks in developing a complex module (14 controls, 9 tables, 84 sprocs) has been to implement IPortable. Although I've done the basics of this for several other simpler modules (usually using the XmlLSerialization classes), I'm wondering how best (and how much time to put into) handling the following data structures:
1. There are two main tables - basically setting up a 1 to many relationship between "requests" and "updates" linked via a RequestID column.
2. Both the Requests table and the Updates table have several columns setting up foreign key relationships with the DNN Users table, a Moderators table (linked via UserID) and 5 different "category" like tables (linked via various ID columns). The "category" tables can be edited and added to by Administrators so do not contain static data.
3. Many ModuleSettings are used - primarily for enabling various module options but also for some module wide statistics storage.
4. Two custom permissions are created - Moderate and Post
Questions:
1. Serialiazation of all of the various data structures (including all the various "category" tables) for ExportModule is tedious but easy. The tough design decisions come in implementing ImportModule:
A. Rebuilding the one to many relationship between "requests" and "updates" can be handled easily as each is added to the database
B. Rebuilding the relationships between the various "categoryID" fields and the restored "category" tables is harder. I'm handling this by first adding the deserialized "category" information to each table, building a key-value dictionary between the text of the "category" and its new ID then as each "request" and "update" is added replacing the exported "category" text with its new ID. Not the most efficient, but I can't think of any other way to do it.
C. My main problem comes with the use of the UserID for tracking authors, editors, moderators and for subscribing to new request/update notifications. Should I try to preserve this information knowing that a only a few or even none of the UserID's might be valid for the portal into which the module content would be imported? Should I export Usernames rather than UserID's and try to match these to users in the destination portal? Or, should I forget about trying to maintain any of the UserID based data? Even if I were able to match by Username and populate the UserID based fields with their corresponding values, there is still the problem of the matched users not having the proper security roles for the two custom permissions.
D. Does one try to export/import appropriate ModuleSettings - particularly when they relate to enabling such features as allowing one to delete/edit their own requests and updates, moderation vs. unmoderated posting, etc.
I'm tempted to skip the whole implementation of IPortable as I don't really need it for my current use case, but feel that it should be included as the module will be offered commercially at a later date. Now I know why the current DNN Forum module does not implement IPortable!!