Validation of publish-on and unpublish-on is now not working (for me) and for every date I enter I get the constraint message saying the date must be in the future. This is odd, as I don't know what has changed to cause it.

I added debug to SchedulerPublishOnConstraintValidator and for manual editing of a node it shows:

$publish_on: 2016-01-26T01:39:00 =  not a number
REQUEST_TIME: 1453111532 = Monday, 18 January, 2016 - 10:05:32

and I get the errors

    The 'publish on' date must be in the future.
    This value should be a valid number.

However, in the automated tests, the same debug shows:

$publish_on: 1453114152 = Monday, January 18, 2016 - 21:49
REQUEST_TIME: 1453110557 = Monday, January 18, 2016 - 20:49

so it is working OK in tests.

What can have caused the date to be returned in the form with the universal timestamp format instead of the unix number we used to have? The constraint is evaluating 2016 against 1453111532 and deducing that it is in the past.

I realise that this might be something in my own setup, but I don't think I have not installed any new modules or changed any config. With this error happening I cannot do any proper manual testing because I cannot save any nodes which are scheduled. I hope someone has an idea ...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonathan1055 created an issue. See original summary.

jonathan1055’s picture

FileSize
89.56 KB

I have found the reason for the error, but not the solution (yet). The form widget for the publish-on and unpublish-on fields were set to the standard 'Datetime Timestamp' whereas they should have been Schedulers custom 'Datetime Timestamp no default' widget. This can be seen in Content Type - Manage Fields - Manage Form Display (image attached). After manually changing back to the correct widget everything works fine because in scheduler\Plugin\Field\FieldWidget\TimestampDatetimeNoDefaultWidget we convert the datetime object to a numeric timestamp. This is not done in the plain 'Datetime Timestamp' widget, hence the error I was getting.

Now we need to discover why the settings changed. I think it is most likely due to an uninstall of Scheduler followed by a reinstall. But we should be able to set the correct widget when re-installing, as that is going to be something that our users may well do. The field widget type is defined in hook_entity_base_field_info() so maybe after a re-install the process is slightly different and this does not get executed because the fields pre-existed? The widget definitely gets reset to 'Datetime Timestamp' when Scheduler is uninstalled (I have checked that) but they are not restored to 'Datetime Timestamp no default' after re-installing the module. On a clean install, as is done during the automated testing, I would guess that the widget is correctly set via hook_entity_base_field_info() and everything works fine.

By the way, we might consider renaming the widget to something like 'Datetime Timestamp for Scheduler' as that would mean far more when looking at the choices of widgets. 'Datetime Timestamp no default' may mean something to us developers who know the code, but the users will not realise what it is or where it has come from. But that's another thing. For now, we need to work out how to get the correct widget settings when reinstalling the module.

jonathan1055’s picture

Title: publish-on date returned as string not number » Dates returned as string not number after re-install
FileSize
84.33 KB
127.78 KB

I think this is going to cause our users a few problems during site set-up, and we will keep seeing support issues being raised about it. Just to confirm the repo steps:

  1. Fresh install of D8 and Scheduler. No widgets are shown on config inspector via admin/config/development/configuration/inspect/core.entity_form_display.node.article.default/tree
  2. Edit article and save (changing nothing, not even enabling Scheduling) - config inspector shows two new widgets, with correct settings. (1st image)
  3. Enable Scheduling for article and save. No change in inspector
  4. Uninstall Scheduler - both fields are removed form 'manage field' tabs. Inspector now shows the wrong widget names (2nd image)
  5. no rows in SELECT * FROM `key_value` WHERE `name` LIKE '%publish%'
  6. Re-install Scheduler. Config has not been changed. Same wrong widget in config inspector.
  7. Uninstall, clear cache, entity type same, config shows wrong widget

What this means if any admin/site builder reinstalls Scheduler it will not work correctly. Entering any scheduler date will continually fail validation.

jonathan1055’s picture

Title: Dates returned as string not number after re-install » Field widget set incorrectly after Scheduler module re-install
Status: Active » Postponed
Related issues: +#2754477: Unexpected config entity delete due to dependency calculations

Core issue #2754477: Unexpected config entity delete due to dependency calculations solves the problem! I had a hunch that this was not the fault of any Scheduler code. I have just checked the steps in #3 and the config is uninstalled cleanly with the patch (which did not happen before). It is much better now - the re-install sets the correct widget and everything works as expected.

Leaving this issue open (but postponed) and will close when #2754477: Unexpected config entity delete due to dependency calculations is fixed.

jonathan1055’s picture

Status: Postponed » Closed (works as designed)

Closed as #2754477: Unexpected config entity delete due to dependency calculations has been committed to core 8.2 and 8.1