Problem/Motivation
Exporting a Workflow Field with Features hardcodes the wid in the feature field base.
This is unwanted behavior as the wid is not necessarily identical (eg. when other workflows already exist on the target system).
Proposed resolution
The workflow_field has a reference to the numeric Workflow ID, not the Workflow machine_name. Thwe machine_name was introduced in 7.x-2.x to be able to export workflows.
Patch #18 contains code to change the ID for the machine_name everywhere. This seems not a good idea for backwards-compatibility reasons.
Patch #25 has another approach.
Remaining tasks
Upon the export of the workflow_field, the workflow_name must be exported (together with the workflow ID).
Upon importing the workflow_field. the workflow ID must be aligned with the machin_name.
The best way to test this, is to export a Field Base only, without Workflows and field_instances, via :
- admin/structure/features/create
and after that via :
- admin/structure/features/MY_FEATURE/recreate, Advanced Options, Generate Feature
And import the field, after that.
Original report by [username]
For the record, as a workaround I'm setting the wid of the field in hook_enable() by doing the following:
$wid = array_search('WORKFLOW_NAME', workflow_get_workflow_names());
$field = field_info_field('FIELD_NAME');
$field['settings']['wid'] = $wid;
field_update_field($field);
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | exporting_export_of-2152435-18.patch | 3.27 KB | vasi |
Comments
Comment #1
johnvNot sure how to accomplish this, but it needs also some dependencies:
And perhaps inclusion of the workflow itself.
Comment #2
johnvThe following blog gives more info: http://foxinbox.org/content/features-magic-how-features-adds-additional-...
Comment #3
johnvAdding this as a feature request. For simple usage, the wid will always be '1'.
Comment #4
johnvComment #5
johnvComment #7
johnvThere is no solution yet, but this fix does the following:
- When a workflow_field is exported with Features, the corresponding Workflow is exported, too.
- The exported workflow contains its machine_name and 'original_wid', so this could be mapped upon insert. Perhaps this is not sufficient, and should the mapping be exported using a 'variable'.
I tried the make the field settings saving the machine_name instead fo the sid, hence all the changes regarding ['settings']['wid'].
But this would break the site if someone changes the machine_name.
Your suggestion in the OP might do the trick, too.
Comment #8
johnvI tried to resolve this. But it is too complicated. D8 will have named entites and UUID-support by default.
I suppose it will take D8 to resolve this ...
Comment #9
steinmb commentedRemind me a bit about problems exporting user groups in D7. Have you tried looking at how they addressed that in https://www.drupal.org/project/role_export ? It is bit "hackish" though it does the trick :)
Comment #10
johnvComment #11
socialnicheguru commentedcould use uuid and uuid_features like taxonomy does.
Comment #12
samwilson commentedIs this likely to be fixed for D7? Or is it a lost cause? I'm rather toast without this, becuase workflow fields in imported features just lose their associated workflows. :(
Comment #13
johnv@samwilson, As a maintainer, I have tried to make this working, adding all bits and pieces one at a time.
ATM I am happy to accept patches, but am not working actively on it. (trying to manage D8 :-/ )
@Artusamak is/was working on a patch in #2286559: [META] Make Workflow's subobjects things exportable (a.k.a. machine names).. It replaces the Workflow Id by the Workflow machine_name.
But As I stated in comment #10 and #19, The machine_name should only used in the export, not in the module itself.
Comment #14
samwilson commented@johnv thanks, sounds good. I'd love to help; I'm still getting my head around how it all works though. I'll try... :-)
Comment #15
kcannick commentedWow... This broke our site several times and never saw this post. Just kept deleting workflow fields and re-addding.
Comment #16
vulfox commentedTook me hours to figure what was wrong in our feature export to testing site:
For the reference if anyone else in the future wonders you might get this error message:
To clarify this issue for anyone who will come here wondering:
So my original site had just one workflow. This workflow was the second one created though hence it is number 1 (first one is 0).
On my testing site I had re-imported the feature many times so now the workflow was on number 4, even though it was the only one it was the fourth one created since installing the module.
I fixed this by editing the workflows table and changing the wid from 4 to 1. Is are there risks in this? My feature wants workflow 1 but is the wid referenced somewhere else?
EDIT:
..Of course there is. Just have to look for wid column and change all 4 to 1 and hope I found everything
Comment #17
guypaddock commentedCan you guys let me know if my patch in #7 of #2484297: Features import / revert broken in 2.5+ works for this case too?
Comment #18
vasi commentedThe code already allows
$field['settings']['wid']to be a machine name (at least in most cases). It's not too hard to just use machine names all the time, which this patch does. It also upgrades existing fields to use the machine name. Now, when you export a workflowfield with features, it will connect to the correct workflow by using machine names.This doesn't solve the issue with wid/sid/tid's existing all over the export of the workflow itself, https://www.drupal.org/node/2484297 . It also doesn't handle the problem with field values, those remain sids, which may break on import.
Comment #19
guypaddock commentedThat's such a hack... wid should be numeric. It's a number in the schema, and mis-using the wid as though it were the machine name is just inviting confusion for developers, especially for existing modules that plug-in to Workflow.
FYI There is no issue with Workflow using numeric wid, sid, etc internally. That's the main reason why I have such an issue with the other patch that you did. Drupal internally uses numeric node IDs, taxonomy uses term IDs, etc. It makes no difference what they use internally as long as the export does not rely on those IDs. Rewriting the whole module to query everything by name is a massive breaking change, and slows down fetching states, etc because the DB has to do the look-up based on strings instead of integers.
I'll address the field export issue separately in my patch.
Comment #20
vasi commentedThanks for the feedback, GuyPaddock. I think you're confusing me with somebody else, though, when you say "That's the main reason why I have such an issue with the other patch that you did." I don't think I made any other patches to workflow…
I definitely agree with your general approach to workflow featurization! Entities can continue to use numeric IDs internally, and use machine names for export only. However, although your patch does a great job featurizing the workflow itself, it doesn't help with the export of the field_base. It still uses a numeric wid, so when you enable the feature, the field may end up pointing at a non-existent (or incorrect) workflow. My patch is a complement to yours, not a competitor.
I'd be very happy if there was a way to keep a numeric wid in the field settings, but then somehow intercept the field_base export so that it becomes a machine name in the feature. However, I haven't been able to find any such mechanism that's at all reasonable. Please let me know if you have any ideas.
On the other hand, I don't think it's terrible to use a machine name in the field settings, for several reasons:
I look forward to more discussion, and I'll take some time to look at your patch in the other bug.
Comment #21
guypaddock commentedOkay, looks like there's now a solution to the other issue and this is the main issue of interest to prevent features from being flagged as overridden.
@vasi: My apologies for confusing you with someone else; I do remember coming across a patch that pretty much just changed everywhere we used wid and sid with machine names, breaking the API.
Comment #22
johnvRemoved
Comment #23
johnvThe exporting of workflow and Workflow Field definition is now decoupled. See #2375261-7: [EXPORTING] Workflow exported to new feature even if it already exists in an other feature
Comment #24
guypaddock commentedJohn, not sure how that applies here. I was saying that the state IDs and workflow IDs won't always be the same across environments. The fact that the two are decoupled doesn't seem to apply, unless I'm missing something.
Comment #25
johnvIndeed. I posted this in 3 relevant issues, so everyone is uptodate.
And this issue is only completely solved if the workflow_field export a workflow machine-name, too.
Comment #26
johnvThe following code sems to update the settigns with the Workflow machine_name, but the ex
Comment #27
kcannick commentedWhat impact does this have for updating a feature on a site with existing content as the field values/revisions table will have data that references the SID. As I'm understanding wouldn't that make all historical data corrupt.
Should enable maybe check for workflow by name and if it exists assign its WID to the field in the case of an update. Otherwise any time feature is enabled or disabled it would create entirely new workflow instance with different WID/SIDs.
I'm new to much of this so please let me know if I'm wrong in my assumption
Comment #28
johnvNew features for D7 are not processed anymore, (unless a patch is provided)