Motivation
As discussed in #3379442: [policy, no patch] Decide whether to enable Announcements Feed for 7.x by default the next D7 release will include the new Announcements Feed module, and will enable it by default.
There will, however, be the facility to opt-out via a variable (e.g. in settings.php or set directly in the db).
Remaining tasks
- Add the
hook_update_N()to enable the module by default. - Test this hook with and without the opt-out flag set.
Release notes snippet
Pending.. but this should definitely have a CR and Release note.
Issue fork drupal-3424898
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mcdruid commentedComment #3
mcdruid commentedThought about adding a link to the (currently draft) CR to the
hook_update_N()comment to clearly signpost instructions for the opt-out - e.g.:However this ends up being output like this by drush:
..so that doesn't quite work.
Comment #4
mcdruid commentedI think maybe just keep it really simple.
I've pushed a very basic update hook with a comment that looks like this via drush:
I'd suggest that we don't add the opt-out variable to default.settings.php as this is a one-off situation; once the update hook has been run, the variable won't do anything.
So if this looks like it'll do the job, we just need to write up the CR and snippet for the Release Notes.
Comment #5
mcdruid commented@Fabianx approved this in a different channel. However I won't mark it as RTBC just yet...
We need to commit the actual module first, and will then perhaps need to start a new MR.
@poker10 has also pointed out that we need to consider whether this is enabled by default for a clean install. I think it probably should be.
Comment #6
mcdruid commentedI think it makes sense to enable announcements_feed by default in the standard profile, but not minimal.
I've pushed a commit for that to the MR.
As this is done via an entry in the .info file of the profile, the opt-out variable won't do anything there... I think that's okay though. It's really for existing sites to opt-out of the module being enabled by the update hook.
Comment #7
mcdruid commentedComment #8
mcdruid commented@Fabianx suggested that the opt-out should also work for a fresh install, which seems reasonable but means we'll need a slightly different approach.
I've removed the entry from
standard.infoand put the same code that checks the opt-out in the system module's update hook intostandard_install().For a quick manual test, here are the relevant watchdog messages after running a
drush site-install:The module seems to be enabled just before the list of dependencies in the .info file, which should be fine in this case.
I've also done a manual test to confirm that adding this to settings.php
...means that the module is not enabled during installation.
I think it's preferable to do this in the standard install profile so that we don't install the module as part of the minimal profile, as that doesn't seem like it'd be appropriate.
Comment #10
poker10 commentedThanks for working on this @mcdruid!
The tests are failing, because we missed a version property in the announcements module info file and Drupal takes the core version from the first enabled module. Therefore the update module thinks that the core is out of date and sends an email about the update (which causes an error later, because sendmail is not available).
We need to fix this first: #3425698: Announcements module info file is missing the version property
Then tests would be hopefully green. Otherwise, I think the change here looks good (and also the placement in the
standard_install()function). If we can add a simple test for the opt-out variable (maybe just check if there is/is not a link in the toolbar after install), it would be great.Comment #11
mcdruid commentedPer @poker10 the problem is that
ModuleUnitTest::testModuleList()compares the list of modules from .info files with whatmodule_list()reports has actually been enabled.With any luck, the commit I just pushed should make the test pass, as we set the opt-out flag when the standard profile is being installed inside a test.
As an added bonus, this also tests the opt-out itself (at least in the install profile).
I would like to find a cleaner way of doing this though; I tried adding a
\ModuleUnitTest::setUp()in which to set the opt-out variable, but that doesn't work because the parentsetUp()method wipes$confclean before installing the test site.We could mess about more with setting a global there, and checking for it during the install in
\DrupalWebTestCase::setUpbut I'm not sure that'd be any better than adding the check instandard_install()?Comment #12
mcdruid commentedTests pass with that hack.
Manually testing the opt-out flag in settings.php
without:
with the opt-out:
I've also manually tested
system_update_7087()with and without the opt-out variable set.So the only remaining question for me is whether we can think of a cleaner way to achieve something similar to the check for the
drupal_test_infoglobal instandard_install()?We also need to write the CR and Release notes snippet.
Comment #13
poker10 commentedIt seems like that there are multiple places in core / contrib (like token module, views module), where practically the same check is done (with
$GLOBALS['drupal_test_info']), so from this point of view it is not that hacky solution. See for example: https://git.drupalcode.org/project/drupal/-/blob/7.x/includes/common.inc...It is only hacky in a way, that this way we will never automatically install the Announcements module in tests directly with standard profile, so it will not simulate the exactly same flow as a user installing D7 will have. But we are installing the module in various tests in
announce_feed_test.test, so I do not think this is a big issue.A small nitpick, the module name is Announcements, so we could probably update this (can be done also on commit):
All tests are green and the rest of the MR looks good to me.
I have drafted a text of the CR, feel free to update it - https://www.drupal.org/node/3424912
Comment #14
mcdruid commentedI tweaked the module name in the update hook per #13.
I've also changed it so that
standard_install()only switches on the opt-out flag for the specific test class that otherwise fails. This meant adding a new element to$GLOBALS['drupal_test_info']which feels a bit icky, but I think it's a reasonable compromise.This means we're getting all tests to pass, plus testing the opt-out itself (within the profile if not the update hook) but all the other tests that use the standard profile will get the module enabled by default. That's good because it means we're more likely to catch any regressions involving the new module.
With the module enabled by default in the standard profile, we could probably tweak some of the tests in announce_feed_test.test where it shouldn't be necessary any more to explicitly enable the new module, but I don't think we need to do that immediately (and it shouldn't do any harm if we never make that change).
Erm, incidentally, should
announce_feed_test.testbe justannounce_feed.test? Again, not an urgent thing to address.Comment #16
poker10 commentedGood idea to disable the auto-install only for the one specific test class! I think that this is the best compromise we can achieve in combination with a way how we want to enable this and also allow opt-out.
I have also tested the MR manually:
On existing Drupal installation - running
update.phpwith the settings configuration option, the module was not installed. Without the settings configuration option, the module was installed and enabled and was working as expected (together with the new menu link added to the toolbar).On new Drupal 7 installation (without
settings.php) - you need to add the configuration variable to thedefault.settings.php, as the mainsettings.phpis overwritten multiple times (as it is copied fromdefault.settings.php). We will document this in CR.All tests are still green. So I think this is good to go. Committed and pushed this. Thanks!