kordan / moodle-mod_surveypro

The surveypro module per moodle
13 stars 15 forks source link

Compliance with Php8.2 #964

Open kordan opened 7 months ago

kordan commented 7 months ago

This PR contains the content of three major improvements achieved in the last two months.

Those three improvements can be described as follows:

  1. 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.

  2. 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.

  3. 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:

===================================================== (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:

                 | AGE           | AUTOFILL    | BOOLEAN        | CHARACTER    | CHECKBOX        | DATE           | DATETIME       | FILEUPLOAD | INTEGER       | MULTISELECT     | NUMERIC       | RADIOBUTTON   | RATE            | RECURRENCE     | SELECT         | SHORTDATE      | TEXTAREA   | TIME           | FIELDSET      | FIELDSETEND | LABEL     | PAGEBREAK |
id (h)           | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
surveyproid (h)  | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
type (h)         | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
plugin (h)       | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |

content          | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | NO          | √         | NO        |
contentformat    | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | NO            | NO          | √         | NO        |

required         | √             | NO          | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | NO            | NO          | NO        | NO        |
indent           | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | NO            | NO          | √         | NO        |
position         | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | NO            | NO          | NO        | NO        |
customnumber     | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | NO            | NO          | √         | NO        |
hideinstructions | √             | NO          | NO             | √            | √               | √              | √              | NO         | √             | √               | √             | NO            | √               | √              | NO             | √              | √          | √              | NO            | NO          | NO        | NO        |

variable         | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | NO            | NO          | NO        | NO        |
extranote        | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | NO            | NO          | NO        | NO        |

hidden           | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
insearchform     | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
reserved         | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |

sortindex (h)    | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
formpage (h)     | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |

parentid         | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
parentvalue      | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |

timecreated (h)  | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
timemodified (h) | √             | √           | √              | √            | √               | √              | √              | √          | √             | √               | √             | √             | √               | √              | √              | √              | √          | √              | √             | √           | √         | √         |
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

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.

                 | AGE           | AUTOFILL    | BOOLEAN        | CHARACTER    | CHECKBOX        | DATE           | DATETIME       | FILEUPLOAD | INTEGER       | MULTISELECT     | NUMERIC       | RADIOBUTTON    | RATE           | RECURRENCE     | SELECT         | SHORTDATE      | TEXTAREA   | TIME           | FIELDSET      | FIELDSETEND | LABEL     | PAGEBREAK |
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
                 | defaultoption | hiddenfield | defaultoption  | trimonsave   | options         | defaultoption  | step           | maxfiles   | defaultoption | options         | defaultvalue  | options        | options        | defaultoption  | options        | defaultoption  | trimonsave | step           | defaultstatus |             | fullwidth |
                 | defaultvalue  | element01   | defaultvalue   | defaultvalue | labelother      | defaultvalue   | defaultvalue   | maxbytes   | defaultvalue  | defaultvalue    | signed        | labelother     | rates          | defaultvalue   | labelother     | defaultvalue   | useeditor  | defaultoption  |                             | leftlabel |
                 | lowerbound    | element02   | downloadformat | pattern      | defaultvalue    | downloadformat | defaultvalue   | filetypes  | lowerbound    | noanswerdefault | lowerbound    | defaultoption  | defaultoption  | downloadformat | defaultoption  | downloadformat | arearows   | defaultvalue   |
                 | upperbound    | element03   | style          | minlength    | noanswerdefault | lowerbound     | downloadformat |            | upperbound    | downloadformat  | upperbound    | defaultvalue   | defaultvalue   | lowerbound     | defaultvalue   | lowerbound     | areacols   | downloadformat |
                                 | element04   |                | maxlength    | downloadformat  | upperbound     | lowerbound     |                            | minimumrequired | decimals      | downloadformat | downloadformat | upperbound     | downloadformat | upperbound     | minlength  | lowerbound     |
                                 | element05   |                               | minimumrequired |                | upperbound     |                            | maximumrequired |               | adjustment     | style          |                                                  | maxlength  | upperbound     |
                                                                               | maximumrequired |                                                              | heightinrows    |                                | differentrates |
                                                                               | adjustment      |

===================================================== (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.

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:

.mb-3, .my-3 {
   margin-bottom: 1rem !important;
}

To override this class I am forced to use:

.path-mod-surveypro #userentry .mb-3,
.path-mod-surveypro #usersearch .mb-3 {
     margin-bottom: 0 !important;
}

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:

mod/surveypro/styles.css
  28:22  ✖  Unexpected !important  declaration-no-important
 348:24  ✖  Unexpected !important  declaration-no-important
 356:24  ✖  Unexpected !important  declaration-no-important
 361:24  ✖  Unexpected !important  declaration-no-important
 366:22  ✖  Unexpected !important  declaration-no-important
 374:22  ✖  Unexpected !important  declaration-no-important
 379:22  ✖  Unexpected !important  declaration-no-important
 384:24  ✖  Unexpected !important  declaration-no-important
 392:24  ✖  Unexpected !important  declaration-no-important
 397:24  ✖  Unexpected !important  declaration-no-important
 402:22  ✖  Unexpected !important  declaration-no-important
 409:22  ✖  Unexpected !important  declaration-no-important
 414:22  ✖  Unexpected !important  declaration-no-important
 419:24  ✖  Unexpected !important  declaration-no-important
 426:24  ✖  Unexpected !important  declaration-no-important
 431:24  ✖  Unexpected !important  declaration-no-important
 436:22  ✖  Unexpected !important  declaration-no-important
 443:22  ✖  Unexpected !important  declaration-no-important
 448:22  ✖  Unexpected !important  declaration-no-important
 453:25  ✖  Unexpected !important  declaration-no-important
 460:25  ✖  Unexpected !important  declaration-no-important
 465:25  ✖  Unexpected !important  declaration-no-important
 470:23  ✖  Unexpected !important  declaration-no-important
 477:23  ✖  Unexpected !important  declaration-no-important
 482:23  ✖  Unexpected !important  declaration-no-important
 487:25  ✖  Unexpected !important  declaration-no-important
 494:25  ✖  Unexpected !important  declaration-no-important
 499:25  ✖  Unexpected !important  declaration-no-important

28 problems (28 errors, 0 warnings)