Comments

legovaer created an issue. See original summary.

legovaer’s picture

Status: Active » Needs review
StatusFileSize
new8.03 KB

This patch replaces _scheduler_scheduler_api() with Symfony's dispatcher.

Status: Needs review » Needs work

The last submitted patch, 2: 2669164-event-subscriber-2.patch, failed testing.

legovaer’s picture

Status: Needs work » Needs review
StatusFileSize
new7.78 KB
new3.01 KB

Fixed issues that caused the CI tests to fail

jonathan1055’s picture

Thanks for working on this. I will do some manual testing too.

legovaer’s picture

@Jonathan any progress on the manual testing?

jonathan1055’s picture

Not yet, as I have spent most of time on #2651338: Create a service for the Scheduler API. I don't know anything about event dispatch and event subscribing, so I am having to learn it all before I can understand what the changes mean :-)

I will requeue the patch in #4 as that was when we only had 32 classes. Now that #2655666: API Testing module - conversion to 8.x has been expanded and completed, the result might be different.

Status: Needs review » Needs work

The last submitted patch, 4: 2669164-event-subscriber-4.patch, failed testing.

  • jonathan1055 committed a8922db on 8.x-1.x
    Issue #2669164 by jonathan1055: Clearer and stronger tests for publish/...
jonathan1055’s picture

Status: Needs work » Needs review

The reasons for the failed tests in #4 would not be very clear to someone who had not written the tests. Also, the unpublishing assertions gave mis-leading passes when they should have failed, which was caused by earlier failed operations. Hence I have made the tests stronger, and given clearer assertion messages, in the commit in #9. I have re-queued the patch to show the improved failure messages.

The reason for patch failure is that the testing module also needs to be updated. It currently implements the existing hook_scheduler_api. But if this function is being replaced by events then our use of it in scheduler_api_test module also needs to updated.

/**
 * Implements hook_scheduler_api().
 */
function scheduler_api_test_scheduler_api($node, $action) {
  // This hook allows modules to react to the Scheduler process being performed.
  // It is invoked during cron processing and also from scheduler_node_presave().
  // Use the standard 'sticky' and 'promote' fields as a simple way to test the
  // processing. Use conditional checks on $node->isPublished() to make the
  // tests stronger so that they will fail if the calls are in the wrong place.
  switch ($action) {
    case 'pre_publish' :
      // Before publishing a node make it sticky.
      if (!$node->isPublished()) $node->set('sticky', TRUE)->save();
      break;
    case 'publish' :
      // After publishing a node promote to front page.
      if ($node->isPublished()) $node->set('promote', TRUE)->save();
      break;
    case 'publish_immediately' :
      // When publishing immediately set the node to sticky and promoted, and
      // also change the title. Do not use ->save() as this breaks the system!
      $node->set('sticky', TRUE)->set('promote', TRUE);
      $node->title->value = 'Published immediately';
      break;
    case 'pre_unpublish' :
      // Before unpublishing a node make it unsticky.
      if ($node->isPublished()) $node->set('sticky', FALSE)->save();
      break;
    case 'unpublish' :
      // After unpublishing a node remove it from front page.
      if (!$node->isPublished()) $node->set('promote', FALSE)->save();
      break;
    default:
  }
}

That's the beauty of automated testing!

@legovaer - what are the instructions for converting an implementation of hook_scheduler_api to use the new event?

Status: Needs review » Needs work

The last submitted patch, 4: 2669164-event-subscriber-4.patch, failed testing.

legovaer’s picture

Status: Needs work » Needs review
StatusFileSize
new34.23 KB
new33.22 KB

Here's another patch that should fix (some) tests. Changes:

  • Renamed scheduler_api_test to scheduler_events_test
  • Created an event listener to the scheduler_events_test module so that we do some updates to the nodes while executing the cron.
  • Added a method setNode() to the EventDispatcher so that the updated node can be used.
  • Updated _scheduler_publish() and _scheduler_unpublish() so that we use the node which has been dispatched.

TODO

While applying this patch, I get this test result:

89 passes, 9 fails, 0 exceptions, 13 debug messages

for Drupal\scheduler\Tests\SchedulerEventsTest

