_scheduler_strtotime() throws a trim error from node_presave when one of the fields is not set.

Steps to recreate:

  1. Using Datepicker Popup
  2. Create a scheduled node
  3. Fill in published time
  4. Save Node

The error is then thrown when the scheduler_node_presave cycles through to the unpublished_on value in the elseif because that value is an array

  foreach (array('publish_on', 'unpublish_on') as $key) {
    if (empty($node->$key)) {
      // Make sure publish_on and unpublish_on are not empty strings.
      $node->$key = 0;
    }
    elseif (!is_numeric($node->$key)) {
      dpm($node->$key, $key);
      // Convert to unix timestamp, but ensure any failure is converted to zero.
      $node->$key = _scheduler_strtotime($node->$key) + 0;
    }
  }

This was fixed in other places in #1319410: Fix "warning: trim() expects parameter 1 to be string" when entering date with no time but is still an issue in this spot of the code.

CommentFileSizeAuthor
#3 scheduler-trim-error-2205809-3.patch491 bytesarcaneadam
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arcaneadam’s picture

Issue summary: View changes
arcaneadam’s picture

Issue summary: View changes

Patch coming...

arcaneadam’s picture

I tracked the error down and realize that it is because of a setting in the Scheduler Workbench module that sets #access on the unpublish_on field to FALSE. This then prevents input in that field which causes it to return as an array rather then a string that is expected.

Since this is something that could be caused by anyone doing a pretty standard form_alter procedure to hide a field, it should probably be taken into account. At the very least should someone else have this problem I'd like them to have a patch available for it.

jonathan1055’s picture

Issue summary: View changes
Status: Active » Needs review

Hi arcaneadam,

Thanks for the diagnosis and the patch. I've not used Scheduler Workbench, but I think I should take a look at it, given that quite a few people use it with our module. Yes, we should definitely protect that code. Setting to 'needs review' to check the automated testing.

Jonathan

hefox’s picture

Status: Needs review » Reviewed & tested by the community

Patch is being used on a project with multiple testers/developers and has not presented any problems yet and has fixed the issue.

  • Commit 5965c08 on 7.x-1.x by jonathan1055:
    Issue #2205809 by arcaneadam: Fixed scheduler_node_presave when date is...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Thanks hefox for testing. Committed and will become part of 7.x-1.3 in due course.

I tried to give credit to arcaneadam for the patch, and used the syntax

git commit -m "Issue #2205809 by arcaneadam: Fixed scheduler_node_presave when date is returned as array."

However, this did not have the desired effect, so I'll have to go a research the git syntax a bit more. Sorry you did not get the credit.

Jonathan

Status: Fixed » Closed (fixed)

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