Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.9.4
    • Fix Version/s: 1.9.8
    • Component/s: Other
    • Labels:
      None
    • Environment:
      Centos Linux 4.6, MySQL 5, Apache 2, PHP 5.2.9
    • Database:
      MySQL
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      One of our clients has a site, running 1.9.4+ (yes I know - they'll be upgrading soon) that has been running fone for a couple of years. All of a sudden, a couple of weeks ago, the stats generation started to fail overnight. THey've only just noticed and asked me to look into it. I increased the debug level and ran cron manually and got this:

      PHP Warning: array_merge(): Argument #2 is not an array in /var/www/vhosts/tripleaworkshops.ibo.org/httpdocs/lib/statslib.php on line 1273
      PHP Warning: array_unique(): The argument should be an array in /var/www/vhosts/tripleaworkshops.ibo.org/httpdocs/lib/statslib.php on line 1279
      PHP Warning: array_values(): The argument should be an array in /var/www/vhosts/tripleaworkshops.ibo.org/httpdocs/lib/statslib.php on line 1279
      PHP Warning: implode(): Invalid arguments passed in /var/www/vhosts/tripleaworkshops.ibo.org/httpdocs/lib/statslib.php on line 124
      Running daily statistics gathering, starting at 1255478400:
      .........PHP Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) AS statsreads,
      (SELECT COUNT('x')
      ' at line 8

      INSERT INTO mdl_stats_user_daily (stattype, timeend, courseid, userid, statsreads, statswrites)

      SELECT 'activity' AS stattype, 1255564800 AS timeend, d.courseid, d.userid,
      (SELECT COUNT('x')
      FROM mdl_log l
      WHERE l.userid = d.userid AND
      l.course = d.courseid AND l.time >= 1255478400 AND l.time < 1255564800 AND
      l.action IN ()) AS statsreads,
      (SELECT COUNT('x')
      FROM mdl_log l
      WHERE l.userid = d.userid AND
      l.course = d.courseid AND l.time >= 1255478400 AND l.time < 1255564800 AND
      in /var/www/vhosts/tripleaworkshops.ibo.org/httpdocs/lib/weblib.php on line 6942
      ...error occured, completed 0 days of statistics.

      I have no idea what is causing this - the moodle code has not been updated for some time, and we haven;t made any changes to their site for months. Any idea what could be causing this?

      This is now really urgent.

      regards

      Sean K

        Gliffy Diagrams

          Activity

          keoghs Sean Keogh created issue -
          mblake Michael Blake made changes -
          Field Original Value New Value
          Assignee Martin Dougiamas [ dougiamas ] Dongsheng Cai [ dongsheng ]
          Hide
          dongsheng Dongsheng Cai added a comment -

          Hi, Sean

          I cannot reproduce the problem, seems the mod actions function return an invalid value, can you try attached patch, I added a few lines to check the return value. Let me know if it worked.

          Thanks.

          Show
          dongsheng Dongsheng Cai added a comment - Hi, Sean I cannot reproduce the problem, seems the mod actions function return an invalid value, can you try attached patch, I added a few lines to check the return value. Let me know if it worked. Thanks.
          dongsheng Dongsheng Cai made changes -
          Attachment statslib.patch [ 18860 ]
          Hide
          keoghs Sean Keogh added a comment -

          Hiya,

          I applied your patch and then re-ran the stats and they all seemed to go through fine. That was several weeks worth of stats. So I'm wondering what had changed that required your patch to make it work, when it was working fine a month ago?

          Anyway, many thanks for the patch.

          Sean K

          Show
          keoghs Sean Keogh added a comment - Hiya, I applied your patch and then re-ran the stats and they all seemed to go through fine. That was several weeks worth of stats. So I'm wondering what had changed that required your patch to make it work, when it was working fine a month ago? Anyway, many thanks for the patch. Sean K
          Hide
          keoghs Sean Keogh added a comment -

          Hi,

          I've got another site where stats has stopped working too - they seem to have a different error:

          Running daily statistics gathering, starting at 1251673200:
          1:0 2:0 3:6 4:2 5:6 6:0 7:0 x:0 x:0 10:0 11:0 PHP Notice: Trying to get property of non-object in /var/moodle_web/learning/lib/statslib.php on line 429
          PHP Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND
          ((rc.capability = 'moodle/course:v' at line 16<br /><br />INSERT INTO mdl_stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)

          SELECT 'activity', timeend, courseid, roleid, SUM(statsreads), SUM(statswrites)
          FROM (
          SELECT 1251676800 AS timeend, pl.courseid, pl.roleid, sud.statsreads, sud.statswrites
          FROM mdl_stats_user_daily sud,
          (SELECT DISTINCT ra.userid, ra.roleid, c.id AS courseid
          FROM mdl_role_assignments ra JOIN mdl_context ctx
          ON ctx.id = ra.contextid
          CROSS JOIN mdl_course c
          JOIN mdl_role_capabilities rc
          ON rc.roleid = ra.roleid LEFT OUTER JOIN mdl_course_categories cc1
          ON cc in /var/moodle_web/learning/lib/weblib.php on line 6939
          ...error occured, completed 0 days of statistics.
          Cron script completed correctly
          Execution took 17.787625 seconds

          However, this site does have some non-standard code in it - it is running a version of 1.9.4+ modified by Catalyst to allow access for teachers to course file areas via webdav.

          I'm not sure if this has any bearing on the stats problem, and stats was working OK up until about six weeks ago - but I am going to mention it to Catalyst as well.

          Sean K

          Show
          keoghs Sean Keogh added a comment - Hi, I've got another site where stats has stopped working too - they seem to have a different error: Running daily statistics gathering, starting at 1251673200: 1:0 2:0 3:6 4:2 5:6 6:0 7:0 x:0 x:0 10:0 11:0 PHP Notice: Trying to get property of non-object in /var/moodle_web/learning/lib/statslib.php on line 429 PHP Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND ((rc.capability = 'moodle/course:v' at line 16<br /><br />INSERT INTO mdl_stats_daily (stattype, timeend, courseid, roleid, stat1, stat2) SELECT 'activity', timeend, courseid, roleid, SUM(statsreads), SUM(statswrites) FROM ( SELECT 1251676800 AS timeend, pl.courseid, pl.roleid, sud.statsreads, sud.statswrites FROM mdl_stats_user_daily sud, (SELECT DISTINCT ra.userid, ra.roleid, c.id AS courseid FROM mdl_role_assignments ra JOIN mdl_context ctx ON ctx.id = ra.contextid CROSS JOIN mdl_course c JOIN mdl_role_capabilities rc ON rc.roleid = ra.roleid LEFT OUTER JOIN mdl_course_categories cc1 ON cc in /var/moodle_web/learning/lib/weblib.php on line 6939 ...error occured, completed 0 days of statistics. Cron script completed correctly Execution took 17.787625 seconds However, this site does have some non-standard code in it - it is running a version of 1.9.4+ modified by Catalyst to allow access for teachers to course file areas via webdav. I'm not sure if this has any bearing on the stats problem, and stats was working OK up until about six weeks ago - but I am going to mention it to Catalyst as well. Sean K
          Hide
          dongsheng Dongsheng Cai added a comment -

          Hi, Sean,

          I cannot reproduce this bug here, is it possible to create a patch against unmodifed moodle 1.9? So I can help debug this problem.

          Thanks.

          Dongsheng Cai

          Show
          dongsheng Dongsheng Cai added a comment - Hi, Sean, I cannot reproduce this bug here, is it possible to create a patch against unmodifed moodle 1.9? So I can help debug this problem. Thanks. Dongsheng Cai
          Hide
          dongsheng Dongsheng Cai added a comment -

          Hi, Sean,
          I cannot reproduce this bug without patches and more details, so I close it temporarily, please feel free to reopen it when you got more details.

          Thanks for reporting.

          Dongsheng Cai

          Show
          dongsheng Dongsheng Cai added a comment - Hi, Sean, I cannot reproduce this bug without patches and more details, so I close it temporarily, please feel free to reopen it when you got more details. Thanks for reporting. Dongsheng Cai
          dongsheng Dongsheng Cai made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Cannot Reproduce [ 5 ]
          Hide
          ashleyholman Ashley Holman added a comment -

          This problem occurs when the $mod->name.'get'.$str.'_actions' function returns a non-array value.

          This code demonstrates the issue:

          <?

          $arr1 = array('a', 'b', 'c');
          $arr2 = true;

          $arr1 = array_merge($arr1, $arr2);

          print_r($arr1);

          ?>

          Fails with: Warning: array_merge(): Argument #2 is not an array in /home/ashley/test.php on line 6 and returns null.

          In older versions of PHP, the merge would work by adding 'true' to the array.

          See the note at http://au2.php.net/array_merge:
          <b>The behavior of array_merge() was modified in PHP 5. Unlike PHP 4, array_merge() now only accepts parameters of type array. However, you can use typecasting to merge other types. See the example below for details.</b>

          Although none of the core modules appear to return a non-array value, some 3rd party ones do and this breaks stats processing. It would make sense to add some extra error checking into the core code to not attempt the merge for non-array values. +1 for the Dongsheng's patch!

          Show
          ashleyholman Ashley Holman added a comment - This problem occurs when the $mod->name.' get '.$str.'_actions' function returns a non-array value. This code demonstrates the issue: <? $arr1 = array('a', 'b', 'c'); $arr2 = true; $arr1 = array_merge($arr1, $arr2); print_r($arr1); ?> Fails with: Warning: array_merge(): Argument #2 is not an array in /home/ashley/test.php on line 6 and returns null. In older versions of PHP, the merge would work by adding 'true' to the array. See the note at http://au2.php.net/array_merge: <b>The behavior of array_merge() was modified in PHP 5. Unlike PHP 4, array_merge() now only accepts parameters of type array. However, you can use typecasting to merge other types. See the example below for details.</b> Although none of the core modules appear to return a non-array value, some 3rd party ones do and this breaks stats processing. It would make sense to add some extra error checking into the core code to not attempt the merge for non-array values. +1 for the Dongsheng's patch!
          ashleyholman Ashley Holman made changes -
          Resolution Cannot Reproduce [ 5 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Fix Version/s 1.9.8 [ 10400 ]
          Hide
          keoghs Sean Keogh added a comment -

          Hi Guys,

          The problem we had at the secomd site was fixed after we spoke to Catalyst.

          This is what they suggested:

          > Line 429 of lib/statslib.php is calling the get_guest function (which
          > is
          > >> deprecated) to get the guest user, and returning a null result. You
          > >> could try creating a user with username "guest" and the error should
          > >> resolve. Let me know if that fixes it
          > >> Cheers, J

          I did this, and it worked...

          Sean K

          Show
          keoghs Sean Keogh added a comment - Hi Guys, The problem we had at the secomd site was fixed after we spoke to Catalyst. This is what they suggested: > Line 429 of lib/statslib.php is calling the get_guest function (which > is > >> deprecated) to get the guest user, and returning a null result. You > >> could try creating a user with username "guest" and the error should > >> resolve. Let me know if that fixes it > >> Cheers, J I did this, and it worked... Sean K
          Hide
          dongsheng Dongsheng Cai added a comment -

          Hi, Sean

          'guest' user should exist by default, seems you deleted it for security issue?

          and looks, Catalyst did a lot work on statslib.php, on official moodle 1.9, we have get_guest function on line 127.

          Anyway, glad to hear you fixed this problem

          Show
          dongsheng Dongsheng Cai added a comment - Hi, Sean 'guest' user should exist by default, seems you deleted it for security issue? and looks, Catalyst did a lot work on statslib.php, on official moodle 1.9, we have get_guest function on line 127. Anyway, glad to hear you fixed this problem
          Hide
          dongsheng Dongsheng Cai added a comment -

          Ashley, I committed the error checking code to CVS, thanks for reviewing this issue.

          Show
          dongsheng Dongsheng Cai added a comment - Ashley, I committed the error checking code to CVS, thanks for reviewing this issue.
          dongsheng Dongsheng Cai made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          dougiamas Martin Dougiamas made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          QA Assignee nobody
          dougiamas Martin Dougiamas made changes -
          Workflow jira [ 34079 ] MDL Workflow [ 63384 ]
          dougiamas Martin Dougiamas made changes -
          Workflow MDL Workflow [ 63384 ] MDL Full Workflow [ 92623 ]

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                25/Mar/10