silverstripe / silverstripe-elemental

Create pages in Silverstripe CMS using content blocks
http://dna.co.nz
BSD 3-Clause "New" or "Revised" License
110 stars 115 forks source link

Site broken after updating to 3.0.0-rc1 #264

Closed Juanitou closed 6 years ago

Juanitou commented 6 years ago

The following error appears when trying to access the CMS after upgrading this module to 3.0.0-rc1.

[Emergency] Uncaught ArgumentCountError: Too few arguments to function
SilverStripe\ORM\UnsavedRelationList::__construct(), 0 passed and exactly 3 expected
GET /

Line 58 in /usr/home/juan/www/juan/vendor/silverstripe/framework/src/ORM/UnsavedRelationList.php
Source

49     protected $extraFields = array();
50 
51     /**
52      * Create a new UnsavedRelationList
53      *
54      * @param string $baseClass
55      * @param string $relationName
56      * @param string $dataClass The DataObject class used in the relation
57      */
58     public function __construct($baseClass, $relationName, $dataClass)
59     {
60         $this->baseClass = $baseClass;
61         $this->relationName = $relationName;
62         $this->dataClass = $dataClass;
63         parent::__construct();
64     }

Trace

    SilverStripe\ORM\UnsavedRelationList->__construct()
    ReflectionClass->newInstance()
    InjectionCreator.php:26
    SilverStripe\Core\Injector\InjectionCreator->create(SilverStripe\ORM\UnsavedRelationList, Array)
    Injector.php:585
    SilverStripe\Core\Injector\Injector->instantiate(Array, SilverStripe\ORM\UnsavedRelationList, prototype)
    Injector.php:993
    SilverStripe\Core\Injector\Injector->getNamedService(SilverStripe\ORM\UnsavedRelationList, , Array)
    Injector.php:946
    SilverStripe\Core\Injector\Injector->get(SilverStripe\ORM\UnsavedRelationList, , Array)
    Injector.php:1116
    SilverStripe\Core\Injector\Injector->createWithArgs(SilverStripe\ORM\UnsavedRelationList, Array)
    Injectable.php:30
    SilverStripe\View\ViewableData::create()
    ArrayList.php:694
    SilverStripe\ORM\ArrayList->filterByCallback(Closure)
    ElementalArea.php:114
    DNADesign\Elemental\Models\ElementalArea->ElementControllers()
    call_user_func_array(Array, Array)
    ViewableData.php:481
    SilverStripe\View\ViewableData->obj(ElementControllers, , 1)
    ViewableData.php:528
    SilverStripe\View\ViewableData->hasValue(ElementControllers, , 1)
    DataObject.php:3929
    SilverStripe\ORM\DataObject->hasValue(ElementControllers, , 1)
    SSViewer_Scope.php:323
    SilverStripe\View\SSViewer_Scope->__call(hasValue, Array)
    SSViewer_DataPresenter.php:309
    SilverStripe\View\SSViewer_DataPresenter->__call(hasValue, Array)
    .cachevendor.dnadesign.silverstripe-elemental.templates.DNADesign.Elemental.Models.ElementalArea.ss:2
    include(/tmp/silverstripe-cache-php7.2.7-usr-home-juan-www-juan/unknown/.cachevendor.dnadesign.silverstripe-elemental.templates.DNADesign.Elemental.Models.ElementalArea.ss)
    SSViewer.php:602
    SilverStripe\View\SSViewer->includeGeneratedTemplate(/tmp/silverstripe-cache-php7.2.7-usr-home-juan-www-juan/unknown/.cachevendor.dnadesign.silverstripe-elemental.templates.DNADesign.Elemental.Models.ElementalArea.ss, DNADesign\Elemental\Models\ElementalArea, , Array, )
    SSViewer.php:674
    SilverStripe\View\SSViewer->process(DNADesign\Elemental\Models\ElementalArea, )
    ViewableData.php:397
    SilverStripe\View\ViewableData->renderWith(SilverStripe\View\SSViewer)
    ElementalArea.php:78
    DNADesign\Elemental\Models\ElementalArea->forTemplate()
    ViewableData.php:545
    SilverStripe\View\ViewableData->XML_val(ElementalArea, , 1)
    SSViewer_Scope.php:323
    SilverStripe\View\SSViewer_Scope->__call(XML_val, Array)
    SSViewer_DataPresenter.php:309
    SilverStripe\View\SSViewer_DataPresenter->__call(XML_val, Array)
    .cachethemes.juan.templates.Layout.Page.ss:9
    include(/tmp/silverstripe-cache-php7.2.7-usr-home-juan-www-juan/unknown/.cachethemes.juan.templates.Layout.Page.ss)
    SSViewer.php:602
    SilverStripe\View\SSViewer->includeGeneratedTemplate(/tmp/silverstripe-cache-php7.2.7-usr-home-juan-www-juan/unknown/.cachethemes.juan.templates.Layout.Page.ss, PageController, , Array, )
    SSViewer.php:674
    SilverStripe\View\SSViewer->process(PageController, )
    SSViewer.php:668
    SilverStripe\View\SSViewer->SilverStripe\View\{closure}()
    SSViewer_DataPresenter.php:330
    SilverStripe\View\SSViewer_DataPresenter->processTemplateOverride(Layout, Array)
    SSViewer_DataPresenter.php:363
    SilverStripe\View\SSViewer_DataPresenter->getValueSource(Layout)
    SSViewer_DataPresenter.php:165
    SilverStripe\View\SSViewer_DataPresenter->getInjectedValue(Layout, Array)
    SSViewer_DataPresenter.php:296
    SilverStripe\View\SSViewer_DataPresenter->__call(XML_val, Array)
    .cachethemes.juan.templates.Page.ss:69
    include(/tmp/silverstripe-cache-php7.2.7-usr-home-juan-www-juan/unknown/.cachethemes.juan.templates.Page.ss)
    SSViewer.php:602
    SilverStripe\View\SSViewer->includeGeneratedTemplate(/tmp/silverstripe-cache-php7.2.7-usr-home-juan-www-juan/unknown/.cachethemes.juan.templates.Page.ss, PageController, , Array, )
    SSViewer.php:674
    SilverStripe\View\SSViewer->process(PageController)
    Controller.php:300
    SilverStripe\Control\Controller->handleAction(SilverStripe\Control\HTTPRequest, index)
    RequestHandler.php:202
    SilverStripe\Control\RequestHandler->handleRequest(SilverStripe\Control\HTTPRequest)
    Controller.php:212
    SilverStripe\Control\Controller->handleRequest(SilverStripe\Control\HTTPRequest)
    ContentController.php:237
    SilverStripe\CMS\Controllers\ContentController->handleRequest(SilverStripe\Control\HTTPRequest)
    ModelAsController.php:100
    SilverStripe\CMS\Controllers\ModelAsController->handleRequest(SilverStripe\Control\HTTPRequest)
    RootURLController.php:142
    SilverStripe\CMS\Controllers\RootURLController->handleRequest(SilverStripe\Control\HTTPRequest)
    Director.php:361
    SilverStripe\Control\Director->SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)
    VersionedHTTPMiddleware.php:40
    SilverStripe\Versioned\VersionedHTTPMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    BasicAuthMiddleware.php:68
    SilverStripe\Security\BasicAuthMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    AuthenticationMiddleware.php:61
    SilverStripe\Security\AuthenticationMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    CanonicalURLMiddleware.php:188
    SilverStripe\Control\Middleware\CanonicalURLMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    HTTPCacheControlMiddleware.php:44
    SilverStripe\Control\Middleware\HTTPCacheControlMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    ChangeDetectionMiddleware.php:27
    SilverStripe\Control\Middleware\ChangeDetectionMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    FlushMiddleware.php:29
    SilverStripe\Control\Middleware\FlushMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    RequestProcessor.php:66
    SilverStripe\Control\RequestProcessor->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    SessionMiddleware.php:20
    SilverStripe\Control\Middleware\SessionMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    AllowedHostsMiddleware.php:60
    SilverStripe\Control\Middleware\AllowedHostsMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    TrustedProxyMiddleware.php:176
    SilverStripe\Control\Middleware\TrustedProxyMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    HTTPMiddlewareAware.php:65
    SilverStripe\Control\Director->callMiddleware(SilverStripe\Control\HTTPRequest, Closure)
    Director.php:370
    SilverStripe\Control\Director->handleRequest(SilverStripe\Control\HTTPRequest)
    HTTPApplication.php:48
    SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)
    call_user_func(Closure, SilverStripe\Control\HTTPRequest)
    HTTPApplication.php:66
    SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)
    call_user_func(Closure, SilverStripe\Control\HTTPRequest)
    ErrorControlChainMiddleware.php:56
    SilverStripe\Core\Startup\ErrorControlChainMiddleware->SilverStripe\Core\Startup\{closure}(SilverStripe\Core\Startup\ErrorControlChain)
    call_user_func(Closure, SilverStripe\Core\Startup\ErrorControlChain)
    ErrorControlChain.php:236
    SilverStripe\Core\Startup\ErrorControlChain->step()
    ErrorControlChain.php:226
    SilverStripe\Core\Startup\ErrorControlChain->execute()
    ErrorControlChainMiddleware.php:69
    SilverStripe\Core\Startup\ErrorControlChainMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
    HTTPMiddlewareAware.php:62
    SilverStripe\Control\HTTPApplication->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
    HTTPMiddlewareAware.php:65
    SilverStripe\Control\HTTPApplication->callMiddleware(SilverStripe\Control\HTTPRequest, Closure)
    HTTPApplication.php:67
    SilverStripe\Control\HTTPApplication->execute(SilverStripe\Control\HTTPRequest, Closure, )
    HTTPApplication.php:49
    SilverStripe\Control\HTTPApplication->handle(SilverStripe\Control\HTTPRequest)
    index.php:26

