diff options
Diffstat (limited to 'shared/classes/build.php')
-rw-r--r-- | shared/classes/build.php | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/shared/classes/build.php b/shared/classes/build.php index 8212d56..d14deb0 100644 --- a/shared/classes/build.php +++ b/shared/classes/build.php @@ -26,10 +26,9 @@ class sql_build extends conf_build_common { 'default' => '' ), 'status' => array ( - 'type' => 'VARCHAR', - 'length' => 255, - 'not_null' => true, - 'default' => '' + 'type' => 'TINYINT', + 'length' => 4, + 'not_null' => true ), 'ctime' => array ( 'type' => 'INT', @@ -51,39 +50,47 @@ class sql_build extends conf_build_common { function display() { global $S; $format='D j M Y G:i:s T'; + $OoA=owner_or_admin($this->id); $html='<div class="build"><span class="name">'.(isset($this->name) && strlen($this->name)?htmlentities($this->name):'Unnamed Build').'</span> '; - $status=explode('/', $this->status, 2); - if ($status[0] == 'config') { - $status[1]=substr($status[1], strpos($status[1], 'p')+1); - $html.='<span class="status config">[Configuration step '.$status[1].']</span><br/><span class="links"><a href="'.url('create/'.$this->id).'">Continue configuring</a></span>'; - } elseif ($status[0] == 'build') { - if ($status[1] == 'ready') { - $total=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`="build/ready"')->fetch(PDO::FETCH_COLUMN); - $num=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`="build/ready" AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN); - $html.="<span class=\"status queued\">[Queued ($num/$total)]</span>"; - } elseif ($status[1]='running') { - // Add link to regular log viewer? - // Build stage X - $html.='<span class="status building">[building]</span><br/><span class="links"><a href="'.url('logs/'.$this->id.'/live').'">Watch</a> • <a href="'.url('logs/'.$this->id).'"> Build log</a></span>'; - } else { - throw_exception('Unrecognized build status '.$this->status); + $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); + $html.="<span class=\"status queued\">[Queued ($num/$total)]</span>"; + } elseif ($this->status == -127) { + $html.='<span class="status successful">[uploading]</span>'; + if ($OoA) $links['Build log']=url("logs/$this->id"); + } elseif ($this->status < 0) { + // TODO Build stage X + $html.='<span class="status building">[building]</span>'; + if ($OoA) { + //$links['Watch']=url("logs/$this->id/live"); + $links['Build Log']=url("logs/$this->id"); } - } elseif ($status[0] == 'finished') { - $status=explode(': ', $status[1], 2); - if ($status[0] == 'success') { - $r=$S['pdo']->query('SELECT COUNT(*) as `count`, MAX(`time`) as `time` FROM `downloads` WHERE `build`="'.$this->id.'"'); - $r=$r->fetch(PDO::FETCH_ASSOC); - $d=$r['count'].' download'.($r['count'] != 1?'s':'').($r['count']?'<br/><span class="time">(last at '.date($format, $r['time']).')</span>':''); - $html.='<span class="downloads">'.$d.'</span><span class="status successful">[successful]</span><br/><span class="links"><a href="'.url('download/'.$this->id).'">Download image</a> • <a href="'.url('logs/'.$this->id).'">Build log</a></span>'; - } elseif ($status[0] == 'failed') { - $html.='<span class="status failed">[failed: '.htmlentities($status[1]).']</span><br/><span class="links"><a href="'.url('logs/'.$this->id.'/failure').'">View output of failed command</a> • <a href="'.url('logs/'.$this->id).'">Build log</a></span>'; - } elseif ($status[0] == 'uploading') { - $html.='<span class="status successful">[uploading]</span><br/><span class="links"><a href="'.url('logs/'.$this->id).'">Build log</a></span>'; - } else { - throw_exception('Unrecognized build status '.$this->status); + } 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); + $d=($OoA && $r['count']?'<a href="'.url("download/$this->id/history").'">':'').$r['count'].' download'.($r['count'] != 1?'s':'').($r['count']?($OoA?'</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']=url("download/$this->id"); + if ($OoA) $links['Build log']=url("logs/$this->id"); + } elseif ($this->status == 127) { + $html.='<span class="status failed">[upload failed]</span>'; + if ($OoA) $links['Build log']=url("logs/$this->id"); + } elseif ($this->status == 126) { + $html.='<span class="status failed">[failed]</span>'; + if ($OoA) { + //$links['View output of failed command']=url("logs/$this->id/failure"); + $links['Build log']=url("logs/$this->id"); } } else { - throw_exception('Unrecognized build status '.$this->status); + $html.='<span class="status failed">[failed: got signal '.$this->status.']</span>'; + if ($OoA) $links['Build log']=url('logs/'.$this->id); + } + if ($links) { + foreach ($links as $label => $url) { + $links[$label]='<a href="'.$url.'">'.htmlentities($label).'</a>'; + } + $html.='<br/><span class="links">'.implode(' • ', $links).'</span>'; } if (isset($this->ctime)) { $html.='<div class="time">Submitted for build at: <span class="time">'.date($format, $this->ctime).'</span><br/>'; @@ -102,5 +109,12 @@ class sql_build extends conf_build_common { $html.='</div>'; return $html; } + function queued_tasks() { + 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); + return $cache; + } } ?> |