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

Calendar preventing a Craft 4 => 5 upgrade #305

Closed
angrybrad opened this issue Jul 26, 2024 · 24 comments · Fixed by #313, #324, #334 or #341
Closed

Calendar preventing a Craft 4 => 5 upgrade #305

angrybrad opened this issue Jul 26, 2024 · 24 comments · Fixed by #313, #324, #334 or #341
Assignees
Labels
issue Something isn't working correctly

Comments

@angrybrad
Copy link
Contributor

Debugging a customer’s failed Craft 4 => 5 upgrade.

It keeps failing with this stack trace:

*** applying m230511_215903_content_refactor
Exception: A field layout element has a duplicate UUID. Reinstall Craft CMS ^4.4.14 and run `utils/fix-field-layout-uids` before upgrading to Craft CMS 5. (/var/www/html/vendor/craftcms/cms/src/migrations/m230511_215903_content_refactor.php:32)
#0 /var/www/html/vendor/craftcms/cms/src/db/Migration.php(50): craft\migrations\m230511_215903_content_refactor->safeUp()
#1 /var/www/html/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(758): craft\db\Migration->up()
#2 /var/www/html/vendor/craftcms/cms/src/console/controllers/MigrateController.php(382): yii\console\controllers\BaseMigrateController->migrateUp('m230511_215903_...')
#3 [internal function]: craft\console\controllers\MigrateController->actionAll()
#4 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#5 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#6 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('all', Array)
#7 /var/www/html/vendor/craftcms/cms/src/console/controllers/MigrateController.php(195): yii\console\Controller->runAction('all', Array)
#8 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\console\controllers\MigrateController->runAction('all', Array)
#9 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#10 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('migrate/all', Array)
#11 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(212): craft\console\Application->runAction('migrate/all', Array)
#12 /var/www/html/vendor/craftcms/cms/src/console/Controller.php(207): yii\base\Controller->run('migrate/all', Array)
#13 /var/www/html/vendor/craftcms/cms/src/console/controllers/UpController.php(60): craft\console\Controller->run('migrate/all', Array)
#14 [internal function]: craft\console\controllers\UpController->actionIndex()
#15 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#16 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#17 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('', Array)
#18 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('', Array)
#19 /var/www/html/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('', Array)
#20 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
#21 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('up', Array)
#22 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('up', Array)
#23 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('up', Array)
#24 /var/www/html/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#25 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))

Running the utils/fix-field-layout-uids CLI command on Craft 4 doesn’t fix the issue.

That utils/fix-field-layout-uids CLI command specifically looks to clean up duplicate UUIDs from project config data.

Calendar doesn’t appear to store field layout UID info in project config, but the database.

After debugging, it looks like all of the duplicate UIDs are Calendar element types.

Our guess is that this happens when duplicating a Calendar and it’s copying field layout elements for each tab verbatim without updating to unique UIDs.

foreach ($oldLayoutTabs as $oldLayoutTab) {
$newLayoutTab = new FieldLayoutTab();
$newLayoutTab->name = $oldLayoutTab->name;
$newLayoutTab->sortOrder = $oldLayoutTab->sortOrder;
$newLayoutTab->setLayout($newLayout);
$newLayoutTab->setElements($oldLayoutTab->getElements());
$newLayoutTabs[] = $newLayoutTab;
}

If you can’t reproduce it based on that information, I’ll check with the customer to see if we can share a database dump and files with you.

Craft & Plugin Info (please complete the following information):

  • Craft Version: Pre upgrade 4.10.6. Post upgrade 5.2.8
  • Calendar Version: Pre upgrade 4.0.14. Post upgrade 5.0.6
  • Calendar Edition: Pro
  • Fresh Install or Upgrade: Upgrade
@angrybrad angrybrad added the issue Something isn't working correctly label Jul 26, 2024
@dMediaJam
Copy link

Is there and progress or update on this? We are still awaiting this solution so that we can update to Craft 5. Thanks,
Dwayne

@kjmartens
Copy link
Contributor

Sorry for the delay @dMediaJam. We're releasing an update this week, probably today. 🙂

@kjmartens
Copy link
Contributor

This should be resolved in Calendar 5.0.8 now. 🙂

@dMediaJam
Copy link

This is not resolved. Please re-open. I'm getting the same issue, and have heard from a fellow developer that they were only able to upgrade to craft 5 if then completely uninstall your Calendar Module.

Please advise.

Dwayne

@dMediaJam
Copy link

dMediaJam commented Sep 17, 2024 via email

@kjmartens kjmartens reopened this Sep 17, 2024
@kjmartens
Copy link
Contributor

Sorry about this @dMediaJam. I have reopened the issue and we'll continue to investigate. 🙂

@seandelaney
Copy link
Contributor

@dMediaJam

What steps are you doing to trigger this error on your end? Can you outline them here, so I can do exactly what you are doing on my end.

The steps I took to replicate the issue was:

Installed Calendar 4.0.14 on Craft 4.10.6.
Updated the default calendar created during Calendar plugin install, adding some text fields to Field layout designer.
Duplicated the default calendar.
Updated PHP to 8.2 in composer.
Updated Calendar to ^5.0.7 in composer (the broken version).
Updated Craft to ^5.0.0 in composer.
Ran composer update -W.
Ran php craft migrate/all.
Got the same error as above. See screenshots attached to show each step I took.

image
image
image
image

The steps I took to test the issue was fixed:

Restored my DB backup.
Ran php craft utils/fix-field-layout-uids/index.
Updated Calendar to ^5.0.8 in composer (the fixed version).
Ran composer update -W again.
Ran php craft migrate/all again.
No errors when upgrading to Craft 5 or Calendar 5 this time. See screenshots attached to show each step I took.

image
image
SCR-20240918-iyup
image

@seandelaney
Copy link
Contributor

seandelaney commented Sep 18, 2024

@dMediaJam

I have another PR pending with some more improvements.

New steps to follow when Calendar 4.0.16 is released.

Restore your DB backup (with Calendar 4.0.14 on Craft 4.10.6 installed).
Updated Calendar to 4.0.16 in composer.
Run php craft migrate/all.
Run php craft calendar/calendars/fix-field-layout-tabs-elements-uids --rebuildProjectConfig.
Now update Calendar to ^5 in composer.
Now update Craft to ^5 in composer.
Run composer update -W.
Run php craft migrate/all again.

You should be good now, with Craft 5 and Calendar 5 both installed.

I will ping here once Calendar 4.0.16 is released.

@dMediaJam
Copy link

dMediaJam commented Sep 18, 2024 via email

@dMediaJam
Copy link

I still have this issue. I'm spending lots of time trying to resolve. I would really like to upgrade to Craft 5 but I am getting the exact same error message. Could someone repost the steps? I am doing them one at a time but still get stuck on the following message:

Screenshot 2024-10-17 at 10 05 17

@kjmartens
Copy link
Contributor

Sorry for the wait @dMediaJam,

We have released Calendar 4.0.16, which includes the a new console command to search for duplicates and repair them.

  1. Back up your database.
  2. Open up your CLI app.
  3. Update to Calendar 4.0.16.
  4. Run the following command: calendar/calendars/fix-field-layout-tabs-elements-uids --rebuildProjectConfig.
  5. That should be it -- you should be able to upgrade to Calendar 5 and Craft 5 without issue. 🙂

Please let me know if you continue to experience any issues.

@dMediaJam
Copy link

Yes. This still doesn't fix the issue.

When I run the command on your step 4, I have no uid errors, which seams to be the purpose of that command. Yet I still get the migration error.

Here is the proof of the calendar uuid thing:

Screenshot 2024-10-18 at 10 36 52

Please Advise.

Dwayne

@dMediaJam
Copy link

dMediaJam commented Oct 18, 2024 via email

@seandelaney
Copy link
Contributor

@dMediaJam Are you restoring your DB back to its original state (with Calendar 4.0.14 on Craft 4.10.6 installed) first?

@dMediaJam
Copy link

I'll try again. perhaps I'm missing something in the process.

@seandelaney
Copy link
Contributor

Steps here #305 (comment)

@dMediaJam
Copy link

Still an error. There's nothing to 'fix' when the uuid command runs.

Worth Noting:

  • Six months ago, I see that my composer.json file shows my calendar jumping from version 4.0.11 to 5

So I've been using the Calendar on the current versions (5 and above) for a while. I suspect this my be causing an issue.

Six months ago

Screenshot 2024-10-18 at 14 54 22

Any chance I'm correct in this?

Our Site has been plugging away on Calendar version 5 for these past 6 months. So if relevant, what are my steps to resolve this?

Steps that I keep trying #305 (comment) don't work for me.

Thanks,
Dwayne

@kjmartens
Copy link
Contributor

Sorry for the continued trouble, @dMediaJam.

This might be a case where we just manually fix it in the database for you. Are you able to share that with us so we can make the fix? If so, please create a new private ticket by emailing [email protected]. 🙂

@dMediaJam
Copy link

dMediaJam commented Oct 21, 2024 via email

@kjmartens
Copy link
Contributor

Got it, thanks @dMediaJam. I'll have a developer check into it shortly. 🙂

@kjmartens
Copy link
Contributor

Hi @dMediaJam,

We made another update to the console command to find additional orphaned rows. We then set up your site locally and tested the command and upgrade process to ensure it would work fully. 🙂

Here's the steps to follow on your side:

  1. Restore your DB backup (with Calendar 5.0.9 on Craft 4.12.7 installed).
  2. Restore composer php version back to 8.0.2 or 8.1.
  3. Update Calendar to latest v5 version composer require solspace/craft-calendar:^5 (5.0.11)
  4. Run php craft calendar/calendars/fix-field-layout-tabs-elements-uids --rebuildProjectConfig
  5. Now update Craft to ^5 in composer, including all plugins to their Craft 5 versions.
  6. Run composer update -W.
  7. Run php craft migrate/all again.

Please let me know how it goes. 🙂

@dMediaJam
Copy link

Hello,

Thank you for the update. I ran this a couple times with mixed results.

The good news, I was able to get to Craft 5.

However, my Event Titles did not migrate over. See attached image below

Screenshot 2024-10-29 at 15 14 00

In the craft admin console I can now see my events, in Craft 5, but the events appear to be given numbered names since the Event TItle fields did not migrate.

Thank you for a fix though, I appear to be able to update with Craft 5, with just this one error.

Dwayne

@kjmartens
Copy link
Contributor

Excellent, thanks @dMediaJam. 🙂

You'll just want to run this command in your console and it'll be good:
php craft calendar/events/fix-titles

https://docs.solspace.com/craft/calendar/v5/developer/console-commands/#migrate-craft-4-element-titles

If you have upgraded your Craft 4 site to Craft 5, please note that the Craft migration process does not automatically migrate submission Element titles. In Craft 5, Element titles are now stored in the elements_sites table, and the content table which used to store Element titles is no longer used.

While most plugins could include a separate migration script to handle this, Calendar 5 supports both Craft 4 and Craft 5, making this path impossible. Instead, a CLI command has been included that needs to be executed once after upgrading from Craft 4 to Craft 5.

@dMediaJam
Copy link

Thank you. That fixed the title issue.

d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment