Author: jfthomps Date: Thu Sep 9 20:23:14 2010 New Revision: 995564 URL: http://svn.apache.org/viewvc?rev=995564&view=rev Log: VCL-378 reservation can be extended into a block allocation for user not in block group
-modified isAvailable - changed $skipRemoveUsedBlock to $altRemoveBlockCheck, then toward end of foreach, if $altRemoveBlockCheck is true, call editRequestBlockCheck and return 0 if it returns true -added editRequestBlockCheck - checks to see if $compid is part of an upcoming block that user is not part of or for a different image -modified maintenanceCheck - if no files in maintenance directory, $files is not an array and is then invalid for foreach; added check for it being an array to surpress the warning Modified: incubator/vcl/trunk/web/.ht-inc/utils.php Modified: incubator/vcl/trunk/web/.ht-inc/utils.php URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/utils.php?rev=995564&r1=995563&r2=995564&view=diff ============================================================================== --- incubator/vcl/trunk/web/.ht-inc/utils.php (original) +++ incubator/vcl/trunk/web/.ht-inc/utils.php Thu Sep 9 20:23:14 2010 @@ -554,6 +554,8 @@ function maintenanceCheck() { $search = preg_replace($reg, '', $_SERVER['SCRIPT_FILENAME']); $search .= "/.ht-inc/maintenance/"; $files = glob("$search*"); + if(! is_array($files)) + return; $inmaintenance = 0; foreach($files as $file) { if(! preg_match("|^$search([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$|", $file, $matches)) @@ -3475,11 +3477,11 @@ function isAvailable($images, $imageid, $computerids = array(); $currentids = array(); $blockids = array(); - $skipRemoveUsedBlock = 0; + $altRemoveBlockCheck = 0; // if we are modifying a request and it is after the start time, only allow // the scheduled computer(s) to be modified if($requestid && datetimeToUnix($requestData["start"]) <= time()) { - $skipRemoveUsedBlock = 1; + $altRemoveBlockCheck = 1; foreach($requestData["reservations"] as $key2 => $res) { if($res["imageid"] == $imageid) { $compid = $res["computerid"]; @@ -3576,7 +3578,13 @@ function isAvailable($images, $imageid, $blockids = array_diff($blockids, $usedComputerids); # remove computers from list that are allocated to block allocations - if(! count($blockids) && ! $skipRemoveUsedBlock) { + if($altRemoveBlockCheck) { + if(editRequestBlockCheck($computerids[0], $imageid, $start, $end)) { + semUnlock(); + return 0; + } + } + elseif(! count($blockids)) { # && ! $altRemoveBlockCheck $usedBlockCompids = getUsedBlockComputerids($start, $end); $computerids = array_diff($computerids, $usedBlockCompids); $currentids = array_diff($currentids, $usedBlockCompids); @@ -3812,6 +3820,46 @@ function checkOverlap($start, $end, $max //////////////////////////////////////////////////////////////////////////////// /// +/// \fn editRequestBlockCheck($compid, $imageid, $start, $end) +/// +/// \param $compid - id of computer to check +/// \param $imageid - id of image being checked +/// \param $start - start of time period in unix timestamp format +/// \param $end - end of time period in unix timestamp format +/// +/// \return 1 if time period overlaps with a block allocation unavailable to the +/// logged in user; 0 if not +/// +/// \brief checks to see if $compid is part of a block allocation that the +/// current user is not part of or is set for a different image than what the +/// user is currently using on the computer +/// +//////////////////////////////////////////////////////////////////////////////// +function editRequestBlockCheck($compid, $imageid, $start, $end) { + global $user; + $groupids = implode(',', array_keys($user['groups'])); + if(! count($user['groups'])) + $groupids = "''"; + $startdt = unixToDatetime($start); + $enddt = unixToDatetime($end); + $query = "SELECT bc.computerid " + . "FROM blockComputers bc, " + . "blockTimes bt, " + . "blockRequest r " + . "WHERE bc.blockTimeid = bt.id AND " + . "bt.blockRequestid = r.id AND " + . "bc.computerid = $compid AND " + . "(bt.start - INTERVAL 15 MINUTE) < '$enddt' AND " + . "bt.end > '$startdt' AND " + . "(r.groupid NOT IN ($groupids) OR " + . "r.imageid != $imageid) AND " + . "r.status = 'accepted'"; + $qh = doQuery($query, 101); + return(mysql_num_rows($qh)); +} + +//////////////////////////////////////////////////////////////////////////////// +/// /// \fn getReloadStartTime() /// /// \return unix timestamp @@ -6192,7 +6240,7 @@ function sortComputers($a, $b) { /// \param $start - starting time in unix timestamp form /// \param $end - ending time in unix timestamp form /// \param $allocatedcompids - array of computer ids that have already been -/// allocated while processing this block allocation +/// allocated while processing this reservation /// /// \return an array of computer ids ///