Issue with Date/Datetime fields in Mautic 4

Your software
My Mautic version is: 4.1.1
My PHP version is: 7.4
My Database type and version is: Maria DB 10.3

Your problem
My problem is:

I am trying to migrate Mautic 3.3.4 to 4.1.1 and have issues with one instance. After migration any form that contains date/datetime field (for example contact edit) does not work and it triggers the error below.

I have migrated other instances from 3 to 4 without any major issues (if any), but for this one instance I am not able to successfully upgrade everytime I do, forms pretty much stop working.

Here is my procedure:

  • Remove custom plugins
  • Clear cache
  • php bin/console mautic:update:find --env=prod
  • php bin/console mautic:update:apply --env=prod
  • php bin/console mautic:update:apply --finish --env=prod

After this I commit all the files on a temporary branch because I want to have mautic official branch installed on a specific version. After the procedure I checkout the branch 4.x like so:

  • git fetch origin 4.x --tags
  • git checkout 4.x
  • git checkout 4.1.1

Install the dependencies:

  • composer clear-cache
  • composer install --no-dev --no-cache

And clear the cache again. And at this point mautic is on 4.1.1. but when I vist the contact and try to edit it, the error below occurs in logs.

If I unpublish the fields of type date/datetime I can edit the contact.

These errors are showing in the log:

[2022-01-20 15:19:49] mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Attempted to call an undefined method named "setDeprecated" of class "Symfony\Component\OptionsResolver\OptionsResolver"." at /<path-to-webdir>/mautic/vendor/symfony/form/Extension/Core/Type/DateTimeType.php line 324 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Attempted to call an undefined method named \"setDeprecated\" of class \"Symfony\\Component\\OptionsResolver\\OptionsResolver\". at /<path-to-webdir>/mautic/vendor/symfony/form/Extension/Core/Type/DateTimeType.php:324)
#0 /<path-to-webdir>/mautic/vendor/symfony/form/ResolvedFormType.php(186): Symfony\\Component\\Form\\Extension\\Core\\Type\\DateTimeType->configureOptions()
#1 /<path-to-webdir>/mautic/vendor/symfony/form/ResolvedFormType.php(97): Symfony\\Component\\Form\\ResolvedFormType->getOptionsResolver()
#2 /<path-to-webdir>/mautic/vendor/symfony/form/FormFactory.php(76): Symfony\\Component\\Form\\ResolvedFormType->createBuilder()
#3 /<path-to-webdir>/mautic/vendor/symfony/form/FormBuilder.php(94): Symfony\\Component\\Form\\FormFactory->createNamedBuilder()
#4 /<path-to-webdir>/mautic/vendor/symfony/form/FormBuilder.php(244): Symfony\\Component\\Form\\FormBuilder->create()
#5 /<path-to-webdir>/mautic/vendor/symfony/form/FormBuilder.php(195): Symfony\\Component\\Form\\FormBuilder->resolveChildren()
#6 /<path-to-webdir>/mautic/vendor/symfony/form/FormFactory.php(30): Symfony\\Component\\Form\\FormBuilder->getForm()
#7 /<path-to-webdir>/mautic/app/bundles/PointBundle/Model/TriggerModel.php(118): Symfony\\Component\\Form\\FormFactory->create()
#8 /<path-to-webdir>/mautic/app/bundles/PointBundle/Controller/TriggerController.php(201): Mautic\\PointBundle\\Model\\TriggerModel->createForm()
#9 /<path-to-webdir>/mautic/app/bundles/CoreBundle/Controller/CommonController.php(456): Mautic\\PointBundle\\Controller\\TriggerController->newAction()
#10 /<path-to-webdir>/mautic/vendor/symfony/http-kernel/HttpKernel.php(158): Mautic\\CoreBundle\\Controller\\CommonController->executeAction()
#11 /<path-to-webdir>/mautic/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()
#12 /<path-to-webdir>/mautic/vendor/symfony/http-kernel/Kernel.php(201): Symfony\\Component\\HttpKernel\\HttpKernel->handle()
#13 /<path-to-webdir>/mautic/app/AppKernel.php(115): Symfony\\Component\\HttpKernel\\Kernel->handle()
#14 /<path-to-webdir>/mautic/app/middlewares/CORSMiddleware.php(91): AppKernel->handle()
#15 /<path-to-webdir>/mautic/app/middlewares/CatchExceptionMiddleware.php(43): Mautic\\Middleware\\CORSMiddleware->handle()
#16 /<path-to-webdir>/mautic/app/middlewares/VersionCheckMiddleware.php(67): Mautic\\Middleware\\CatchExceptionMiddleware->handle()
#17 /<path-to-webdir>/mautic/app/middlewares/TrustMiddleware.php(51): Mautic\\Middleware\\VersionCheckMiddleware->handle()
#18 /<path-to-webdir>/mautic/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Mautic\\Middleware\\TrustMiddleware->handle()
#19 /<path-to-webdir>/mautic/vendor/stack/run/src/Stack/run.php(13): Stack\\StackedHttpKernel->handle()

Steps I have tried to fix the problem:

  • In addition to above procedure I tried to install mautic using release with vendor folder already in mautic directory.
  • I checked the vendor folder setDeprecated method which error is refering to, exist in the vendor folder source code.
  • I tried upgrading to PHP8

A little update on this.

I was able to migrate to Mautic 4 using database from server on my local machine, but still no luck when I am migrating this on the server.

I even exported my local database and upload vendor folder from my local computer and imported locally exported database on the server. It works on my local machine without any problem, but when I try it on the server it does not work.

Regards, M.

I solved this, by cloning new copy of the repository on the server.

There were some leftovers (trash) that were causing php dependencies to not install properly. By cloning a new repository I got rid of conflicting files and migrated Mautic successfully.

1 Like