Even i install plugin but install method not called in pimcore

主宰稳场 提交于 2019-12-25 18:41:48

问题


Note here install and uninstall method. I am writing code for creating table. But i want to call this install method as plugin installed automatically, and it should behave this way as pimcore doc suggest.

namespace Newsletter;

use Pimcore\API\Plugin as PluginLib;
use Pimcore\Db;

class Plugin extends PluginLib\AbstractPlugin implements PluginLib\PluginInterface
{
    public function init()
    {
        parent::init();
        // register your events here

        // using anonymous function
        \Pimcore::getEventManager()->attach("document.postAdd", function ($event) {
            // do something
            $document = $event->getTarget();
        });

        // using methods
        \Pimcore::getEventManager()->attach("document.postUpdate", [$this, "handleDocument"]);

    }

    public function handleDocument($event)
    {
        // do something
        $document = $event->getTarget();
    }

    public static function install()
    {
        $this->dbConnection = Db::getConnection();
        $this->dbConnection->query("CREATE TABLE IF NOT EXISTS newsLetter(id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, cname VARCHAR(100) NOT NULL)");
        return true;
    }

    public static function uninstall()
    {
        // implement your own logic here
        $this->dbConnection->query("DROP TABLE newsLetter");
        Db::close(); // closes connection
        return true;
    }

    public static function isInstalled()
    {
        // implement your own logic here
        return true;
    }
}

回答1:


You should implement the isInstalled method and in that method check if the table was already created and return false if not. Then the user must click on the install button to actually trigger the installation. Since you are returning true in isInstalled method, the system never triggers the installation.



来源:https://stackoverflow.com/questions/42159639/even-i-install-plugin-but-install-method-not-called-in-pimcore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!