craftcms / feed-me

Craft CMS plugin for importing entry data from XML, RSS or ATOM feeds—routine task or on-demand.
Other
286 stars 139 forks source link

parseString() error #1287

Closed jmauzyk closed 1 year ago

jmauzyk commented 1 year ago

Description

Running into an error when trying to import a string representation of a date to an element's Post Date. Date strings follow the format 2023-04-18 10:00:00. Getting the following error and stack trace:

2023-04-18 18:41:48 [queue.ERROR] [TypeError] TypeError: craft\feedme\helpers\DateHelper::parseString(): Argument #2 ($formatting) must be of type string, null given, called in /var/www/html/vendor/craftcms/feed-me/src/base/Element.php on line 334 and defined in /var/www/html/vendor/craftcms/feed-me/src/helpers/DateHelper.php:24
Stack trace:
#0 /var/www/html/vendor/craftcms/feed-me/src/base/Element.php(334): craft\feedme\helpers\DateHelper::parseString('2007-01-01 10:5...', NULL)
#1 /var/www/html/vendor/craftcms/feed-me/src/elements/CommerceProduct.php(496): craft\feedme\base\Element->parseDateAttribute('2007-01-01 10:5...', NULL)
#2 /var/www/html/vendor/craftcms/feed-me/src/base/Element.php(107): craft\feedme\elements\CommerceProduct->parsePostDate(Array, Array)
#3 /var/www/html/vendor/craftcms/feed-me/src/services/Process.php(364): craft\feedme\base\Element->parseAttribute(Array, 'postDate', Array)
#4 /var/www/html/vendor/craftcms/feed-me/src/queue/jobs/FeedImport.php(99): craft\feedme\services\Process->processFeed(7, Array, Array)
#5 /var/www/html/vendor/yiisoft/yii2-queue/src/Queue.php(246): craft\feedme\queue\jobs\FeedImport->execute(Object(craft\queue\Queue))
#6 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('2214831', 'O:34:"craft\\fee...', '2400', '1')
#7 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Command.php(146): yii\queue\cli\Queue->execute('2214831', 'O:34:"craft\\fee...', '2400', '1', '4069')
#8 [internal function]: yii\queue\cli\Command->actionExec('2214831', '2400', '1', '4069')
#9 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#10 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#11 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('exec', Array)
#12 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(87): yii\console\Controller->runAction('exec', Array)
#13 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\queue\Command->runAction('exec', Array)
#14 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)
#15 /var/www/html/vendor/craftcms/cms/src/console/Application.php(90): yii\console\Application->runAction('queue/exec', Array)
#16 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('queue/exec', Array)
#17 /var/www/html/vendor/craftcms/cms/src/console/Application.php(121): yii\console\Application->handleRequest(Object(craft\console\Request))
#18 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#19 /var/www/html/craft(13): yii\base\Application->run()

Steps to reproduce

  1. Set a string with the above format to be imported into element's Post Date.
  2. Run import, error shows in logs.

Additional info

i-just commented 1 year ago

Hi, thanks for getting in touch. I’m having a hard time reproducing this error. Could you please share a snippet of your feed that triggers this error and maybe a screenshot from the mapping screen that shows the options you selected for the post date?

jmauzyk commented 1 year ago

@i-just Below is a snippet of the XML feed showing the date layout and a screenshot of the settings. This error does not occur in Craft 3, only in Craft 4. If it makes a difference, the element type for the feed is Commerce Product. Let me know if there's any additional info I can provide to help.

<?xml version="1.0" encoding="UTF-8"?>
<products>

  <product>
    <Product_Name___EN><![CDATA[Nitrile Mechanic's Gloves]]></Product_Name___EN>
    <Post_Date><![CDATA[2017-11-17 13:49]]></Post_Date>
    ...
  </product>

</products>
Screenshot 2023-04-19 at 9 41 13 AM
i-just commented 1 year ago

Perfect, thank you. That helped me reproduce the issue. PR has been raised.

i-just commented 1 year ago

One more thing - once released, you will need to re-save your feed so that the date fields get the formatting option (currently missing from the mapping screen for Commerce Products).

angrybrad commented 1 year ago

Fixed in https://github.com/craftcms/feed-me/pull/1296 for the next v4 and v5 releases.

angrybrad commented 1 year ago

We just released Feed Me 4.6.3. and 5.1.3 with this fix.