summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-03 14:04:10 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-03 14:04:10 -0400
commitb38ffa446425cad5bd1f7bedffb311903c58c823 (patch)
treed5ec561a722c5e1fae079f0a647836de23704826 /shared
parentBackend can upload finished images; caches state after emerge system completes (diff)
downloadingenue-b38ffa446425cad5bd1f7bedffb311903c58c823.tar.gz
ingenue-b38ffa446425cad5bd1f7bedffb311903c58c823.tar.bz2
ingenue-b38ffa446425cad5bd1f7bedffb311903c58c823.zip
Separated configurations from builds of those configurations, added configurations manager to frontend
Diffstat (limited to 'shared')
-rw-r--r--shared/classes/configopt.php22
-rw-r--r--shared/classes/configuration.php106
2 files changed, 128 insertions, 0 deletions
diff --git a/shared/classes/configopt.php b/shared/classes/configopt.php
new file mode 100644
index 0000000..178d0bb
--- /dev/null
+++ b/shared/classes/configopt.php
@@ -0,0 +1,22 @@
+<?php
+class sql_configopt extends sql_row_obj {
+ protected $table='configopts', $primary_key=array('configuration', 'name'), $columns=array(
+ 'configuration' => array (
+ 'type' => 'CHAR',
+ 'length' => 6,
+ 'not_null' => true,
+ 'refers_to' => 'configurations.id'
+ ),
+ 'name' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => ''
+ ),
+ 'value' => array (
+ 'type' => 'TEXT'
+ )
+
+ );
+}
+?>
diff --git a/shared/classes/configuration.php b/shared/classes/configuration.php
new file mode 100644
index 0000000..088908f
--- /dev/null
+++ b/shared/classes/configuration.php
@@ -0,0 +1,106 @@
+<?php
+class sql_configuration extends sql_row_obj {
+ 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
+ ),
+ 'status' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => ''
+ )
+
+ );
+ // 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/step1';
+ $fails=0;
+ while (true) {
+ $id=randstring(6);
+ debug("Trying id=$id...");
+ $r=$S['pdo']->query('SELECT `id` FROM `configurations` WHERE `id`="'.$id.'"');
+ if ($r->rowCount() == 0) {
+ break;
+ }
+ if (++$fails == 10) {
+ throw_exception('Failed 10 times to find a unique configuration id... this shouldn\'t happen.');
+ }
+ }
+ $this->id=$id;
+ $this->write();
+ return $this->id;
+ }
+ // Fetches all available configopts pertaining to this configuration in a nice array
+ function &get_configopts() {
+ global $S;
+ $r=$S['pdo']->query('SELECT * FROM `configopts` WHERE `configuration`="'.$this->id.'"');
+ $opts=array();
+ while ($opt=$r->fetch(PDO::FETCH_ASSOC)) {
+ $opt=new sql_configopt($opt);
+ $opts[$opt->name]=$opt->value; // TODO maybe we should return the actual objects
+ }
+ return $opts;
+ }
+ function build($name=null) {
+ $build=new sql_build();
+ $build->init();
+ $build->name=$name;
+ $opts=$this->get_configopts();
+ $opts['configuration']=$this->id;
+ foreach ($opts as $name => $val) {
+ $opt=new sql_buildopt($build->id, $name, $val);
+ $opt->write();
+ }
+ $build->ctime=time();
+ $build->status='build/ready';
+ $build->write();
+ return $build;
+ }
+ function summary() {
+ $opts=$this->get_configopts();
+ $r=array();
+ foreach($opts as $name => $val) {
+ $name=htmlentities($name);
+ $val=htmlentities($val);
+ $r[]="$name</td><td class=\"val\">$val";
+ }
+ if ($r) {
+ return '<table class="configsummary"><tr><td class="name">'.implode('</td></tr><tr><td class="name">', $r).'</td></tr></table>';
+ } else {
+ return '<i>No options set</i>';
+ }
+ }
+ // Returns an array of the IDs of all the builds that report this configuration as their source
+ function get_builds() {
+ global $S;
+ $r=$S['pdo']->query('SELECT `build` FROM `buildopts` WHERE `name`="configuration" AND `value`="'.$this->id.'"');
+ if ($r->rowCount()) {
+ $builds=array();
+ while ($b=$r->fetch(PDO::FETCH_COLUMN)) {
+ $builds[]=$b;
+ }
+ return $builds;
+ } else {
+ return null;
+ }
+ }
+}
+?>