Skip to content

Commit

Permalink
Homepage|Build Repository: Added 'direct_download_fallback_uri' to JS…
Browse files Browse the repository at this point in the history
…ON package graphs

Parse <downloadFallbackUri> from the XML event log and include this
additional download URI in the JSON package graph.
  • Loading branch information
danij-deng committed Jun 19, 2012
1 parent d99a26e commit d157308
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 22 deletions.
27 changes: 19 additions & 8 deletions web/plugins/buildrepository/buildrepository.php
Expand Up @@ -404,6 +404,7 @@ private function populateStaticPackages(&$packages)

$pack = PackageFactory::newDistribution(PID_WIN_X86, 'Doomsday', '1.8.6',
'http://sourceforge.net/projects/deng/files/Doomsday%20Engine/1.8.6/deng-inst-1.8.6.exe/download',
NULL/*no fallback download uri*/,
false/*not an autobuilder packaged*/);
$pack->setReleaseNotesUri('http://dengine.net/dew/index.php?title=Doomsday_version_1.8.6');
$packages[] = $pack;
Expand Down Expand Up @@ -705,7 +706,7 @@ private function &choosePackage($platformId=PID_ANY, $title="Doomsday",
if($pack->platformId() !== $platformId) continue;
if($matchTitle && strcasecmp($pack->title(), $title)) continue;
if($unstable != ($pack instanceof AbstractUnstablePackage)) continue;
if($downloadable != ($pack instanceof iDownloadable && $pack->hasDirectDownloadUri())) continue;
if($downloadable != ($pack instanceof iDownloadable && ($pack->hasDirectDownloadUri() || $pack->hasDirectDownloadFallbackUri()))) continue;

// Found something suitable.
return $pack;
Expand Down Expand Up @@ -901,7 +902,7 @@ private function outputPackageList(&$packages, $notThisPack=NULL,
// Filtered out?
if($pack === $notThisPack) continue;
if($unstable != -1 && (boolean)$unstable == ($pack instanceof AbstractUnstablePackage)) continue;
if($downloadable != -1 && (boolean)$downloadable != ($pack instanceof iDownloadable && $pack->hasDirectDownloadUri())) continue;
if($downloadable != -1 && (boolean)$downloadable != ($pack instanceof iDownloadable && ($pack->hasDirectDownloadUri() || $pack->hasDirectDownloadFallbackUri()))) continue;
if(!is_null($chosenPlatformId) && $pack->platformId() === $chosenPlatformId) continue;

// Begin the list?
Expand Down Expand Up @@ -945,12 +946,17 @@ private function outputPackageRedirect(&$pack)
$FrontController->beginPage($pageTitle);

// Output the redirect directive.
?><meta http-equiv="REFRESH" content="2;url=<?php echo $pack->directDownloadUri(); ?>"><?php
if($pack->hasDirectDownloadUri())
$downloadUri = $pack->directDownloadUri();
else
$downloadUri = $pack->directDownloadFallbackUri();

?><meta http-equiv="REFRESH" content="2;url=<?php echo $downloadUri; ?>"><?php

// Generate page content.
?><div id="builds"><?php

?><p>Redirecting to the download for <em><?php echo htmlspecialchars($pack->composeFullTitle()); ?></em>. Your package should begin to download automatically within a few seconds, if not please use this <a href="<?php echo $pack->directDownloadUri(); ?>" title="<?php echo htmlspecialchars('Download '. $pack->composeFullTitle()); ?>">direct link</a> instead.</p><?php
?><p>Redirecting to the download for <em><?php echo htmlspecialchars($pack->composeFullTitle()); ?></em>. Your package should begin to download automatically within a few seconds, if not please use this <a href="<?php echo $downloadUri; ?>" title="<?php echo htmlspecialchars('Download '. $pack->composeFullTitle()); ?>">direct link</a> instead.</p><?php

?><p>Not what you wanted? Here are some alternatives:</p><?php

Expand Down Expand Up @@ -1046,7 +1052,7 @@ private function countInstallablePackages(&$build)
{
foreach($build->packages as &$pack)
{
if($pack instanceof iDownloadable && $pack->hasDirectDownloadUri())
if($pack instanceof iDownloadable && ($pack->hasDirectDownloadUri() || $pack->hasDirectDownloadFallbackUri()))
{
$count++;
}
Expand Down Expand Up @@ -1117,7 +1123,7 @@ private function outputBuildPackageList(&$build)
}

// Determine issue level (think defcon).
if($errors > 0 || !$pack->hasDirectDownloadUri())
if($errors > 0 || (!$pack->hasDirectDownloadUri() && !$pack->hasDirectDownloadFallbackUri()))
{
$issueLevel = 'major';
$issueTooltip = "$errors major errors occurred during the build";
Expand All @@ -1139,9 +1145,14 @@ private function outputBuildPackageList(&$build)
<td><?php

$packTitle = $pack->composeFullTitle(true/*include version*/, false/*do not include the platform name*/, false/*do not include build Id*/);
if($pack instanceof iDownloadable && $pack->hasDirectDownloadUri())
if($pack instanceof iDownloadable && ($pack->hasDirectDownloadUri() || $pack->hasDirectDownloadFallbackUri()))
{
?><a href="<?php echo $pack->directDownloadUri(); ?>" title="Download <?php echo htmlspecialchars($pack->composeFullTitle()); ?>"><?php echo htmlspecialchars($packTitle); ?></a><?php
if($pack->hasDirectDownloadUri())
$downloadUri = $pack->directDownloadUri();
else
$downloadUri = $pack->directDownloadFallbackUri();

?><a href="<?php echo $downloadUri; ?>" title="Download <?php echo htmlspecialchars($pack->composeFullTitle()); ?>"><?php echo htmlspecialchars($packTitle); ?></a><?php
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions web/plugins/buildrepository/downloadable.interface.php
Expand Up @@ -29,5 +29,9 @@ interface iDownloadable
{
public function &directDownloadUri();
public function hasDirectDownloadUri();

public function &directDownloadFallbackUri();
public function hasDirectDownloadFallbackUri();

public function genDownloadBadge();
}
43 changes: 33 additions & 10 deletions web/plugins/buildrepository/packagefactory.class.php
Expand Up @@ -44,22 +44,28 @@ public static function newNullPackage()
return self::$nullPackage;
}

public static function newDistribution($platformId, $name, $version, $directDownloadUrl, $builder=true)
public static function newDistribution($platformId, $name, $version, $directDownloadUri,
$directDownloadFallbackUri=NULL, $builder=true)
{
if($builder)
{
return new DistributionBuilderPackage($platformId, $name, $version, $directDownloadUrl);
return new DistributionBuilderPackage($platformId, $name, $version,
$directDownloadUri, $directDownloadFallbackUri);
}
return new DistributionPackage($platformId, $name, $version, $directDownloadUrl);
return new DistributionPackage($platformId, $name, $version,
$directDownloadUri, $directDownloadFallbackUri);
}

public static function newDistributionUnstable($platformId, $name, $version, $directDownloadUrl, $builder=true)
public static function newDistributionUnstable($platformId, $name, $version, $directDownloadUri,
$directDownloadFallbackUri=NULL, $builder=true)
{
if($builder)
{
return new DistributionUnstableBuilderPackage($platformId, $name, $version, $directDownloadUrl);
return new DistributionUnstableBuilderPackage($platformId, $name, $version,
$directDownloadUri, $directDownloadFallbackUri);
}
return new DistributionUnstablePackage($platformId, $name, $version, $directDownloadUrl);
return new DistributionUnstablePackage($platformId, $name, $version,
$directDownloadUri, $directDownloadFallbackUri);
}

/**
Expand All @@ -74,7 +80,16 @@ public static function newFromSimpleXMLElement(&$log_pack, $releaseType='unstabl
throw new Exception('Received invalid log_pack');

$platformId = BuildRepositoryPlugin::parsePlatformId(clean_text($log_pack->platform));

$cleanDirectDownloadUri = safe_url($log_pack->downloadUri);
if(!empty($log_pack->downloadFallbackUri))
{
$cleanDirectDownloadFallbackUri = safe_url($log_pack->downloadFallbackUri);
}
else
{
$cleanDirectDownloadFallbackUri = NULL;
}

if(!empty($log_pack->name))
{
Expand Down Expand Up @@ -108,21 +123,29 @@ public static function newFromSimpleXMLElement(&$log_pack, $releaseType='unstabl
case 'plugin':
if($releaseType === RT_STABLE)
{
$pack = new PluginBuilderPackage($platformId, $name, $version, $cleanDirectDownloadUri);
$pack = new PluginBuilderPackage($platformId, $name, $version,
$cleanDirectDownloadUri,
$cleanDirectDownloadFallbackUri);
}
else
{
$pack = new PluginUnstableBuilderPackage($platformId, $name, $version, $cleanDirectDownloadUri);
$pack = new PluginUnstableBuilderPackage($platformId, $name, $version,
$cleanDirectDownloadUri,
$cleanDirectDownloadFallbackUri);
}
break;
default:
if($releaseType === RT_STABLE)
{
$pack = new DistributionBuilderPackage($platformId, $name, $version, $cleanDirectDownloadUri);
$pack = new DistributionBuilderPackage($platformId, $name, $version,
$cleanDirectDownloadUri,
$cleanDirectDownloadFallbackUri);
}
else
{
$pack = new DistributionUnstableBuilderPackage($platformId, $name, $version, $cleanDirectDownloadUri);
$pack = new DistributionUnstableBuilderPackage($platformId, $name, $version,
$cleanDirectDownloadUri,
$cleanDirectDownloadFallbackUri);
}
break;
}
Expand Down
36 changes: 32 additions & 4 deletions web/plugins/buildrepository/packages/abstractpackage.class.php
Expand Up @@ -31,19 +31,25 @@ abstract class AbstractPackage extends BasePackage implements iDownloadable
static protected $emptyString = '';

protected $directDownloadUri = NULL;
protected $directDownloadFallbackUri = NULL;
protected $releaseNotesUri = NULL;
protected $releaseChangeLogUri = NULL;

protected $compileLogUri = NULL;
protected $compileWarnCount = NULL;
protected $compileErrorCount = NULL;

public function __construct($platformId=PID_ANY, $title=NULL, $version=NULL, $directDownloadUri=NULL)
public function __construct($platformId=PID_ANY, $title=NULL, $version=NULL,
$directDownloadUri=NULL,
$directDownloadFallbackUri=NULL)
{
parent::__construct($platformId, $title, $version);

if(!is_null($directDownloadUri) && strlen($directDownloadUri) > 0)
$this->directDownloadUri = "$directDownloadUri";

if(!is_null($directDownloadFallbackUri) && strlen($directDownloadFallbackUri) > 0)
$this->directDownloadFallbackUri = "$directDownloadFallbackUri";
}

// Extends implementation in AbstractPackage.
Expand All @@ -56,7 +62,11 @@ public function populateGraphTemplate(&$tpl)

parent::populateGraphTemplate($tpl);

$tpl['direct_download_uri'] = $this->directDownloadUri();
if($this->hasDirectDownloadUri())
$tpl['direct_download_uri'] = $this->directDownloadUri();

if($this->hasDirectDownloadFallbackUri())
$tpl['direct_download_fallback_uri'] = $this->directDownloadFallbackUri();

if($this->hasReleaseChangeLogUri())
$tpl['release_changeloguri'] = $this->releaseChangeLogUri;
Expand Down Expand Up @@ -170,13 +180,31 @@ public function hasDirectDownloadUri()
return !is_null($this->directDownloadUri);
}

// Implements iDownloadable
public function &directDownloadFallbackUri()
{
if(!$this->hasDirectDownloadFallbackUri()) return $emptyString;
return $this->directDownloadFallbackUri;
}

// Implements iDownloadable
public function hasDirectDownloadFallbackUri()
{
return !is_null($this->directDownloadFallbackUri);
}

// Implements iDownloadable
public function genDownloadBadge()
{
$fullTitle = $this->composeFullTitle();
if($this->hasDirectDownloadUri())
if($this->hasDirectDownloadUri() || $this->hasDirectDownloadFallbackUri())
{
$html = '<a href="'. htmlspecialchars($this->directDownloadUri)
if($this->hasDirectDownloadUri())
$downloadUri = $this->directDownloadUri();
else
$downloadUri = $this->directDownloadFallbackUri();

$html = '<a href="'. htmlspecialchars($downloadUri)
.'" title="'. htmlspecialchars("Download $fullTitle")
.'">'. htmlspecialchars($fullTitle) .'</a>';
}
Expand Down

0 comments on commit d157308

Please sign in to comment.