-
Notifications
You must be signed in to change notification settings - Fork 0
/
csdb-linkrepair.php
67 lines (61 loc) · 1.52 KB
/
csdb-linkrepair.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once("scripts-bootstrap.inc.php");
$id = (int)$argv[1] ?: 64280;
function fixCSDB( $prod )
{
if (!$prod->csdb) return false;
printf("%6d -> ",$prod->id);
printf("%6d -> ",$prod->csdb);
$csdbID = $prod->csdb;
$csdbXML = file_get_contents(sprintf("http://csdb.dk/webservice/?type=release&id=%d",$csdbID));
$url = false;
$xml = @simplexml_load_string($csdbXML);
if (!$xml)
{
printf("*xmlerror:%s*\n",substr($csdbXML,0,10));
return;
}
if ($xml->Release->DownloadLinks)
{
foreach($xml->Release->DownloadLinks->DownloadLink as $v)
{
if (strstr($v->Link,"getinternalfile.php")!==false && $v->Status == "Ok")
{
$url = $v->Link;
}
}
if (!$url)
{
foreach($xml->Release->DownloadLinks->DownloadLink as $v)
{
if ($v->Status == "Ok")
{
$url = $v->Link;
}
}
}
if (!$url)
{
printf("*allurlsbroken*\n");
}
}
if ($url)
{
printf("%s\n",$url);
SQLLib::UpdateRow("prods",array("download"=>$url),sprintf_esc("id=%d",$prod->id));
SQLLib::Query(sprintf_esc("delete from prods_linkcheck where prodID = %d",$prod->id));
return true;
}
printf("*urlnotfound*\n");
return false;
}
$prods = SQLLib::SelectRows("select * from prods_linkcheck ".
" left join prods on prods_linkcheck.prodid = prods.id ".
" where (returncode = 0 or returncode >= 400) and csdb > 0");
$i = 0;
foreach($prods as $prod)
{
printf("%5d / %5d | ",$i++,count($prods));
fixCSDB($prod);
//exit();
}