Downgrading to 3.0.0-beta3 (or removing elements from the config) prevents the error.

This is a really simple test site.

composer.json:

{
    "name": "silverstripe/installer",
    "type": "silverstripe-recipe",
    "description": "The SilverStripe Framework Installer",
    "require": {
        "php": ">=5.6.0",
        "silverstripe/recipe-plugin": "^1.2",
        "silverstripe/recipe-cms": "4.3.x-dev",
        "gdmedia/ss-auto-git-ignore": "^1.0",
        "dnadesign/silverstripe-elemental": "3.0.0-beta3",
        "silverstripe/elemental-bannerblock": "1.x-dev"
    },
    "require-dev": {
        "phpunit/phpunit": "^5.7"
    },
    "extra": {
        "branch-alias": {
            "4.x-dev": "4.2.x-dev",
            "dev-master": "5.x-dev"
        },
        "expose": [
            "themes/juan/dist"
        ],
        "project-files-installed": [
            "app/.htaccess",
            "app/_config.php",
            "app/_config/mysite.yml",
            "app/src/Page.php",
            "app/src/PageController.php"
        ],
        "public-files-installed": [
            ".htaccess",
            "index.php",
            "install-frameworkmissing.html",
            "install.php",
            "web.config"
        ]
    },
    "config": {
        "process-timeout": 600
    },
    "prefer-stable": true,
    "minimum-stability": "dev"
}
kinglozzer commented 6 years ago

