phase2/oa_core — pull request #24 by dsnopek (2014-02-21 20:40:04+00:00)
Title: Cloning in Open Atrium (part 2!)

This is the mythical part 2 of my cloning in Open Atrium work. :-)

This does a number of things:

1. **Removes dependency on og_clone and implements Atrium-specific "child content cloning" logic.** og_clone basically just looped through all the group content and cloned it too. However, Open Atrium's content is highly heirarchical and so this actually didn't work correctly. You need to clone Spaces before Sections, and Sections before their content, parent Discussion posts before replies, etc -- so that each could be attached to the new parent. I think the architecture used is pretty strong and should allow us to continue to extend it as Atrium evolves.

2. **Clones some more Atrium/OG metadata about Spaces.** This will now correctly clone OG variables, OG roles and permissions, Atrium appearance settings (ie. colorizer), and the "Test content" flag (ie. if you clone test content, it will also be test content).

3. **Clones Group memberships when cloning Groups.** Groups are basically containers for membership, so cloning them without cloning the memberships is pretty useless. :-) The new version will clone Group memberships, but not Space memberships.

4. **Adds jump links for fast creation of Spaces/Sections.** If more than one Space or Section type exists, it will add "jump links" to the smart breadcrumbs. ![selection_005](https://f.cloud.github.com/assets/191561/2234337/b448fe7a-9b36-11e3-927c-8a71e778b0b1.png)

5. **Adds a "Create Space Type from this Space" link for users with enough permission.** Basically, just a convenience link to take them to the "Add term" form, filling in the the Space to clone automatically. ![selection_007](https://f.cloud.github.com/assets/191561/2234341/de68670e-9b36-11e3-859c-957923280f0c.png)

I did TONs of testing on this and lots of things work as they should! I tried cloning just Sections, whole Spaces, Spaces with sub-Spaces, various Atrium content types, etc. Many things just plain worked without extra code! For example, all the banner stuff and pretty much anything with fields. However, I'm sure this could use more testing.

However, even without extra testing, this code is objectively better than what's already committed! Without the changes for point 1 above, the cloning is basically broken and does some really unexpected things, for example: it would clone a node into a new Space, but leaves it's Section ref pointing at the old Section in the old Space. So, I'd recommend committing this right away even if it isn't perfect.

There's one major thing that I know the current code DOESN'T clone and that's OG menus. It's challenging because the menu heirarchy could be different than the content heirarchy and we need to be sure to clone parent menu items before children, which means keeping track of the mapping between old content and new content while cloning and then creating the new OG menu in a second pass afterwards. I have some ideas about how to do this, but haven't had time to act on them yet.

And one final note: I'll be posting a seperate PR for adding cloning support to oa_discussions. Without that PR, oa_discussions has some pretty strange behavior (I'll explain on that PR).

Anyway, I'm pretty excited about this functionality! Please let me know what you think! :-)