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

Invalid argument supplied for foreach() in /var/www/html/moodle/admin/cron.php

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.10
    • Fix Version/s: 1.9.14
    • Component/s: Administration
    • Labels:
    • Database:
      MySQL
    • Testing Instructions:
      Hide

      First you will need to upload one or more new users. There is a csv file attached to this issue that you can use. The 2 users in the file have no password so it will be generated by cron. Upload the users at Site administration > Users > Accounts > Upload users. During the upload set "new user password" to "create password if needed"

      Now run /admin/cron.php. Unfortunately the code involved is only run 20% of the time and that is random. You can either run it repeatedly or insert "$random100 = 10;" at line 236 to get it to run every time.

      In cron's output you should see the following 2 lines.

      checking for create_password
      creating passwords for new users

      If there is no error then all is well.

      Show
      First you will need to upload one or more new users. There is a csv file attached to this issue that you can use. The 2 users in the file have no password so it will be generated by cron. Upload the users at Site administration > Users > Accounts > Upload users. During the upload set "new user password" to "create password if needed" Now run /admin/cron.php. Unfortunately the code involved is only run 20% of the time and that is random. You can either run it repeatedly or insert "$random100 = 10;" at line 236 to get it to run every time. In cron's output you should see the following 2 lines. checking for create_password creating passwords for new users If there is no error then all is well.
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      In Moodle 1.9.10+ (Build: 20110119), when running the admin cron job from command line or as a cron, the error "Invalid argument supplied for foreach() in /var/www/html/moodle/admin/cron.php" is entered in the log for this line:

      foreach ($newusers as $newuserid => $newuser)

      in this section of code:

      //
      // generate new password emails for users 
      //
      mtrace('checking for create_password');
      if (count_records('user_preferences', 'name', 'create_password', 'value', '1')) {
          mtrace('creating passwords for new users');
          $newusers = get_records_sql("SELECT  u.id as id, u.email, u.firstname, 
                                              u.lastname, u.username,
                                              p.id as prefid 
                                      FROM {$CFG->prefix}user u 
                                           JOIN {$CFG->prefix}user_preferences p ON u.id=p.userid
                                      WHERE p.name='create_password' AND p.value='1' AND u.email !='' ");
       
          foreach ($newusers as $newuserid => $newuser) {  // ERROR ON THIS LINE
              $newuser->emailstop = 0; // send email regardless
              // email user                               
              if (setnew_password_and_mail($newuser)) {
                  // remove user pref
                  delete_records('user_preferences', 'id', $newuser->prefid);
              } else {
                  trigger_error("Could not create and mail new user password!");
              }
          }
      }

        Gliffy Diagrams

          Attachments

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  10/Oct/11