Changeset 1629
- Timestamp:
- 1/21/2010 10:16:24 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/website/scripts/downloads.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/website/scripts/downloads.php
r1437 r1629 113 113 class Build extends Download 114 114 { 115 public function Build($ path, $revision)115 public function Build($branch, $revision) 116 116 { 117 117 $query = mysql_query(sprintf('SELECT downloads.DownloadID FROM downloads INNER JOIN builds ON 118 118 downloads.DownloadID=builds.DownloadID WHERE 119 builds. Path=\'%s\' AND builds.Revision=%d',120 mysql_real_escape_string($ path), intval($revision)));119 builds.Branch=\'%s\' AND builds.Revision=%d', 120 mysql_real_escape_string($branch), intval($revision))); 121 121 122 122 //See if the build already has a database entry 123 123 if (($row = mysql_fetch_row($query)) === false || !$row[0]) 124 124 { 125 $this->ID = Build::InsertBuild($ path, $revision);125 $this->ID = Build::InsertBuild($branch, $revision); 126 126 } 127 127 else … … 130 130 131 131 //Check that the folder has not been removed. This may indicate supersedence. 132 if (!file_exists(Build::GetPath($this->Path, $this->Revision))) 132 $downloadFolder = dirname(__FILE__) . '/../downloads/'; 133 if (!file_exists($downloadFolder . $this->Link)) 133 134 $this->Superseded = 1; 134 135 } … … 139 140 $result = array(); 140 141 $builds = array('Eraser5' => 'Eraser 5', 'Eraser6' => 'Eraser 6', 'Eraser6.2' => 'Eraser 6.2'); 141 foreach ($builds as $ path=> $buildName)142 { 143 $revisions = opendir(Build::GetPath($ path));142 foreach ($builds as $branchName => $buildName) 143 { 144 $revisions = opendir(Build::GetPath($branchName)); 144 145 $result[$buildName] = array(); 145 146 146 147 while (($revision = readdir($revisions)) !== false) 147 148 { 148 if ( !sprintf('downloads/builds/%s/%s', $path, $revision) ||$revision == '.' || $revision == '..')149 if ($revision == '.' || $revision == '..') 149 150 continue; 150 151 … … 177 178 { 178 179 case 'Revision': 179 case ' Path':180 case 'Branch': 180 181 $sql = sprintf($sql, $varName); 181 182 break; … … 191 192 } 192 193 193 private static function InsertBuild($path, $revision) 194 { 195 //It doesn't. Find the binary that users will get to download. 196 $directory = opendir(Build::GetPath($path, $revision)); 197 $installer = null; 198 $installerFilesize = 0; 199 while (($file = readdir($directory)) !== false) 200 { 201 $filePath = Build::GetPath($path, $revision) . '/' . $file; 202 if (is_file($filePath)) 194 private static function InsertBuild($branch, $revision) 195 { 196 //Find the binary that users will get to download. 197 $buildPath = Build::GetPath($branch, $revision); 198 $installerPath = null; 199 200 //If $buildPath is a file, it's the installer we want. 201 if (is_file($buildPath)) 202 { 203 $installerPath = $buildPath; 204 } 205 206 //Otherwise, it's a directory containing the installer. 207 else 208 { 209 $directory = opendir(); 210 211 while (($file = readdir($directory)) !== false) 203 212 { 204 $ pathInfo = pathinfo($filePath);205 if ( $pathInfo['extension'] == 'exe')213 $filePath = $buildPath . '/' . $file; 214 if (is_file($filePath)) 206 215 { 207 $installer = sprintf('builds/%s/r%s/%s', $path, $revision, $file); 208 $installerFilesize = filesize($filePath); 209 break; 216 $pathInfo = pathinfo($filePath); 217 if ($pathInfo['extension'] == 'exe') 218 { 219 $installerPath = sprintf('builds/%s/r%s/%s', $branch, $revision, $file); 220 break; 221 } 210 222 } 211 223 } 212 224 } 213 214 if (empty($installer) || $installerFilesize == 0)225 226 if (empty($installer)) 215 227 { 216 228 //It is a build in progress, don't create anything. 217 throw new Exception(sprintf('Build %s r%d is incomplete.', $ path, $revision));229 throw new Exception(sprintf('Build %s r%d is incomplete.', $branch, $revision)); 218 230 } 219 231 … … 224 236 \'%1$s r%2$d\', \'%4$s\' , \'build\', \'r%2$d\', 1, \'any\', %3$d, \'?%5$s\' 225 237 )', 226 mysql_real_escape_string($path), intval($revision), $installerFilesize, 227 PhpToMySqlTimestamp(filemtime(Build::GetPath($path, $revision))), 228 mysql_real_escape_string($installer))) 238 mysql_real_escape_string($branch), intval($revision), filesize($installerPath), 239 PhpToMySqlTimestamp(filemtime($buildPath)), mysql_real_escape_string($installerPath))) 229 240 or die(mysql_error()); 230 mysql_query(sprintf('INSERT INTO builds (DownloadID, Path, Revision)241 mysql_query(sprintf('INSERT INTO builds (DownloadID, Branch, Revision, Path) 231 242 VALUES ( 232 LAST_INSERT_ID(), \'% 1s\', %2$d243 LAST_INSERT_ID(), \'%s\', %d, \'%s\' 233 244 )', 234 mysql_real_escape_string($path), intval($revision))) or die(mysql_error()); 245 mysql_real_escape_string($branch), intval($revision), 246 mysql_real_escape_string($installerPath))) 247 or die(mysql_error()); 235 248 236 249 if (!mysql_affected_rows())
Note: See TracChangeset
for help on using the changeset viewer.
