Skip to content

Feature plugins framework #4255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Conversation

objecttothis
Copy link
Member

This framework provides the custom events which, when triggered, can be used by plugins to make API calls or other read-only data manipulations.

  1. A plugins folder will be created in app/Controllers, and app/Models for plugins to place their code to be called.
  2. Model code for now will be restricted to read-only function calls. Plans for a API endpoints allowing controlled read and write operations are in place.
  3. Each plugin will be allowed a table in the database for its use. Read and write operations will be allowed by the plugin to this table.
  4. A plugin_settings table will be created for plugin settings storage (api keys, behavioral settings, etc). keys will be named [pluginName]_[keyName] format.

- Add custom events for item changes, sales, returns, and inventory.
- Add custom events for item and customer csv imports.

Signed-off-by: objecttothis <objecttothis@gmail.com>
- Add custom events for item changes, sales, returns, and inventory.
- Add custom events for item and customer csv imports.
- Refactor variable names for PSR-12 compliance.
- Refactor function names for PSR-12 compliance.
- Moved retrieving of $employeeId to actually where it's going to be used for readability.
- Added trigger point for item save.
- Added trigger point for item delete.
- Added debug logging for item_change event trigger.
- Added itemId to be sent in the item_change event.

Signed-off-by: objecttothis <objecttothis@gmail.com>
@objecttothis objecttothis added this to the 3.5.0 milestone May 29, 2025
@objecttothis objecttothis self-assigned this May 29, 2025
@@ -65,3 +65,52 @@

$method = new Method();
Events::on('pre_controller', [$method, 'validate_method']);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jekkos can you think of other events that we want to include?


echo json_encode(['success' => true, 'message' => $message, 'id' => $item_id]);
Events::trigger('item_change', $itemId);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jekkos this is an example of the trigger. It's nice and clean because none of the plugin code gets injected here. Just these triggers.