A list of errors:

  • An unapproved node is not published during cron processing. Other SchedulerEventsTest.php 77 Drupal\scheduler\Tests\SchedulerEventsTest->testAllowedPublishingAndUnpublishing()
  • An unapproved node with a date in the past is not published immediately after saving. Other SchedulerEventsTest.php 95 Drupal\scheduler\Tests\SchedulerEventsTest->testAllowedPublishingAndUnpublishing()
  • An unapproved node is not unpublished during cron processing. Other SchedulerEventsTest.php 118 Drupal\scheduler\Tests\SchedulerEventsTest->testAllowedPublishingAndUnpublishing()
  • After cron, node 1 "nid_list publish me" is published. Other SchedulerEventsTest.php 265 Drupal\scheduler\Tests\SchedulerEventsTest->testNidList()
  • After cron, node 2 "nid_list unpublish me" is unpublished. Other SchedulerEventsTest.php 266 Drupal\scheduler\Tests\SchedulerEventsTest->testNidList()
  • After cron, node 1 "nid_list_alter do not publish me" is still unpublished. Other SchedulerEventsTest.php 310 Drupal\scheduler\Tests\SchedulerEventsTest->testNidListAlter()
  • After cron, node 2 "nid_list_alter publish me" is published. Other SchedulerEventsTest.php 311 Drupal\scheduler\Tests\SchedulerEventsTest->testNidListAlter()
  • After cron, node 3 "nid_list_alter do not unpublish me" is still published. Other SchedulerEventsTest.php 312 Drupal\scheduler\Tests\SchedulerEventsTest->testNidListAlter()
  • After cron, node 4 "nid_list_alter unpublish me" is unpublished. Other SchedulerEventsTest.php 313 Drupal\scheduler\Tests\SchedulerEventsTest->testNidListAlter()

Status: Needs review » Needs work

The last submitted patch, 12: 2669164-event-subscriber-12.patch, failed testing.

legovaer’s picture

Status: Needs work » Needs review
StatusFileSize
new19.2 KB
new10.33 KB

For some reason my patch was missing a lot of code, here's the update patch for #12.

Status: Needs review » Needs work

The last submitted patch, 14: 2669164-event-subscriber-14.patch, failed testing.

jonathan1055’s picture

Thanks for working on this.

Renamed scheduler_api_test to scheduler_events_test

Please can I suggest that we do not rename the test module until after the bulk of the actual work is complete. I tried to read your patch and interdiff, but because the module name was changed it was just a complete list of deleted files and new files, making it impossible to read what you have actually done. I understand that we should change the test module name in due course, but for other people to understand what coding you have done and what changes have actually been made, please can you revert the name change, for now. Trying to review a patch of 880 lines and an interdiff of 930, and understand what changes have actually been done is a big task, and it would be much easier if the module name was kept the same in the first instance.

By the way, patch 14 is smaller than 12, did you mean that?

I'm looking forward to seeing what is actually needed to convert the test module, as we will have to document this to allow our users to upgrade their own scheduler hooks to 8.x. Making the changes in stages will assist in this task.

Thanks again for your work on this. Hope you are not too annoyed with my request.

legovaer’s picture

StatusFileSize
new11.1 KB
new5.12 KB

Fair enough! Here's another patch. The interdiff is now only 180 lines, so it should be easier to review.

legovaer’s picture

Status: Needs work » Needs review
StatusFileSize
new11.16 KB
new533 bytes

And this (final?) patch should have a 100% pass on the testing.

Status: Needs review » Needs work

The last submitted patch, 18: 2669164-event-subscriber-18.patch, failed testing.

legovaer’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes
new10.16 KB

Another attempt to fix the CI tests. Fixed the namespace in both sheduler_api_test.services.yml and EventSubscriber.php

Status: Needs review » Needs work

The last submitted patch, 20: 2669164-event-subscriber-20.patch, failed testing.

legovaer’s picture

StatusFileSize
new11.15 KB
new1.46 KB

Did a diff against my local branch instead of 8.x-1.x.

legovaer’s picture

Status: Needs work » Needs review
legovaer’s picture

StatusFileSize
new11.06 KB
new6.25 KB

Updated the patch according to the changes in #2651338: Create a service for the Scheduler API. The interdiff looks a bit weird, but the only thing I've done in this patch is replacing the _scheduler_scheduler_api() functions with the Event dispatcher.

legovaer’s picture

StatusFileSize
new11.05 KB

Because of the committed changes of the namespace of the Exceptions, the patch no longer applied. Here's the one that does apply.

Changes:

Changed line # 246:

    * @throws \Drupal\scheduler\Plugin\Exception\SchedulerNodeTypeNotEnabledException

To

    * @throws \Drupal\scheduler\Exception\SchedulerNodeTypeNotEnabledException

Change line # 213

    * @throws \Drupal\scheduler\Plugin\Exception\SchedulerNodeTypeNotEnabledException

