Changeset 1916


Ignore:
Timestamp:
4/16/2010 6:52:25 AM (5 years ago)
Author:
lowjoel
Message:
  • Implemented creating new builds and adding to database
  • Implemented removal of old builds from database
Location:
trunk/website/scripts
Files:
2 edited

Legend:

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

    r1915 r1916  
    5959 
    6060    /** 
    61      * Gets the Builds which are still active for the given branch. 
     61     * Gets the Builds which are still active for the given branch. The result is ordered by 
     62     * decreasing age. 
    6263     * 
    6364     * @param string $branch The name of the Build branch. 
     
    6869        $statement = $pdo->prepare('SELECT builds.DownloadID FROM builds 
    6970            INNER JOIN downloads ON builds.DownloadID=downloads.DownloadID 
    70             WHERE downloads.Superseded=0 AND builds.Branch=?'); 
     71            WHERE downloads.Superseded=0 AND builds.Branch=? 
     72            ORDER BY builds.DownloadID'); 
    7173        $statement->bindParam(1, $branch); 
    7274        $statement->execute(); 
     
    9092     * to the public web server before allowing the build to be downloaded. 
    9193     * 
    92      * @param string $branch   The name of the Build branch. 
    93      * @param <type> $revision The revision of the Build. 
     94     * @param mixed $branch    The name of the Build branch or a BuildBranch object containing the 
     95     *                         branch. 
     96     * @param int $revision    The revision of the Build. 
     97     * @param int $filesize    The size of the file, in bytes. 
     98     * @param string $link     The link to the download. 
    9499     */ 
    95     public static function CreateBuild($branch, $revision) 
     100    public static function CreateBuild($branch, $revision, $filesize, $link) 
    96101    { 
    97          
     102        $pdo = new Database(); 
     103        $pdo->beginTransaction(); 
     104 
     105        //Define the download properties. 
     106        $statement = $pdo->prepare('INSERT INTO downloads ( 
     107                Name, Released, `Type`, Version, PublisherID, Architecture, Filesize, Link 
     108            ) 
     109            VALUES 
     110            ( 
     111                CONCAT(\'Eraser \', :Version), NOW(), \'build\', :Version, 1, 
     112                \'any\', :Filesize, :Link 
     113            )'); 
     114 
     115        if (is_string($branch)) 
     116        { 
     117            $branches = BuildBranch::Get(); 
     118            $branchName = $branch; 
     119            $branch = $branches[$branchName]; 
     120            if (!$branch) 
     121                throw new Exception('The provided branch ' . $branchName . ' does not exist.'); 
     122        } 
     123        else if (!is_a($branch, 'BuildBranch')) 
     124            throw new Exception('The provided branch is invalid.'); 
     125 
     126        $statement->bindParam('Version', sprintf('%s.%s', $branch->Version, $revision)); 
     127        $statement->bindParam('Filesize', $filesize); 
     128        $statement->bindParam('Link', $link); 
     129        $statement->execute(); 
     130 
     131        //Define the build properties. 
     132        $statement = $pdo->prepare('INSERT INTO builds ( 
     133                DownloadID, Branch, Revision 
     134            ) VALUES ( 
     135                LAST_INSERT_ID(), ?, ? 
     136            )'); 
     137        $statement->bindParam(1, $branch->ID); 
     138        $statement->bindParam(2, $revision); 
     139        $statement->execute(); 
     140 
     141        //Commit to the database. 
     142        $pdo->commit(); 
    98143    } 
    99144} 
  • trunk/website/scripts/BuildPublish.php

    r1915 r1916  
    1111 
    1212require_once('Credentials.php'); 
     13require_once('Database.php'); 
    1314require_once('Build.php'); 
    1415 
     
    6667        die('The branch ' . $argv[1] . ' does not exist.'); 
    6768 
     69    define('SHELL_WEB_ROOT', 'sftp://web.sourceforge.net/home/groups/e/er/eraser/htdocs'); 
     70    define('HTTP_WEB_ROOT', 'http://eraser.sourceforge.net'); 
     71 
    6872    $branch = $branches[$argv[1]]; 
    6973    $pathInfo = pathinfo($argv[3]); 
    7074    $fileName = sprintf('Eraser %s.%d.%s', $branch->Version, $argv[2], $pathInfo['extension']); 
    71     $uploadURL = sprintf('sftp://web.sourceforge.net/home/groups/e/er/eraser/htdocs/builds/%s/%s', 
    72         $branch->ID, $fileName); 
    73     Upload($uploadURL, $file, $sftp_username, $sftp_password); 
    74     Delete($uploadURL, $sftp_username, $sftp_password); 
     75    $installerPath = sprintf('/builds/%s/%s', $branch->ID, $fileName); 
     76 
     77    //Then upload the installer to the URL. 
     78    Upload(SHELL_WEB_ROOT . $installerPath, $file, $sftp_username, $sftp_password); 
     79 
     80    //Insert the build to the database. 
     81    printf('Inserting build into database... '); 
     82    Build::CreateBuild($branch->ID, intval($argv[2]), filesize($argv[3]), HTTP_WEB_ROOT . $installerPath); 
     83    printf("Inserted.\n"); 
     84 
     85    //Remove old builds 
     86    printf('Removing old builds from database... '); 
     87 
     88    $pdo = new Database(); 
     89    $pdo->beginTransaction(); 
     90    $statement = $pdo->prepare('UPDATE downloads SET Superseded=1 WHERE DownloadID=?'); 
     91 
     92    $builds = Build::GetActive($branch->ID); 
     93    for ($i = 0, $j = count($builds) - 3; $i < $j; ++$i) 
     94    { 
     95        $statement->bindParam(1, $builds[$i]->ID); 
     96        $statement->execute(); 
     97    } 
     98    $pdo->commit(); 
    7599} 
    76100catch (Exception $e) 
Note: See TracChangeset for help on using the changeset viewer.