craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 626 forks source link

Craft2 to Craft3 scenario (Plugin development) #2518

Closed andrelopez closed 6 years ago

andrelopez commented 6 years ago

Description

We have a problem where a plugin on Craft2 has some settings in the plugins table. We remove those settings on Craft3 so we create a migration to set to null the settings in the plugins table and removed any method related to settings in the Main class of the plugin. When testing an update from Craft2 to Craft3 we got an error after the Craft3 update. It looks like the plugin's migrations do not have a chance to run before the plugin is loaded and is throwing an error because we don't have a settings model but there is a json in the settings column of the plugin table.

Error
Call to a member function setAttributes() on null. in ...\craft\vendor\craftcms\cms\src\base\Plugin.php at line 174

    /**
     * @inheritdoc
     */
    public function setSettings(array $settings)
    {
        $this->getSettings()->setAttributes($settings, false);
    }

A quick fix was Override the setSettings function with an empty body in the main plugin class. Glad to hear any thoughts on this fix.

Additional info

brandonkelly commented 6 years ago

Rather than an empty body, just unset whatever settings you no longer support.

public function setSettings(array $settings)
{
    unset($settings['foo'], $settings['bar']);
    parent::setSettings($settings);
}
andrelopez commented 6 years ago

I'll do. Thanks, brandon!