At the moment, Koha plugins implementing the "background_jobs" hook can't provide a template to "View" the job. Instead, you get an error like: Template process failed: file error - background_jobs/plugin_TYPE_ACTION.inc: not found at /kohadevbox/koha/C4/Templates.pm line 127 This should be a pretty easy fix. Basically, Koha::BackgroundJob should have a method that returns "background_jobs/{job type}" and a Koha plugin can override this method to provide its own template. We use the ABSOLUTE option for Template::Toolkit, so you can provide an absolute filepath to a template within the plugin and it'll get processed.
Another solution would be to let plugins add paths to Template::Toolkit's INCLUDE_PATH option. It would also allow plugin's templates to INCLUDE their own .inc files
Created attachment 157323 [details] [review] Bug 35070: Proof of concept Add the following methods to your plugin sub template_include_paths { my ($self) = @_; return [ $self->mbf_path('inc'), ] } Then create a file Koha/Plugin/YourPlugin/inc/background_jobs/plugin_NAMESPACE_JOBTYPE.inc with 3 TT BLOCKs: "process", "report" and "js"
(In reply to Julian Maurice from comment #1) > Another solution would be to let plugins add paths to Template::Toolkit's > INCLUDE_PATH option. It would also allow plugin's templates to INCLUDE their > own .inc files I was thinking about that the other day. Sounds good to me I think.
Created attachment 159205 [details] [review] Bug 35070: Add plugin hook template_include_paths It allows to add paths to Template::Toolkit's INCLUDE_PATH option http://template-toolkit.org/docs/manual/Config.html#section_INCLUDE_PATH Test plan: 1. Install the modified kitchen sink plugin: git clone --branch template-include-paths \ https://github.com/jajm/dev-koha-plugin-kitchen-sink.git 2. Run misc/devel/install_plugins.pl 3. Restart memcached and koha 4. Go to Administration -> Manage Plugins 5. Run the KitchenSink plugin's tool 6. Click on "Schedule greeting" 7. Go to Administration -> Manage jobs 8. If you don't see any jobs, uncheck "Current jobs only" 9. You should see a job of type "Unknown job type 'plugin_kitchensink_greeter". Click on the "View" button 10. Under the Report section you should see "This is the report block" 11. Under the Detailed messages section you should see "This is the detail block" 12. Open the browser console, you should see a message "This is the js block"
Added a test, and forked the kitchen sink plugin so that it's easier to test.
Created attachment 159248 [details] [review] Bug 35070: Add plugin hook template_include_paths It allows to add paths to Template::Toolkit's INCLUDE_PATH option http://template-toolkit.org/docs/manual/Config.html#section_INCLUDE_PATH Test plan: 1. Install the modified kitchen sink plugin: git clone --branch template-include-paths \ https://github.com/jajm/dev-koha-plugin-kitchen-sink.git 2. Run misc/devel/install_plugins.pl 3. Restart memcached and koha 4. Go to Administration -> Manage Plugins 5. Run the KitchenSink plugin's tool 6. Click on "Schedule greeting" 7. Go to Administration -> Manage jobs 8. If you don't see any jobs, uncheck "Current jobs only" 9. You should see a job of type "Unknown job type 'plugin_kitchensink_greeter". Click on the "View" button 10. Under the Report section you should see "This is the report block" 11. Under the Detailed messages section you should see "This is the detail block" 12. Open the browser console, you should see a message "This is the js block" Signed-off-by: David Nind <david@davidnind.com>
Testing notes (using KTD): 1. The first step in the test plan didn't work for me. Instead, I cloned the repository and moved the dev-koha-plugin-kitchen-sink/Koha directory to /var/lib/koha/kohadev/plugins/. 2. Plugins are already enabled in the kohadev/koha-conf.xml file, with the plugins directory set as /var/lib/koha/kohadev/plugins/
Created attachment 159901 [details] [review] Bug 35070: Add plugin hook template_include_paths It allows to add paths to Template::Toolkit's INCLUDE_PATH option http://template-toolkit.org/docs/manual/Config.html#section_INCLUDE_PATH Test plan: 1. Install the modified kitchen sink plugin: git clone --branch template-include-paths \ https://github.com/jajm/dev-koha-plugin-kitchen-sink.git 2. Run misc/devel/install_plugins.pl 3. Restart memcached and koha 4. Go to Administration -> Manage Plugins 5. Run the KitchenSink plugin's tool 6. Click on "Schedule greeting" 7. Go to Administration -> Manage jobs 8. If you don't see any jobs, uncheck "Current jobs only" 9. You should see a job of type "Unknown job type 'plugin_kitchensink_greeter". Click on the "View" button 10. Under the Report section you should see "This is the report block" 11. Under the Detailed messages section you should see "This is the detail block" 12. Open the browser console, you should see a message "This is the js block" Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 159902 [details] [review] Bug 35070: Tidy Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Julian, can you add a test proving plugin authors cannot override (maliciously) core templates?
Created attachment 159938 [details] [review] Bug 35070: Add test verifying plugins cannot override core templates
The added test is not very robust, as it depends on the existence of a specific core template. If this core template is renamed or removed, the test will fail. That's the best I can do right now.
(In reply to Julian Maurice from comment #12) > The added test is not very robust, as it depends on the existence of a > specific core template. If this core template is renamed or removed, the > test will fail. > That's the best I can do right now. Tomas, can you please check if Julian's follow-up does what you had in mind?
Created attachment 160378 [details] [review] Bug 35070: Add test verifying plugins cannot override core templates Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This should be backported to stables, IMHO.
FAIL t/lib/plugins/Koha/Plugin/Test/inc/csrf-token.inc FAIL filters missing_filter at line 2 ([%~ 'OVERRIDE' ~%]) Will fix.
Pushed for 24.05! Well done everyone, thank you!
t/db_dependent/selenium/00-onboarding.t is failing I am seeing this in the logs: DBIx::Class::Storage::DBI::_dbh_execute(): Table 'koha_kohadev.plugin_data' doesn't exist at /kohadevbox/koha/Koha/Plugins.pm line 122 at /usr/share/perl5/DBIx/Class/Exception.pm line 77 DBIx::Class::Exception::throw('DBIx::Class::Exception', 'Table \'koha_kohadev.plugin_data\' doesn\'t exist', 0) called at /usr/share/perl5/DBIx/Class/Schema.pm line 1118 DBIx::Class::Schema::throw_exception('Koha::Schema=HASH(0x55fc8aec4730)', 'Table \'koha_kohadev.plugin_data\' doesn\'t exist') called at /usr/share/perl5/DBIx/Class/Storage.pm line 113
Should we add a followup here or on a new bug report ?
Created attachment 160565 [details] [review] Bug 35070: Fix get_enabled_plugins when database is not created yet Koha::Plugins::get_enabled_plugins is called by Koha::Plugins::call which is called by C4::Templates->new, which is used in the web installer when the database is not created yet
I didn't try t/db_dependent/selenium/00-onboarding.t but I was able to reproduce the error by running the web installer. After the patch I was able to complete the installation and the onboarding process.
Pushed the follow-up to master. Thanks for taking care of this so quickly!
Hook moved in wiki page : https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks#Implemented_hooks
Pushed to 23.11.x for 23.11.02
Backported to 23.05.x for upcoming 23.05.08