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

PHP Notice – yii\base\ErrorException Undefined offset: 1 #5525

Closed
brambeekman opened this issue Jan 29, 2020 · 28 comments
Closed

PHP Notice – yii\base\ErrorException Undefined offset: 1 #5525

brambeekman opened this issue Jan 29, 2020 · 28 comments

Comments

@brambeekman
Copy link

After update i get this error

@andris-sevcenko
Copy link
Contributor

Do you have a stack trace in your log files?

@brambeekman
Copy link
Author

brambeekman commented Jan 29, 2020

Do you have a stack trace in your log files?

Yes.

Stack trace:
#0 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\helpers\ProjectConfig.php(275): yii\base\ErrorHandler->handleError(8, 'Undefined offse...', 'C:\\Users\\bramb\\...', 275, Array)
#1 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\helpers\ProjectConfig.php(284): craft\helpers\ProjectConfig::unpackAssociativeArray(Array, true)
#2 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\helpers\ProjectConfig.php(254): craft\helpers\ProjectConfig::unpackAssociativeArray(Array)
#3 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\services\Plugins.php(1372): craft\helpers\ProjectConfig::unpackAssociativeArrays(Array)
#4 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\services\Plugins.php(206): craft\services\Plugins->_getPluginConfigData('feed-me')
#5 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\base\ApplicationTrait.php(1351): craft\services\Plugins->loadPlugins()
#6 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\console\Application.php(59): craft\console\Application->_postInit()
#7 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\base\BaseObject.php(109): craft\console\Application->init()
#8 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\base\Application.php(206): yii\base\BaseObject->__construct(Array)
#9 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\console\Application.php(89): yii\base\Application->__construct(Array)
#10 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\src\console\Application.php(48): yii\console\Application->__construct(Array)
#11 [internal function]: craft\console\Application->__construct(Array)
#12 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\di\Container.php(400): ReflectionClass->newInstanceArgs(Array)
#13 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\di\Container.php(159): yii\di\Container->build('craft\\console\\A...', Array, Array)
#14 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\yiisoft\yii2\BaseYii.php(365): yii\di\Container->get('craft\\console\\A...', Array, Array)
#15 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\bootstrap\bootstrap.php(245): yii\BaseYii::createObject(Array)
#16 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\vendor\craftcms\cms\bootstrap\console.php(43): require('C:\\Users\\bramb\\...')
#17 C:\Users\bramb\Documents\Websites\leendersbiketotaal.nl\craft(21): require('C:\\Users\\bramb\\...')
#18 {main}
2020-01-29 11:07:15 [-][-][-][info][application] $_GET = []

@andris-sevcenko
Copy link
Contributor

Ah okay, that was fixed today. To fix this,change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#67d2a4aa7724189682897035c1b90baeb358ebf7 as 3.4.0.2",
  "...": "..."
}

Then run composer update.

And then perform the update again? I'm afraid there was a small oversight in how Project Config changes were migrated which borked plugin settings that used associative arrays.

Sorry about that!

@brambeekman
Copy link
Author

"craftcms/cms": "dev-develop#67d2a4aa7724189682897035c1b90baeb358ebf7 as 3.4.0.2",

Still not working.

@andris-sevcenko
Copy link
Contributor

Did you perform the update on a pre-3.4 update database?

@brambeekman
Copy link
Author

Did you perform the update on a pre-3.4 update database?

Yes i think so..

@andris-sevcenko
Copy link
Contributor

@brambeekman in that case, can you send over the pre-update database, your composer.json, and composer.lock files to [email protected] and reference this issue, please?

@brambeekman
Copy link
Author

@brambeekman in that case, can you send over the pre-update database, your composer.json, and composer.lock files to [email protected] and reference this issue, please?

I'm not sure if i did, can you explain what it means?

@andris-sevcenko
Copy link
Contributor

I mean can you zip up your pre-update database (from the installation that was before you updated to 3.4.x) and send it over email to [email protected]. Also, please attach the composer.json and composer.lock files, so I can install the site locally and see what problem you're having. Make sure to mention this Github issue in the subject, so we know what that is all about :)

@brambeekman
Copy link
Author

I mean can you zip up your pre-update database (from the installation that was before you updated to 3.4.x) and send it over email to [email protected]. Also, please attach the composer.json and composer.lock files, so I can install the site locally and see what problem you're having. Make sure to mention this Github issue in the subject, so we know what that is all about :)

Done

@brandonkelly
Copy link
Member

Closing this; we’ll get this resolved offline.

