Repository navigation
Conversation
146ff4d to
48904ea
Compare
|
@rmellmer can you take a look at these changes and see if they correctly finish out what you think the rest of the feature was going to look like? Can you see any potential downsides to this implementation? If not, I think we will just merge this branch so I can begin moving forward with porting plugins that are in my current production OSPOS 3.2.2 environment to this repo. |
|
@objecttothis check the README.md in the plugins folder of this PR for a reference on how the system would work. The PR description is a bit outdated (after your comments) |
objecttothis
left a comment
There was a problem hiding this comment.
@jekkos I have a much better feel for how you have the architecture setup here and in general I like it, but I have a few questions regarding how multi-language strings, injecting plugin code into core code views and how to vet code security. See my questions below
…events This implements a clean plugin architecture based on PR #4255 discussion: Core Components: - PluginInterface: Standard contract all plugins must implement - BasePlugin: Abstract class with common functionality - PluginManager: Discovers and loads plugins from app/Plugins/ - Plugin_config: Model for plugin settings storage Architecture: - Each plugin registers its own event listeners via registerEvents() - No hardcoded plugin dependencies in core Events.php - Generic event triggers (item_sale, item_change, etc.) remain in core code - Plugins can be enabled/disabled via database settings - Clean separation: plugin orchestrators vs MVC components Example Implementations: - ExamplePlugin: Simple plugin demonstrating event logging - MailchimpPlugin: Integration with Mailchimp for customer sync Admin UI: - Plugin management controller at Controllers/Plugins/Manage.php - Plugin management view at Views/plugins/manage.php Database: - ospos_plugin_config table for plugin settings (key-value store) - Migration creates table with timestamps Documentation: - Comprehensive README with architecture patterns - Simple vs complex plugin examples - MVC directory structure guidance
- PluginManager now recursively scans app/Plugins/ to discover plugins - Supports both single-file plugins (MyPlugin.php) and directory plugins (MyPlugin/MyPlugin.php) - Plugins can contain their own Models, Controllers, Views, Libraries, Helpers - Uses PSR-4 namespacing: App\Plugins\PluginName for files, App\Plugins\PluginName\Subdir for subdirectories - Users can install plugins by simply dropping a folder into app/Plugins/ - Updated README with comprehensive documentation on both plugin formats This makes plugin installation much easier - just drop the plugin folder and it works.
48904ea to
bd8b4fa
Compare
…views Add event-based view hook system allowing plugins to inject UI elements into core views without modifying core files. Includes helper functions and example CasposPlugin demonstrating the pattern.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
…language files Adds documentation example showing how plugins can embed their own language files within the plugin directory structure, keeping plugins fully self-contained without modifying core language files.
|
I've updated the README.md with a new Internationalization (Language Files) section that shows how plugins can include self-contained language files. The example demonstrates:
This keeps plugins fully self-contained - no need to modify core See commit 6bd4bb5 for the changes. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
objecttothis
left a comment
There was a problem hiding this comment.
Take a look at my comments on the readme. Languages is now much clearer to me. Views is also cleaner this way because it limits plugin code.
Sorry it took me so long to get back to looking at this. I just scanned through and looks good to me, seems in line with what I was thinking it would be. |
- Add Language folder to all plugin structure examples - Convert snake_case to camelCase for class names (PSR-12) - Add Language folder to initial plugin structure diagram - Add Language folder to Complex Plugin structure - Update all namespace references to use camelCase
This comment was marked as resolved.
This comment was marked as resolved.
objecttothis
left a comment
There was a problem hiding this comment.
I got through 9 of the files. I'll take a look at the rest later.
- Consolidate duplicate documentation sections - Move Internationalization section after Plugin Views - Remove redundant Example Plugin Structure and View Hooks sections - Fix PSR-12 brace style in plugin_helper.php - Fix PSR-12 brace style in PluginInterface.php (remove unnecessary PHPdocs) - Fix PSR-12 brace style in BasePlugin.php (remove unnecessary PHPdocs) - Use log_message() instead of error_log() in migration - Add IF NOT EXISTS to plugin_config table creation for resilience - Convert snake_case to camelCase for class names throughout docs
This comment was marked as resolved.
This comment was marked as resolved.
Add getExportDataBulk() to Item model for plugin use. - Fetches item_id, item_number, name, description, unit_price, and pic_filename for multiple item IDs in single query - Returns results keyed by item_id for easy lookup - Guards against empty input array Signed-off-by: objecttothis <[email protected]>
Add explicit guidance in AGENTS.md and app/Plugins/README.md stating core code must never reference a specific plugin. - Clarify no plugin name/path may appear in composer.json, package.json, app/Config/*, or other core files - State plugins resolve solely via PSR-4 autoloading and PluginManager runtime auto-discovery - Note installing/removing a plugin must never require editing files outside app/Plugins/<PluginName>/ Signed-off-by: objecttothis <[email protected]>
Resolve language file conflicts: take master's translations, strip MailChimp phrases (MailChimp is now a plugin instead of core), and retain plugin-system additions (plugins/plugins_configuration keys). Co-Authored-By: Claude Sonnet 5 <[email protected]>
Remove Georgian (ka) locale entries for mailchimp integration strings that are no longer referenced in the app. - app/Language/ka/Config.php: drop mailchimp_* config labels - app/Language/ka/Customers.php: drop mailchimp_activity_*, mailchimp_info, mailchimp_member_rating, mailchimp_status, mailchimp_vip entries Signed-off-by: objecttothis <[email protected]>
MailchimpConnector called curl_close($ch) immediately after curl_exec, before checking curl_errno/curl_error on failure. Closing the handle early invalidates it for any subsequent curl_getinfo/curl_error calls that rely on the handle. - Drop curl_close call in MailchimpConnector.php so the handle stays valid through error inspection; connector is responsible for closing it later where appropriate Signed-off-by: objecttothis <[email protected]>
…m-fresh # Conflicts: # app/Controllers/Items.php # app/Models/Item.php # app/Models/Stock_location.php # app/Views/items/form_count_details.php
Align method naming with codebase conventions by converting snake_case model/controller methods to camelCase. - Employee::get_info -> getInfo, updated in Employees and Sales controllers - Sale::get_info -> getInfo, updated in Sales controller - Item::get_multiple_info -> getMultipleInfo, updated in ItemTest - Customers import: fix loop counter bug where $i was reused/ reassigned inconsistently, renamed to $rowNumber with ++$rowNumber pre-increment for clarity - Sales::save_row_customer_data: fix variable typo $sale_id -> $saleId to match surrounding naming and avoid undefined variable Signed-off-by: objecttothis <[email protected]>
Rename snake_case locals (cash_adjustment, amount_tendered, sale_id, sale_info) to camelCase (cashAdjustment, amountTendered, saleId, saleInfo) in Sales::processPayment cash-adjustment branch. Aligns with surrounding camelCase usage (amountTendered, saleInfo already referenced below in the same block) and fixes undefined-variable bug caused by naming mismatch. Signed-off-by: objecttothis <[email protected]>
- Fix broken array/method chain in debug-js task where a stray string concatenation left `.pipe(rev()).pipe(gulp.dest(...))` embedded inside the file list array instead of after it - Close file list array properly after plugin_data_helper.js entry so the pipeline methods run once, after the array is complete Signed-off-by: objecttothis <[email protected]>
Map plugin.svg source icon to plugins.svg in MENUBAR_ICONS list so build pipeline generates correct icon for plugins menu item. Signed-off-by: objecttothis <[email protected]>
- composer.json: exclude Plugins/*/Migrations from classmap, matching existing Database/Migrations exclusion so plugin migration classes aren't autoloaded directly - composer.json: widen platform PHP requirement from ^8.2 to allow patch ranges across 8.2/8.3/8.4 (>=8.2.35 <8.3 || >=8.3.36 <8.4 || >=8.4.27), likely to exclude vulnerable patch versions - composer.lock: regenerate content-hash to match composer.json changes Signed-off-by: objecttothis <[email protected]>
- Add allowScripts entry for [email protected] in package.json so its postinstall lifecycle script is permitted during install Signed-off-by: objecttothis <[email protected]>
… table - Rename core migration 20260627000000_PluginMigrationsTableCreate to 20261026000000_PluginConfigTableCreate, merging plugin_migrations table creation into the same SQL script as plugin_config and adding a startup log message; down() now drops both tables. - Consolidate the plugin_migrations CREATE TABLE statement into 3.5.0_PluginConfigTableCreate.sql and remove the now-redundant 3.5.1_PluginMigrationsTableCreate.sql script. - Update app/Plugins/README.md reference to the renamed migration class. - Add WhatsAppPlugin migration CreateWhatsAppMessagesTable to create the whatsapp_messages conversation log table (utf8mb4, unique wa_message_id to dedupe webhook redelivery); dropped explicitly by WhatsAppPlugin::uninstall() instead of a down() method. Signed-off-by: objecttothis <[email protected]>
…m-fresh # Conflicts: # app/Controllers/Customers.php # app/Models/Item.php
…m-fresh Resolve language-file conflicts by taking master's English-removal cleanup across non-English locales, while stripping the MailChimp keys master reintroduced (already moved to MailchimpPlugin on this branch) and reapplying this branch's plugins/integrations rename and new Module.php plugins keys where master lacked them. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Remove 'integrations' and 'integrations_configuration' (and 'plugins'/'plugins_configuration' in ckb) entries from Config.php across all language files under app/Language/*. - Dead keys no longer referenced in UI, dropped repo-wide for consistency across locales (ar-EG, ar-LB, az, bg, bs, ckb, cs, da, de-CH, de-DE, el, en-GB, en, es-ES, es-MX, fa, fr, and others) - Keeps all language Config.php files structurally in sync Signed-off-by: objecttothis <[email protected]>
- Add static getParsedFile() helper that caches include-based file parses per file path - Replace repeated `include $file` calls in testLanguageFile_ParsesToArray, key-matching, and key-sorting tests with calls to the cached helper - Avoid redundant file includes/parsing when the same language file is loaded across multiple test methods, speeding up the test suite Signed-off-by: objecttothis <[email protected]>
…m-fresh # Conflicts: # app/Config/Filters.php
Summary
This PR implements a modular plugin system for OSPOS, based on the design discussion in
#4255. Plugins are self-contained: they register their own event listeners, ship their own MVC components, their own translations, and their own logs — keeping the core free of hardcoded plugin dependencies.Core Infrastructure
PluginInterface(app/Libraries/Plugins/PluginInterface.php) — contract every plugin must implement (getPluginId(),getPluginName(),getPluginDescription(),getVersion(),registerEvents(),install(),uninstall(),isEnabled(),getConfigView(),getSettings(),saveSettings()).BasePlugin(app/Libraries/Plugins/BasePlugin.php) — abstract base class providing settings persistence (getSetting()/setSetting()/getSettings()/saveSettings(), JSON-encoding arrays/objects) and plugin-scoped logging (log()/logTo()).PluginManager(app/Libraries/Plugins/PluginManager.php) — discovers plugin classes underapp/Plugins/, validates them withis_subclass_of(PluginInterface), and registers events only for plugins that are enabled. Namespaces are loaded duringpre_system(registerAllNamespaces()) so plugin handlers can register before any event fires.PluginLogger(app/Libraries/Plugins/PluginLogger.php) — routes plugin log output to per-plugin log files (WRITEPATH/logs/plugins/{pluginId}.log) instead of the main application log, avoiding log spam as more plugins are installed. Exposed via thelog_plugin_message()helper and thelog()/logTo()methods onBasePlugin.PluginConfig(app/Models/PluginConfig.php) — model backed by theospos_plugin_configtable (id,plugin_id,key,value,is_control, timestamps, with aUNIQUE KEY (plugin_id, key)). Accessors are namedgetValue()/setValue()(notget()/set()) to avoid conflicting withCodeIgniter\Model.20250531000000_PluginConfigTableCreate.phpcreates theospos_plugin_configtable (with adown()rollback) and seeds thepluginsmodule/permission/grants.Example Implementation
MailchimpPlugin(app/Plugins/MailchimpPlugin/) — the working reference plugin, refactored from the previous core Mailchimp integration. Demonstrates settings storage, a self-containedLanguage/{locale}/MailchimpPlugin.phptranslation file with alang()helper, and safe logging (customer ID logged instead of email).Internationalization
Plugins keep their own translations self-contained under
Plugins/{PluginName}/Language/{locale}/{PluginName}.php, loaded via alang()helper — no need to modify coreapp/Language/files. SeeREADME.mdinapp/Plugins/for the full pattern.Admin UI
Pluginscontroller (app/Controllers/Plugins.php) — lists/searches plugins, and exposes enable/disable/uninstall/configure endpoints.pluginspermission/module wired intoADMIN_MODULESand the menu.Design Notes
item_saved,customer_saved,customer_loaded) pass only the relevant ID(s); plugins query the model for anything else they need. This keeps events from becoming a permanent, ever-growing data contract, and lines up with a future REST API for plugins.customer_deletedis a narrow exception — it must carry['id' => $customerId, 'email' => $email]captured before deletion/anonymization, since the record (and the email specifically, when "enforce privacy" is enabled) is not reliably queryable afterward.Documentation
README.md(underapp/Plugins/) documents plugin structure, i18n, examples, and usage.Related
#4255#4404(closed due to merge conflicts)