summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-07 17:19:21 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-07 17:19:21 -0400
commit2b92850a6aaa28074cddba730b11ab606a3adcd9 (patch)
tree43c29ba3cf393cc7d541af1cb824388cea6def00 /shared
parentFix blip with favicon.ico (diff)
downloadingenue-2b92850a6aaa28074cddba730b11ab606a3adcd9.tar.gz
ingenue-2b92850a6aaa28074cddba730b11ab606a3adcd9.tar.bz2
ingenue-2b92850a6aaa28074cddba730b11ab606a3adcd9.zip
Major restructuring of frontend modules (package selection not done yet); created conf_build_common class for shared code among configurations and builds
Diffstat (limited to 'shared')
-rw-r--r--shared/classes/1conf_build_common.php92
-rw-r--r--shared/classes/build.php34
-rw-r--r--shared/classes/configuration.php62
-rw-r--r--shared/config.php3
4 files changed, 105 insertions, 86 deletions
diff --git a/shared/classes/1conf_build_common.php b/shared/classes/1conf_build_common.php
new file mode 100644
index 0000000..4e74d09
--- /dev/null
+++ b/shared/classes/1conf_build_common.php
@@ -0,0 +1,92 @@
+<?php
+abstract class conf_build_common extends sql_row_obj {
+ private $info;
+ private function set_vars() {
+ if (isset($this->info)) {
+ return;
+ }
+ $array=array(
+ 'sql_configuration' => array(
+ 'optsclass' => 'sql_configopt',
+ 'optstable' => 'configopts',
+ 'self' => 'configuration',
+ ),
+ 'sql_build' => array(
+ 'optsclass' => 'sql_buildopt',
+ 'optstable' => 'buildopts',
+ 'self' => 'build'
+ )
+ );
+ $this->info=$array[get_class($this)];
+ }
+ // Fetches all available configopts pertaining to this configuration in a nice array (cached)
+ private $opt_cache;
+ public function &get_opts($get_objs=false) {
+ $this->set_vars();
+ global $S;
+ if (!isset($this->opt_cache)) {
+ $this->opt_cache=array();
+ $r=$S['pdo']->query('SELECT * FROM `'.$this->info['optstable'].'` WHERE `'.$this->info['self'].'`="'.$this->id.'"');
+ while ($opt=$r->fetch(PDO::FETCH_ASSOC)) {
+ $this->opt_cache[$opt['name']]=new $this->info['optsclass']($opt);
+ }
+ }
+ if ($get_objs) {
+ return $this->opt_cache;
+ } else {
+ $opts=array();
+ foreach ($this->opt_cache as $opt) {
+ $opts[$opt->name]=$opt->value;
+ }
+ }
+ return $opts;
+ }
+ // Generates a unique id and sets status to 1, writes self to db and returns id
+ public function init() {
+ global $S;
+ $this->owner=$S['user']->id;
+ $this->status=1;
+ $fails=0;
+ while (true) {
+ $id=randstring(6);
+ debug("Trying id=$id...");
+ $r=$S['pdo']->query('SELECT `id` FROM `'.$this->table.'` WHERE `id`="'.$id.'"');
+ if ($r->rowCount() == 0) {
+ break;
+ }
+ if (++$fails == 10) {
+ throw_exception('Failed 10 times to find a unique id in table `'.$this->table.'`... this shouldn\'t happen.');
+ }
+ }
+ $this->id=$id;
+ $this->write();
+ return $this->id;
+ }
+ public function summary() {
+ $opts=$this->get_opts();
+ $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>';
+ }
+ }
+ // Sets a particular config/buildopt, using either UPDATE or INSERT
+ public function set_opt($name, $val) {
+ $this->set_vars();
+ $opts=$this->get_opts(true);
+ if (isset($opts[$name])) {
+ $opts[$name]->value=$val;
+ $opts[$name]->write();
+ } else {
+ $this->opt_cache[$name]=new $this->info['optsclass']($this->id, $name, $val);
+ $this->opt_cache[$name]->write();
+ }
+ }
+}
+?>
diff --git a/shared/classes/build.php b/shared/classes/build.php
index 9b2decc..b13ac29 100644
--- a/shared/classes/build.php
+++ b/shared/classes/build.php
@@ -1,5 +1,5 @@
<?php
-class sql_build extends sql_row_obj {
+class sql_build extends conf_build_common {
protected $table='builds', $primary_key=array('id'), $columns=array(
'id' => array (
'type' => 'CHAR',
@@ -41,38 +41,6 @@ class sql_build extends sql_row_obj {
'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/step1';
- $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_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->name]=$opt->value; // TODO maybe we should return the actual objects
- }
- return $opts;
- }
// Returns HTML code describing this build's status (for human consumption)
function display() {
global $S;
diff --git a/shared/classes/configuration.php b/shared/classes/configuration.php
index 088908f..fedef12 100644
--- a/shared/classes/configuration.php
+++ b/shared/classes/configuration.php
@@ -1,5 +1,5 @@
<?php
-class sql_configuration extends sql_row_obj {
+class sql_configuration extends conf_build_common {
protected $table='configurations', $primary_key=array('id'), $columns=array(
'id' => array (
'type' => 'CHAR',
@@ -19,51 +19,25 @@ class sql_configuration extends sql_row_obj {
'type' => 'VARCHAR',
'length' => 255
),
- 'status' => array (
+ 'module' => array (
'type' => 'VARCHAR',
'length' => 255,
'not_null' => true,
'default' => ''
+ ),
+ 'status' => array (
+ 'type' => 'TINYINT',
+ 'length' => 4,
+ 'not_null' => true,
+ 'default' => 0
)
);
- // 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) {
+ public function build($name=null) {
$build=new sql_build();
$build->init();
$build->name=$name;
- $opts=$this->get_configopts();
+ $opts=$this->get_opts();
$opts['configuration']=$this->id;
foreach ($opts as $name => $val) {
$opt=new sql_buildopt($build->id, $name, $val);
@@ -74,22 +48,8 @@ class sql_configuration extends sql_row_obj {
$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() {
+ public function get_builds() {
global $S;
$r=$S['pdo']->query('SELECT `build` FROM `buildopts` WHERE `name`="configuration" AND `value`="'.$this->id.'"');
if ($r->rowCount()) {
diff --git a/shared/config.php b/shared/config.php
index d48d17e..b42cb8a 100644
--- a/shared/config.php
+++ b/shared/config.php
@@ -6,8 +6,7 @@ $conf['sqlpass']='socpassword'; // MySQL password
$conf['sqldb']='soc'; // MySQL database
$conf['debug']=true; // Whether to print debugging information
$conf['cache']=true; // Whether to enable built-in caching
-$conf['backend_modules']='gentoo_portage gentoo_catalyst'; // Space-separated list of backend modules to offer the user
-$conf['frontend_modules']='gentoo'; // Space-separated list of frontend modules to offer the user
+$conf['modules']='gentoo_portage x gentoo_catalyst'; // Space-separated list of modules to offer the user
$conf['cookiename']='ingenueid'; // Name of the cookie to send for keeping sessions
$conf['sessionlength']=1814400; // Time in seconds before sessions are purged
$conf['timezone']=10800; // Time difference in seconds between UTC and the default timezone