Ignore:
Timestamp:
01/22/10 00:30:40 (5 years ago)
Author:
lowjoel
Message:
  • Optimized the selection algorithm for picking builds from the builds table
  • If we can't find a build by the given branch and revision, then we should throw an exception. The handling of new builds is now done in the Build::Get function
  • Define the Build::BuildExists? function to check whether a build exists/has been created
  • Build::InsertBuild? now accepts a path to the revision so it can accept files with the revision as its filename
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/website/scripts/downloads.php

    r1630 r1631  
    115115    public function Build($branch, $revision) 
    116116    { 
    117         $query = mysql_query(sprintf('SELECT downloads.DownloadID FROM downloads INNER JOIN builds ON 
    118             downloads.DownloadID=builds.DownloadID WHERE 
    119                 builds.Branch=\'%s\' AND builds.Revision=%d', 
     117        $query = mysql_query(sprintf('SELECT DownloadID FROM builds WHERE 
     118                Branch=\'%s\' AND Revision=%d', 
    120119            mysql_real_escape_string($branch), intval($revision))); 
    121120         
     
    123122        if (($row = mysql_fetch_row($query)) === false || !$row[0]) 
    124123        { 
    125             $this->ID = Build::InsertBuild($branch, $revision); 
     124            throw new Exception('Build does not exist'); 
    126125        } 
    127126        else 
     
    150149                    continue; 
    151150                 
    152                 try 
     151                $pathInfo = pathinfo($revision); 
     152                $revisionID = intval(substr($pathInfo['filename'], 1)); 
     153                if (Build::BuildExists($branchName, $revisionID)) 
    153154                { 
    154                     $result[$buildName][] = new Build($branchName, intval(substr($revision, 1))); 
     155                    $result[$buildName][] = new Build($branchName, $revisionID); 
    155156                } 
    156                 catch (Exception $e) 
     157                else 
    157158                { 
     159                    $result[$buildName][] = Build::GetBuildFromID( 
     160                        Build::InsertBuild($branchName, $revisionID, 
     161                            Build::GetPath($branchName, $revision))); 
    158162                } 
    159163            } 
     
    161165         
    162166        return $result; 
     167    } 
     168     
     169    public static function BuildExists($branch, $revision) 
     170    { 
     171        $query = mysql_query(sprintf('SELECT DownloadID FROM builds WHERE 
     172                Branch=\'%s\' AND Revision=%d', 
     173            mysql_real_escape_string($branch), intval($revision))); 
     174        return mysql_num_rows($query) == 1; 
    163175    } 
    164176     
     
    192204    } 
    193205     
    194     private static function InsertBuild($branch, $revision) 
     206    private static function InsertBuild($branch, $revision, $buildPath) 
    195207    { 
    196208        //Find the binary that users will get to download. 
    197         $buildPath = Build::GetPath($branch, $revision); 
    198209        $installerPath = null; 
    199210         
     
    220231        else if (is_file($buildPath)) 
    221232        { 
    222             $installerPath = sprintf('builds/%s/r%s', $branch, $revision); 
     233            $installerPath = sprintf('builds/%s/r%s', $branch, basename($buildPath)); 
    223234        } 
    224235 
Note: See TracChangeset for help on using the changeset viewer.