Installing, upgrading, and uninstalling ####################################### Mautic informs your Plugin when it gets installed or updated through the ``ON_PLUGIN_INSTALL`` and ``ON_PLUGIN_UPDATE`` events. This can be useful in scenarios where you need to set up certain data structures or do other configuration work. Note that there is currently no hook for when your Plugin gets uninstalled. If that's of interest, please feel free to :xref:`contribute that feature`. .. note:: If your Plugin manages its own schema, Mautic recommends using :ref:`plugins/installation:database migrations` instead of the generic events mentioned earlier. Install and update events ========================= .. note:: The events below are available since Mautic 4.2.0. You can create event listeners as follows: .. code-block:: php ['onPluginInstall', 0], PluginEvents::ON_PLUGIN_UPDATE => ['onPluginUpdate', 0], ]; } public function onPluginInstall(PluginInstallEvent $event) { // Handle your logic here } public function onPluginUpdate(PluginUpdateEvent $event) { // Handle your logic here } } Database migrations =================== Mautic supports database migrations for Plugins to better manage their schema. Queries are in migration files that match the Plugin's version number in its config. When a Plugin gets installed or upgraded, Mautic loops over the migration files up to the latest version. Check your Plugin's root bundle class ------------------------------------- The Plugin's root bundle class should extend ``MauticPlugin\IntegrationsBundle\Bundle\AbstractPluginBundle``: .. code-block:: php getTable($this->concatPrefix($this->table))->hasColumn('is_enabled'); } catch (SchemaException $e) { return false; } } protected function up(): void { $this->addSql("ALTER TABLE `{$this->concatPrefix($this->table)}` ADD `is_enabled` tinyint(1) 0"); $this->addSql("CREATE INDEX {$this->concatPrefix('is_enabled')} ON {$this->concatPrefix($this->table)}(is_enabled);"); } }