Skip to content

Commit

Permalink
Added fix for endless recursion in collecting downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Guinn committed Feb 5, 2014
1 parent 32d8f97 commit 01c67fa
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions code/Downloadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,29 @@ public function HasDownloads() {


/**
* @param array $blacklist [optional] - list of id's to blacklist (only used internally for avoiding endless loops)
* @return SS_List
*/
public function getDownloads() {
public function getDownloads($blacklist=array()) {
$blacklist[$this->owner->ID] = $this->owner->ID;
if (!isset($this->_downloads)) {
if ($this->owner->IncludeParentDownloads || $this->owner->IncludeChildDownloads) {
$files = new ArrayList();
$files->merge( $this->owner->DownloadableFiles() );

if ($this->owner->IncludeParentDownloads) {
$p = $this->owner instanceof ProductVariation ? $this->owner->Product() : $this->owner->Parent();
if ($p && $p->exists() && $p->hasExtension('Downloadable')) $files->merge( $p->getDownloads() );
if ($p && $p->exists() && $p->hasExtension('Downloadable') && !isset($blacklist[$p->ID])) {
$files->merge( $p->getDownloads($blacklist) );
}
}

if ($this->owner->IncludeChildDownloads) {
$kids = $this->owner->hasMethod('ChildProducts') ? $this->owner->ChildProducts() : $this->owner->Children();
foreach ($kids as $kid) {
if ($kid->hasExtension('Downloadable')) $files->merge( $kid->getDownloads() );
if ($kid->hasExtension('Downloadable') && !isset($blacklist[$kid->ID])) {
$files->merge( $kid->getDownloads($blacklist) );
}
}
}

Expand Down

0 comments on commit 01c67fa

Please sign in to comment.