@Tam
Copy link

Tam commented Feb 10, 2020

I'm getting this error as well (Craft 3.4.5). Looks like something went wrong when project config tried to store an associative array from a config file where the value was a function.

return [
    'geoLocationAutoRedirect' => true,
    'geoLocationRedirectMap' => [
        'example' => [ 'isEU' => function ($isEu) { return $isEu; } ],
        //                       ^ looks like this is causing the error
        'default' => '*',
    ],
];
2020-02-10 06:56:48 [-][-][44dee9d50e61b8684ab6d44a80fd7482][error][yii\base\ErrorException:8] yii\base\ErrorException: Undefined offset: 1 in /var/www/html/vendor/craftcms/cms/src/helpers/ProjectConfig.php:275
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php(74): yii\base\ErrorHandler->handleError(8, 'Undefined offse...', '/var/www/html/v...', 275)
#1 /var/www/html/vendor/craftcms/cms/src/helpers/ProjectConfig.php(275): craft\web\ErrorHandler->handleError(8, 'Undefined offse...', '/var/www/html/v...', 275, Array)
#2 /var/www/html/vendor/craftcms/cms/src/helpers/ProjectConfig.php(284): craft\helpers\ProjectConfig::unpackAssociativeArray(Array, true)
#3 /var/www/html/vendor/craftcms/cms/src/helpers/ProjectConfig.php(254): craft\helpers\ProjectConfig::unpackAssociativeArray(Array)
#4 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(1372): craft\helpers\ProjectConfig::unpackAssociativeArrays(Array)
#5 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(206): craft\services\Plugins->_getPluginConfigData('simplemap')
#6 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(1351): craft\services\Plugins->loadPlugins()
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(103): craft\web\Application->_postInit()
#8 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()
#9 /var/www/html/vendor/yiisoft/yii2/base/Application.php(206): yii\base\BaseObject->__construct(Array)
#10 /var/www/html/vendor/craftcms/cms/src/web/Application.php(91): yii\base\Application->__construct(Array)
#11 [internal function]: craft\web\Application->__construct(Array)
#12 /var/www/html/vendor/yiisoft/yii2/di/Container.php(400): ReflectionClass->newInstanceArgs(Array)
#13 /var/www/html/vendor/yiisoft/yii2/di/Container.php(159): yii\di\Container->build('craft\\web\\Appli...', Array, Array)
#14 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\web\\Appli...', Array, Array)
#15 /var/www/html/vendor/craftcms/cms/bootstrap/bootstrap.php(245): yii\BaseYii::createObject(Array)
#16 /var/www/html/vendor/craftcms/cms/bootstrap/web.php(51): require('/var/www/html/v...')
#17 /var/www/html/web/index.php(20): require('/var/www/html/v...')
#18 {main}

@brandonkelly
Copy link
Member

@Tam Hm yeah… that shouldn’t have been saved to begin with. Can you send your composer.json and composer.lock files, along with a database backup, over to [email protected]?

@Tam
Copy link

Tam commented Feb 12, 2020

@brandonkelly That's sent, let me know if you need anything else!

@mizziness
Copy link

This just happened to me in my local environment after I had removed a language-based site from the system, running Craft CMS version 3.4.15. The issue seems to have been caused by the associated row in the sites table remaining after the site delete.

Here's the table contents after the site had been deleted already:

image

As a result, code where the site IDs were being iterated over would throw this error. I was able to fix it by manually removing the dead site row from the sites table.

Hope this helps someone!

@brandonkelly
Copy link
Member

@mizziness Sites only get soft-deleted initially. Shouldn’t result in any errors though. Do you still have a database backup from before you went in and deleted that row? If so can you please send into [email protected]?

@mizziness
Copy link

@mizziness Sites only get soft-deleted initially. Shouldn’t result in any errors though. Do you still have a database backup from before you went in and deleted that row? If so can you please send into [email protected]?

Apologies for the slow reply!

I do believe I may have the database backups from around then - I will go spelunking and see if a) I do and b) if I can recreate the issue - if so, I'll send it all over to you :) Thanks!

@timkelty
Copy link
Contributor

timkelty commented Jun 10, 2020

@brandonkelly People are seeing this issue here as well, when saving settings in the CP: studioespresso/craft-scout#152.

I presume this is due to having complex data types in the config/scout.php file, and then project.yaml trying to write them to project.yaml?

@martinhellwagner
Copy link

