summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-08-04 17:58:55 -0400
committerEudyptula <eitan@mosenkis.net>2009-08-04 17:58:55 -0400
commitd3da989d3e2d2cb03cdc4bd2e23783f716ef5035 (patch)
tree2f9f8c413d2800a3f72282dec0f86170a00ff4f6 /shared
parentAdd visibility column to builds, configurations (diff)
downloadingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.tar.gz
ingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.tar.bz2
ingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.zip
Widespread cleanup - moved $conf, $death into $S; $S is given as arg to init_x() and body_x(); $request removed in favor of $_REQUEST; query() replaces $S[pdo]->query(); etc.
Diffstat (limited to 'shared')
-rw-r--r--shared/classes/0sql_row_obj.php2
-rw-r--r--shared/classes/1conf_build_common.php4
-rw-r--r--shared/classes/build.php16
-rw-r--r--shared/classes/configuration.php3
-rw-r--r--shared/classes/gentoo_package.php2
-rw-r--r--shared/classes/gentoo_profile.php16
-rw-r--r--shared/classes/registrationtoken.php2
-rw-r--r--shared/classes/session.php10
-rw-r--r--shared/classes/task.php2
-rw-r--r--shared/classes/validate.php4
-rw-r--r--shared/functions/debug.php4
-rw-r--r--shared/functions/get_timezones.php8
-rw-r--r--shared/functions/load_config.php2
-rw-r--r--shared/functions/query.php8
-rw-r--r--shared/functions/url.php12
-rw-r--r--shared/functions/xhtmlemail.php6
-rw-r--r--shared/include/dbinit.php5
-rw-r--r--shared/include/includes.php1
18 files changed, 56 insertions, 51 deletions
diff --git a/shared/classes/0sql_row_obj.php b/shared/classes/0sql_row_obj.php
index 239dae3..4efacbd 100644
--- a/shared/classes/0sql_row_obj.php
+++ b/shared/classes/0sql_row_obj.php
@@ -285,8 +285,6 @@ abstract class sql_row_obj { // If the name of this class changes, it must be up
if (!array_key_exists($name, $this->db_values) || $this->values[$name] !== $this->db_values[$name]) {
$sql_val=$col->sql_value($this->values[$name]);
if (is_array($sql_val)) {
- //echo $name."\n";
- print_r($sql_val);
throw new Exception('Failed to write '.get_class($this).' object to table `'.$this->table.'` because column `'.$name.'` ('.$sql_val['description'].') '.$sql_val['reason'].' (value: '.$sql_val['value'].')');
}
if (++$i > 1) {
diff --git a/shared/classes/1conf_build_common.php b/shared/classes/1conf_build_common.php
index f5721a4..af20eba 100644
--- a/shared/classes/1conf_build_common.php
+++ b/shared/classes/1conf_build_common.php
@@ -26,7 +26,7 @@ abstract class conf_build_common extends sql_row_obj {
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.'"');
+ $r=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);
}
@@ -59,7 +59,7 @@ abstract class conf_build_common extends sql_row_obj {
while (true) {
$id=randstring(6);
debug("Trying id=$id...");
- $r=$S['pdo']->query('SELECT `id` FROM `'.$this->table.'` WHERE `id`="'.$id.'"');
+ $r=query('SELECT `id` FROM `'.$this->table.'` WHERE `id`="'.$id.'"');
if ($r->rowCount() == 0) {
break;
}
diff --git a/shared/classes/build.php b/shared/classes/build.php
index db12801..7230673 100644
--- a/shared/classes/build.php
+++ b/shared/classes/build.php
@@ -60,8 +60,8 @@ class sql_build extends conf_build_common {
$html='<div class="build"><span class="name">'.(isset($this->name) && strlen($this->name)?htmlentities($this->name):'Unnamed Build').'</span> ';
$links=array();
if ($this->status == -128) {
- $total=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128')->fetch(PDO::FETCH_COLUMN);
- $num=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128 AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN);
+ $total=query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128')->fetch(PDO::FETCH_COLUMN);
+ $num=query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128 AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN);
$html.="<span class=\"status queued\">[Queued ($num/$total)]</span>";
} elseif ($this->status == -127) {
$html.='<span class="status successful">[uploading]</span>';
@@ -74,7 +74,7 @@ class sql_build extends conf_build_common {
$links['Build Log']="build/$this->id";
}
} elseif ($this->status == 0) {
- $r=$S['pdo']->query('SELECT COUNT(*) as `count`, MAX(`time`) as `time` FROM `downloads` WHERE `build`="'.$this->id.'"')->fetch(PDO::FETCH_ASSOC);
+ $r=query('SELECT COUNT(*) as `count`, MAX(`time`) as `time` FROM `downloads` WHERE `build`="'.$this->id.'"')->fetch(PDO::FETCH_ASSOC);
$d=($perms && $r['count']?'<a href="'.url("build/$this->id/history").'">':'').$r['count'].' download'.($r['count'] != 1?'s':'').($r['count']?($perms?'</a>':'').'<br/><span class="time">(last at '.date($format, $r['time']).')</span>':'');
$html.='<span class="downloads">'.$d.'</span><span class="status successful">[successful]</span>';
$links['Download image']="build/$this->id/download";
@@ -125,15 +125,15 @@ class sql_build extends conf_build_common {
global $S;
static $cache;
if (!isset($cache))
- $cache=$S['pdo']->query('SELECT COUNT(`order`) FROM `tasks` WHERE `start` IS NULL AND `build`="'.$this->id.'"')->fetch(PDO::FETCH_COLUMN);
+ $cache=query('SELECT COUNT(`order`) FROM `tasks` WHERE `start` IS NULL AND `build`="'.$this->id.'"')->fetch(PDO::FETCH_COLUMN);
return $cache;
}
public function delete() {
global $S;
- $S['pdo']->query('DELETE FROM `buildlogs` WHERE `build`="'.$this->id.'"');
- $S['pdo']->query('DELETE FROM `tasks` WHERE `build`="'.$this->id.'"');
- $S['pdo']->query('DELETE FROM `buildopts` WHERE `build`="'.$this->id.'"');
- $S['pdo']->query('DELETE FROM `downloads` WHERE `build`="'.$this->id.'"');
+ query('DELETE FROM `buildlogs` WHERE `build`="'.$this->id.'"');
+ query('DELETE FROM `tasks` WHERE `build`="'.$this->id.'"');
+ query('DELETE FROM `buildopts` WHERE `build`="'.$this->id.'"');
+ query('DELETE FROM `downloads` WHERE `build`="'.$this->id.'"');
foreach (glob(COMPLETED."/build-.$this->id.*") as $file)
unlink($file);
parent::delete();
diff --git a/shared/classes/configuration.php b/shared/classes/configuration.php
index c6d5766..c7795f4 100644
--- a/shared/classes/configuration.php
+++ b/shared/classes/configuration.php
@@ -48,6 +48,7 @@ class sql_configuration extends conf_build_common {
}
}
$build=new sql_build();
+ $build->visibility='public';
$build->init();
$build->name=$name;
$build->module=$this->module;
@@ -65,7 +66,7 @@ class sql_configuration extends conf_build_common {
// Returns an array of the IDs of all the builds that report this configuration as their source
public function get_builds() {
global $S;
- $r=$S['pdo']->query('SELECT `build` FROM `buildopts` WHERE `name`="configuration" AND `value`="'.$this->id.'"');
+ $r=query('SELECT `build` FROM `buildopts` WHERE `name`="configuration" AND `value`="'.$this->id.'"');
if ($r->rowCount()) {
$builds=array();
while ($b=$r->fetch(PDO::FETCH_COLUMN)) {
diff --git a/shared/classes/gentoo_package.php b/shared/classes/gentoo_package.php
index 2c06a26..01d6da4 100644
--- a/shared/classes/gentoo_package.php
+++ b/shared/classes/gentoo_package.php
@@ -88,7 +88,7 @@ class sql_gentoo_package extends sql_row_obj {
}
if ($name != '*') $c[]='`name`="'.$name.'"';
$c=implode(' AND ', $c);
- $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE '.$c);
+ $r=query('SELECT * FROM `gentoo_packages` WHERE '.$c);
while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) {
$pkg=new sql_gentoo_package($pkg);
if (!$pkg->is_masked())
diff --git a/shared/classes/gentoo_profile.php b/shared/classes/gentoo_profile.php
index 7184aad..d7726f8 100644
--- a/shared/classes/gentoo_profile.php
+++ b/shared/classes/gentoo_profile.php
@@ -55,8 +55,8 @@ class sql_gentoo_profile extends sql_row_obj {
}
// Reads the data from the Packages file in $this->pkgdir
public function read_Packages($update_pkgs=false, $verbose=false) {
- global $conf;
- if (!is_readable($file="{$conf['pkgdir_root']}/$this->pkgdir/Packages")) {
+ global $S;
+ if (!is_readable($file="{$S['conf']['pkgdir_root']}/$this->pkgdir/Packages")) {
throw_exception("Packages file doesn't exist for pkgdir $this->pkgdir");
}
$file=fopen($file, 'r');
@@ -104,7 +104,7 @@ class sql_gentoo_profile extends sql_row_obj {
$u=$d=$t=0;
if ($update_pkgs) {
global $S;
- $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id);
+ $r=query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id);
while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) {
$pkg=new sql_gentoo_package($pkg);
if (isset($p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version])) {
@@ -152,7 +152,7 @@ class sql_gentoo_profile extends sql_row_obj {
$name=array_shift($pkgs);
$obj=new sql_gentoo_pkgset();
if ($update) {
- $r=$S['pdo']->query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.' AND `name`="'.$name.'" LIMIT 1');
+ $r=query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.' AND `name`="'.$name.'" LIMIT 1');
if ($r->rowCount())
$obj->from_array($r->fetch(PDO::FETCH_ASSOC), true);
}
@@ -169,13 +169,13 @@ class sql_gentoo_profile extends sql_row_obj {
}
}
if ($update)
- $S['pdo']->query('DELETE FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.($exists?' AND `id` NOT IN ('.implode(',', $exists).')':''));
+ query('DELETE FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.($exists?' AND `id` NOT IN ('.implode(',', $exists).')':''));
}
public function read_stage3($update=false) {
global $S;
if ($update) {
- $S['pdo']->query('DELETE FROM `gentoo_basepkgs` WHERE `profile`='.$this->id);
- $S['pdo']->query('DELETE FROM `gentoo_baseinit` WHERE `profile`='.$this->id);
+ query('DELETE FROM `gentoo_basepkgs` WHERE `profile`='.$this->id);
+ query('DELETE FROM `gentoo_baseinit` WHERE `profile`='.$this->id);
}
$file=realpath(CACHE.'/stage3/'.$this->stage3);
if (!is_readable($file)) return false;
@@ -198,7 +198,7 @@ class sql_gentoo_profile extends sql_row_obj {
public function &get_packages($omit_masked=false, $trim=null) {
global $S;
$skip_masked=!in_array('masked', $trim);
- $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id);
+ $r=query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id);
$p=array();
while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) {
$pkg=new sql_gentoo_package($pkg);
diff --git a/shared/classes/registrationtoken.php b/shared/classes/registrationtoken.php
index 9f331ae..93fe4e6 100644
--- a/shared/classes/registrationtoken.php
+++ b/shared/classes/registrationtoken.php
@@ -33,7 +33,7 @@ class sql_registrationtoken extends sql_row_obj {
$id=null;
do {
$id=randstring(30);
- if ($S['pdo']->query('SELECT COUNT(*) FROM `registrationtokens` WHERE `id`=\''.$id.'\'')->fetch(PDO::FETCH_COLUMN))
+ if (query('SELECT COUNT(*) FROM `registrationtokens` WHERE `id`=\''.$id.'\'')->fetch(PDO::FETCH_COLUMN))
$id=null;
} while ($id==null);
return new sql_registrationtoken($id, null, null, null);
diff --git a/shared/classes/session.php b/shared/classes/session.php
index e422b21..1233a71 100644
--- a/shared/classes/session.php
+++ b/shared/classes/session.php
@@ -33,18 +33,18 @@ class sql_session extends sql_row_obj {
);
// Creates a new session for the user at $S['user'] with a unique id, sends a cookie to the user and returns true for success, false for failure
static function create() {
- global $S, $conf;
+ global $S;
$id=null;
while (!$id) {
$id=randstring(30);
- $r=$S['pdo']->query('SELECT * FROM `sessions` WHERE `id`="'.$id.'"');
+ $r=query('SELECT * FROM `sessions` WHERE `id`="'.$id.'"');
if ($r->rowCount()) {
$id=null;
}
}
- $S['session']=new sql_session($id, $S['user']->id, time(), $conf['sessionlength']);
- debug('setcookie', $conf['cookiename'].'='.$id);
- if (setcookie($conf['cookiename'], $S['session']->id, time()+$conf['sessionlength'], $S['cookie_dir'], '', false, true)) {
+ $S['session']=new sql_session($id, $S['user']->id, time(), $S['conf']['sessionlength']);
+ debug('setcookie', $S['conf']['cookiename'].'='.$id);
+ if (setcookie($S['conf']['cookiename'], $S['session']->id, time()+$S['conf']['sessionlength'], $S['cookie_dir'], '', false, true)) {
$S['session']->write();
return true;
} else {
diff --git a/shared/classes/task.php b/shared/classes/task.php
index cdcd15c..d763107 100644
--- a/shared/classes/task.php
+++ b/shared/classes/task.php
@@ -73,7 +73,7 @@ class sql_task extends sql_row_obj {
$html.='<span class="status running">[running]</span> <span class="time">Running for <span class="time">'.display_time(time()-$this->start).'</span></span>';
}
} else {
- $num=$S['pdo']->query('SELECT COUNT(*) FROM `tasks` WHERE `builds`="'.$this->build.'" AND `start` IS NULL AND `order` <= '.$this->order)->fetch(PDO::FETCH_ASSOC);
+ $num=query('SELECT COUNT(*) FROM `tasks` WHERE `builds`="'.$this->build.'" AND `start` IS NULL AND `order` <= '.$this->order)->fetch(PDO::FETCH_ASSOC);
$html.="<span class=\"status queued\">[queued $num/".$build->queued_tasks()."]</span>";
}
$html.='</div></div>';
diff --git a/shared/classes/validate.php b/shared/classes/validate.php
index c409db4..6c6f479 100644
--- a/shared/classes/validate.php
+++ b/shared/classes/validate.php
@@ -37,8 +37,8 @@ class Validate {
}
}
// Checking DNS to make sure the domain is real is total overkill
- global $conf;
- if ($conf['check_email_dns'] && $isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
+ global $S;
+ if ($S['conf']['check_email_dns'] && $isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
// domain not found in DNS
$isValid = false;
}
diff --git a/shared/functions/debug.php b/shared/functions/debug.php
index 4231e21..8a054f9 100644
--- a/shared/functions/debug.php
+++ b/shared/functions/debug.php
@@ -1,7 +1,7 @@
<?php
function debug ($type, $text=null) {
- global $conf, $S;
- if ($conf['debug']) {
+ global $S;
+ if ($S['conf']['debug']) {
if ($text===null) {
$text=$type;
$type=null;
diff --git a/shared/functions/get_timezones.php b/shared/functions/get_timezones.php
index 4c495cd..12ccc81 100644
--- a/shared/functions/get_timezones.php
+++ b/shared/functions/get_timezones.php
@@ -1,23 +1,23 @@
<?php
function &get_timezones($dir=null) {
- global $conf;
+ global $S;
static $results;
if ($dir == null) {
if (isset($results))
return $results;
$results=array();
- $dir=realpath($conf['timezone_root']);
+ $dir=realpath($S['conf']['timezone_root']);
}
foreach (glob($dir.'/*') as $file) {
if (is_dir($file) && !is_link($file))
get_timezones($file);
else {
- $file=substr($file, strlen($conf['timezone_root'])+1);
+ $file=substr($file, strlen($S['conf']['timezone_root'])+1);
if ($file != 'zone.tab')
$results[$file]=str_replace('_', ' ', $file);
}
}
- if ($dir == $conf['timezone_root']) {
+ if ($dir == $S['conf']['timezone_root']) {
natsort($results);
}
return $results;
diff --git a/shared/functions/load_config.php b/shared/functions/load_config.php
index eb07879..a212b16 100644
--- a/shared/functions/load_config.php
+++ b/shared/functions/load_config.php
@@ -5,7 +5,7 @@ function load_config() {
$modules=explode(' ', $modules);
foreach (explode(' ', 'title url sqlhost sqluser sqlpass sqldb debug modules bundlers cookiename sessionlength mod_rewrite timezone_root emailfrom check_email_dns split_setup registration invite logview_max progressbar_width pkgdir_root emerge_default_opts portdir backend_id') as $var) {
if (isset($$var)) {
- $GLOBALS['conf'][$var]=$$var;
+ $GLOBALS['S']['conf'][$var]=$$var;
}
}
}
diff --git a/shared/functions/query.php b/shared/functions/query.php
new file mode 100644
index 0000000..d92ee0f
--- /dev/null
+++ b/shared/functions/query.php
@@ -0,0 +1,8 @@
+<?php
+function query($q) {
+ debug('query', $q);
+ // 5.3.0: func_get_args() can be used directly in call_user_func_array()
+ $args=func_get_args();
+ return call_user_func_array(array(&$GLOBALS['S']['pdo'], 'query'), $args);
+}
+?>
diff --git a/shared/functions/url.php b/shared/functions/url.php
index f2ff5ba..0234b2b 100644
--- a/shared/functions/url.php
+++ b/shared/functions/url.php
@@ -1,23 +1,23 @@
<?php
// Makes all URLs absolute
function url($url='') {
- global $conf;
+ global $S;
if (strlen($url) == 0) {
- return $conf['url'].($conf['mod_rewrite']?'':'/index.php');
+ return $S['conf']['url'].($S['conf']['mod_rewrite']?'':'/index.php');
} elseif (substr($url, 0, 7) == 'http://') {
return $url;
}
- if ($conf['mod_rewrite']) {
- return $conf['url'].'/'.$url;
+ if ($S['conf']['mod_rewrite']) {
+ return $S['conf']['url'].'/'.$url;
} else {
if (strpos($url, '?')) {
$q=substr($url, strpos($url, '?')+1);
$url=substr($url, 0, strpos($url, '?'));
}
if (strlen($url)) {
- return $conf['url'].'/index.php?req='.$url.(isset($q)?'&'.$q:'');
+ return $S['conf']['url'].'/index.php?req='.$url.(isset($q)?'&'.$q:'');
} else {
- return $conf['url'].'/index.php?'.$q;
+ return $S['conf']['url'].'/index.php?'.$q;
}
}
}
diff --git a/shared/functions/xhtmlemail.php b/shared/functions/xhtmlemail.php
index 2e71388..d4924f7 100644
--- a/shared/functions/xhtmlemail.php
+++ b/shared/functions/xhtmlemail.php
@@ -1,14 +1,14 @@
<?php
// Sends an XHTML email with the appropriate headers and the necessary opening and closing for an XHTML document
function xhtmlemail($to,$from,$subj,$cont,$inheads=null) {
- global $conf;
+ global $S;
if ($from===null) {
- $from=$conf['emailfrom'];
+ $from=$S['conf']['emailfrom'];
}
$heads='MIME-Version: 1.0' . "\r\n";
$heads.='Content-type: text/html; charset=utf-8' . "\r\n";
$heads.='From: '.$from."\r\n";
- $heads.='X-Mailer: PHP/'.$conf['title']."\r\n";
+ $heads.='X-Mailer: PHP/'.$S['conf']['title']."\r\n";
if ($inheads!==null) {
$heads.=$inheads."\r\n";
}
diff --git a/shared/include/dbinit.php b/shared/include/dbinit.php
index e52498a..45b7eb7 100644
--- a/shared/include/dbinit.php
+++ b/shared/include/dbinit.php
@@ -1,11 +1,8 @@
<?php
-require_once(dirname(__FILE__).'/../config.php'); // Use __DIR__ in 5.3.0
-$pdoclass=(class_exists('pdo_debug')?'pdo_debug':'PDO');
try {
- $S['pdo']=new $pdoclass('mysql:dbname='.$conf['sqldb'].';host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass'], array(PDO::ATTR_PERSISTENT => true));
+ $S['pdo']=new PDO('mysql:dbname='.$S['conf']['sqldb'].';host='.$S['conf']['sqlhost'], $S['conf']['sqluser'], $S['conf']['sqlpass'], array(PDO::ATTR_PERSISTENT => true));
} catch (Exception $e) {
die(print_error('Database connection failure.', $e->getMessage()));
}
-unset($pdoclass);
sql_row_obj::set_pdo_obj($S['pdo']);
?>
diff --git a/shared/include/includes.php b/shared/include/includes.php
index bfd358d..8a75b58 100644
--- a/shared/include/includes.php
+++ b/shared/include/includes.php
@@ -1,4 +1,5 @@
<?php
+date_default_timezone_set('UTC');
require_once(dirname(__FILE__).'/paths.php'); // USE __dir__ in 5.3.0
// Load functions and classes from the shared directory and either foreground or background
foreach (array('functions', 'classes') as $type) {