The attached patch makes captcha points exportable if the ctools module is enabled. If the module isn't available, everything works as usual. This has also be tested with the Features module.
The attached patch makes captcha points exportable if the ctools module is enabled. If the module isn't available, everything works as usual. This has also be tested with the Features module.
Comments
Comment #1
jmiccolis commentedIn fact, this patch doesn't work. The issue is that ctools' export.inc takes `type` as a reserved attribute on the exportable object. In captcha `type` is used to represent the kind of captcha challenge that will be used. Before putting more work into this I'd like to know if others are interested in having exportable support in Captcha. So, is anybody?
If so we'd want to rename the `type` column in the `captcha_points` table. I'd be willing to do this work if there is consensus around the idea.
Comment #2
soxofaan commentedHi Jeff,
Thanks for your contribution.
I think it's difficult to know if there is much interest in ctools exportables support. As CAPTCHA maintainer, I've experienced that questions like this sometimes get very few response (if any) in the CAPTCHA issue queue.
There is also a CAPTCHA drupal group (http://groups.drupal.org/captcha) where you could ask this, but the traffic over there is also pretty low.
About the possibility to rename a the type column: there is this critical issue #810534: Fix CAPTCHA session reuse, for which the fix involves a database update (in the captcha_sessions table). Maybe it's a good idea for end user friendliness to do both database updates in the same release, if the timing allows this. The critical issue should be fixed as soon as possible of course, so waiting on #825088: Exportables support for CAPTCHA points would be a bad idea, but on the other hand, the column rename could be done before the ctools-exportables patch is ready. Just an idea.
Comment #3
Josh Benner commentedI'm a fan of making captcha points exportable. I want to export everything!
Comment #4
nedjoYes, exportables support is very important. E.g., I'm wanting to include CAPTCHA support in the Debut feature set, and lack of exportables support prevents doing so.
This is certainly worth an update to the existing 'type' column name.
Comment #5
soxofaan commentedok then, I'll try to rename the column before for the CAPTCHA 6.x-2.3 release
Is there any documentation on this " 'type' as reserved column name" feature of ctools?
Comment #6
nedjoYes, the reserved column names are documented in the ctools Advanced Help--see the help page at help/ctools/export.
Here's a patch with the column name change. Export now works via features, but captcha configuration from enabled features doesn't yet show up on the captcha config screen.
Comment #7
soxofaan commentedGreat!
Let's see what the testbot thinks
Comment #8
nedjoThe patch actually works fine, as far as it goes. Captchas can be exported into features and, when a feature with captchas in it is enabled, they show up in the list of captchas.
However, there are remaining problems that stem from the existing install function and the UI for editing captchas.
1. The first problem I found in testing relates to the install function. Because the captcha_points table is populated with an initial set of records, if there are code-based defaults for the same forms, they are overridden. Since the defaults include some of the forms most likely to be assigned captchas, this is a significant problem. For example, if a feature module added a captcha challenge to the comment_form, that captcha would be overridden (removed) in the initial install state.
2. The second problem stems from the fact that data are saved for all forms at once. If you enable a feature module with captcha information, the data are not initially overridden (unless they were already on the site). But submitting the settings form even once saves a record for each captcha in the database, meaning that all default captchas are overridden (even if no change was made). This doesn't break anything, but makes it hard for an admin to determine if s/he is using the default or has overridden it.
Re problem 1, a possibility would be to remove the inserts from the install script and instead alter the array of available captcha data in hook_captcha_default_points_alter(), providing captchas for given forms if none was already provided by a module. Draft:
As an added advantage, we can test module_exists() and provide only suitable suggestions.
Re problem 2, we could detect in the form submit handler whether there is a default version of a particular captcha and, if so, save a record to the db only if the data are different from the default.
Alternately, we could consider switching to using Ctools exportables UI, but that would mean bigger changes.
Comment #9
nedjoHere's a patch with the two fixes described in #8.
There are some details still missing, e.g., enabling settings that are disabled by default (as noted in a code comment by jmiccolis), but the basics are here and - with a look over from someone else - this should be ready to go.
soxofaan, please let me know if you have further questions or concerns.
I suggest after this patch goes in that any further changes begin with consideration of switching to CTools exportables UI.
Comment #10
soxofaan commentedFYI: sorry about the radio silence on my part, for the moment I don't have a lot of time to review/followup this thread/patch. I hope to give it some love soon.
Comment #11
aschiwi commentedOh great, wish I would have found this yesterday :)
I used the patch and was able to export a setting for a custom form_id.
It seems all of the default form_ids that come with captcha are now using a captcha by default, correct?
Comment #12
soxofaan commentedHi all,
Because I couldn't allocate a long enough time slot to review patch #9 properly in full (I'm not very experienced with ctools exportables), I decided to chop this task in parts and already committed a part of the patch #9: the rename of the column name from 'type' to 'captcha_type': http://drupal.org/cvs?commit=457682
In attachment: the remainder of the patch (all the Ctools export stuff)
In case this could be interested to anybody: I maintain the module with Git (easier to work with per feature branches and small incremental commits) and push regularly to https://github.com/soxofaan/drupal-captcha-dev (CVS branch DRUPAL-6--2 corresponds to git branch "master-d6")
The branch for this issue is "825088-ctools-export" (https://github.com/soxofaan/drupal-captcha-dev/tree/825088-ctools-export) and already contains the remainder of patch #9
Comment #13
soxofaan commentedFYI: ported and committed the patch from http://drupal.org/cvs?commit=457682 for D7: http://drupal.org/cvs?commit=471330
Comment #14
scothiam commentedsubscribing
Comment #15
nedjoHere's a patch for the D7 version.
Comment #17
nedjo@aschiwi, "It seems all of the default form_ids that come with captcha are now using a captcha by default, correct?"
Yes, this is the one significant change from the D6 functionality. From an exportables perspective, it seems incorrect to force the captchas to none when the point is the opposite--that these are forms that likely should have captchas. Probably what we want here is to set them to use captchas but to have an initial state of disabled, allowing users to enable them--but we don't yet have support for the ctools exportables disabled flag.
To retain the D6 functionality, we would change this line in
captcha_captcha_default_points_alter()to
Comment #18
nedjocross post
Comment #19
nedjoFix one glaring error at least.
Comment #20
nedjoThe patch sort of works, but has some remaining issues related to the defaults.
The patch replaces the current db inserts that create an initial set of form data with an alter. As a result, these forms appear to have default settings on an initial install. This makes it non-intuitive to add a captcha setting for these forms to a feature. To do so, you have to:
* Change the setting for the form from the default to another setting, e.g., disable the captcha, and save the configuration. This creates a record in the database.
* Now, if you actually wanted the default setting, select it and save again.
* Only now will the form be available for export.
So, it works, but it's awkward.
However, it's not clear what would be better. Options:
* Drop all the initial data population, relying instead on the regular methods of adding presets to forms. But this would raise problems for the user register and login forms, which aren't available to logged in users and so can't be effectively selected by admins for adding captchas.
* Drop all but forms that don't appear for logged in users.
* Convert the initial population into a regular hook_captcha_default_points() implementation, meaning that (a) any features wanting to affect these forms would need to do so in an alter hook and (b) any sites wanting to have something different would need to either use an alter hook or override through the UI.
The last option might be the best.
Besides these considerations, there is also the question of whether CTools is still the best way to do this. Entity API is another option and may be a better choice. See #624018: Exportables and Features support for WYSIWYG 7.x comment #119 and later.
Comment #21
alberto56 commentedsubscribing
Comment #22
alphageekboy commented#19: 825088-19-captcha_ctools_export.patch queued for re-testing.
Comment #23
samhassell commentedsubscribe
Comment #24
neurojavi commentedSubscribe
Comment #25
jec006 commentedSimple change to remove warnings that occur in strict error reporting.
Comment #27
jec006 commentedAh, never mind - was a version behind with the warnings ... sorry for the confusion.
Comment #28
soxofaan commentedHi all,
I finally found a bit of time to look into this issue a bit more.
I committed the patch for Drupal6 from #9 and #12 (with some extra tweaks) in commits
http://drupalcode.org/project/captcha.git/commit/afda4a3
http://drupalcode.org/project/captcha.git/commit/92cf795
http://drupalcode.org/project/captcha.git/commit/e4988d1
http://drupalcode.org/project/captcha.git/commit/f528630
I included the suggestion from #17 to default to no CAPTCHA. This also makes the issue from #20 almost inexistent.
I hope this closes the issue for the Drupal6 version.
Still to be ported to D7
Comment #29
pwhiteside commentedComment #30
scottrigby@pwhiteside please do not change the issue status
Comment #31
pwhiteside commented@scottrigby Sorry pal I didn't mean to.
I clicked a re-test link and it automatically did it and I don't know how to delete comments.
Comment #32
neurojavi commentedI've been using the patch in #19 for D7 and it worked fine. I've done an upgrade of drupal core (7.12) and features (1.0-beta6) and now, when I do a feature update, it removes my captcha points exports.
Something new here?
Thanks.-
Comment #33
ao2 commentedHere is a reroll of the patch in #25 which fixes this warning with newer PHP versions:
the incremental change is just this one:
but I am attaching the full patch here; easier for drush-make users.
Comment #36
patty.fresonke commentedJust wondering what the status of CAPTCHA points being exportable to features?
I tried the last patch (#33) and it just set EVERY form to use the default challenge...
Comment #37
SebCorbin commentedWhat does the testbot say of the latest patch?
Comment #38
neurojavi commentedHi:
Path in #19 worked for me for some time but in some point it stopped working. I've try patch #33 with beta2 and last dev and it doesn't seem to work. When I make "drush fu" the line of my info file that instructs features to export captcha points gets removed:
features[captcha_points][] = "contact_site_form"
and no captcha points are exported.
Any news about this?
Thanks.-
Comment #39
crabsoul commentedCheck attached patch working fine with Captcha 7.x-1.0-beta2 version.
Comment #41
crabsoul commentedPlease check fixed version.
Comment #42
samhassell commentedComment #44
crabsoul commentedplease check patch attached for Captcha 7.x-1.x-dev. I've tested it properly. its working now.
Comment #45
jdleonardComment #47
akalam commentedPatch well formated for applying (path fixed)
Comment #48
soxofaan commentedComment #50
akalam commentedPatch had problem with filename becouse of the "#" character. File renamed and reuploaded
Comment #51
joachim commentedI'm getting weird behaviour where my Feature is reporting it's overridden, with this as the diff:
The only exported captcha point is the 'user_register_form'; all others are set to 'none' in the UI and their DB rows have NULLs.
Reverting the feature is not fixing the problem.
On the plus side, my feature deployed to the staging site perfectly :) -- though the staging site is showing the same problem.
Comment #52
joachim commentedThe problem is caused by captcha_captcha_default_points_alter():
This takes the default captcha points that have come from the default hook (ie, from features), and adds defaults.
So:
- install captcha module
- set login captcha to 'none'
- export another captcha point to a feature
- when the feature is reverted or diff'ed, hook_captcha_default_points_alter() fires, and because the feature has nothing to say about the login captcha, it enables it
This seems pretty weird to me.
One way to deal with the problem is to just add the captcha points captcha_points:user_login captcha_points:user_login_block captcha_points:user_pass to the feature, even though they are set to no captcha. This seems very weird -- nobody would think to try that, so this would need documenting.
I think the problem is really that while this module sets those forms up to have a captcha in hook_install(), these should be taken to be installation defaults, not permanent defaults. Hence the behaviour in captcha_captcha_default_points_alter() in incorrect. Though even removing that would still mean that on deployment you'd get hook_install() adding those in.
I'm inclined to say that having defaults forced in hook_install() isn't really compatible with supporting exportables. But that would be a fairly big change in how this module works.
Comment #53
geek-merlinso needswork as of #52...
additional note: i enabled captcha module by rolling out a premade captcha feature, without this patch.
user forms did NOT get captcha-auto-enabled (which i wanted...) using 7.x-1.0-beta2. did not investigate that yet.
Comment #54
joachim commentedIIRC, without this patch, this module has no Feature support at all - so no forms will get enabled.
Comment #55
joachim commentedIIRC, without this patch, this module has no Feature support at all - so no forms will get enabled.
Comment #56
wundo commented#50: captcha-patch-on-44-well-formated-825088-47.patch queued for re-testing.
Comment #58
vincenzodb commentedsubscribe
Comment #59
hefox commentedHaving defaults via hook_install is fairly usual I think -- media does it now tmk. The problem is realizing when those defaults should be gone.
Comment #60
hefox commentedComment #61
hefox commentedComment #62
pachabhaiya commentedPatch #61 failed to apply successfully in the latest '7.x-1.x-dev' version of CAPTCHA module.
Got the following message when trying to apply patch #61 (825088-captcha-export-60.patch)
Comment #65
pachabhaiya commentedThe latest patch does not apply successfully to the latest 7.x-1.x-dev version. This latest patch needs to be rerolled for it to apply successfully.
Comment #66
pachabhaiya commentedRerolled the patch #61 to apply successfully in the latest 7.x-1.x-dev version.
Comment #67
jastraat commentedWe're using the patch in #66 successfully.
Comment #69
wundo commentedComment #71
rjacobs commentedWere the issues from #51 and #52 ever addressed? It appears they were perhaps overlooked? See the related follow-up:
#2552279: Feature is overridden always