public function __construct($thirdPartyPath, $themePath, $tempPath) { $manifestPath = __DIR__.'/../config/manifest.js'; if (! is_readable($manifestPath)) { throw new \Exception('Could not find a readable Github Addon Installer manifest.'); } $manifestContents = file_get_contents($manifestPath); if ($manifestContents === false) { throw new \Exception('Could not load the Github Addon Installer manifest.'); } $this->manifest = json_decode($manifestContents, true); if (! $this->manifest) { throw new \Exception('Could not load the Github Addon Installer manifest.'); } ksort($this->manifest); $this->api = new Api(); $this->installer = Installer::create($thirdPartyPath, $themePath, $tempPath); }
public function install(Repo $repo, $addonName, $addonPath = null, $themePath = null, $addFolder = null) { $filePath = $this->tempPath.$repo->getSha().'.zip'; if ( ! file_exists($filePath)) { $handle = fopen($filePath, 'w'); fwrite($handle, $repo->getZipball()); fclose($handle); $this->unzip($filePath); } //this is how github names the zipball, usually $shortSha = substr($repo->getSha(), 0, 7); $tempDir = $repo->getUser().'-'.$repo->getRepo().'-'.$shortSha; $files = array(); //the sha numbering is off, else is a somewhat messy fallback if (! is_dir($this->tempPath.$tempDir)) { $tempDir = null; $iterator = new \DirectoryIterator($this->tempPath); foreach ($iterator as $file) { // does it start with this user/repo combo? if (! $file->isDot() && $file->isDir() && preg_match('/^'.preg_quote($repo->getUser()).'-'.preg_quote($repo->getRepo()).'-/', $file->getBasename())) { $tempDir = $file->getBasename(); break; } } } if (is_null($tempDir)) { throw new \Exception(sprintf('Could not find unzipped contents for %s/%s in %s', $repo->getUser(), $repo->getRepo(), $this->tempPath)); } $this->tempDir = $tempDir; parent::install($repo, $addonName, $addonPath, $themePath, $addFolder); unlink($this->tempPath.$repo->getSha().'.zip'); }