5 Replies - 496 Views - Last Post: 11 February 2014 - 06:24 AM Rate Topic: -----

#1 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 471
  • View blog
  • Posts: 1,729
  • Joined: 15-January 14

Sanity check

Posted 05 February 2014 - 05:20 PM

Periodically I've been getting bug reports, almost all from a single client, where students are trying to register for various classes and they are not being put onto the waiting list even though the roster has too many students. For example, a class session is set up with 20 seats, and after 20 people register then the next registration should go onto the waiting list. This isn't happening in all cases, in some cases multiple additional people are registering and are not being put onto the waiting list. For other sessions, everything is fine. I'm trying to narrow down the exact way that those students are registering, and it looks like they are registering themselves which is a pretty simple piece of code to figure out how many students are currently registered, how many seats are in the session, and therefore whether they are on the waiting list. Here's a part of that code, which I've gone over many times and I see no reason why this should happen. Can anyone see anything amiss? I should also mention that this process happens correctly the vast majority of the time.

// Get information about the selected session
$db->sql('SELECT seats, open_reg, ug_open_reg, cid, location, date_time, end_date_time, hours_per_day, days, timezone, timezone_country, notes, cost, reg_end_date FROM standup_instance WHERE id=%d');
$db->add_param($id, false);
$inst = $db->select();
$inst = $inst[0];

// Get the number of students currently on the roster
$db->sql('SELECT COUNT(id) AS num FROM standup_roster WHERE class=%d');
$db->add_param($id, false);
$num = $db->select();
$num = $num[0]['num'];

// Determine the waiting list status
$wait_list = $num >= $inst['seats'] ? 1 : 0;

// Check registration constraints
$cur_time = time();
$reg_end_date = getdate($inst['reg_end_date']);
$reg_end_date = mktime(23, 59, 59, $reg_end_date['mon'], $reg_end_date['mday'], $reg_end_date['year']);
if($reg_end_date < $cur_time)
{
  $reg_date = $sess->local_date($reg_end_date);
  $response['errors']['reason'] = $lang->get_string('reg_close_date_sess', array($reg_date));
  return;
}

if ($inst['open_reg'] == 0)
{
  $response['errors']['reason'] = $lang->get_string('reg_closed');
  return;
}

if ($db->num_rows('SELECT * FROM standup_roster WHERE class=' . $id . ' AND uid=' . $sess->userid) > 0)
{
  $response['errors']['reason'] = $lang->get_string('already_regged');
  return;
}

// Add the student to the roster
$db->insert('standup_roster', array('class' => $id, 'uid' => $sess->userid, 'wait_list' => $wait_list, 'signup_date' => time()));


That code is part of an included file, so there are many things that are defined elsewhere ($db, $sess, $id, etc), but this is the part of the code that is responsible for determining the waiting list status. This file doesn't modify the waiting list value after this piece of code.

Is there anything in this that I've been missing, which would periodically cause this problem? I have to rule out a race condition, because I've seen one class with this problem where the last few students registered days apart and this problem still showed up. There are a couple other ways that students can get registered for classes, and I'm still looking, but I've been told by the client that this piece of code is being used for registration.

Is This A Good Question/Topic? 0
  • +

Replies To: Sanity check

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3740
  • View blog
  • Posts: 13,069
  • Joined: 12-December 12

Re: Sanity check

Posted 05 February 2014 - 05:40 PM

Quote

..this process happens correctly the vast majority of the time.

I've only looked at this briefly but my first instinct is to check the dates held in the tables, particularly the reg_end_date.
Was This Post Helpful? 0
  • +
  • -

#3 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: Sanity check

Posted 10 February 2014 - 07:27 AM

I would have a real good look into $wait_list = $num >= $inst['seats'] ? 1 : 0; and determine what values you are getting for a wide range of your sessions. You may find that what you expect and what is actually being returned are different. I am assuming this is the single statement that determines whether a student goes to the waiting list or can actually be booked into the class.

Test it rigorously.
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 471
  • View blog
  • Posts: 1,729
  • Joined: 15-January 14

Re: Sanity check

Posted 10 February 2014 - 09:16 AM

I've updated that client's installation to add logging every time a wait list value is changed in any circumstance, I'm determined to get to the bottom of this. Thanks for the responses.
Was This Post Helpful? 0
  • +
  • -

#5 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,619
  • Joined: 15-May 08

Re: Sanity check

Posted 10 February 2014 - 04:40 PM

Also check $sess->userid, I assume you are storing this in your session. Not sure how the information is displayed, however are the UID's entered into the DB all valid? Is there any odd values?

The following line
if ($db->num_rows('SELECT * FROM standup_roster WHERE class=' . $id . ' AND uid=' . $sess->userid) > 0)



if the $sess->userid value is random or incorrect i.e. not corresponding to a given user, then you will mess the whole script up. This might be something not to do with the script but actually the value stored in $sess->userid. Just food for thought and worth investigating also.

This post has been edited by DaneAU: 10 February 2014 - 04:49 PM

Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: Sanity check

Posted 11 February 2014 - 06:24 AM

I might add that there is no point in receiving DB data if all youre interested in is the row count. for this case simply use SQLs COUNT() function.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1