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
68
69
70
71
72
73
|
<?php
class sql_build extends sql_row_obj {
protected $table='builds', $ids='id owner', $columns=array(
'id' => array (
'type' => 'CHAR',
'length' => 6,
'not_null' => true,
),
'owner' => array (
'type' => 'INT',
'length' => 10,
'unsigned' => true,
'not_null' => true,
'refers to' => 'users.id'
),
'name' => array (
'type' => 'VARCHAR',
'length' => 255
),
'status' => array (
'type' => 'VARCHAR',
'length' => 255,
'not_null' => true
),
'ctime' => array (
'type' => 'INT',
'length' => 10,
'unsigned' => true
),
'start' => array (
'type' => 'INT',
'length' => 10,
'unsigned' => true
),
'finish' => array (
'type' => 'INT',
'length' => 10,
'unsigned' => true
)
);
// Generates a unique id and sets status to config/step0, writes self to db and returns id
public function init() {
global $S;
$this->owner=$S['user']->id;
$this->status='config/step0';
$fails=0;
while (true) {
$id=randstring(6);
debug("Trying id=$id...");
$r=$S['pdo']->query('SELECT `id` FROM `builds` WHERE `id`="'.$id.'"');
if ($r->rowCount() == 0) {
break;
}
if (++$fails == 10) {
throw new Exception('Failed 10 times to find a unique build id... this shouldn\'t happen.');
}
}
$this->id=$id;
$this->write();
return $this->id;
}
// Fetches all available buildopts pertaining to this build in a nice array
function get_buildopts() {
global $S;
$r=$S['pdo']->query('SELECT * FROM `buildopts` WHERE `build`="'.$this->id.'"');
$opts=array();
while ($opt=$r->fetch(PDO::FETCH_ASSOC)) {
$opt=new sql_buildopt($opt);
$opts=&$opt;
}
}
}
?>
|