Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | daniel-mar | 1 | #!/usr/bin/php |
2 | <?php |
||
3 | |||
4 | require_once __DIR__ . '/includes/db.inc.php'; |
||
5 | require_once __DIR__ . '/includes/src.inc.php'; |
||
6 | |||
6 | daniel-mar | 7 | $stam_cfg = array(); |
8 | $stam_cfg['simulation'] = false; |
||
9 | require_once __DIR__ . '/includes/config.inc.php'; |
||
10 | |||
3 | daniel-mar | 11 | if ($argc <> 2) { |
12 | echo "Syntax: $argv[0] <id>\n"; |
||
13 | #db_close(); |
||
14 | exit(2); |
||
15 | } |
||
16 | |||
17 | $id = trim($argv[1]); |
||
18 | |||
19 | # Range support |
||
20 | if (strpos($id, '-') !== false) { |
||
21 | $ary = explode('-', $id, 2); |
||
22 | $id_min = $ary[0]; |
||
23 | $id_max = $ary[1]; |
||
24 | } else { |
||
25 | $id_min = $id; |
||
26 | $id_max = $id; |
||
27 | } |
||
28 | if (($id_min == 0) || ($id_max == 0)) { |
||
29 | fwrite(STDERR, "0 not a valid ID\n"); |
||
30 | #db_close(); |
||
31 | exit(3); |
||
32 | } |
||
6 | daniel-mar | 33 | $id_min = (int)$id_min; |
34 | $id_max = (int)$id_max; |
||
3 | daniel-mar | 35 | if ($id_min>$id_max) { |
36 | fwrite(STDERR, "RANGE ERROR $id_min>$id_max\n"); |
||
37 | #db_close(); |
||
38 | exit(3); |
||
39 | } |
||
6 | daniel-mar | 40 | $id_cnt = $id_max - $id_min + 1; |
3 | daniel-mar | 41 | |
42 | # Simulation mode |
||
43 | if ($stam_cfg['simulation']) { |
||
44 | fwrite(STDERR, "============ STRIKE SIMULATION: $id_min..$id_max\n"); |
||
45 | #db_close(); |
||
46 | exit(0); |
||
47 | } |
||
48 | |||
49 | $str = db_query("SELECT id, cat, txt FROM stam_entries WHERE |
||
50 | id >= '".db_real_escape_string($id_min)."' |
||
51 | AND id <= '".db_real_escape_string($id_max)."' |
||
52 | "); |
||
53 | if (!$str) { |
||
54 | fwrite(STDERR, db_error()."\n"); |
||
55 | #db_close(); |
||
56 | exit(1); |
||
57 | } |
||
58 | while ($row = db_fetch_array($str)) { |
||
59 | $id = $row['id']; |
||
60 | $cat = $row['cat']; |
||
61 | $txt = $row['txt']; |
||
62 | |||
63 | $x = db_query("UPDATE stam_entries SET state = 'S' WHERE |
||
64 | id = '".db_real_escape_string($id)."'"); |
||
65 | if (!$x) { |
||
66 | fwrite(STDERR, db_error()."\n"); |
||
67 | #db_close(); |
||
68 | exit(1); |
||
69 | } |
||
70 | |||
71 | $afr = db_affected_rows(); |
||
72 | if ($afr != 1) { |
||
73 | fwrite(STDERR, "Error: Could not update $id <$cat> '$txt'\n"); |
||
74 | #db_close(); |
||
75 | exit(1); |
||
76 | } else { |
||
77 | #echo green("OK! Striked: $id <$cat> $txt\n"); |
||
78 | echo green("OK! $id - <$cat> $txt\n"); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | # --- |
||
83 | |||
84 | function green($txt) { |
||
85 | return "\033[1;32;40m".$txt."\033[0m"; |
||
86 | } |
||
87 |