From b0d9b188952efa2874516c93404af2f6f5b2ea5e Mon Sep 17 00:00:00 2001 From: "cst%andrew.cmu.edu" Date: Sun, 23 Jan 2005 20:08:32 +0000 Subject: [PATCH] Bug 278016 VersionCheck should support multiple items in one pass Patch by Ted Mielczarek (luser) , r=me --- webtools/update/update/VersionCheck.php | 204 ++++++++++++------------ 1 file changed, 106 insertions(+), 98 deletions(-) diff --git a/webtools/update/update/VersionCheck.php b/webtools/update/update/VersionCheck.php index bd6ca53e3cfa..965321c2d817 100644 --- a/webtools/update/update/VersionCheck.php +++ b/webtools/update/update/VersionCheck.php @@ -21,6 +21,7 @@ * * Contributor(s): * Vladimir Vukicevic + * Ted Mielczarek * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -105,38 +106,41 @@ function vercmp ($a, $b) { } // -// These are passed in the GET string +// These are passed in the GET string / POST request // -if (!array_key_exists('reqVersion', $_GET)) +if (!array_key_exists('reqVersion', $_REQUEST)) bail ("Invalid request."); -$reqVersion = $_GET['reqVersion']; +$reqVersion = $_REQUEST['reqVersion']; if ($reqVersion == 1) { - if (!array_key_exists('id', $_GET) || - !array_key_exists('version', $_GET) || - !array_key_exists('maxAppVersion', $_GET) || - !array_key_exists('appID', $_GET) || - !array_key_exists('appVersion', $_GET)) + if (!array_key_exists('id', $_REQUEST) || + !array_key_exists('version', $_REQUEST) || + !array_key_exists('maxAppVersion', $_REQUEST) || + !array_key_exists('appID', $_REQUEST) || + !array_key_exists('appVersion', $_REQUEST)) bail ("Invalid request."); - $reqItemGuid = mysql_real_escape_string($_GET['id']); - $reqItemVersion = mysql_real_escape_string($_GET['version']); - $reqItemMaxAppVersion = mysql_real_escape_string($_GET['maxAppVersion']); - $reqTargetAppGuid = mysql_real_escape_string($_GET['appID']); - $reqTargetAppVersion = mysql_real_escape_string($_GET['appVersion']); + // these three can have multiple values + $reqItemGuid = explode(",",mysql_real_escape_string($_REQUEST['id'])); + $reqItemVersion = explode(",",mysql_real_escape_string($_REQUEST['version'])); + // are we even using this? + $reqItemMaxAppVersion = explode(",",mysql_real_escape_string($_REQUEST['maxAppVersion'])); + $reqTargetAppGuid = mysql_real_escape_string($_REQUEST['appID']); + $reqTargetAppVersion = mysql_real_escape_string($_REQUEST['appVersion']); // For backwards compatibility, not required. - $reqTargetOS = mysql_real_escape_string($_GET['appOS']); + $reqTargetOS = mysql_real_escape_string($_REQUEST['appOS']); } else { // bail bail ("Bad request version received"); } // check args -if (empty($reqItemGuid) || empty($reqItemVersion) || empty($reqTargetAppGuid)) { +if (empty($reqItemGuid) || empty($reqItemVersion) || empty($reqTargetAppGuid) + || (count($reqItemGuid) != count($reqItemVersion))) { bail ("Invalid request."); } @@ -203,68 +207,6 @@ if ( ( $reqTargetOS == 'WINNT' ) $osid = 6; } -$query = -"SELECT main.guid AS extguid, - main.type AS exttype, - version.version AS extversion, - version.uri AS exturi, - version.minappver AS appminver, - version.maxappver AS appmaxver, - applications.guid AS appguid - FROM main - INNER JOIN version ON main.id = version.id - INNER JOIN applications ON version.appid = applications.appid "; - -/* We want to filter the results so that only OS=ALL and OS specific -results show up. */ - -$where = " WHERE main.guid = '" . $reqItemGuid . "' - AND applications.guid = '" . $reqTargetAppGuid . "' - AND (version.OSID = 1 OR version.OSID = " . $osid . ") - AND version.approved = 'YES'"; - -/* Sort the result set so that the greatest OS Specific is the last one -at each level. */ - -$order = " ORDER BY version.MaxAppVer_int DESC, version.version -DESC, version.osid DESC"; - -$result = mysql_query ($query . $where . $order); - -if (!$result) { - bail ('Query error: ' . mysql_error()); -} - -// info for this version -$thisVersionData = ''; - -// info for highest version -$highestVersionData = ''; - -$itemType = ''; - -while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { - if (empty($itemType)) { - $itemType = $ext_typemap[$line['exttype']]; - } - - // Do we already have the current or a newer one? - if (vercmp($line['extversion'], $reqItemVersion) <= 0) { - $thisVersionData = $line; - break; - } - - // Is this one compatible? - if (vercmp($line['appmaxver'], $reqTargetAppVersion) >= 0 && - vercmp($line['appminver'], $reqTargetAppVersion) <= 0) { - $highestVersionData = $line; - break; - } - // Keep going until we find one that is -} - -mysql_free_result ($result); - // // Now to spit out the RDF. We hand-generate because the data is pretty simple. // @@ -272,24 +214,6 @@ mysql_free_result ($result); print "\n"; print "\n\n"; -print "\n"; - -// output list of updates (just highest and this) -print " \n"; -if (!empty($thisVersionData)) - print " \n"; -if (!empty($highestVersionData)) - print " \n"; -print " \n"; - -// output compat bits for firefox 0.9 -if (!empty($highestVersionData)) { - print " {$highestVersionData['extversion']}\n"; - print " {$highestVersionData['exturi']}\n"; -} - -print "\n\n"; - function print_update ($data) { global $ext_typemap; $dataItemType = $ext_typemap[$data['exttype']]; @@ -303,14 +227,98 @@ function print_update ($data) { print " {$data['exturi']}\n"; print " \n"; print " \n"; - print "\n"; + print "\n\n"; } -if (!empty($thisVersionData)) +// now we query for each item +for($i=0; $i < count($reqItemGuid); $i++) +{ + $query = + "SELECT main.guid AS extguid, + main.type AS exttype, + version.version AS extversion, + version.uri AS exturi, + version.minappver AS appminver, + version.maxappver AS appmaxver, + applications.guid AS appguid + FROM main + INNER JOIN version ON main.id = version.id + INNER JOIN applications ON version.appid = applications.appid "; + + /* We want to filter the results so that only OS=ALL and OS specific +results show up. */ + + $where = " WHERE main.guid = '" . $reqItemGuid[$i] . "' + AND applications.guid = '" . $reqTargetAppGuid . "' + AND (version.OSID = 1 OR version.OSID = " . $osid . ") + AND version.approved = 'YES'"; + + /* Sort the result set so that the greatest OS Specific is the last one +at each level. */ + + $order = " ORDER BY version.MaxAppVer_int DESC, version.version +DESC, version.osid DESC"; + + $result = mysql_query ($query . $where . $order); + + if (!$result) { + bail ('Query error: ' . mysql_error()); + } + + // info for this version + $thisVersionData = ''; + + // info for highest version + $highestVersionData = ''; + + $itemType = ''; + + while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { + if (empty($itemType)) { + $itemType = $ext_typemap[$line['exttype']]; + } + + // Do we already have the current or a newer one? + if (vercmp($line['extversion'], $reqItemVersion[$i]) <= 0) { + $thisVersionData = $line; + break; + } + + // Is this one compatible? + if (vercmp($line['appmaxver'], $reqTargetAppVersion) >= 0 && + vercmp($line['appminver'], $reqTargetAppVersion) <= 0) { + $highestVersionData = $line; + break; + } + // Keep going until we find one that is + } + + print "\n"; + + // output list of updates (just highest and this) + print " \n"; + if (!empty($thisVersionData)) + print " \n"; + if (!empty($highestVersionData)) + print " \n"; + print " \n"; + + // output compat bits for firefox 0.9 + if (!empty($highestVersionData)) { + print " {$highestVersionData['extversion']}\n"; + print " {$highestVersionData['exturi']}\n"; + } + + print "\n\n"; + + if (!empty($thisVersionData)) print_update ($thisVersionData); -if (!empty($highestVersionData)) + if (!empty($highestVersionData)) print_update ($highestVersionData); + mysql_free_result ($result); +} + print "\n"; ?>