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

[4.x]: Deleting Sites and Site-Group throws an "Undefined array key 2" error, when trying to open an entry. #14373

Closed
hhentschel opened this issue Feb 13, 2024 · 10 comments

Comments

@hhentschel
Copy link

What happened?

Description

I updated to latest version (4.7.2.1) and deleted some sites and one site group I don't need anymore.
I also changed site name handles.
After that, I cannot open entries in the control panel. Seems that Site ID are mixed up or something.
It gives a php error: Undefined array key 2

Steps to reproduce

  1. Deleting Site and changing site handle names

I tried to resave entries via cli but get the same error there.

Craft CMS version

4.7.2.1

PHP version

8.1.27

Operating system and version

MacOS X 13.21.1

Database type and version

MariaDB 10.6.16

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-62)

Installed plugins and versions

CKEditor | 3.6.0
CP Field Inspect | 1.4.4
Expanded Singles | 2.0.5
ImageOptimize | 4.0.5
Image Resizer | 3.0.9
Neo | 4.0.2
QRCode | 2.1.0
SEOmatic | 4.0.37
Twigpack | 4.0.0-beta.4

@hhentschel
Copy link
Author

Could solve the issue myself.
I am not sure if this is the expected order to delete sites, but before deleting a site i had to disable/set inactive a site within the setting of a structure. Then wait that the entries are saved again and then go to the sites settings and delete a site.

@brandonkelly
Copy link
Member

@hhentschel Can you try searching your logs for that error message (storage/logs/)? If you can find it, please post the stack trace that follows it.

@hhentschel
Copy link
Author

hhentschel commented Feb 15, 2024

@brandonkelly That's what I found in the web.log. error message and stack trace.
replaced my url with xyz.com

2024-02-13 08:26:15 [web.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Undefined array key 2 in /home/oromomic/www/xyz.com/craft/vendor/craftcms/cms/src/elements/Entry.php:891
Stack trace:
#0 /home/oromomic/www/xxx.com/craft/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError(2, 'Undefined array...', '/home/oromomic/...', 891)
#1 /home/oromomic/www/xyz.com/craft/vendor/craftcms/cms/src/elements/Entry.php(891): craft\web\ErrorHandler->handleError(2, 'Undefined array...', '/home/oromomic/...', 891)
#2 /home/oromomic/www/xyz.com/craft/vendor/craftcms/cms/src/helpers/ElementHelper.php(295): craft\elements\Entry->getSupportedSites()
#3 /home/oromomic/www/xyz.com/craft/vendor/craftcms/cms/src/controllers/ElementsController.php(300): craft\helpers\ElementHelper::supportedSitesForElement(Object(craft\elements\Entry), true)
#4 [internal function]: craft\controllers\ElementsController->actionEdit(Object(craft\elements\Entry), 10202)
#5 /home/oromomic/www/xyz.com/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#6 /home/oromomic/www/xyz.com/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#7 /home/oromomic/www/xyz.com/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('edit', Array)
#8 /home/oromomic/www/xyz.com/craft/vendor/craftcms/cms/src/web/Application.php(305): yii\base\Module->runAction('elements/edit', Array)
#9 /home/oromomic/www/xyz.com/craft/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('elements/edit', Array)
#10 /home/oromomic/www/xyz.com/craft/vendor/craftcms/cms/src/web/Application.php(290): yii\web\Application->handleRequest(Object(craft\web\Request))
#11 /home/oromomic/www/xyz.com/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#12 /home/oromomic/www/xyz.com/craft/web/index.php(12): yii\base\Application->run()
#13 {main} {"memory":4186512,"exception":"[object] (yii\\base\\ErrorException(code: 2): Undefined array key 2 at /home/oromomic/www/xyz.com/craft/vendor/craftcms/cms/src/elements/Entry.php:891)"} 
Bildschirm­foto 2024-02-13 um 08 52 54

@maxstrebel
Copy link

Hey, I have the same issue - when the site removal is applied via project config. I think it only applies to pages that have matrix on them. Would be happy about some hints how to tackle this, as I need to apply this change via project-config

brandonkelly added a commit that referenced this issue Jun 4, 2024
@brandonkelly
Copy link
Member

brandonkelly commented Jun 4, 2024

Sorry, missed your last response @hhentschel. Thanks for posting that.

Believe I just fixed this for the next releases. @maxstrebel you can test by changing your craftcms/cms requirement in composer.json to one of the following values:

  • 4.x-dev as 4.9.6 (Craft 4.9)
  • 4.10.x-dev as 4.10.0-beta.1 (Craft 4.10 beta)
  • 5.x-dev as 5.1.8 (Craft 5.1)
  • 5.2.x-dev as 5.2.0-beta.1 ^5.2.0-beta.2 (Craft 5.2 beta)

Then run composer update.

@maxstrebel
Copy link

Thanks @brandonkelly – that seems to do the job 🙏

@brandonkelly
Copy link
Member

Great, thanks for confirming!

@brandonkelly
Copy link
Member

Craft 4.9.7 and 5.1.9 are out now with that fix.

@ntmagda
Copy link

ntmagda commented Jun 6, 2024

@brandonkelly

Hey Brandon - thank you for doing the fix so quickly. 
I work on the project with @maxstrebel.

Unfortunately I noticed the following behaviour:

  • I work on the clean version pulled from production updated to craft 4.6.9.
  • Download database from production and import it with ddev import-db
  • I go to Utilities -> Project Config -> Click “reapply everything”
  • Check git status and I can see that a big number of yaml files was altered. Many sections and fields are removed.

If I do the following:

  • I work on the clean version pulled from production updated to craft 4.6.9.
  • Download database from production and import it with ddev import-db
  • Execute craft up
  • Checking git status -> no changes to yaml files, so as expected
  • BUT as soon as I change anything in the backend. (In my case added a new Category field), the same unexpected altered yaml files appear.

Why I think it can be related to that issue ->

If I do the following:

  • discard the unwanted changes via git
  • Run craft up

I end up with the same php error: Undefined array key 1 related to the sites.

I have a hard time making sense of it. Do you think this issue could be related?

@maxstrebel
Copy link

maxstrebel commented Jun 6, 2024

I think we might have committed to early. The generation of the YAML files takes very long in this project. I just thought I can reproduce but after a minute the deleted files were recreated. We will test this together tomorrow morning and write again.

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

No branches or pull requests

4 participants