-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add export
command for managed entities and afforms
#312
Conversation
e6d5f25
to
06bc8b0
Compare
Thanks for adding the test @totten - I'm pretty unfamiliar with the civix test framework (or the civix framework in general, although hey I figured out enough to add a new Builder class!) so that test would have taken me a long time to figure out. |
@colemanw Yeah, the test framework was added several years after the original development. 👀 But I did a big push last year to make it more agreeable. I have to admit... the I've been thinking/wondering about how this is likely to evolve and how much to accommodate these bits. Main thoughts:
|
@totten I'd be fine with adding a new command namespace for export. I wasn't comfortable doing that since I don't know my way around the
Well... ok but not every entity has a
Yes, that was tempting, but I settled on not doing that because exporting an Afform actually can result in the creation of one (or more) If we change the name of the command to
Sure, although this command is already set to overwrite files instead of aborting if the file exists, since I pictured that use-case of wanting to iterate on your export. So you can already do what you described with the current command by passing the id of the thing you want to re-export. |
export
command for managed entities and afforms
@totten ok I've cleaned up the commit history and pushed an update which renames the command from I gave this some real-world testing by using the command on https://lab.civicrm.org/extensions/cividiscount/-/merge_requests/284 to update the Afforms generated 10 months ago. Using this command it converted all the All-in-all I'm happy with it. What do you say? |
For example: * Install `civi_campaign` and `civicrm_admin_ui` * Run `cv api4 SavedSearch.get +s id,name -T`. Note the id of `SavedSearch_Administer_Campaigns` * In `civicrm_admin_ui`, export `SavedSearch_Administer_Campaigns` * Problem: We now have two modules trying to provide `SavedSearch_Administer_Campaigns` (with the same value of `civicrm_saved_search.name`) The mistake here is that this search is actually owned by `civi_campaign`. Allowing `civicrm_admin_ui` to make a copy with the exact same content (but a different `civicrm_managed` record) ensures a conflict. This situation is most likely a user-error (e.g. you forgot where the mgd was supposed to live, or you didn't pay attention to PWD). `
civibot, test this please |
Wow, that's pretty cool! I like how you can do some edits in the database, re-export, and run There is a big caveat -- it only regenerates correctly if it created the original file. When I look through
Of course, all of that speaks to follow-up work. For the moment, this PR does the work it was aiming to, and I know your anxious to get the functionality out there. I've just added a couple more sanity-checks/warnings. We can obviously continue to discuss/iterate in other PRs. |
@totten can you clarify what you mean by "file-layout"? Are you referring to filename? Or layout of code within the file? If the former, FYI this PR simply uses the name returned by If the latter, I'm not quite sure what you mean, but I would expect there are some code-style inconsistencies between autogenerated php files and hand-written ones. These files do pass |
I see (basically) three file naming patterns. I expected two of these (based on things we've published), and the third was originally a surprise to me (but makes sense in retrospect). The patterns can be roughly described as:
Just for illustration, here are few random examples:
(Aside: Each has some adhoc variations -- like These layouts have strengths and weaknesses. None is perfect for everything.
Heretofore, This PR follows the Single Folder layout -- the PR makes But |
Oh wow, I didn't realize
APIv3 and CiviReport are both on their way out IMO. We could just leave them alone and let them die a natural death. |
Just a note that I've switched to always putting mgd.php files in |
@mattwire I have a nasty feeling I mix & match managed & Managed though.. |
Adds a useful command which exports Afforms and managed records, leveraging the APIv4 Export action which collects sub-records into a single
.mgd.php
file (or in the case of Afforms,.aff.php
and.aff.html
and.mgd.php
s for the search displays).The resulting file includes
E::ts()
around translatable strings.For a full demonstration, try exporting an existing afform, e.g.:
It will write out the 2 files for the Afform plus 3 files for the 3 embedded SavedSearches into your extension (in this example
civi_pledge
), plus the navigation menu item.