Problem/Motivation

Schedule a Task action plugin does not actually support datetime fields but claims to.

Datetime fields store their values as text, but the plugin expects them as integer (timestamps).

This issue causes scheduled tasks to be not editable (due to a PHP error), as well as not executable.

Proposed resolution

Add support for datetime fields.

Remaining tasks

Review a patch

User interface changes

No

API changes

No

Data model changes

No

Original report

Hi @yuriseki,

I have successfully created a scheduled task using the action: Schedule a task to delete a node with a specific nid.

However, when I visit /admin/config/workflow/business_rules/schedule/collection and try to edit this schedules task, I receive a FATAL ERROR on a dead white screen:

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: The timestamp must be numeric. in <em class="placeholder">Drupal\Component\Datetime\DateTimePlus::createFromTimestamp()</em> (line <em class="placeholder">198</em> of <em class="placeholder">core\lib\Drupal\Component\Datetime\DateTimePlus.php</em>). <pre class="backtrace">Drupal\business_rules\Form\ScheduleForm-&gt;buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 518)
Drupal\Core\Form\FormBuilder-&gt;retrieveForm(&#039;business_rules_schedule_edit_form&#039;, Object) (Line: 275)
Drupal\Core\Form\FormBuilder-&gt;buildForm(&#039;business_rules_schedule_edit_form&#039;, Object) (Line: 93)
Drupal\Core\Controller\FormController-&gt;getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>

and in the dblog, the below error is logged:

InvalidArgumentException: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp() (line 198 of S:\sites\dev.####\web\core\lib\Drupal\Component\Datetime\DateTimePlus.php).

My action: Schedule a task settings is as below:

Field: Created: Authored On [created]
Identifier: Delete the node nid: [node:nid] after 1 Year.
Time offset: 12
Time Unit: Months

Thank you,

Comments

C.E.A created an issue. See original summary.

c.e.a’s picture

Assigned: Unassigned » yseki
Drutech’s picture

Same error here... (Fatal Error)
any help yet ?

thanks

yseki’s picture

I'm pushing the beta-7 today, that is supposed to fix it.

c.e.a’s picture

The issue still the same using the beta-7 version with the below error when I try to edit a scheduled task.

InvalidArgumentException: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp() (line 198 of \web\core\lib\Drupal\Component\Datetime\DateTimePlus.php).

Thank you,

c.e.a’s picture

Status: Active » Needs work
c.e.a’s picture

@yuriseki the patch provided here (#3043734: Update to beta7 fails: SQLSTATE[42000] Assigned to: yseki) does not solve this issue... same error as mentioned above

publishing future’s picture

Same problem here with the latest dev. Any progress on this issue?

demon326’s picture

You also get the error when running cron to excute this action. Would be great if somebody could create a patch to test a fix :)

colan’s picture

Assigned: yseki » Unassigned
Priority: Critical » Major
Status: Needs work » Active

Updating status as there's no code here. Also, this is definitely not critical as the module works fine if not using tasks.

Patches welcome as this doesn't appear to be affecting any of us maintainers.

#8 & #9: Sorry, but comments like that add no value, and only serve to spam folks subscribed to this issue. If you'd like to move things forward, you can either provide a patch yourself, or (offer to) pay someone to write a patch. Thanks.

deciphered’s picture

Status: Active » Needs review
StatusFileSize
new604 bytes

I got this issue when using a datetime field as the source of the schedule time, which is ignored due to the is_int check.

Simple fix, simple patch.

taran2l’s picture

Title: Edit a scheduled task returns error "The timestamp must be numeric" » Schedule a Task action plugin does not actually support datetime fields but claims to
Issue summary: View changes
taran2l’s picture

taran2l’s picture

StatusFileSize
new3.69 KB

The previous patch contains a typo

thib’s picture

Hi,
Patch from #11 work for me.
Thanks!

thib’s picture

but... I get WSOD when running cron if "Enable schedule on cron" is set...

kris77’s picture

Patch #14 works like a charm for me, along with this other patch https://www.drupal.org/project/business_rules/issues/3123554#comment-135....

Thanks a lot @Taran2L...you are the rock.

EDIT:

I'm using beta10

kris77’s picture

you have to apply the patch also in the version 2.0.0-beta1.

I applied it without problems.

Is it possible to insert it in the next release please?

kris77’s picture

Status: Needs review » Reviewed & tested by the community
muaz7731’s picture

Version: 8.x-1.x-dev » 2.x-dev

Hi, +1 for RTBC. The patch fix my problem with error:

Exception: DateTime::__construct(): Failed to parse time string (1633327241) at position 7 (2): Unexpected character in DateTime->__construct() (line 430 of /home/testing/web/modules/contrib/business_rules/src/Plugin/BusinessRulesAction/ScheduleTask.php).

I have also change this to ver 2.x-dev.

muaz7731’s picture

Hello, sometimes I've getting error as below:

Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/public_html/web/modules/contrib/business_rules/src/Plugin/BusinessRulesAction/ScheduleTask.php on line 420
Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/public_html/web/modules/contrib/business_rules/src/Plugin/BusinessRulesAction/ScheduleTask.php on line 426
The website encountered an unexpected error. Please try again later.

I edited the patch from #14 $time_unit{0} to $time_unit[0]

muaz7731’s picture

Status: Reviewed & tested by the community » Needs review