Conversation
Archiving moved to event listener
There was a problem hiding this comment.
Pull request overview
This PR introduces a plugin system that allows external code to react to link lifecycle events (creation, update, deletion) through an event-driven architecture. The existing Wayback Machine backup functionality has been refactored from a direct method call into an example plugin, demonstrating the new extensibility pattern.
Key Changes:
- Created
LinkCreated,LinkUpdated, andLinkDeletedevents dispatched fromLinkRepository - Implemented
PluginManagerthat uses reflection to auto-register plugin listeners based on theirhandlemethod signatures - Migrated Wayback Machine backup logic from
Link::initiateInternetArchiveBackup()toNewLinkToWaybackMachineplugin
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| app/Events/LinkCreated.php | New event class dispatched when a link is created |
| app/Events/LinkUpdated.php | New event class dispatched when a link is updated |
| app/Events/LinkDeleted.php | New event class dispatched when a link is deleted (passes ID only) |
| app/Helper/PluginManager.php | Core plugin registration logic using reflection to detect event types from handle method signatures |
| app/Providers/AppServiceProvider.php | Integrates plugin registration into application boot process |
| app/Plugins/NewLinkToWaybackMachine.php | Refactored Wayback Machine plugin demonstrating the new system |
| app/Models/Link.php | Removed initiateInternetArchiveBackup() method (migrated to plugin) |
| app/Repositories/LinkRepository.php | Updated to dispatch events instead of directly calling backup logic |
| config/linkace.php | Added plugin configuration with NewLinkToWaybackMachine as default |
| tests/Helper/PluginManagerTest.php | Tests plugin registration including union type support |
| tests/Plugins/NewLinkToWaybackMachineTest.php | Tests Wayback Machine plugin behavior with various settings |
| tests/Plugins/SamplePlugin.php | Test fixture demonstrating union type event handling |
| tests/Controller/Models/LinkControllerTest.php | Updated tests to verify events are dispatched instead of testing direct queue calls |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
The errors Codacy is coming up with are in mock classes that are only used for testing, which I don't see a reasonable way to fix. |
|
Awesome, many thanks for taking the time to work on this. I will go through the code as soon as I have a bit more time. But from what I saw yet, it's a good first step for a plugin system and I'm happy to merge this as soon as it's ready. |
Makes issues #203 #94 #18 and #496 much easier to solve.
This PR creates events for LinkCreated, LinkUpdated, and LinkDeleted and creates a simple plugin system to hook in to those events. The
SaveLinkToWaybackMachinejob has been moved to a plugin, which functions as a nice example for the system.New plugins should be classes with a
handlefunction with a typehinted$eventparameter. The system will identify which events the plugin listens to using reflection and register listeners for them. The plugin can then run a job to, say, index for full-text search or hit a webhook for a service to save screenshots or any other webhook. In theory, plugins can be separate packages that other authors are responsible for maintaining.It adds a config value called
pluginswhich expects an array of listener classes. (It also provides a default of just the SaveLinkToWaybackMachine plugin so that existing installs won't blow up when they're upgraded.) Admins can enable whichever plugins work for them.Possible enhancement: set plugins up to be per-user, though I think I prefer the idea of having them be system-wide with config settings per user enable/disable them (like
archive_backups_enabledcurrently does).