Cloned Questionnaire plugin - issue when both are installed

Cloned Questionnaire plugin - issue when both are installed

av heli g -
Antall svar: 7
We have a legacy cloned module which is a hack of the Questionnaire module. I have been trying to reproduce the hack for Moodle4.1 using the latest Questionnaire module code.
I was under the impression it was working perfectly until I also installed the Questionnaire module on the site. There is now this error when adding the cloned activity:
[22-Mar-2024 09:08:23 Africa/Johannesburg] Database transaction aborted automatically in /var/www/html/learndev/course/modedit.php
[22-Mar-2024 09:08:23 Africa/Johannesburg] Default exception handler: Exception - Class "questionnaire" not found Debug:
Error code: generalexceptionmessage
* line 1282 of /mod/questionnaire/lib.php: Error thrown
* line 208 of /course/modlib.php: call to mod_questionnaire_coursemodule_edit_post_actions()
* line 397 of /course/modlib.php: call to plugin_extend_coursemodule_edit_post_actions()
* line 190 of /course/modlib.php: call to edit_module_post_actions()
* line 170 of /course/modedit.php: call to add_moduleinfo()

When I uninstall the Questionnaire module the hacked module appears to be working again with no php errors. I don't understand why it is pointing to /mod/questionnaire/lib.php when Questionnaire is installed but has no issue when it is not installed. I have checked the code in the line mentioned and it does point to the new module name. When I comment our the function in the original Questionnaire code both activities can be added with no error. 

The function is this:

* Called after the activity and module have been created. Use this to copy any images if the questionnaire was created from another
 * questionnaire survey.

Why are two separate modules still pointing to the same code? What have I missed? I don't think I need that functionality in the hacked clone, but the Questionnaire module should not need to be modified for the custom plugin to work... If anyone can point me in the right direction to sort this out I would really appreciate it.

Thank you


Gjennomsnittlig vurdering: -
Som svar til heli g

Re: Cloned Questionnaire plugin - issue when both are installed

av AL Rachels -
Bilde av Core developers Bilde av Particularly helpful Moodlers Bilde av Plugin developers Bilde av Testers
I bet that you did not change all the items that needed to be renamed in your hacked version of the plugin. Then when you installed the normal version, the name is already taken and creates the bug. When you hack a plugin and make your own version, you need to search and replace the old name in every location and in every file. e.g. myquestionnaire instead of questionnaire. For instance, I did this to the Journal plugin to create the Diary plugin from it. Using match case, I searched for EVERY occurrence of "journal" and changed to "diary" and I also had to search and replace "Journal" with "Diary." Once I made all the changes, I made sure that both plugins worked singly and then together without interference, and then started making changes to Diary so that it would do what I wanted it to do.
Gjennomsnittlig vurdering:Useful (2)
Som svar til AL Rachels

Re: Cloned Questionnaire plugin - issue when both are installed

av heli g -
That must be it... damn. I really thought I had done the search and replace perfectly.
But this reminds me, I have been meaning to check out your Diary plugin. Thanks for the reminder smiler
Som svar til heli g

Re: Cloned Questionnaire plugin - issue when both are installed

av heli g -
Unfortunately I can't see that I missed anything with the search and replace. I was so hoping I would.
Som svar til heli g

Re: Cloned Questionnaire plugin - issue when both are installed

av AL Rachels -
Bilde av Core developers Bilde av Particularly helpful Moodlers Bilde av Plugin developers Bilde av Testers

Your debug message is pointing to your hacked questionnaire lib.php file for the function, mod_questionnaire_coursemodule_edit_post_actions(). Look and compare it to the same function in the lib.php file in the questionnaire plugin.

You might also want to check in the database table, mdl_config_plugins. Do a search using something like phpMyAdmin where it will let you search the "plugin" field using Like %...% as the operator and value of questionnaire. I suspect a problem there as I only have the questionnaire plugin installed and there are four config settings with a different plugin name than the other twelve settings. I accidentally did this one time and it was a mess to fix. Your hacked plugin cannot safely share anything with the same name there.

Som svar til AL Rachels

Re: Cloned Questionnaire plugin - issue when both are installed

av heli g -
What is so weird for me is that the debug message is pointing to the original questionnaire lib.php. When I comment out the code in the questionnaire module, both modules appear to work with no issue. When I comment it out in the hacked "qpaquest" lib.php, it has no effect. Interestingly in the the 3.9 version where they both worked together, qpaquest does not include this code, while questionnaire does (but then questionnaire has been upgraded, while qpaquest has not been kept up to date).

I checked mdl_config_plugins and both have 17 entries (some of which are prefixed with mod_ - good catch). I checked the 3.9 versions and qpaquest has one fewer record. It does not include 'allowemailreporting' - but I don't think this is relevant.


I have compared the function and I cannot see what could be causing the issue... I am going to go through everything again, hopefully I can spot something I have missed this time.


Som svar til heli g

Re: Cloned Questionnaire plugin - issue when both are installed

av heli g -
I have gone down so many rabbit-holes trying to get to the bottom of this. (It must be so frustrating for people who write and understand code to have desperate copy and paste-ers like myself fumbling around). I even started from scratch twice and to my horror successfully reproduced the issue. Eventually in desperation I commented out references to 'copy' in lib.php that did not exist in the 3.5 hack that was working in 3.9.
Namely
  $copyfiles = false; on line 95
  $qpaquest->copyid = $copyid; on line 139
and the whole copy function starting on 1277 in the error above.

... and... it appears to be working now. At least I can add new instances with no error reported as yet. I will do extensive testing and hope for the best. I just wish I could understand more about what I am doing.
Thank you so much for your time AL smiler
Som svar til heli g

Re: Cloned Questionnaire plugin - issue when both are installed

av AL Rachels -
Bilde av Core developers Bilde av Particularly helpful Moodlers Bilde av Plugin developers Bilde av Testers
Hi heli g,
I am sorry to read that you have not found the "smoking gun" but I am happy that you do have it working the way you want it too. I truly sympathies with your "frustrating" feeling of "fumbling around" because that seems to be mostly what I do.
Gjennomsnittlig vurdering:Useful (1)