summaryrefslogtreecommitdiff
blob: 8780b9dfbe2c0753ffd6d4b35a4b25c2a3046f24 (plain)
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
74
75
76
77
78
79
80
81
<?php
class sql_configuration extends conf_build_common {
	protected $table='configurations', $primary_key=array('id'), $columns=array(
		'id' => array (
			'type' => 'CHAR',
			'length' => 6,
			'not_null' => true,
			'default' => ''
		),
		'owner' => array (
			'type' => 'INT',
			'length' => 10,
			'unsigned' => true,
			'not_null' => true,
			'default' => 0,
			'refers_to' => 'users.id'
		),
		'name' => array (
			'type' => 'VARCHAR',
			'length' => 255
		),
		'module' => array (
			'type' => 'VARCHAR',
			'length' => 255,
			'not_null' => true,
			'default' => ''
		),
		'visibility' => array (
			'type' => 'ENUM',
			'length' => '\'public\',\'private\'',
			'not_null' => true
		),
		'status' => array (
			'type' => 'TINYINT',
			'length' => 4,
			'not_null' => true,
			'default' => 0
		)
	);
	public function build($name=null) {
		$module=new module($this->module);
		for ($i=1; $i<=$module->numsteps; $i++) {
			$step=new wizard_step($this, $i);
			if (!$step->verify()) {
				$this->status=$i;
				$this->write();
				return $i;
			}
		}
		$build=new sql_build();
		$build->visibility='public';
		$build->init();
		$build->name=$name;
		$build->module=$this->module;
		$opts=$this->get_opts();
		$opts['configuration']=$this->id;
		foreach ($opts as $name => $val) {
			$opt=new sql_buildopt($build->id, $name, $val);
			$opt->write();
		}
		$build->ctime=time();
		$build->status='queued';
		$build->write();
		return $build;
	}
	// Returns an array of the IDs of all the builds that report this configuration as their source
	public function get_builds() {
		global $S;
		$r=query('SELECT `builds`.* FROM `buildopts` INNER JOIN `builds` WHERE `buildopts`.`name`="configuration" AND `buildopts`.`value`="'.$this->id.'" AND `builds`.`id`=`buildopts`.`build`');
		if ($r->rowCount()) {
			$builds=array();
			while ($b=$r->fetch(PDO::FETCH_ASSOC)) {
				$builds[]=new sql_build($b);
			}
			return $builds;
		} else {
			return null;
		}
	}
}
?>