EnAccess / EnAccess/micropowermanager

[Feature Request]: Run plugin initialisation every time a plugin is enabled

Open
#1,338 0 comments 0 reactions 0 assignees View on GitHub
Code base improvement enhancement good first issue help wanted
Dominant language
PHP
Stars
27
Forks
19
Avg merge
1d 18h
Merged PRs (30d)
27

Description

### Preflight Checklist

- [x] I have read the [Contributing Guidelines](https://github.com/EnAccess/micropowermanager/blob/main/CONTRIBUTING.md) for this project, if it exists.
- [x] I agree to follow the [Code of Conduct](https://github.com/EnAccess/micropowermanager/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [x] I have searched the [issue tracker](https://github.com/EnAccess/micropowermanager/issues) for a feature request that matches the one I want to file, without success.

### Problem Description

Plugins are given the possibility to provide a `plugin:install` command. This command is run automatically when the **first time** a plugin is enabled for a tenant.

This behaviour leads to a couple on inconveniences

- Users have to option to re-run these initialisation commands, for example when new changes or fixes have been added
- The check for "first time" is very obscure, i.e. `if (!$this->pluginsService->getByMpmPluginId($mpmPluginId) instanceof Plugins)`
- Painful developer experience as this leads to the need to reset the development demo data quite frequently.

### Proposed Solution

Please change the behaviour to

- Run `package:install` every time a plugin is enabled for a tenant

For this to work (apart from the obvious changes to the Plugin Service logic) a few steps have to be taken.

- Review each each Plugin's `install` command to make them **idempotent**, i.e. it should be save to run the `install` multiple times.
- Ensure Manufacturer registration is also **idempotent**

For example, an `install` command that creates default credentials using `->create()` should be changed to `->firstOrCreate()`

### Alternatives Considered

N/A

### Additional Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.