Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-67696

PHP 7.3 Warning: count(): Parameter must be an array or an object that implements Countable in mod/forum/classes/task/refresh_forum_post_counts.php

XMLWordPrintable

    • MOODLE_38_STABLE
    • MOODLE_38_STABLE
    • MDL-67696-master
    • Hide

      Setup

      1. PHP 7.2 is required.
      2. Download test_67696.php and save it on your Moodle root folder.
      3. Login as admin.
      4. Create a course with a forum.
      5. Post some messages to the forum.

      Testing instructions

      1. Execute the following SQL: 

        UPDATE mdl_forum_posts
        SET charcount = null, wordcount = null

      2. Execute the following SQL: 

        SELECT count(*)
        FROM mdl_forum_posts
        WHERE wordcount IS NULL OR charcount IS NULL

      3. Check the result from the previous query is not 0.
      4. Run the script in your browser: http://yourlocalhostname/xxxxx/test_67696.php
      5. Make sure you don't see the following warning:

        Warning: count(): Parameter must be an array or an object that implements Countable in moodle/mod/forum/classes/task/refresh_forum_post_counts.php on line 73

      6. Execute the following SQL: 

        SELECT count(*)
        FROM mdl_forum_posts
        WHERE wordcount IS NULL OR charcount IS NULL

      7. Check the result from the previous query is 0.

       

      Show
      Setup PHP 7.2 is required. Download test_67696.php and save it on your Moodle root folder. Login as admin. Create a course with a forum. Post some messages to the forum. Testing instructions Execute the following SQL:  UPDATE mdl_forum_posts SET charcount = null, wordcount = null Execute the following SQL:  SELECT count(*) FROM mdl_forum_posts WHERE wordcount IS NULL OR charcount IS NULL Check the result from the previous query is not 0. Run the script in your browser: http://yourlocalhostname/xxxxx/test_67696.php Make sure you don't see the following warning: Warning: count(): Parameter must be an array or an object that implements Countable in moodle/mod/forum/classes/task/refresh_forum_post_counts.php on line 73 Execute the following SQL:  SELECT count(*) FROM mdl_forum_posts WHERE wordcount IS NULL OR charcount IS NULL Check the result from the previous query is 0.  
    • International 3.9 - Sprint 6

      PHP Warning: count(): Parameter must be an array or an object that implements Countable in mod/forum/classes/task/refresh_forum_post_counts.php on line 73

      code block reads:

          protected function update_null_forum_post_counts(): bool {
              global $CFG, $DB;
       
              // Default to chunks of 5000 records per run, unless overridden in config.php
              $chunksize = $CFG->forumpostcountchunksize ?? 5000;
       
              $select = 'wordcount IS NULL OR charcount IS NULL';
              $recordset = $DB->get_recordset_select('forum_posts', $select, null, 'discussion', 'id, message', 0, $chunksize);
       
              if (!$recordset->valid()) {
                  $recordset->close();
                  return false;
              }
       
              foreach ($recordset as $record) {
                  \mod_forum\local\entities\post::add_message_counts($record);
                  $DB->update_record('forum_posts', $record);
              }
       
              $recordscount = count($recordset);
              $recordset->close();
       
              return ($recordscount == $chunksize);
          }
      

      Emitted during a cli cron job, which in turn emails me with the warning. Since it's buried within a cron task run, I'm not sure of the state which is required to reproduce the warning, but the recordset must not implement Countable, so this function probably needs a slight rewrite to clear the warning.

        1. test_after.php
          0.3 kB
          Jay Churchward
        2. test_before.php
          0.3 kB
          Jay Churchward
        3. test_67696.php
          0.1 kB
          Simey Lameze
        4. image-2020-03-05-13-29-46-168.png
          53 kB
          Janelle Barcega

            jaychurchward Jay Churchward
            ln Alan Jackson
            Simey Lameze Simey Lameze
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Janelle Barcega Janelle Barcega
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day
                1d

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.