source: subversion/sites/other/tilesAtHome/lib/requests.inc @ 3655

Last change on this file since 3655 was 3057, checked in by ojw, 13 years ago

Count the number of retried requests

File size: 1.2 KB
Line 
1<?php
2define("REQUEST_PENDING", 0);
3define("REQUEST_NEW", 1);
4define("REQUEST_ACTIVE", 2);
5define("REQUEST_DONE", 3);
6#include("log.inc");
7
8function deleteRequest($X, $Y, $Mode){
9
10  $SQL = sprintf(
11    "delete from `tiles_queue` where `x`=%d and `y`=%d and `status`=%d;",
12    $X,
13    $Y,
14    $Mode);
15 
16  mysql_query($SQL);
17  #logSqlError();
18}
19
20function requestExists($X,$Y,$Mode){
21  $SQL = sprintf("select NULL from tiles_queue where `x`=%d and `y`=%d and `status`=%d;",$X,$Y,$Mode);
22  $Result = mysql_query($SQL);
23  if(mysql_error())
24    return(0);
25 
26  return(mysql_num_rows($Result) > 0 ? 1 : 0);
27}
28function moveRequest($X, $Y, $FromMode, $ToMode, $Debug = 0){
29
30  if(!requestExists($X,$Y,$FromMode))
31    return(0);
32   
33  # Delete any existing request already occupying the new mode (
34  deleteRequest($X, $Y, $ToMode);
35
36  # Move the specified request to the new mode
37  $SQL = sprintf(
38    "update `tiles_queue` set `status`=%d, `retries`=`retries`+1, `date`=now() where `x`=%d and `y`=%d and `status`=%d;",
39    $ToMode,
40    $X,
41    $Y,
42    $FromMode);
43 
44  $Result = mysql_query($SQL);
45  #logSqlError();
46 
47  if($Debug)
48    printf("\n$SQL\n".mysql_error()."\n");
49 
50  return(1);
51}
52
53?>
Note: See TracBrowser for help on using the repository browser.