Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while setting postDate and expiryDate (Object of class DateTime could not be converted to string) on Craft 3.7/FeedMe 4.5 #1232

Closed
luke-nehemedia opened this issue Feb 6, 2023 · 3 comments
Assignees
Labels

Comments

@luke-nehemedia
Copy link

Description

I import a table from Google sheets that has 4 columns: ID (not a craft-id, just an increasing integer), Startdate (Format: dd/mm/yy), Text, Enddate (same format). After running without any problems for about a year now, it suddenly does not work anymore.

I get the error-message:

Starting processing of node #29.
Match existing element with data {"slug":"394"}
Data ready to import {"title":"394","slug":"394","postDate":"2023-01-28T23:00:00.000000Z","expiryDate":"2023-01-29T23:00:00.000000Z","enabled":true,"datum":"2023-01-28T23:00:00.000000Z","text":"Some short text"}.
Object of class DateTime could not be converted to string - 3641473fa3f8fb2ada8f0c73452aa78b.php: 38

It seems like all the data has been detected correctly. However, something must go wrong while creating the entry.
Interestingly, an update of an already existing entry does work:

Starting processing of node #28.
Match existing element with data {"slug":"393"}.
Existing element [#328064] found.
Data to update for title: "393".
Data to update for slug: "393".
Data to update for postDate: "2023-01-27 23:00:00".
Data to update for expiryDate: "2023-01-28 23:00:00"
Data to update for enabled: true
Data ready to import {"title":"393","slug":"393","postDate":"2023-01-27T23:00:00.000000Z","expiryDate":"2023-01-28T23:00:00.000000Z","enabled":true,"datum":"2023-01-27T23:00:00.000000Z","text":"Some short text"}.
Entry [#328064] updated successfully.
Finished processing of node #28.

Maybe this is also more craft-related than feedme-related. I am not sure.

When running the debug mode, I get the following:

Error: Object of class DateTime could not be converted to string in craft3/storage/runtime/compiled_templates/36/3641473fa3f8fb2ada8f0c73452aa78b.php:38
Stack trace:
#0 craft3/vendor/twig/twig/src/Template.php(405): __TwigTemplate_9312ca7f215c07669530cf34f5b9bdf2->doDisplay()
#1 /craft3/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#2 /craft3/vendor/twig/twig/src/Template.php(390): Twig\Template->display()
#3 /craft3/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render()
#4 /craft3/vendor/craftcms/cms/src/web/View.php(623): Twig\TemplateWrapper->render()
#5 /craft3/vendor/craftcms/cms/src/elements/Entry.php(1534): craft\web\View->renderObjectTemplate()
#6 /craft3/vendor/craftcms/cms/src/elements/Entry.php(1625): craft\elements\Entry->updateTitle()
#7 /craft3/vendor/craftcms/cms/src/services/Elements.php(2544): craft\elements\Entry->beforeSave()
#8 /craft3/vendor/craftcms/cms/src/services/Elements.php(1352): craft\services\Elements->_saveElementInternal()
#9 /craft3/vendor/craftcms/cms/src/services/Revisions.php(168): craft\services\Elements->duplicateElement()
#10 /craft3/vendor/craftcms/cms/src/elements/Entry.php(1734): craft\services\Revisions->createRevision()
#11 /craft3/vendor/craftcms/cms/src/services/Elements.php(2788): craft\elements\Entry->afterPropagate()
#12 /craft3/vendor/craftcms/cms/src/services/Elements.php(785): craft\services\Elements->_saveElementInternal()
#13 /craft3/vendor/craftcms/feed-me/src/base/Element.php(246): craft\services\Elements->saveElement()
#14 /craft3/vendor/craftcms/feed-me/src/services/Process.php(471): craft\feedme\base\Element->save()
#15 /craft3/vendor/craftcms/feed-me/src/services/Process.php(598): craft\feedme\services\Process->processFeed()
#16 /craft3/vendor/craftcms/feed-me/src/controllers/FeedsController.php(270): craft\feedme\services\Process->debugFeed()
#17 [internal function]: craft\feedme\controllers\FeedsController->actionDebug()
#18 /craft3/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#19 /craft3/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#20 /craft3/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#21 /craft3/vendor/craftcms/cms/src/web/Application.php(293): yii\base\Module->runAction()
#22 /craft3/vendor/craftcms/cms/src/web/Application.php(602): craft\web\Application->runAction()
#23 /craft3/vendor/craftcms/cms/src/web/Application.php(272): craft\web\Application->_processActionRequest()
#24 /craft3/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#25 /htdocs/index.php(22): yii\base\Application->run()
#26 {main}

I have already tried to strip down the import data to only one row, use various date-formats etc.

The site still runs on Craft 3 and it will need some more time to upgrade to Craft4, although that's planned for this year. However, we therefore really need this plugin right now.

Additional info

  • Craft version: 3.7.64.1
  • PHP version: 8.1.15
  • Database driver & version: MySQL 5.7.22
  • Plugins & versions: FeedMe 4.5.4
@i-just
Copy link
Contributor

i-just commented Feb 7, 2023

Hi, thanks for reaching out. I’m having a hard time replicating this issue. One more thing you could try from your end is to clear compiled template caches via php craft clear-caches/compiled-templates and see if that makes any difference at all. If not, would you be able to share a screenshot of your feed mapping screen and a snippet of data you’re trying to import that triggers this issue?

@i-just i-just self-assigned this Feb 7, 2023
@luke-nehemedia
Copy link
Author

Thank you for your answer.

I cleared the compiled templates, but it did not solve the problem.

Here is a screenshot of the feed mapping screen:
Data Mapping

And here on of the data. It is gathered from a google spreadsheet.
Google Spreadsheet

If necessary I can also give you access to the google spreadsheet.

@i-just
Copy link
Contributor

i-just commented Feb 8, 2023

Thanks for the info. This looks to be happening when trying to update the title field:
#6 /craft3/vendor/craftcms/cms/src/elements/Entry.php(1625): craft\elements\Entry->updateTitle()

craft\elements\Entry->updateTitle() is only triggered when the entry type has a dynamic title format.
I can replicate this issue if I use {postDate} as a title format. It works as expected if I change that to {postDate|date('d/m/y')}. The same would happen if I used expiryDate in the title format.

I’m going to go ahead and close this, but if you have any more issues, please feel free to let me know.

@i-just i-just closed this as completed Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants