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

Upgrade from 3.0.0-beta.2 to 3.0.4 fails #178

Open
CAIDcreative opened this issue Jan 8, 2025 · 2 comments
Open

Upgrade from 3.0.0-beta.2 to 3.0.4 fails #178

CAIDcreative opened this issue Jan 8, 2025 · 2 comments

Comments

@CAIDcreative
Copy link

Describe the bug

Trying to update from 3.0.0-beta.2 to 3.0.4 fails

Integrity constraint violation: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '8665-1-24-0' for key 'PRIMARY'
The SQL being executed was: UPDATE changedfields SET layoutElementUid=CASE WHEN fieldId = 49 THEN '52e8858d-6c09-4778-8237-009ff6b00d1d' WHEN fieldId = 47 THEN 'ba709184-e786-4ac8-b6d9-3d900a87eaa4' WHEN fieldId = 26 THEN '546cb376-62bf-4e5d-b23d-4b3b7faa278a' ELSE '0' END WHERE elementId IN (SELECT DISTINCT id
FROM events_events
WHERE typeId=1)

Migration: verbb\events\migrations\m240921_000000_events3

I believe the error happens around line 215 to 242 on m240921_000000_events3.php

//
// Update Element Content
//

// Before proceeding, update the legacy Ticket Types and Ticket elements to have their content moved for Craft 4 > 5
// We'll need to do this to fetch field values for the new Ticket Types/Ticket elements.
$contentRefactorMigration = new BaseContentRefactorMigration();

// Use reflection to access the protected method
$reflectionClass = new ReflectionClass($contentRefactorMigration);
$updateElements = $reflectionClass->getMethod('updateElements');
$updateElements->setAccessible(true);

$eventTypes = (new Query())
    ->from('{{%events_event_types}}')
    ->all();

foreach ($eventTypes as $eventType) {
    $query = (new Query())->from('{{%events_events}}')->where(['typeId' => $eventType['id']]);

    if ($eventType['fieldLayoutId']) {
        $layout = Craft::$app->getFields()->getLayoutById($eventType['fieldLayoutId']);

        if ($layout) {
            $updateElements->invoke($contentRefactorMigration, $query, $layout);
        }
    }
}

Steps to reproduce

In my changedfields table I have certain fields like this (id 8665 is an event element) where serveral rows have elementId, siteId, fieldId, and userId that is the same but with different layoutElementUid.

| elementId | siteId | fieldId | layoutElementUid                           | dateUpdated          | propagated | userId |
|-----------|--------|---------|--------------------------------------------|----------------------|------------|--------|
| 8665      | 1      | 24      | 0                                          | 2024-08-01 06:47:44 | 0          | 1      |
| 8665      | 1      | 24      | d9263ac1-588c-4e4b-8bf4-ba0009dfa6b5       | 2024-08-20 07:05:31 | 0          | 1      |
| 8665      | 1      | 25      | 0                                          | 2024-08-01 06:47:44 | 0          | 1      |
| 8665      | 1      | 25      | 29320d33-4e3a-427a-94bc-1fd67fdb513c       | 2024-08-20 07:05:31 | 0          | 1      |
| 8665      | 1      | 26      | 546cb376-62bf-4e5d-b23d-4b3b7faa278a       | 2024-08-20 07:05:31 | 0          | 1      |
| 8665      | 1      | 47      | ba709184-e786-4ac8-b6d9-3d900a87eaa4       | 2024-08-20 07:05:31 | 0          | 1      |
| 8665      | 1      | 49      | 52e8858d-6c09-4778-8237-009ff6b00d1d       | 2024-08-20 07:05:31 | 0          | 1      |
| 8665      | 1      | 61      | 0                                          | 2024-08-01 06:47:44 | 0          | 1      |
| 8665      | 1      | 61      | 2133531b-9178-4358-95cb-8e0103e02006       | 2024-08-20 07:05:31 | 0          | 1      |

I tested (locally in ddev) deleting all rows where the fieldId was 0 in the table and the update and migrations seemed to work then, but I'm unsure of the consequences for doing so and would maybe like a proper solution

I'm wondering if there even should be multiple rows like this with different fieldId or if that's some sort of error?

Craft CMS version

5.4.6

Plugin version

3.0.0-beta.2

Multi-site?

No

Additional context

Currently doing all updating/testing and such in ddev locally for the moment

@engram-design
Copy link
Member

Deleting the rows in changedfields is pretty safe in this instance, mainly because Events 3 is such a large refactor, any noted fields that have been marked as changed, likely are no longer valid.

I believe the changedfields database table is there to keep track of what fields have changed data with regards to drafts and delta updates, along with who has updated things.

@CAIDcreative
Copy link
Author

Thanks for the reassurance. I thought they had to do something with drafts, just difficult to find documentation on what a craft tables in the database is for. I just opted for deleting those rows, and updating went smoothly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants