/** * Parse array to \Packagist\Api\Result\Result * @param array $package * * @return Package */ public function createPackageResults(array $package) { $created = array(); if (isset($package['maintainers']) && $package['maintainers']) { foreach ($package['maintainers'] as $key => $maintainer) { $package['maintainers'][$key] = $this->createResult('Packagist\\Api\\Result\\Package\\Maintainer', $maintainer); } } if (isset($package['downloads']) && $package['downloads']) { $package['downloads'] = $this->createResult('Packagist\\Api\\Result\\Package\\Downloads', $package['downloads']); } foreach ($package['versions'] as $branch => $version) { if (isset($version['authors']) && $version['authors']) { foreach ($version['authors'] as $key => $author) { $version['authors'][$key] = $this->createResult('Packagist\\Api\\Result\\Package\\Author', $author); } } $version['source'] = $this->createResult('Packagist\\Api\\Result\\Package\\Source', $version['source']); if (isset($version['dist']) && $version['dist']) { $version['dist'] = $this->createResult('Packagist\\Api\\Result\\Package\\Dist', $version['dist']); } $package['versions'][$branch] = $this->createResult('Packagist\\Api\\Result\\Package\\Version', $version); } $created = new Package(); $created->fromArray($package); return $created; }
/** * Adds new package to info to Smuggler * * @param RemotePackage $remotePackage */ protected function addPackage(RemotePackage $remotePackage) { list($vendor, $name) = explode('/', $remotePackage->getName()); $package = new Package(); $package->setFullName($remotePackage->getName()); $package->setName($name); $package->setVendor($vendor); $this->getDoctrineHelper()->getEntityManager()->persist($package); }
/** * Get the readme file contents if one exists * @param Package $package * @return string */ private function getReadmeFileFor(Package $package) { $readmeLocation = 'storage/modules/' . $package->getName(); if ($this->diskFactory->disk('local')->exists($readmeLocation . '/readme.md')) { return $this->diskFactory->disk('local')->get($readmeLocation . '/readme.md'); } if ($this->diskFactory->disk('local')->exists($readmeLocation . '/README.md')) { return $this->diskFactory->disk('local')->get($readmeLocation . '/README.md'); } return ''; }
private function updateAddon(Addon $addon, Package $package, array $versions) { if (!$addon->VendorID) { $vendor = AddonVendor::get()->filter('Name', $addon->VendorName())->first(); if (!$vendor) { $vendor = new AddonVendor(); $vendor->Name = $addon->VendorName(); $vendor->write(); } $addon->VendorID = $vendor->ID; } $addon->Type = str_replace('silverstripe-', '', $package->getType()); $addon->Description = $package->getDescription(); $addon->Released = strtotime($package->getTime()); $addon->Repository = $package->getRepository(); $addon->Downloads = $package->getDownloads()->getTotal(); $addon->DownloadsMonthly = $package->getDownloads()->getMonthly(); $addon->Favers = $package->getFavers(); foreach ($versions as $version) { $this->updateVersion($addon, $version); } // If there is no build, then queue one up if the add-on requires // one. if (!$addon->BuildQueued) { if (!$addon->BuiltAt) { $this->resque->queue('first_build', 'BuildAddonJob', array('id' => $addon->ID)); $addon->BuildQueued = true; } else { $built = (int) $addon->obj('BuiltAt')->format('U'); foreach ($versions as $version) { if (strtotime($version->getTime()) > $built) { $this->resque->queue('update', 'BuildAddonJob', array('id' => $addon->ID)); $addon->BuildQueued = true; break; } } } } $addon->LastUpdated = time(); $addon->write(); }