putyourlightson / craft-blitz

Intelligent static page caching for creating lightning-fast sites with Craft CMS.
https://putyourlightson.com/plugins/blitz
Other
149 stars 36 forks source link

Invalid owner ID #205

Closed Osze closed 4 years ago

Osze commented 4 years ago

I get an error when saving an entry. It seems to happened only on a very few entries in the system. Just had the issue on one entry on one site and one entry on another site.

On those two entries I can't save because it will throw the same error.

Invalid Configuration – yii\base\InvalidConfigException Invalid owner ID: 360744

I thought it was a NEO plugin error first but it works perfectly after disableing Blitz.

Not sure if this will help but below is the beginning of the error report on the page.

1. in /srv/users/craft/apps/test-env/craft/vendor/spicyweb/craft-neo/src/elements/Block.phpat line 285
276277278279280281282283284285286287288289290291292293294     */
    public function getOwner(): ElementInterface
    {
         if ($this->_owner === null) {
             if ($this->ownerId === null) {
                 throw new InvalidConfigException(Neo block is missing its owner ID);
             }

             if (($this->_owner = Craft::$app->getElements()->getElementById($this->ownerId, null, $this->siteId)) === null) {
                 throw new InvalidConfigException(Invalid owner ID:  . $this->ownerId);
             }
      }

      return $this->_owner;
    }

    /**
     * Sets this blocks owner.
     *
2. in /srv/users/craft/apps/test-env/craft/vendor/craftcms/cms/src/helpers/ElementHelper.php at line 333– benf\neo\elements\Block::getOwner()
327328329330331332333334335336337338339     * @return ElementInterface
     * @since 3.2.0
     */
    public static function rootElement(ElementInterface $element): ElementInterface
    {
        if ($element instanceof BlockElementInterface) {
            return static::rootElement($element->getOwner());
        }
        return $element;
    }

    /**
     * Returns whether the given element (or its root element if a block element) is a draft or revision.
3. in /srv/users/craft/apps/test-env/craft/vendor/craftcms/cms/src/helpers/ElementHelper.php at line 333– craft\helpers\ElementHelper::rootElement(benf\neo\elements\Block)
327328329330331332333334335336337338339     * @return ElementInterface
     * @since 3.2.0
     */
    public static function rootElement(ElementInterface $element): ElementInterface
    {
        if ($element instanceof BlockElementInterface) {
            return static::rootElement($element->getOwner());
        }
        return $element;
    }

    /**
     * Returns whether the given element (or its root element if a block element) is a draft or revision.
4. in /srv/users/craft/apps/test-env/craft/vendor/craftcms/cms/src/helpers/ElementHelper.php at line 348– craft\helpers\ElementHelper::rootElement(craft\elements\MatrixBlock)
342343344345346347348349350351352353354     * @return bool
     * @since 3.2.0
     */
    public static function isDraftOrRevision(ElementInterface $element): bool
    {
        /** @var Element $root */
        $root = ElementHelper::rootElement($element);
        return $root->getIsDraft() || $root->getIsRevision();
    }

    /**
     * Returns the element, or if it’s a draft/revision, the source element.
     *
5. in /srv/users/craft/apps/test-env/craft/vendor/putyourlightson/craft-blitz/src/services/RefreshCacheService.php at line 168– craft\helpers\ElementHelper::isDraftOrRevision(craft\elements\MatrixBlock)
162163164165166167168169170171172173174    public function addElement(ElementInterface $element)
    {
        // Dont proceed if not an Element, if propagating, if element is a draft or revision,
        // or if the element is an asset that is being indexed
        if (!($element instanceof Element)
            || $element->propagating
            || ElementHelper::isDraftOrRevision($element)
            || ($element instanceof Asset && $element->getScenario() == Asset::SCENARIO_INDEX)
        ) {
            return;
        }

        // Refresh the entire cache if this is a global set since they are populated on every request
6. in /srv/users/craft/apps/test-env/craft/vendor/putyourlightson/craft-blitz/src/Blitz.php at line 325– putyourlightson\blitz\services\RefreshCacheService::addElement(craft\elements\MatrixBlock)
319320321322323324325326327328329330331 
        foreach ($events as $event) {
            Event::on(Elements::class, $event,
                /** @var ElementEvent|BatchElementActionEvent $event */
                function($event) {
                    if ($event->element !== null) {
                        $this->refreshCache->addElement($event->element);
                    }
                }
            );
        }
    }

7. putyourlightson\blitz\Blitz::putyourlightson\blitz\{closure}(craft\events\ElementEvent)
8. in /srv/users/craft/apps/test-env/craft/vendor/yiisoft/yii2/base/Event.php at line 312– call_user_func(Closure, craft\events\ElementEvent)
9. in /srv/users/craft/apps/test-env/craft/vendor/yiisoft/yii2/base/Component.php at line 636– yii\base\Event::trigger(craft\services\Elements, afterDeleteElement, craft\events\ElementEvent)
10. in /srv/users/craft/apps/test-env/craft/vendor/craftcms/cms/src/services/Elements.php at line 1269– yii\base\Component::trigger(afterDeleteElement, craft\events\ElementEvent)

Versions

bencroker commented 4 years ago

Thanks, fixed in https://github.com/putyourlightson/craft-blitz/commit/c66f8112a9695a2fcd31a2b5354afa003e317545 for the next release (likely today).