* This event triggered when an item is changed. This can be an item create, update or delete.
* Plugin functionality is triggered here.
*/
Events::on('item_change', static function (int $itemId): void {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$itemId is an example of being able to pass data from the trigger point. So for example, when someone changes an item, it sends the itemId that was changed here and, let's say a plugin decides to make an API call to a website to update the item on the website. In this static function we could call the controller method of the plugin to make the API call. Easy peasy. Plugin Controller code is in it's own space.

@objecttothis
Copy link
Member Author

The refactoring of variable and function names to camelCase are variables and functions in sections of code I am modifying and are for PSR-12 compliance.

objecttothis and others added 4 commits May 29, 2025 21:07
- Place trigger in Sale Controller.
- Refactor variable names to camelCase for PSR-12 compliance
- Refactor function names to camelCase for PSR-12 compliance
- Minor readability refactoring of if/else to ternary notation
- Removed hungarian notation

Signed-off-by: objecttothis <objecttothis@gmail.com>
- Refactor function names to camelCase for PSR-12 compliance

Signed-off-by: objecttothis <objecttothis@gmail.com>
- This fix properly creates Primary Keys on both MariaDB and MySQL

Signed-off-by: objecttothis <objecttothis@gmail.com>
- Migration to create the table in the database
- Removed unneeded using statements

Signed-off-by: objecttothis <objecttothis@gmail.com>
@objecttothis
Copy link
Member Author

@jekkos we need to make a few design decisions with this.

image

  1. We need to refactor Integrations to Plugins. This means the Config.integrations and Config.Integrations_configuration need to be renamed to Config.Plugins and Config.Plugins_configuration. How do we do this in such a way that weblate retains the values that were in the former fields? People can then update the translations through weblate.
  2. I think Mailchimp API is a prime candidate to refactor into the first plugin. It's already in the codebase and functioning. We just need to move the settings variables from ospos_app_config to ospos_plugin_config.
  3. I think we need to create a new language file called Plugins.php which will contain all the language strings for plugins. This keeps with our efforts to segregate plugin code from the rest of the codebase.

The question is how to do 1 and 3 so that weblate does not flip out. Also, do you have any objection to 2?

- Renamed view from integrations_config to plugins_config.php
- Added Plugin
- Added todo in the code for refactoring
- Refactored config.php strings
- Moved mailchimp strings to Plugins.php for en.  We will need to do this for all the languages perhaps to retain current translations.
- Refactored view to use plugins naming

Signed-off-by: objecttothis <objecttothis@gmail.com>
- Renamed view from integrations_config to plugins_config.php
- Added Plugin
- Added todo in the code for refactoring
- Refactored config.php strings
- Moved mailchimp strings to Plugins.php for en.  We will need to do this for all the languages perhaps to retain current translations.
- Refactored view to use plugins naming
- Refactored Savefunction name
- Refactored view identifiers to be more generic
- Added Plugins folders in Controllers, Models and Views
- Refactored check_encryption function for PSR-12 compliance

Signed-off-by: objecttothis <objecttothis@gmail.com>
@odiea
Copy link
Collaborator

odiea commented May 31, 2025

I don't know why the following is happening when trying to get a migration.

CRITICAL - 2025-05-31 15:06:25 --> Error: Call to undefined function App\Database\Migrations\execute_script()
[Method: POST, Route: login]
in APPPATH\Database\Migrations\20250531000000_PluginConfigTableCreate.php on line 16.
 1 SYSTEMPATH\Database\MigrationRunner.php(866): App\Database\Migrations\PluginConfigTableCreate->up()
 2 SYSTEMPATH\Database\MigrationRunner.php(182): CodeIgniter\Database\MigrationRunner->migrate('up', Object(stdClass))
 3 APPPATH\Controllers\Login.php(67): CodeIgniter\Database\MigrationRunner->latest()
 4 SYSTEMPATH\CodeIgniter.php(933): App\Controllers\Login->index()
 5 SYSTEMPATH\CodeIgniter.php(507): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Login))
 6 SYSTEMPATH\CodeIgniter.php(354): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
 7 SYSTEMPATH\Boot.php(334): CodeIgniter\CodeIgniter->run()
 8 SYSTEMPATH\Boot.php(67): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter))
 9 FCPATH\index.php(56): CodeIgniter\Boot::bootWeb(Object(Config\Paths))

@objecttothis
Copy link
Member Author

I don't know why the following is happening when trying to get a migration.

CRITICAL - 2025-05-31 15:06:25 --> Error: Call to undefined function App\Database\Migrations\execute_script()
[Method: POST, Route: login]
in APPPATH\Database\Migrations\20250531000000_PluginConfigTableCreate.php on line 16.
 1 SYSTEMPATH\Database\MigrationRunner.php(866): App\Database\Migrations\PluginConfigTableCreate->up()
 2 SYSTEMPATH\Database\MigrationRunner.php(182): CodeIgniter\Database\MigrationRunner->migrate('up', Object(stdClass))
 3 APPPATH\Controllers\Login.php(67): CodeIgniter\Database\MigrationRunner->latest()
 4 SYSTEMPATH\CodeIgniter.php(933): App\Controllers\Login->index()
 5 SYSTEMPATH\CodeIgniter.php(507): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Login))
 6 SYSTEMPATH\CodeIgniter.php(354): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
 7 SYSTEMPATH\Boot.php(334): CodeIgniter\CodeIgniter->run()
 8 SYSTEMPATH\Boot.php(67): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter))
 9 FCPATH\index.php(56): CodeIgniter\Boot::bootWeb(Object(Config\Paths))

This happened to me the other day but it was because I tried to run a migration when my .env file had already been modified by the upgrade to CI4 which converts encryption from CI3 encryption to CI4 in the database and lengthens the encryption key. I've thought about making it more robust, but really it's a use case that should only be encountered during testing. Are you migrating a clean or pre-existing database? before running the migration did you have a CI3 key or was it a CI4 key?

@odiea
Copy link
Collaborator

odiea commented Jun 2, 2025

I really don't know. I use what db happens to be available at the time. Probably multiple pre-existing ci3 databases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants