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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.9.10
    • 1.9.14
    • Administration
    • MySQL
    • MOODLE_19_STABLE
    • MOODLE_19_STABLE
    • 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.

    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!");
              }
          }
      }

      Attachments

        Activity

          People

            andyjdavis Andrew Davis
            smartin Stephen Martin
            Sam Hemelryk Sam Hemelryk
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Sam Hemelryk Sam Hemelryk
            David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10/Oct/11