问题
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