]> git.pld-linux.org Git - projects/buildlogs.git/blob - obsolete/buildlogs.sql/addlog.php
06fa3238bc066dcf1ba78e752b21529d103b8bdf
[projects/buildlogs.git] / obsolete / buildlogs.sql / addlog.php
1 #!/usr/bin/php.cli
2 <?php
3 // $Revision: 1.3 $, $Date: 2007-11-24 11:10:33 $
4 $database = 'sqlite:/home/services/ftp/buildlogs.db';
5 $root_directory = '/home/services/ftp/pub/pld-buildlogs';
6 // $database and $root_directory are taken from buildlogs.inc .
7 include_once('buildlogs.inc');
8 // parameter: argv[1] - full path to the log file.
9 // Keep in sync with database
10 $result = array("FAIL" => 0, "OK" => 1);
11 $arch = array(
12         "th/SRPMS" => 1,
13         "th/i486" => 2,
14         "th/i686" => 3,
15         "th/athlon" => 4,
16         "th/x86_64" => 5,
17         "th/ia64" => 6,
18         "th/alpha" => 7,
19         "th/ppc" => 8,
20         "th/sparc" => 9,
21         "ac/SRPMS" => 10,
22         "ac/i386" => 11,
23         "ac/i586" => 12,
24         "ac/i686" => 13,
25         "ac/athlon" => 14,
26         "ac/amd64" => 15,
27         "ac/alpha" => 16,
28         "ac/ppc" => 17,
29         "ac/sparc" => 18,
30         "ac/sparc64" => 19
31 );
32
33 if (!isset($argv[1])) {
34         die("Usage: $argv[0] full_path_to_the_log\n");
35 }
36 preg_match("|$root_directory/(.*/.*)/(.*)/(.*)\.bz2|", $argv[1], $matches);
37
38 $arch_name = $matches[1];
39 if (!array_key_exists($arch_name, $arch)) {
40         die("$argv[1]: Nieznana architektura \"$arch_name\"\n");
41 }
42 else $arch_id = $arch[$arch_name];
43
44 $result_name = $matches[2];
45 if (!array_key_exists($result_name, $result)) {
46         die("$argv[1]: Nieznany resultat \"$result_name\"\n");
47 }
48 else $result_id = $result[$result_name];
49
50 $spec_name = $matches[3];
51 if ($spec_name == '') {
52         die("$argv[1]: Brak nazwy speca.\n");
53 }
54
55 $spec_name = addslashes($spec_name);
56 $size = filesize($argv[1]);
57 $mtime = filemtime($argv[1]);
58
59 try {
60         $dbh = new PDO("$database");
61 } catch (PDOException $e) {
62         die ($e->getMessage());
63 }
64 $result = $dbh->query("SELECT log_id FROM logs WHERE spec = '$spec_name' AND arch_id = $arch_id AND result = $result_id LIMIT 1")->fetchAll();
65 if (count($result) == 1) {
66         foreach ($result as $row) {
67                 $query = "UPDATE logs SET result = $result_id, size = $size, mtime = $mtime WHERE log_id = $row[log_id]";
68                 break;
69         }
70 } else {
71         $query = "INSERT INTO logs(arch_id, result, size, mtime, spec) VALUES($arch_id, $result_id, $size, $mtime, '$spec_name')";
72 }
73 //echo "$query\n";
74 $dbh->beginTransaction();
75 $dbh->exec("$query");
76 $dbh->commit();
77 ?>
This page took 0.028772 seconds and 2 git commands to generate.