For what it's worth, I've modified the function unpackAssociativeArray in the file ProjectConfig.php in order to get in working. Of course this is overwritten when composer packages are installed anew.

    public static function unpackAssociativeArray(array $array, bool $recursive = true): array
    {
        if (isset($array[ProjectConfigService::CONFIG_ASSOC_KEY])) {
            $associative = [];
            if (!empty($array[ProjectConfigService::CONFIG_ASSOC_KEY])) {
                foreach ($array[ProjectConfigService::CONFIG_ASSOC_KEY] as $items) {
                    if (sizeof($items) > 1) { // Necessary because of problem with Scout
                        $associative[$items[0]] = $items[1];
                    }
                }
            }
            $array = $associative;
        }

        if ($recursive) {
            foreach ($array as &$value) {
                if (is_array($value)) {
                    $value = static::unpackAssociativeArray($value, true);
                }
            }
        }

        return $array;
    }

@brandonkelly
Copy link
Member

What exactly is Scout doing with the project config that is messing things up?

@timkelty
Copy link
Contributor

@brandonkelly Scout isn't doing anything explicit with project config.

The setting that is causing the error is indices, which is only settable via config/scout.php: https://github.com/riasvdv/craft-scout/blob/master/src/models/Settings.php#L28, and is an array of objects (instances of https://github.com/riasvdv/craft-scout/blob/master/src/ScoutIndex.php).

When the settings are saved in the CP, the instances are converted to yaml, and then we get the unpackAssociativeArray error.

@brandonkelly
Copy link
Member

Ahh, gotcha.

@brandonkelly brandonkelly reopened this Jun 15, 2020
@brandonkelly
Copy link
Member

The way Scout 2 is storing nested objects in its field settings would have been problematic even before project config.

I’ve just submitted studioespresso/craft-scout#162 which should fix this error going forward.

@timkelty
Copy link
Contributor

Thanks @brandonkelly.

Is/should there be something in the docs stating plugin settings shouldn't contain values like this, or should explicitly exclude them as you PR'd?

@brandonkelly
Copy link
Member

Probably! cc @mattstein

@mattstein
Copy link
Contributor

Added a note to the Plugin Settings page, @timkelty.

@williamhibberd
Copy link

I'm getting the same error related to the TotalRevenue commerce widget.
Any advice on how to fix it and get back into the cp?

yii\base\ErrorException: Undefined offset: 1 in /home/forge/***.com/vendor/craftcms/commerce/src/widgets/TotalRevenue.php:140
Stack trace:
#0 /home/forge/myurl.com/vendor/craftcms/cms/src/web/ErrorHandler.php(76): yii\base\ErrorHandler->handleError(8, 'Undefined offse...', '/home/forge/pip...', 140)
#1 /home/forge/myurl.com/vendor/craftcms/commerce/src/widgets/TotalRevenue.php(140): craft\web\ErrorHandler->handleError(8, 'Undefined offse...', '/home/forge/pip...', 140, Array)
#2 [internal function]: craft\commerce\widgets\TotalRevenue::craft\commerce\widgets\{closure}(NULL)
#3 /home/forge/myurl.com/vendor/craftcms/commerce/src/widgets/TotalRevenue.php(139): array_map(Object(Closure), Array)
#4 /home/forge/myurl.com/vendor/craftcms/cms/src/controllers/DashboardController.php(508): craft\commerce\widgets\TotalRevenue->getBodyHtml()
#5 /home/forge/myurl.com/vendor/craftcms/cms/src/controllers/DashboardController.php(107): craft\controllers\DashboardController->_getWidgetInfo(Object(craft\commerce\widgets\TotalRevenue))
#6 [internal function]: craft\controllers\DashboardController->actionIndex()
#7 /home/forge/myurl.com/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /home/forge/myurl.com/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#9 /home/forge/myurl.com/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('index', Array)
#10 /home/forge/myurl.com/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('index', Array)
#11 /home/forge/myurl.com/vendor/craftcms/cms/src/web/Application.php(278): yii\base\Module->runAction('dashboard/index', Array)
#12 /home/forge/myurl.com/vendor/yiisoft/yii2/web/Application.php(104): craft\web\Application->runAction('dashboard/index', Array)
#13 /home/forge/myurl.com/vendor/craftcms/cms/src/web/Application.php(263): yii\web\Application->handleRequest(Object(craft\web\Request))
#14 /home/forge/myurl.com/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#15 /home/forge/myurl.com/web/index.php(22): yii\base\Application->run()
#16 {main}

@brandonkelly
Copy link
Member

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

9 participants