Pennebaker / craftcms-thearchitect

CraftCMS plugin to generate content models from JSON data.
MIT License
171 stars 9 forks source link

Raw Import: Invalid argument supplied for foreach() #21

Closed NickTomlin closed 7 years ago

NickTomlin commented 7 years ago

I'm getting the following error when trying to import JSON:

PHP Warning: Invalid argument supplied for foreach() 

craft/plugins/thearchitect/services/TheArchitectService.php(1813)

1801             }
1802         }
1803         if ($object->type == 'Tags') {
1804             if (isset($object->typesettings->source)) {
1805                 $category = $this->getTagGroupByHandle($object->typesettings->source);
1806                 if ($category) {
1807                     $object->typesettings->source = 'taggroup:'.$category->id;
1808                 }
1809             }
1810         }
1811         if ($object->type == 'Users') {
1812             if (isset($object->typesettings->sources)) {
1813 >>>>          foreach ($object->typesettings->sources as $k => &$v) {
1814                     $userGroup = $this->getUserGroupByHandle($v);
1815                     if ($userGroup) {
1816                         $v = 'group:'.$userGroup->id;
1817                     }
1818                 }
1819             }
1820         }
1821         if ($object->type == 'FruitLinkIt') {
1822             if (isset($object->typesettings->entrySources)) {
1823                 foreach ($object->typesettings->entrySources as $k => &$v) {
1824                     $section = craft()->sections->getSectionByHandle($v);
1825                     if ($section) {

Craft Version: Craft CMS 2.6.2796 PHP Version 7.0.10 The Architect Version: 1.5.1

I understand it's a bit of a bummer to get a random stacktrace, so please let me know if there's any additional information I can get you.

NickTomlin commented 7 years ago

Looks like I can avoid this error by not including a matrix field that was automatically selected when I exported a section. Not sure if there's a way to have a more helpful error message here (or at least some documentation that this is something to watch out for)

spAnser commented 7 years ago

What you provided is perfectly fine. I think I know the problem. I thought it was fixed though.

https://github.com/Pennebaker/craftcms-thearchitect/wiki/Users

I am assuming that your typesettings for a Users field is

    "typesettings": {
        "sources": "*",
        "selectionLabel": "Add a user"
    }

Try removing the "sources" line. After import double check the users field in your matrix.

I will look into fixing this again.

NickTomlin commented 7 years ago

Thanks for the fix!