To

    * @throws \Drupal\scheduler\Exception\SchedulerNodeTypeNotEnabledException
jonathan1055’s picture

StatusFileSize
new15.91 KB
new12.74 KB

Great work, thanks. I've taken your patch and made a few changes:

  1. In scheduler.manager, function publish() I removed an unnecessary $node->save(). I would say it is better to do the save only at the end of the function, where it is already handled by the actions process
  2. In tests/modules/src/EventSubscriber.php, renamed the functions so they reflect the event not the node changes being done. This file can be used as the basis for our events documentation and examples, so using names which match the event will be easier for developers to follow
  3. Added the conditional logic within these test event functions, which was in the original api test module. It makes the tests stronger, as mentioned in the comments
  4. Removed definition of scheduler_api_test_scheduler_api() from tests/modules/scheduler_api_test.module
  5. Removed example of hook_scheduler_api() from scheduler.api.php
  6. All the other changes are only to the comments, either expanding the explanations, improving the grammar, or copying details from the old functions that got dropped

Patch has the full changes, interdiff shows just my changes between 25 and 26.

jonathan1055’s picture

Hi legovaer,
Have you had a chance to review the latest changes in #26? As explained, there is nothing major that I have changed from your patch, it is mainly the naming of functions and a bit of tidying up. It all works, and passes the full set of tests, but I know that that's only half the story. These events replace all the calls to hook_scheduler_api(), but I think that hook_scheduler_nid_list() and hook_scheduler_allow() will remain unchanged.

You asked a question about the possible clash of events that I had started in #2651348: Port Rules integration for Scheduler to Drupal 8. Does this need to be looked at now?

This is the last blocker issue that we've identified before we can make an alpha1 release, and it would be really good if I could do that soon. I will also ask pfrenssen to review this, as I definitely want his agreement that we are doing the right thing before going ahead with the alpha release.

Jonathan

legovaer’s picture

Status: Needs review » Reviewed & tested by the community

Jonathan,

Sorry to keep you waiting. I was quite busy.

I had a final review of your changes and it all looks good to me so I'd say RTBC.

About the discussion on #2651348 -- Your comment in that issue makes a lot of sense. I haven't done research on how Rules is working in D8. But it makes a lot of sense to keep the events separate. I'll add the same comment in that issue.

Let's get Alpha1 released! ;-)

jonathan1055’s picture

Thanks for the review. Good that you are OK with my changes.

I did contact Pieter and he said just over a week ago that he would like to review this final alpha1 blocker. I would appreciate his input, and I am not sure of the limitations we would be creating if we make alpha1 now, then Pieter wants to change the structure. I guess anyone using the dev release or upcoming alpha1 would just have to re-install Scheduler if we did make major changes, and possibly re-write any implementations of the new event subscriber.

I am unsure of the implications of #2651348: Port Rules integration for Scheduler to Drupal 8 and how that may clash with this issue. That's also what I would like Pieter's view on.

... or maybe we go ahead, and try to fix things if we find we need to do major changes later? You are right, it would be good to get a proper non-dev release on the project page.

legovaer’s picture

Fair enough. I think it'd be good to have an extra pair of eyes on the code changes. We don't want to go re-factoring.

Pieter seems to be quite busy, so we could alternatively launch a "beta" version which is designed for testing purposes. Then people can start using the beta version in order to detect bugs we didn't see. We should clearly mention that it's only a beta version and that code changes are most likely.

In the meantime Pieter can take his time to do a full review.

jonathan1055’s picture

I think that making a separate version would add more confusion. And doesn't a 'beta' release follow a few 'alpha' releases, when the structure and API are stable. We certainly must be confident that nothing major will change before we name anything 'beta'.

Thanks for the idea, but I am now considering waiting until after this weekend, and if Pieter has not reviewed, I will commit this change and release alpha1 anyway. I'm sure we can fix things afterwards, and for a first alpha release other users should accept that an update might require a re-install of the module, and that some restructuring might be needed if they have started coding to react to the new event subscribers.

jonathan1055’s picture

StatusFileSize
new16.53 KB

Re-rolled the patch to cater for my change to the API test module in #2655666-36: API Testing module - conversion to 8.x.

  • jonathan1055 committed af9ca78 on 8.x-1.x authored by legovaer
    Issue #2669164 by legovaer, jonathan1055: Introduce event subscriber for...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Great work, Levi. Thank you for all this work. I decided to go ahead and commit - Pieter can review later and I am happy to make changes as required. Now for alpha1!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jonathan1055’s picture

Assigned: legovaer » Unassigned

This is fixed so setting to Unassigned