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->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 518)
Drupal\Core\Form\FormBuilder->retrieveForm('business_rules_schedule_edit_form', Object) (Line: 275)
Drupal\Core\Form\FormBuilder->buildForm('business_rules_schedule_edit_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->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,
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | business_rules-schedule_task_datetime_support-3040719-14-edit.patch | 3.69 KB | muaz7731 |
| #14 | business_rules-schedule_task_datetime_support-3040719-14.patch | 3.69 KB | taran2l |
| #11 | datetime_field-3040719-11.patch | 604 bytes | deciphered |
Comments
Comment #2
c.e.a commentedComment #3
Drutech commentedSame error here... (Fatal Error)
any help yet ?
thanks
Comment #4
yseki commentedI'm pushing the beta-7 today, that is supposed to fix it.
Comment #5
c.e.a commentedThe 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,
Comment #6
c.e.a commentedComment #7
c.e.a commented@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
Comment #8
publishing future commentedSame problem here with the latest dev. Any progress on this issue?
Comment #9
demon326 commentedYou also get the error when running cron to excute this action. Would be great if somebody could create a patch to test a fix :)
Comment #10
colanUpdating 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.
Comment #11
decipheredI got this issue when using a datetime field as the source of the schedule time, which is ignored due to the
is_intcheck.Simple fix, simple patch.
Comment #12
taran2lComment #13
taran2lComment #14
taran2lThe previous patch contains a typo
Comment #15
thibHi,
Patch from #11 work for me.
Thanks!
Comment #16
thibbut... I get WSOD when running cron if "Enable schedule on cron" is set...
Comment #17
kris77 commentedPatch #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
Comment #18
kris77 commentedyou 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?
Comment #19
kris77 commentedComment #20
muaz7731Hi, +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.
Comment #21
muaz7731Hello, sometimes I've getting error as below:
I edited the patch from #14 $time_unit{0} to $time_unit[0]
Comment #22
muaz7731