Moodle
  1. Moodle
  2. MDL-38378

DB Upgrade script contains hard coded database prefix.

    Details

    • Rank:
      48287

      Description

      MDL-38173 Introduced update code in '/lib/db/upgrade.php' which contains a hard coded database prefix:

              $sql = 'SELECT s2.id, s2.course, s2.sequence
                      FROM mdl_course_sections s2
                      JOIN(
                          SELECT DISTINCT s.id
                          FROM
                          {course_modules} cm
                          JOIN {course_sections} s
                          ON
                              cm.course = s.course
                          WHERE cm.section != s.id AND ' . $sequenceconcat . ' LIKE ' . $moduleconcat . '
                      ) d
                      ON s2.id = d.id';
              $coursesections = $DB->get_recordset_sql($sql);
      

      This means that if the database prefix is not 'mdl_' then an error occurs and the upgrade fails:

      Debug info: Table 'moodlegjb.mdl_course_sections' doesn't exist
      SELECT s2.id, s2.course, s2.sequence 
      FROM mdl_course_sections s2 
      JOIN( 
      SELECT DISTINCT s.id 
      FROM 
      mdl23_course_modules cm 
      JOIN mdl23_course_sections s 
      ON 
      cm.course = s.course 
      WHERE cm.section != s.id AND CONCAT(',', s.sequence, ',') LIKE CONCAT('%,', cm.id, ',%') 
      ) d 
      ON s2.id = d.id
      [array (
      )] 
      Error code: dmlreadexception
      Stack trace:
      line 407 of \lib\dml\moodle_database.php: dml_read_exception thrown
      line 903 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
      line 1091 of \lib\db\upgrade.php: call to mysqli_native_moodle_database->get_recordset_sql()
      line 1480 of \lib\upgradelib.php: call to xmldb_main_upgrade()
      line 275 of \admin\index.php: call to upgrade_core()
      

      The workaround is to manually edit 'upgrade.php' and change the prefix.

        Issue Links

          Activity

          Hide
          Eloy Lafuente (stronk7) added a comment -

          Working on this, I'll mini-bump all version by +0.01. Many thanks Gareth!

          Show
          Eloy Lafuente (stronk7) added a comment - Working on this, I'll mini-bump all version by +0.01. Many thanks Gareth!
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Ouch, you're using $CFG->prefix and it should be

          {course_sections}

          instead, np, fixing it...

          Show
          Eloy Lafuente (stronk7) added a comment - Ouch, you're using $CFG->prefix and it should be {course_sections} instead, np, fixing it...
          Hide
          Gareth J Barnard added a comment -

          If I change my branches to '

          {course_sections}

          ' can I be credited with the fix?

          Show
          Gareth J Barnard added a comment - If I change my branches to ' {course_sections} ' can I be credited with the fix?
          Hide
          Eloy Lafuente (stronk7) added a comment -

          too late, the fixes have been pushed with my commits, sorry. And automated build is already happening.

          So commits aren't yours but our gratitude is immense, thanks!

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - too late, the fixes have been pushed with my commits, sorry. And automated build is already happening. So commits aren't yours but our gratitude is immense, thanks! Ciao
          Hide
          Gareth J Barnard added a comment -

          Dear Eloy Lafuente (stronk7),

          All my branches now have the

          '{course_sections}'

          syntax.

          Cheers,

          Gareth

          Show
          Gareth J Barnard added a comment - Dear Eloy Lafuente (stronk7) , All my branches now have the '{course_sections}' syntax. Cheers, Gareth
          Hide
          Gareth J Barnard added a comment -

          No worries - Need to save up for a faster Netbook!

          Show
          Gareth J Barnard added a comment - No worries - Need to save up for a faster Netbook!
          Hide
          Eloy Lafuente (stronk7) added a comment -

          git repositories and downloads updated to build with date 20130308.

          Closing this, again, many thanks Gareth J Barnard!

          Show
          Eloy Lafuente (stronk7) added a comment - git repositories and downloads updated to build with date 20130308. Closing this, again, many thanks Gareth J Barnard !

            People

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

              Dates

              • Created:
                Updated:
                Resolved: