]> git.pld-linux.org Git - projects/buildlogs.git/blame - pld-buildlogs/scripts/migration.php
- add index
[projects/buildlogs.git] / pld-buildlogs / scripts / migration.php
CommitLineData
a7f1713c 1#!/usr/bin/php.cli
2<?php
13845e57 3// $Revision: 1.3 $, $Date: 2009/01/20 07:49:34 $
a7f1713c 4/*
5$root_directory = '/home/services/ftp/pub/pld-buildlogs';
9dcdc6b4 6$database = 'sqlite:/home/services/httpd/html/pld-buildlogs/db/buildlogs2.db';
a7f1713c 7// $root_directory and $database are taken from buildlogs.inc
a7f1713c 8*/
9dcdc6b4 9include('buildlogs.inc');
a7f1713c 10
11if (file_exists($database_file)) {
12 unlink($database_file);
13}
14
15$query = " CREATE TABLE LOGS(log_id INTEGER PRIMARY KEY, dist TEXT, arch TEXT, ok INTEGER, name TEXT, "
13845e57 16 . "size INTEGER, mtime INTEGER, id TEXT DEFAULT ''); CREATE INDEX IF NOT EXISTS dao_index ON LOGS(dist, arch, ok);";
a7f1713c 17try {
18 $dbhandle = new PDO("$database");
19} catch (PDOException $e) {
20 die("new PDO: ". $e->getMessage());
21}
22
23$result = array("FAIL", "OK");
24
25$dh = opendir($root_directory);
8f0e31ba 26if (!$dh) {
a7f1713c 27 die("opendir $root_directory");
28}
29while ($dist = readdir($dh)) {
30 if ($dist[0] == '.') continue;
31 if (!is_dir("$root_directory/$dist")) continue;
32 $ah = opendir("$root_directory/$dist");
8f0e31ba 33 if (!$ah) die("opendir $dist");
a7f1713c 34 while ($arch = readdir($ah)) {
35 if ($arch[0] == '.') continue;
36 if (!is_dir("$root_directory/$dist/$arch")) continue;
37 for ($ok = 0; $ok < 2; $ok++) {
8f0e31ba 38 $directory = "$root_directory/$dist/$arch/" . $result[$ok];
a7f1713c 39 $sh = opendir($directory);
40 if (!$sh) continue;
41 while ($file = readdir($sh)) {
8f0e31ba 42 if (preg_match("/^(.*)\.bz2$/", $file, $match)) {
43 if (preg_match("/(.*),(.*)/", $match[1], $m2)) {
44 $name = $m2[1];
45 $id = $m2[2];
a7f1713c 46 } else {
8f0e31ba 47 $name = $match[1];
a7f1713c 48 $id = "";
49 }
8f0e31ba 50 $f = "$directory/" . $match[0];
51 $size = filesize($f);
52 $mtime = filemtime($f);
a7f1713c 53$query .= " INSERT INTO logs(dist, arch, ok, name, size, mtime, id) "
54. "VALUES('$dist', '$arch', $ok, '$name', $size, $mtime, '$id');";
55 }
56
57 }
58 closedir($sh);
59 }
60 }
61 closedir($ah);
62}
63closedir($dh);
64
65$dbhandle->beginTransaction();
66$dbhandle->exec("$query");
67$dbhandle->commit();
68?>
This page took 0.113128 seconds and 4 git commands to generate.