Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The Drupal 7 version of the Cron Example uses variable_set() and variable_get() to store data for bogus operations while demonstrating cron runs.
Unfortunately (for us, not for Drupal) variable_*() is removed from Drupal 8, so we'll have to come up with a better way to demonstrate cron.
Change notice: https://drupal.org/node/1500260
Proposed resolution
Figure out a way to demo cron.
The new config system is probably a bad way to do it.
In the mean time, I'll remove cron_example from 8.x-1.x and turn it into a patch here.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#38 | interdiff-36.38.txt | 2.12 KB | martin107 |
#38 | 2197267-38.patch | 18.46 KB | martin107 |
#36 | interdiff-34-36.txt | 5.16 KB | martin107 |
#36 | 2197267-36.patch | 17.81 KB | martin107 |
#35 | interdiff.txt | 4.72 KB | willzyx |
Comments
Comment #1
Mile23This is the D8 version of cron_example from #1867662: Port cron_example to D8
Comment #2
Mile23Removed cron_example: http://drupalcode.org/project/examples.git/commitdiff/3ea34b98d3a5c3bf78...
Sigh.
Comment #3
rpayanmPlease review.
Comment #4
Alan D. CreditAttribution: Alan D. commentedAny reason that REQUEST_TIME is not used and time() is? Was going to create a separate D7 issue related for this, but I see time() is used a lot in this patch.
Comment #5
rpayanm@Alan D. You are right!
The changes in this patch.
Comment #8
joshi.rohit100Suggestion -
1. As drupal core is going near to short array syntax, I think we should also do the same.
2. In Form class, we are extending configformbase and still we are using old style t() not $this->t().
I think $form_state should not be referenced.
it will be good if service is injected.
Comment #9
rpayanm@joshi.rohit100 thank you for your review and your suggestions.
Here the patch.
Comment #10
joshi.rohit100Wrong patch extension.
Comment #11
rpayanmUpss sorry :)
Comment #12
joshi.rohit100namespace is wrong.
Also as I noticed, cron_example module is not using PSR-4 standard (as currently drupal 8 is using).
Comment #13
rpayanmHere the fix :)
Comment #15
rpayanmRight!
Comment #19
Mile23Thanks for sticking with it.
I'm not entirely sure about why the tests are failing, but here's some other review:
This method really needs some line-by-line explanation, since it's the thing we're trying to explain. :-)
Inline comments for why we're doing this, and why it's before the parent call.
Comment #20
martin107 CreditAttribution: martin107 commentedI was bug hunting so I did not resolve any of the things from #19.
1) Fixed a couple of minor nitpicks in /cron_example/src/Form/CronExampleForm.php
2) Replaced a couple of reference to $this->t in a *.module file.
(2) should bring the error count down.
Comment #22
joshi.rohit100I think, config name should be defined here for 'examples.cron'
Comment #23
martin107 CreditAttribution: martin107 commented1) #22 Yep, I also think that....
2) it is best practise to call your parent - and let it do its things, rather that implement what the parent currently does. Things change and that creates and maintenance problem.
Comment #25
martin107 CreditAttribution: martin107 commentedIf we are going to call set, we need to call getEditable() first
Here is the relevant change record.
https://www.drupal.org/node/2407153
Comment #27
martin107 CreditAttribution: martin107 commentedThis next change record points out that hook_cron_queue_info() has been removed and we should use plugins to define our queue workers
https://www.drupal.org/node/2341649
I have made a start on the change. - Somewhere I have made a mistake and I don't think the new queue workers are being registered as plugins
I am posting early, in the hope others may easily see the flaw in my work and suggest a fix :-)
I will have more time on the weekend to fix this.
Also I have made a series of minor coding standard changes
so $cron_config becomes cronConfig where appropriate etc.
Comment #29
martin107 CreditAttribution: martin107 commented1) I was using the old function name.
2) Improved a comment.
The same failures persist.
Comment #31
willzyx CreditAttribution: willzyx commentedthis patch should at least fix the test
Comment #32
martin107 CreditAttribution: martin107 commentedThank you
This is the code I wanted and was missing, willzyx++
All the MANY other fixes look good also :)
There were some comments in the code before I started making changes ... that as I changed things have gotten lost.
I will have a look tomorrow and put similar comments in the new code as appropriate.
This is demonstration quality code and so I want to criticize my own work ...
Having ReportWorkerBase is simple and gets the job done, but I think there is a better solution!
Should we use a Trait? ... or should the 2 plugins be using a decorator pattern to provide the functionality found in ReportWorkerBase::reportWork?
I will have to have a think...
Comment #33
willzyx CreditAttribution: willzyx commentedthe real problem was in the QueueWorker plugins.
The id was
cron_example_queue_*_worker
but in CronExampleForm and in test was usedcron_example_queue_*
:)Comment #34
willzyx CreditAttribution: willzyx commentedComment #35
willzyx CreditAttribution: willzyx commentedthe interdiff
Comment #36
martin107 CreditAttribution: martin107 commentedJust making notes on #34
Visually the form looks much better so +1 to that change
The dependencies of the sub module are more correctly defined so +1.
All other changes look good.
So for changes in #36
1) Instead of using the $GLOBALS to pass messages - I have changed to using the state system.
2) I am using the string translation trait - as in the fullness of time t() will be deprecated.
3) As per #32 I have gone back and looked at #15 and reintroduced/refreshed some comments.
regarding #32 and a potential mini redesign ... after sleeping on it I think let just keep things simple and keep ReportWorkerBase.
So remaining tasks?
We need to implement the suggestions from #19 - I am out of time today but will try and get to it soon :)
Comment #37
martin107 CreditAttribution: martin107 commentedI can see a flaw, that I will fix next week
The tests don't find this but once the new state variable is set to TRUE there is no mechanism to set it back to FALSE!
Comment #38
martin107 CreditAttribution: martin107 commented1) As per #37 - cron_example_show_status_message now resets correctly each time.
2) I have add comments as per the review in 19.
@Miles
I am not sure why it's called before the parent. - but then again apart from stylistic reasons I am not sure that is important.
the form state is not modified.
Please let me know if I have made a mistake.
I regard the text as a starting point I will happily tweak the language as people see fit.
Comment #39
Mile23Thanks, Martin and everyone!
I've tweaked some of the documentation and fixed all the coding standards errors I could find, and now it's committed.
We can make minor changes in follow-ups.