Closed (fixed)
Project:
Scheduler
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
16 Jan 2016 at 11:04 UTC
Updated:
27 Apr 2016 at 13:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
pfrenssenComment #3
legovaerIn attachment a patch which introduces this service. I've checked the test scripts and there's no need to update them as the functionality remains the same.
Comment #5
jonathan1055 commentedThank legovaer for starting this.
I have just committed #2655666: API Testing module - conversion to 8.x so will re-queue the above patch. It will now actually test the hook_scheduler_allow() function.
Comment #7
jonathan1055 commentedThat's good. The two API classes that were failing (before I converted the API test module code) are now passing.
Comment #8
pfrenssenGreat start! I would rename the method to "isAllowed()" so that it is clear it is a check that returns a boolean. "allow()" implies that it is allowing something.
We need to think about the hook_scheduler_api() too, this should be turned into a set of event subscribers.
Comment #9
legovaerAgreed that we should turn hook_scheduler_api() into events. I created #2669164: Introduce event subscriber for the Scheduler hooks, otherwise the change in this issue might get too big.
Comment #10
legovaerUpdated method name to "isAllowed()" as suggested in #8
Comment #12
pfrenssenLast patch has mistakenly taken on some unnecessary baggage.
Comment #13
legovaerComment #14
legovaerI've done a pull on the latest code we have in the
8.x-1.xbranch and re-applied the patch of #3 manually. Also the changes of #10 (without the garbage) have been added. I've also removed the function_scheduler_api()as we won't need it anymore now that we have this service.The interdiff may look a bit odd, but that's because several changes already went in the code.
Comment #15
legovaerWhile going through the code again, I noticed that the entire
scheduler.cron.incshould have become part of a service as well. So now I introduced one service:SchedulerManager.What do you think about this one?
Comment #16
jonathan1055 commented... um ... I think your patch is the wrong way round, isn't it?
Comment #17
legovaerWhat do you exactly mean? Wrong implementation?
Comment #19
jonathan1055 commentedAh, I looked at the interdiff, and it has been made the reverse way round. In the first chunk, you try to create a new file scheduler.cron.inc, and likewise the other files have the reverted change. I did not look at the actual patch, but that has been made the right way round. So you can ignore my comment, other than nothing when you make an interdiff, take a quick look to check it rather than confuse us ;-)
Pieter will have to advise on the idea of moving the whole of cron.inc to be part of the service. I will wait until your patch passes automated testing, then take a closer look.
Comment #20
jonathan1055 commentedI have now added test coverage for all the existing hooks, see #2655666-23: API Testing module - conversion to 8.x. The files that changed in this commit are
SchedulerApiTestCase.phpandscheduler_api_test.moduleso this will not affect your code changes in the patches above.Comment #21
jonathan1055 commentedThe patch in 15 no longer applies due to my recent commits. I've created a new one which does apply. I have not altered any of the actual code, hence this will fail in the same way as #15 did, but at least you can take this new patch and work on it directly with the new code-base.
Comment #23
jonathan1055 commentedI cannot see any error messages to explain the exceptions on the d.o. testing console output, but on my local site I get
Hope that helps.
Comment #24
jonathan1055 commented@legovaer, hope you don't mind but I wanted to work on this blocker, as it has been three weeks since your last post.
logger.channel.scheduleris not defined in .services.yml, so I added that (copied the definition from core/modules/contact). That solved the first error.class: Drupal\scheduler\SchedulerManagerin .services.yml\Drupal::service('scheduler.manager')->isAllowed()but they were still\Drupal::service('scheduler.authorizer')->isAllowed()_scheduler_scheduler_nid_list()which had not been changed to$this->nidList()\Drupal::entityManager()->getStorage('action')...had been changed to$this->moduleHandler->getStorage('action')...when it should be$this->entityManager->getStorage('action').... This finally got cron running :-)The automated tests fail, so that's the next step to solve.
Posting this work here, plus an interdiff of #21 to #24.
Comment #26
jonathan1055 commentedThat's progress with 26 passes, up from 0.
Further fixes:
isAllowed()the initial conversion missed the ! in front, so that had the effect of denying publication for every node (apart from the ones which were denied), and likewise for unpublishing. This fixes all but two of the failing test classesDrupal\scheduler\Plugin\Exception\and attempted to be used viause Drupal\scheduler\Plugin\Exception\SchedulerMissingDateException. This can be corrected by creating them in the normalDrupal\scheduler\namespace\Drupal::service('scheduler.manager')->runCron()instead of including the old scheduler.cron.inc file [same change as in .module scheduler_cron]New full patch, plus interdiff from 24 to 26 to show the changes discussed above.
Comment #27
legovaerNice! Great progress Jonathan! As far I can see, we have 35 passes and no fails so it seems to be working fine now. Should we wait for Pieter's review?
Comment #28
pfrenssenBetter don't wait for me, I've been very busy lately with preparing sessions for camps and working on the D8 port of Organic Groups. I really can't make any promises at the moment for availability for reviews. I will pop in from time to time but don't hold up anything on me.
This is in capable hands, you guys are doing a great job!
Comment #29
legovaerI've just done a full review and it looks OK to me!
Comment #30
jonathan1055 commentedThank you Pieter for your confidence in us, and thank you Levi for reviewing. I am happy with the majority of the changes I made in #24 and #26 as they were corrections with an obvious answer. However, I would just like to ask your opinion specifically on two of them given that I am relatively new to OO and having to do lots of learning:
In #24.2
Alternatively could we rename the file
manager.phpand the class to be justManagerand leave the namespace asDrupal\scheduler\Manager. Is there a prefered naming convention here?Similarly, in #26.2
Did I pick a sensible correction to this? Or should the exceptions be in a more specific namespace such
Drupal\scheduler\Exception. It works fine at the base level ofDrupal\schedulerbut I just wondered if this is actually the correct place?Comment #31
legovaerJonathan,
As you can see in the Naming Conventions in #10:
I'd suggest to keep the name
SchedulerManager. If you have a look at the core modules, you'll see that they also use this naming convention (E.g. BookManager).About the exceptions: I'd keep them in a separate namespace. This allows us to keep the code and the PHP files structured. I don't want the
src/folder to become a mess. An example of this namespace usage can be found in themigratemodule. The custom exception's namespace inmigrationis\Drupal\migrate\Exception\RequirementsException.I've added a patch which updated the namespace again.
Comment #32
legovaerForgot to update the namespace in the docblock.
Comment #33
jonathan1055 commentedThanks for the explanations in #31. I am pleased I picked the right place for
SchedulerManager.Yes I agree with your suggestion for the exceptions. Just to confirm - the exception namespace is now
Drupal\scheduler\Exceptionwhich is better than both the original Drupal\scheduler\Plugin\Exception\ and the working but not-to-standard Drupal\scheduler. The files are stored in/src/Exception/not just at /src/I have seen a few things in the comments which need adjusting, but I have noted those and will make the amendments afterwards, rather than fiddling with more interdiffs. I am happy with committing this. It will have an impact on the patch in #2669164: Introduce event subscriber for the Scheduler hooks which will have to be re-done given that .cron.inc will no longer exist. But that was always going to be the case. Getting this first commit in will allow us to work on the other things.
Comment #34
legovaerLet's ship it. I'll start updating the other issue so that we can get that in as well.
Comment #36
jonathan1055 commentedHere you go! Great work, thanks.
This issue is not closed yet, as I mentioned above, there are few minor tweaks, comments and adherence to standards which I will do now.
Comment #37
jonathan1055 commentedHere's the tidy-up patch
I have avoided changing a couple of comments which are part of your new patch in #2669164-24: Introduce event subscriber for the Scheduler hooks so hopefully that wont need to be re-rolled again.
Comment #38
legovaerLooks good to me! Great work!
Comment #40
jonathan1055 commentedVery good to get this moving. We can adjust anything later, but we needed to get these files in. Thank you for all your work on this.
Comment #41
pfrenssenGreat work! Thanks!