Looks like the error is coming from this line specifically: https://github.com/silverstripe/silverstripe-framework/blob/4/src/ORM/ArrayList.php#L694. It could be argued that it’s a framework bug - a call to UnsavedRelationList::filterByCallback() should probably return an ArrayList, not attempt to return an UnsavedRelationList - but I’m more interested in how you’re hitting this error.

If $this->Elements() is returning an UnsavedRelationList, I guess that means that either the page doesn’t have an ElementArea or the page/area are both new records not yet written to the database. Do you know if either of those guesses are correct?

A simple fix would be to amend ElementArea::ElementControllers() to something like:

$controllers = ArrayList::create();
$elements = $this->Elements();

// Or perhaps if (!$this->isInDB())
if ($elements instanceof UnsavedRelationList) {
    return $controllers;
}

$items = $this->Elements()->filterByCallback(function (BaseElement $item) {
    // ...
robbieaverill commented 6 years ago

I can't reproduce this error by creating variations of saved pages or elements in the page, but I'm happy to fix it anyway

robbieaverill commented 6 years ago

Fix at #265

robbieaverill commented 6 years ago

Fixed in 3.0.0-rc2: https://github.com/dnadesign/silverstripe-elemental/compare/3.0.0-rc1...3.0.0-rc2

Juanitou commented 6 years ago

Thank you for the quick fix.

If $this->Elements() is returning an UnsavedRelationList, I guess that means that either the page doesn’t have an ElementArea or the page/area are both new records not yet written to the database. Do you know if either of those guesses are correct?

This was not my case. Both page and its elements were saved and published days ago the update.