dotmailer / dotmailer-magento2-extension

The official Dotdigital for Magento2 extension
https://dotdigital.com/integrations/magento
MIT License
48 stars 64 forks source link

Deprecated Functionality: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in ../dotdigital-magento2-extension/Model/Newsletter/Resubscriber.php on line 275 #588

Closed deemantha22 closed 1 year ago

deemantha22 commented 1 year ago

Hi,

Need advice please.

I am getting deprecated error on latest dotdigital/dotdigital-magento2-extension (4.18.1).

main.ERROR: Cron Job ddg_automation_resubscribe has an error: Deprecated Functionality: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in vendor/dotdigital/dotdigital-magento2-extension/Model/Newsletter/Resubscriber.php on line 275

Magento 2.4.4 PHP 8.1

Thanks

sta1r commented 1 year ago

@deemantha22 Hi, this would suggest that you have rows in newsletter_subscriber without a value in the change_status_at column. Is this correct?

The Resubscriber class:

sta1r commented 1 year ago

Just to follow up - is this something that occurred naturally in Magento, or do you think your records in newsletter_subscriber were just a bit funky for some reason? We can easily cast to string to prevent the error, but potentially the bigger issue is that new \DateTime("", new \DateTimeZone('UTC')) would return the current time, which would always be the most recent, thus resubscribing everyone thus failing to resubscribe.

deemantha22 commented 1 year ago

@sta1r - This happend after upgrading magento from 2.3 to 2.4.4 PHP 8.1. I have added line to check the value of getChangeStatusAt. Seems like it fixed the problem. I will monitor it for the next few hours and let you know.