This PR contains the content of three major improvements achieved in the last two months.
Those three improvements can be described as follows:
translation of the content and content_format fields from the item plugin specific tables (surveypro(field|format)_itemplugin) to the parent table (surveypro_item).
This first result is described in the content_among_basics branch (https://github.com/kordan/moodle-mod_surveypro/tree/content_among_basics).
I have never created a pull request for this branch because I have never been able to perform a rebase that satisfied me.
In practice: the method, named in master "item_add_mandatory_base_fields" was renamed in the branch to "item_add_defaults_for_base_fields".
By rebasing content_among_basics on master the rename of the method was discarded so, after the rebase, I still found the original name.
I spent a few days trying to understand the reason for this behavior. I asked my colleagues and then abandoned the problem.
translation of the most frequent properties (among all item plugins) from the specific item plugin tables (surveypro(field|format)_itemplugin) to the parent table (surveypro_item).
This second step is clearly the natural continuation of the previous one and, for this reason, I created this new branch (https://github.com/kordan/moodle-mod_surveypro/tree/others_to_base_property) on top of content_among_basics.
Once I had a clear idea of how the itemplugin attributes were managed, I finally proceeded to adapt surveypro to php8.2 by creating the php8.2 branch.
Obviously this branch was created on top of others_to_base_propertye, consequently, the php8.2 merge makes the first two branches useless.
The outcome of "content_among_basics" is described in (1).
The outcome of "others_to_base_property" is described in (2).
The outcome of "php8.2" is described in (3).
=====================================================
(1) Content and contentformat moved among base fields
As part of a work of standardization and modernization of the module aimed at making the code homogeneous and, consequently, easily understandable and modifiable, I realized that the use of PHP 8.2 highlights a significant and very long series of errors that I must absolutely address.
The first error among these is that the class of each item (item = fields + format) must have its own properties that it must manage on its own. But to define the list of properties of each item I have to decide which properties to consider "common" to all items and which to consider "specific" to each individual item.
There are two reflections related to this problem:
Theoretically there are very few properties common to all items. Among these I only see: hidden, insearchform and reserved. All the others cannot be common to ALL items because, for example, the "pagebreak" item only has these three properties just mentioned;
I already accepted this "lack" of properties ACTUALLY common to all items when I chose to create the itemsetup form (the form to setup a new item for the surveypro) from the union of a "item_setupbaseform" and an "itemsetupform".
The item_setupbaseform has the fields it has and each item has a rule that says what it wants in its form and what it doesn't want to appear. (Each item defines a static vector called insetupform which declares what it wants to appear in the item_setupbaseform and what not. Obviously there is no similar vector for the specific form of each item because, having been created for the single item, it contains only and exclusively whatever you want.)
I therefore realize that the answer to the question: which properties must be classified as "common" to all items and which, instead, must be classified as "specific" of each individual item is in the list of fields that I included, 10 years ago, in the "itemsetupbaseform" and in the "itemsetupform".
So in order to make the code more homogeneous and self-consistent, I have to start moving all the "common" fields from the tables of each individual item ('surveypro'.$type.''.$plugin) to the surveypro_item table.
The two most difficult fields to move are 'content' and 'contentformat'. This is the reason that led me to this PR.
I lose compatibility with the past. I will write somewhere that if you want to keep your usertemplates and mastertemplates, you need to:
-- before upgrading surveypro you have to load each usertemplate and mastertemplate into a course;
-- upgrade your surveypro;
-- regenerate each usertemplate and each mastertemplate.
obviously the next PR I will make will relate to moving the other "common" properties from the specific tables to the surveypro_item table (and I will create them on top of this one).
=====================================================
(2) Each common propery is now saved to surveypro_item
When "content_among_basics" (that saves content and contentformat to surveypro_item and no longer into db tables of item plugins) and this PR will land to mastwer, I hope all will be ready to start to modify surveypro to let it correctly run in php8.2 and 8.3.
With this PR the situation of properties should be:
All the properties in the first column are relative to a field of the table surveypro_item.
All the properties in the first column correspond to a field of the item_setupbaseform that is the initial part of each itemsetupform.
Not all the items use ALL of that properties. They declare the use of each property throught $this->insetupform[] = (false|true);
If $this->insetupform[] == false, the corresponding field in the formbase is not displayed in item_setupbaseform (and the useless default goes into the database).
Marked with (h) are properties hidden to user.
In the next table the list of specific properties item per item.
These properties are save in surveypro(field|format)_.
Yes, some of them coincide, but the number of plugins sharing the same property is too low and even the semantic is too specific of each single plugin so
I decided to save these properties among the fields of the child table and not in surveypro_item.
=====================================================
(3) php8.2
This improvement makes surveypro compatible with php8.2.
There is some small problem, however, that I don't understand and which, for this reason, I describe below.
The problem that php8.2 raises is practically always linked to the fact that I can not evaluate a property without first declare it.
One of the properties common to all surveypro items is "content" (alias, the content of the question) followed by the content_format. To define an item via the corresponding form at submission time, the HTML editor is processed through
file_prepare_standard_editor that changes the content_editor property. When I pass the object $item to the file_prepare_standard_editor method, php8.2 raises an exception claiming that the content_editor property (that I must have defined previously) and that I have defined as protected cannot be modified because it is protected. I know it is a good practice to always define properties as protected so my question is: How should I behave? Do I have to make the property public?
(b) Furthermore, but this is a completely secondary detail, protected $content_editor is considered an error by Code Checker.
FILE: /home/runner/work/moodle-mod_surveypro/moodle-mod_surveypro/moodle/mod/surveypro/classes/itembase.php
93 | ERROR | [x] Member variable "content_editor" must not contain underscores.
| | (moodle.NamingConventions.ValidVariableName.MemberNameUnderscore)
1128 | ERROR | [x] Variable "content_editor" must not contain underscores.
| | (moodle.NamingConventions.ValidVariableName.VariableNameUnderscore)
1129 | ERROR | [x] Variable "content_editor" must not contain underscores.
| | (moodle.NamingConventions.ValidVariableName.VariableNameUnderscore)
(c) In php8.2 and moodle master, I frequently get the error "Javascript code and/or AJAX requests are not ready after 10 seconds".
At my eyes, it seems related to TinyMCE editor. Executing a submission of the item_setupbaseform with values that inhibit the submission itself, when the form is reloaded it is impossible to paste something in the content textarea.
(d) I'm having a problem with style sheets.
Moodle 4.4 defines the style class:
This PR contains the content of three major improvements achieved in the last two months.
Those three improvements can be described as follows:
translation of the content and content_format fields from the item plugin specific tables (surveypro(field|format)_itemplugin) to the parent table (surveypro_item). This first result is described in the content_among_basics branch (https://github.com/kordan/moodle-mod_surveypro/tree/content_among_basics). I have never created a pull request for this branch because I have never been able to perform a rebase that satisfied me. In practice: the method, named in master "item_add_mandatory_base_fields" was renamed in the branch to "item_add_defaults_for_base_fields". By rebasing content_among_basics on master the rename of the method was discarded so, after the rebase, I still found the original name. I spent a few days trying to understand the reason for this behavior. I asked my colleagues and then abandoned the problem.
translation of the most frequent properties (among all item plugins) from the specific item plugin tables (surveypro(field|format)_itemplugin) to the parent table (surveypro_item). This second step is clearly the natural continuation of the previous one and, for this reason, I created this new branch (https://github.com/kordan/moodle-mod_surveypro/tree/others_to_base_property) on top of content_among_basics.
Once I had a clear idea of how the itemplugin attributes were managed, I finally proceeded to adapt surveypro to php8.2 by creating the php8.2 branch. Obviously this branch was created on top of others_to_base_propertye, consequently, the php8.2 merge makes the first two branches useless.
The outcome of "content_among_basics" is described in (1). The outcome of "others_to_base_property" is described in (2). The outcome of "php8.2" is described in (3).
===================================================== (1) Content and contentformat moved among base fields
As part of a work of standardization and modernization of the module aimed at making the code homogeneous and, consequently, easily understandable and modifiable, I realized that the use of PHP 8.2 highlights a significant and very long series of errors that I must absolutely address. The first error among these is that the class of each item (item = fields + format) must have its own properties that it must manage on its own. But to define the list of properties of each item I have to decide which properties to consider "common" to all items and which to consider "specific" to each individual item. There are two reflections related to this problem:
Theoretically there are very few properties common to all items. Among these I only see: hidden, insearchform and reserved. All the others cannot be common to ALL items because, for example, the "pagebreak" item only has these three properties just mentioned; I already accepted this "lack" of properties ACTUALLY common to all items when I chose to create the itemsetup form (the form to setup a new item for the surveypro) from the union of a "item_setupbaseform" and an "itemsetupform". The item_setupbaseform has the fields it has and each item has a rule that says what it wants in its form and what it doesn't want to appear. (Each item defines a static vector called insetupform which declares what it wants to appear in the item_setupbaseform and what not. Obviously there is no similar vector for the specific form of each item because, having been created for the single item, it contains only and exclusively whatever you want.) I therefore realize that the answer to the question: which properties must be classified as "common" to all items and which, instead, must be classified as "specific" of each individual item is in the list of fields that I included, 10 years ago, in the "itemsetupbaseform" and in the "itemsetupform". So in order to make the code more homogeneous and self-consistent, I have to start moving all the "common" fields from the tables of each individual item ('surveypro'.$type.''.$plugin) to the surveypro_item table.
The two most difficult fields to move are 'content' and 'contentformat'. This is the reason that led me to this PR.
I lose compatibility with the past. I will write somewhere that if you want to keep your usertemplates and mastertemplates, you need to: -- before upgrading surveypro you have to load each usertemplate and mastertemplate into a course; -- upgrade your surveypro; -- regenerate each usertemplate and each mastertemplate. obviously the next PR I will make will relate to moving the other "common" properties from the specific tables to the surveypro_item table (and I will create them on top of this one).
===================================================== (2) Each common propery is now saved to surveypro_item
When "content_among_basics" (that saves content and contentformat to surveypro_item and no longer into db tables of item plugins) and this PR will land to mastwer, I hope all will be ready to start to modify surveypro to let it correctly run in php8.2 and 8.3.
With this PR the situation of properties should be:
All the properties in the first column are relative to a field of the table surveypro_item. All the properties in the first column correspond to a field of the item_setupbaseform that is the initial part of each itemsetupform. Not all the items use ALL of that properties. They declare the use of each property throught $this->insetupform[] = (false|true);
If $this->insetupform[] == false, the corresponding field in the formbase is not displayed in item_setupbaseform (and the useless default goes into the database).
Marked with (h) are properties hidden to user.
In the next table the list of specific properties item per item. These properties are save in surveypro(field|format)_.
Yes, some of them coincide, but the number of plugins sharing the same property is too low and even the semantic is too specific of each single plugin so
I decided to save these properties among the fields of the child table and not in surveypro_item.
===================================================== (3) php8.2 This improvement makes surveypro compatible with php8.2. There is some small problem, however, that I don't understand and which, for this reason, I describe below.
(a) I see a theoretical problem that I believe is closely related to my request for help in: https://moodle.org/mod/forum/discuss.php?d=457241
The problem that php8.2 raises is practically always linked to the fact that I can not evaluate a property without first declare it. One of the properties common to all surveypro items is "content" (alias, the content of the question) followed by the content_format. To define an item via the corresponding form at submission time, the HTML editor is processed through file_prepare_standard_editor that changes the content_editor property. When I pass the object $item to the file_prepare_standard_editor method, php8.2 raises an exception claiming that the content_editor property (that I must have defined previously) and that I have defined as protected cannot be modified because it is protected. I know it is a good practice to always define properties as protected so my question is: How should I behave? Do I have to make the property public?
(b) Furthermore, but this is a completely secondary detail, protected $content_editor is considered an error by Code Checker.
(c) In php8.2 and moodle master, I frequently get the error "Javascript code and/or AJAX requests are not ready after 10 seconds". At my eyes, it seems related to TinyMCE editor. Executing a submission of the item_setupbaseform with values that inhibit the submission itself, when the form is reloaded it is impossible to paste something in the content textarea.
(d) I'm having a problem with style sheets. Moodle 4.4 defines the style class:
To override this class I am forced to use:
specifying NECESSARILY !important to be able to override the parent class.
The "!important" specification, however, is classified by Grunt (in the context of the GHA) as an error: