即使我安装插件但在pimcore中未调用安装方法 [英] Even i install plugin but install method not called in pimcore

查看:127
本文介绍了即使我安装插件但在pimcore中未调用安装方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意此处的安装和卸载方法.我正在编写用于创建表的代码.但是我想将这种安装方法称为自动安装的插件,并且它的行为应与pimcore doc建议的一样.

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;
    }
}

推荐答案

您应该实现isInstalled方法,并在该方法中检查表是否已创建,否则返回false. 然后,用户必须单击安装按钮才能实际触发安装. 由于您在isInstalled方法中返回true,因此系统永远不会触发安装.

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.

这篇关于即使我安装插件但在pimcore中未调用安装方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