Moodle
  1. Moodle
  2. MDL-35966

Database error when submitting an assignment when Moodle is installed on Windows with non-utf8 locale (Traditional Chinese)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.2
    • Fix Version/s: 2.3.4
    • Component/s: Assignment
    • Labels:
    • Environment:
      Windows, non-utf8 system locale, MySQL.
    • Testing Instructions:
      Hide

      Test pre-requisites: moodle installed on a windows machine set to simplified chinese language in the os using MySQL as the database.

      1. Create an assignment in a course with at least one student and one teacher. Leave "Notify graders about submission" set to "Yes"
      2. Login as the student and make a submission to the assignment
      3. Verify you do not receive a database error.
      Show
      Test pre-requisites: moodle installed on a windows machine set to simplified chinese language in the os using MySQL as the database. Create an assignment in a course with at least one student and one teacher. Leave "Notify graders about submission" set to "Yes" Login as the student and make a submission to the assignment Verify you do not receive a database error.
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-35966-master
    • Rank:
      44725

      Description

      Error writing to database occurred while submitting for grading.

      Server OS : Windows 2008 Server R2 Traditional Chinese Version
      Web Server: IIS 7.5
      PHP: Zend Server 5.5

      Php error log:

      [10-Oct-2012 00:29:41 UTC] Default exception handler: 撖怠鞈?摨急??潛??航炊 Debug: Incorrect string value: '\xA4W\xA4\xC8 0...' for column 'fullmessage' at row 1
      INSERT INTO mdl_message (useridfrom,useridto,subject,fullmessage,fullmessageformat,fullmessagehtml,smallmessage,notification,contexturl,contexturlname,timecreated) VALUES(?,?,?,?,?,?,?,?,?,?,?)
      [array (
      0 => '15530',
      1 => '808',
      2 => '97135508 蝪⊥??? 撌脫?嫣?(??撌脩像鈭斤?雿平 kkkkk.',
      3 => '?典?憭批飛 NCNU Moodle 2.3 皜祈岫隤脩? -> 雿平 -> kkkkk
      ---------------------------------------------------------------------
      97135508 蝪⊥??? 撌脫?嫣?(??撌脩像鈭斤?雿平?批捆
      [kkkkk] ??2012/10/10 上午 08:29:41

      摰?ㄐ:

      http://moodletest.ncnu.edu.tw/mod/assign/view.php?id=224906

      ---------------------------------------------------------------------
      ',
      4 => '2',
      5 => '<p><font face="sans-serif"><a href="http://moodletest.ncnu.edu.tw/course/view.php?id=19614">?典?憭批飛 NCNU Moodle 2.3 皜祈岫隤脩?</a> -><a href="http://moodletest.ncnu.edu.tw/mod/assign/index.php?id=19614">雿平</a> -><a href="http://moodletest.ncnu.edu.tw/mod/assign/view.php?id=224906">kkkkk</a></font></p><hr /><font face="sans-serif"><p>97135508 蝪⊥??? 撌脫?嫣?(??撌脩像鈭斤?雿平?批捆
      <i>[kkkkk] ??2012/10/10 上午 08:29:41</i><br /><br />
      摰 <a href="http://moodletest.ncnu.edu.tw/mod/assign/view.php?id=224906"> 甇斤雯?€</a>.</p></font><hr />',
      6 => '97135508 蝪⊥??? 撌脫?嫣?(??撌脩像鈭斤?雿平 kkkkk.',
      7 => 1,
      8 => 'http://moodletest.ncnu.edu.tw/mod/assign/view.php?id=224906',
      9 => 'kkkkk',
      10 => 1349828981,
      )]
      Error code: dmlwriteexception

      • line 410 of \lib\dml\moodle_database.php: dml_write_exception thrown
      • line 1050 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
      • line 1092 of \lib\dml\mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
      • line 179 of \lib\messagelib.php: call to mysqli_native_moodle_database->insert_record()
      • line 2463 of \mod\assign\locallib.php: call to message_send()
      • line 2477 of \mod\assign\locallib.php: call to assign::send_assignment_notification()
      • line 2518 of \mod\assign\locallib.php: call to assign->send_notification()
      • line 2546 of \mod\assign\locallib.php: call to assign->notify_graders()
      • line 316 of \mod\assign\locallib.php: call to assign->process_submit_for_grading()
      • line 53 of \mod\assign\view.php: call to assign->view()
        ===============================================================================

      I traced assign::send_assignment_notification().

      A bug in assign::send_assignment_notification().

      PHP strftime - Format a local time/date according to locale settings.

      My server OS is Windows 2008 Server R2 Traditional Chinese Version,

      so strftime return non-UTF-8 string.

      I fixed the error by changing \mod\assign\locallib.php.

      Replaced

      $info->timeupdated = strftime('%c',$updatetime);

      with

      $info->timeupdated = userdate( $updatetime, get_string('strftimerecentfull') );

        Issue Links

          Activity

          Hide
          Damyon Wiese added a comment -

          Thanks for reporting this and providing a solution. I've added a patch tag to this issue so it gets higher priority and set it waiting for peer review.

          Regards, Damyon

          Show
          Damyon Wiese added a comment - Thanks for reporting this and providing a solution. I've added a patch tag to this issue so it gets higher priority and set it waiting for peer review. Regards, Damyon
          Hide
          Damyon Wiese added a comment -

          Tested on Linux and could reproduce the bug and verify the fix by doing the following:

          1. Install clean instance running on MySQL
          2. Install non-utf8 locale on system: (sudo locale-gen zh_TW)
          3. Restart apache
          4. Add setting to config file: $CFG->ostype = 'WINDOWS'; (userdate has special utf-8 handling for windows - other oses assume all locales are utf-8)
          5. Modify mod/assign/locallib.php Line 3174 (function send_assignment_notification)

          Add

          setlocale(LC_ALL, 'zh_TW');
          
          1. Follow the rest of the test instructions.

          These changes trigger this error and applying the patch fixes the error.

          Show
          Damyon Wiese added a comment - Tested on Linux and could reproduce the bug and verify the fix by doing the following: Install clean instance running on MySQL Install non-utf8 locale on system: (sudo locale-gen zh_TW) Restart apache Add setting to config file: $CFG->ostype = 'WINDOWS'; (userdate has special utf-8 handling for windows - other oses assume all locales are utf-8) Modify mod/assign/locallib.php Line 3174 (function send_assignment_notification) Add setlocale(LC_ALL, 'zh_TW'); Follow the rest of the test instructions. These changes trigger this error and applying the patch fixes the error.
          Hide
          Damyon Wiese added a comment -

          Thanks for reporting this issue - I am sending it for integration now.

          Show
          Damyon Wiese added a comment - Thanks for reporting this issue - I am sending it for integration now.
          Hide
          Dan Poltawski added a comment -

          Thanks guys, i've integrated this now.

          Show
          Dan Poltawski added a comment - Thanks guys, i've integrated this now.
          Hide
          Ankit Agarwal added a comment -

          I followed Damyon's instruction and I was able to submit without any error.
          Passing thanks!

          Show
          Ankit Agarwal added a comment - I followed Damyon's instruction and I was able to submit without any error. Passing thanks!
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Y E S !

          Closing as fixed, many thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - Y E S ! Closing as fixed, many thanks!

            People

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

              Dates

              • Created:
                Updated:
                Resolved: