When exporting scald contexts into a feature, it looks like this :
$context_config = new stdClass();
$context_config->disabled = FALSE;
$context_config->api_version = 1;
$context_config->context = 'context_name';
$context_config->transcoder = array(
'image' => array(
'*' => 'default',
),
'video' => array(
'*' => 'default',
),
);
$context_config->player = array(
'image' => array(
'*' => 'default',
),
'video' => array(
'*' => 'default',
'settings' => array(),
),
);
$context_config->data = array();
$export['context_name'] = $context_config;
It may lead to features that are constantly overridden if you want to share it across many websites (in an installation profile for example) with different scald providers (like image, video,...).
Instead of exporting the whole context into one exportable, would it be possible to export it into several one split by provider type ?
It would fix the previously described issue.
What do you think of this ?
Regards,
Renrhaf
Comments
Comment #1
renrhafComment #2
pvhee commentedThis would definitely help in packaging some scald exportables in a base profile and allow different sites to export other scald exportables. Right now, this is impossible since only one feature can export all the scald contexts.
Comment #3
renrhafAtfer some investigations I think that a column "type" referencing the atom provider type should be added to the table "scald_context_config".
After that, the code should be refactored to take these modifications into account and the export will be per type, am I right ?
Comment #4
renrhafAdding support for feature exports by types.
You can now export only the context configuration by type in features.
What do you think of this ?
There is some code included in the patch that I did not modify but merging 7.x-1.x told everything was up to date before making the patch...
Comment #5
renrhafHere is the proper patch file.
Comment #6
jcisio commentedThanks for the patch, I test an export and it looks clean. There are however a few bugs:
1. I think the "type" column mentioned in #3 is outdated, and the idea was to split the context_config object (in CTools means) into separate object, but now become a workaround in Features to avoid an update. I'm ok with that.
2. "You can now export only the context configuration by type in features." - several question:
- When I apply the patch and update my feature, code from mymodule.context_config.inc was copied into mymodule.features.inc and I have bug when mymodule_default_scald_context_config() is defined twice.
- I think we should continue to support the context_config export as a whole to keep upgrade easier. I.e. when I export a context_config, it exports all scald_context_type for that context. In the other way, context_config depends on all scald_context_type of existing providers. Then upgrade will be smooth because I don't have to change anything to support this new kind of export.
3. Why 4 spaces "____" is used as separator? Why not just 2 underscores? I think the best separator is the traditional one: dash (-).
4. Minor one: the export array is rather large, could be use the format
$context_types['context_name-type'] = ...;to help debugging?Comment #7
renrhafHello and thanks for your reply,
1. Yes it was at the beginning of my investigations.
2. I totally agree and I will look for the bug you are talking about as soon as possible.
3. I decided to put 4 spaces to avoid any conflicts with features names. I had not many time to check every implications so I decided to choose something I know would not cause problems. I'll go for one dash then if it's possible without conflicts.
4. I'll see that too.
Comment #8
renrhafHello again,
"When I apply the patch and update my feature, code from mymodule.context_config.inc was copied into mymodule.features.inc and I have bug when mymodule_default_scald_context_config() is defined twice."
I can't reproduce this error. For me, old "my_feature_default_scald_context_config()" is still present in the file my_feature.context_config.inc and no duplicates exists in the my_feature.features.inc because the new hook is "my_feature_scald_default_context_types()".
"I think we should continue to support the context_config export as a whole to keep upgrade easier"
I don't really understand, I saw that the old way to export context data disapeared. You mean that you want to keep it to have people migrate easier from CTools to Features exports ?
And for the other things, I changed separator and code generated to fit the needs.
Regards,
Renrhaf
Comment #9
renrhafCorrected a small issue with patch generation. The content was truncated due to an error I made modifying the patch by hand like a N00b. Sorry.
Comment #10
ciss commentedComment #14
nicoloye commentedI have regenerated your patch, hope it is ok now. :)
Comment #15
nicoloye commentedComment #17
nicoloye commentedAnd failed ... lol, ok let's check why ...
Comment #18
nicoloye commentedMmmh I must admit that I don't understand the error right now :(
Comment #19
nicoloye commentedThere were still some CRLF in the new file to be generated. Trying this one, better luck this time ?
Comment #20
ciss commentedComment #21
ciss commentedSorry, that was an accidental submission. Restored and added php tags as a bonus.
Comment #22
nagy.balint commentedPatch seems to be working.
I think that backwards compatibility should get some attention.
It seems that there is no real way to migrate over to the new solution, since we cannot change code in features.
So the old feature should remain operational until the site builder decides to switch over to the new way of doing things.
However when the feature is recreated and the new method is used, the old file module.context_config.inc should not be present anymore i think.
Comment #23
renrhafHello,
Here is the patch reworked with your requirements :
1. Backward compatibility : the user has to explicitly choose to switch to the new export method.
2. Deletion of the old module.context_config.inc file if new export is used.
Regards
Comment #24
nagy.balint commentedHi!
Thanks for the patch.
1) The following diff might be a mistake as its already in the menu hook:
2) That deletion method will only work if php has access to write the module files if I'm not mistaken.
The best would be if when using drush fu, or simply feature recreate it would delete / not include that old file in that case.
Not sure that this will solve that.
Comment #25
nagy.balint commentedThe best solution would be of course to do something like the features module does. Is that it could read both the old and new config, but when drush fu or recreate, it will write the new config automatically deleting the old. And so it keeps backward compatibility, and then we dont need this extra variable, but after the first recreate it will use the new one.
If the new and the old are equivalent that should be doable, otherwise if switching to the new version requires some manual steps as well, then maybe thats not a good idea, and your switch variable is better.
Comment #26
renrhaf1) There is the updated patch, it was a mistake, thanks.
2) Yes I think the same, but PHP must have this right theoretically as features has the right to write files in such places, don't you think ?
The problem is that the two export methods can't coexist. If you enable the "hook_features_api", the old way to export won't work anymore (unless I misunderstood something with CTools/feature exports).
What do you think ?
Comment #27
nagy.balint commented2) Yes you can configure your development environment so php has access to all files. And you can use the feature to replace your files automatically on the UI.
However If someone uses the drush fu, or recreate from the UI, then when drupal creates the package with the feature, the old file should not be included. That was the issue i reported at least.
Comment #28
renrhafHello,
I have re-tested export via drush fu and via the UI, and the old file feature.context_config.inc is removed in both cases. So this last issue is resolved. Anything else to do ?
Regards
Comment #29
nagy.balint commentedBut wont this clean export function be called when recreating a feature (when i just download a zip of the feature)? And then it will try to delete a file when it should not?
Comment #30
renrhafI got no such problem when I developed and tried the patch.
Have you encountered anything like this ?
If you can provide me steps about how to reproduce this I would be able to fix it but now I don't know what to do exactly...
Regards
Comment #31
nagy.balint commentedIt was more like a theoretical question.
But if it would be the case, then if you have an old feature with the old format, and then you press recreate on the features UI then it would delete the file from the feature (if php has write permission on the module's folder that is), and then it would give you the zip with the feature of course.
I was just wondering if in this case that happens or not.
Of course I will test the patch again soon.
Comment #32
renrhafIf the old export method is still used, the clean function won't be called, and so the old file won't be deleted as well. This clean only takes place when using the new feature export.
Comment #33
nagy.balint commentedBut if you have an old feature in your folder. And then you go into the feature UI, you switch over to the new method and then click on recreate then it will use the new method and tries to delete the file when I was just recreating.
I think therefore when i recreate, it should not try to delete a file in the module's folder, because when i recreate on the UI i just receive a zip file and it should not manipulate files in the module's folder.
Comment #34
renrhafOooh I see ! Yes you are right, that may be confusing...
But how to get rid of this old file then, when using generate feature or via drush ?
Comment #35
nagy.balint commentedWhen the field configuration was split to instance and base, they did something like this: https://www.drupal.org/node/1959076
So just simply marking those as deprecated and not deleting them.
But then not sure if its possible to achieve to not have the file still in the zip when recreating the feature. Maybe the only way is to let the user know that the file should be deleted?
Comment #36
renrhafAfter reading the linked issue comments, I think that the best thing to do is just warn the user if the old file is still present.
I wasn't able to remove this old file from the exported zip when recreating the feature.
It would be possible if context_config was a feature component but it's only a Ctools component.
Comment #39
nagy.balint commentedSorry but I have a few more feedbacks about the switch to the new method:
- For security reasons (XSS) there should be no links that execute something right away. Like in this patch if i call "admin/structure/scald/switch-to-feature" then it will execute the switch right away.
Usually there should be a button on that page, or a button should be on some other page where the user can switch with clicking on the button.
- It would be nice if this functionality would be enabled by default for new installs.
So for new installs it would be TRUE by default, and for old installs it would be FALSE by default, and then that would mean that we prefer everyone used the new method, but we don't want to affect any old site running the old method. And any old site can choose to switch to the new method whenever they please.
Comment #40
nagy.balint commentedAnd of course once the new system is in use, the switch button does not need to be there anymore.
I guess there wont be a way to switch it back to the old method, so depending on the value of the variable we can hide the button of course. And depending on whether this is on an existing page or on a new page, we can disable the menu entry as well.
Comment #41
renrhaf- Menu entry removed, use of a custom form instead.
- Set the variable to TRUE in hook_install to enable it by default on new installs.
- There is no switch back method.
Is everything OK for you ? Thanks !
Regards
Comment #42
nagy.balint commentedI have made a few wording changes.
Also it turns out that you cannot even define the function for features, otherwise the ctools export wont work. So if we want to make it work for old installs until the functionality is enabled then we have to conditionally define the hook.
This of course means that after setting the option to TRUE, a cache clear is required.
In order to get this into 1.4 possibly, i reconsidered, and decided to set the option to FALSE in the install hook, and then the idea is that when 1.4 is released we can set it back to TRUE in the dev branch.
That way this can remain an experimental feature, which most likely works, but i would like to be extra careful and avoid a potential issue on new installs.
Please test, and I will still need to test it myself as well of course.
Comment #43
renrhafI understand we need to be careful with such a modification.
I will test this ASAP, thanks !
Comment #44
nagy.balint commentedMoved the button in the scald dashboard below the atom type table, as the atom type table is used a lot, and this button belongs next to the context table.
Also added that it should only appear if the features module is installed, as otherwise not much point enabling it :)
Comment #45
renrhafGood catch ;) I'm not used enough to contributing to think to these small but important things :)
I had a feature using the old CTools export, then I activated the new export mode with the button.
Then, I regenerated the feature and got code exported in the new way, and a warning about the old file that is deprecated and can be deleted.
Finally, I removed it and regenerated the feature again with no deprecation message as intended.
All lights green for me !
Comment #46
nagy.balint commentedNice.
Maybe this patch will only go in right after 1.4 into the dev branch, we will see.
So we might have a few days delay here, but I will keep you posted :)
But you can safely use this patch for now. As it will get in soon.
Comment #47
renrhafThanks a lot for your time and help.
If anything remains to do, I'll try to find some more time too.
Comment #48
si.mon commentedChanging this to RTBC as the patch seems validated.
Comment #50
nagy.balint commentedThanks!
Sorry for the delay, its now committed.
Comment #51
renrhafGreat, many thanks, it was a pleasure !