Moodle
  1. Moodle
  2. MDL-15094

M2-M3-M4 Upgrade all code using DML

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: Database SQL/XMLDB
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      30858

      Description

      Since the new DML 2.0 API is now in place, all code using the old dmllib needs to be upgraded. In essence, this means the following changes:

      1. Wherever old functions are used (get_record*, get_field*, set_field, insert_record, update_record), the global $DB must be used as the object on which these functions are called (e.g. get_record_select becomes $DB->get_record_select).

      2. All the functions that used to accept a list of string params in the form "param1, value1, param2, value2" now need to be given an array of key=>value pairs as a replacement for these params. Other params remain as before. Check the new API for any exceptions.

      3. rs_fetch_next_record($rs) is deprecated, in favour of the simple foreach($rs as $var). Calls to rs_close() must be replaced by $rs->close();

      As an example to #3, if you have the original code:

      while($result = rs_fetch_next_record($rs))

      { ... }

      rs_close();

      you would replace it with

      foreach ($rs as $result)

      { .... }

      $rs->close();

      1. search_dml
        0.4 kB
        Nicolas Connault

        Issue Links

          Activity

          Hide
          Petr Škoda added a comment -

          At the same time code should be converted to not rely on magic quotes:

          1/ form->get_data(false) returns form data without magic quotes

          2/ data_submitted(false) return form data without magic quotes

          3/ add stripslashes() after optional|required_param() - separate line preferable

          4/ keep addslashes_js()!! - javascript quoting, XSS prevention; some existing addslashes() are incorrect

          Show
          Petr Škoda added a comment - At the same time code should be converted to not rely on magic quotes: 1/ form->get_data(false) returns form data without magic quotes 2/ data_submitted(false) return form data without magic quotes 3/ add stripslashes() after optional|required_param() - separate line preferable 4/ keep addslashes_js()!! - javascript quoting, XSS prevention; some existing addslashes() are incorrect
          Hide
          Pierre Pichet added a comment -

          Can you give us the time scale (in the northern hemisphere summer holidays are coming) to do the job.

          This will also put a major "chinese wall" between 2.0 and older versions so that merging down to even 1.9 will be a very "cautious if not impossible " procedure. But I suppose that have been discussed elsewhere.

          Show
          Pierre Pichet added a comment - Can you give us the time scale (in the northern hemisphere summer holidays are coming) to do the job. This will also put a major "chinese wall" between 2.0 and older versions so that merging down to even 1.9 will be a very "cautious if not impossible " procedure. But I suppose that have been discussed elsewhere.
          Hide
          Pierre Pichet added a comment -

          Sorry, I probably misreaded
          ." All the functions that used to accept a list of string params in the form "param1, value1, param2, value2" now need to be given an array of key=>value pairs as a replacement for these params. Other params remain as before. Check the new API for any exceptions. "

          So list of string params in the form "question_id1, question_id2,question_id3 "remains as they are?

          And the only changes are adding $DB-> before functions as $DB->get_record_select ()?

          If this is so, the height of the "chinese wall" decreased...

          Show
          Pierre Pichet added a comment - Sorry, I probably misreaded ." All the functions that used to accept a list of string params in the form "param1, value1, param2, value2" now need to be given an array of key=>value pairs as a replacement for these params. Other params remain as before. Check the new API for any exceptions. " So list of string params in the form "question_id1, question_id2,question_id3 "remains as they are? And the only changes are adding $DB-> before functions as $DB->get_record_select ()? If this is so, the height of the "chinese wall" decreased...
          Hide
          Nicolas Connault added a comment -

          Please read http://docs.moodle.org/en/Development:dmllib_2.0_migration_docs for more complete documentation.

          Show
          Nicolas Connault added a comment - Please read http://docs.moodle.org/en/Development:dmllib_2.0_migration_docs for more complete documentation.
          Hide
          Pierre Pichet added a comment -

          Nicolas,
          Thanks for the reference.
          I am willing to do the work on the part of the question code that I know well, so to be able to test everything correctly.
          However I cannot do this before mid-august, is it to late ?

          Show
          Pierre Pichet added a comment - Nicolas, Thanks for the reference. I am willing to do the work on the part of the question code that I know well, so to be able to test everything correctly. However I cannot do this before mid-august, is it to late ?
          Hide
          Nicolas Connault added a comment -

          Thanks Pierre, but it will be too late I think, maybe Petr can correct me on this...

          Show
          Nicolas Connault added a comment - Thanks Pierre, but it will be too late I think, maybe Petr can correct me on this...
          Hide
          Nicolas Connault added a comment -

          Just attached a script which recursively searches the folder in which it is run, looking for patterns of code that needs upgrading to the new DML syntax. It uses grep to output all the matching lines to standard output, and produces a summary text file (dml_search_summary) listing the files with matches, and showing the count of matches within each file.

          Show
          Nicolas Connault added a comment - Just attached a script which recursively searches the folder in which it is run, looking for patterns of code that needs upgrading to the new DML syntax. It uses grep to output all the matching lines to standard output, and produces a summary text file (dml_search_summary) listing the files with matches, and showing the count of matches within each file.
          Hide
          Petr Škoda added a comment -

          oh, this conversion must be finished next week

          Show
          Petr Škoda added a comment - oh, this conversion must be finished next week
          Hide
          Petr Škoda added a comment -

          I am planning to finish the dml conversion on Monday (9th) and on Tuesday start the magic quotes elimination
          Please hurry with the commits, minor breakages are not a problem

          Show
          Petr Škoda added a comment - I am planning to finish the dml conversion on Monday (9th) and on Tuesday start the magic quotes elimination Please hurry with the commits, minor breakages are not a problem
          Hide
          Petr Škoda added a comment -

          all except global search finished - yay!

          Show
          Petr Škoda added a comment - all except global search finished - yay!
          Hide
          Petr Škoda added a comment -

          reopening searchlib missing

          Show
          Petr Škoda added a comment - reopening searchlib missing
          Hide
          Petr Škoda added a comment -

          done

          Show
          Petr Škoda added a comment - done
          Hide
          Petr Škoda added a comment -

          seems to be working fine for some time, reclosing

          Show
          Petr Škoda added a comment - seems to be working fine for some time, reclosing

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: