working on bundle upgrade routine.
This commit is contained in:
@@ -6,6 +6,24 @@ use Laravel\CLI\Tasks\Task;
|
||||
|
||||
class Bundler extends Task {
|
||||
|
||||
/**
|
||||
* The bundle API repository.
|
||||
*
|
||||
* @var Repository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Create a new bundle manager task.
|
||||
*
|
||||
* @param Repository $repository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the given bundles into the application.
|
||||
*
|
||||
@@ -30,9 +48,41 @@ class Bundler extends Task {
|
||||
// Each bundle provider implements the Provider interface and
|
||||
// is repsonsible for retrieving the bundle source from its
|
||||
// hosting party and installing it into the application.
|
||||
$provider = "bundle.provider: {$bundle['provider']}";
|
||||
$this->download($bundle, $this->path($bundle));
|
||||
|
||||
IoC::resolve($provider)->install($bundle);
|
||||
echo "Bundle [{$bundle['name']}] has been installed!".PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade the given bundles for the application.
|
||||
*
|
||||
* @param array $bundles
|
||||
* @return void
|
||||
*/
|
||||
public function upgrade($bundles)
|
||||
{
|
||||
foreach ($bundles as $name)
|
||||
{
|
||||
$bundle = Bundle::get($name);
|
||||
|
||||
if (is_nulL($bundle))
|
||||
{
|
||||
throw new \Exception("Bundle [{$name}] is not installed!");
|
||||
}
|
||||
|
||||
$data = $this->retrieve($bundle);
|
||||
|
||||
if ($response['status'] == 'not-found')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
File::rmdir($bundle->location);
|
||||
|
||||
$this->download($bundle, $bundle->location);
|
||||
|
||||
echo "Bundle [{$bundle['name']}] has been upgraded!".PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,20 +117,13 @@ class Bundler extends Task {
|
||||
{
|
||||
$responses = array();
|
||||
|
||||
$repository = IoC::resolve('bundle.repository');
|
||||
|
||||
foreach ($bundles as $bundle)
|
||||
{
|
||||
// First we'll call the bundle repository to gather the bundle data
|
||||
// array, which contains all of the information needed to install
|
||||
// the bundle into the application. We'll verify that the bundle
|
||||
// exists and the API is responding for each bundle.
|
||||
$response = $repository->get($bundle);
|
||||
|
||||
if ( ! $response)
|
||||
{
|
||||
throw new \Exception("The bundle API is not responding.");
|
||||
}
|
||||
$response = $this->retrieve($bundle);
|
||||
|
||||
if ($response['status'] == 'not-found')
|
||||
{
|
||||
@@ -101,4 +144,47 @@ class Bundler extends Task {
|
||||
return $responses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a bundle using a provider.
|
||||
*
|
||||
* @param string $bundle
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
protected function download($bundlem, $path)
|
||||
{
|
||||
$provider = "bundle.provider: {$bundle['provider']}";
|
||||
|
||||
IoC::resolve($provider)->install($bundle, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a bundle from the repository.
|
||||
*
|
||||
* @param string $bundle
|
||||
* @return array
|
||||
*/
|
||||
protected function retrieve($bundle)
|
||||
{
|
||||
$response = $this->repository->get($bundle);
|
||||
|
||||
if ( ! $response)
|
||||
{
|
||||
throw new \Exception("The bundle API is not responding.");
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path for a given bundle.
|
||||
*
|
||||
* @param array $bundle
|
||||
* @return string
|
||||
*/
|
||||
protected function path($bundle)
|
||||
{
|
||||
return array_get($bundle, 'path', $bundle['name']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
<?php namespace Laravel\CLI\Tasks\Bundle\Providers;
|
||||
|
||||
use Laravel\Request;
|
||||
<?php namespace Laravel\CLI\Tasks\Bundle\Providers; use Laravel\Request;
|
||||
|
||||
class Github extends Provider {
|
||||
|
||||
@@ -8,70 +6,14 @@ class Github extends Provider {
|
||||
* Install the given bundle into the application.
|
||||
*
|
||||
* @param string $bundle
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
public function install($bundle)
|
||||
{
|
||||
$method = (Request::server('cli.git')) ? 'submodule' : 'zipball';
|
||||
|
||||
$this->$method($bundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a Github hosted bundle from Zip.
|
||||
*
|
||||
* @param string $bundle
|
||||
* @return void
|
||||
*/
|
||||
protected function zipball($bundle)
|
||||
public function install($bundle, $path)
|
||||
{
|
||||
$url = "http://nodeload.github.com/{$bundle['location']}/zipball/master";
|
||||
|
||||
parent::zipball($bundle, $url, true);
|
||||
|
||||
echo "Bundle [{$bundle['name']}] has been installed!".PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a Github hosted bundle using submodules.
|
||||
*
|
||||
* @param string $bundle
|
||||
* @return void
|
||||
*/
|
||||
protected function submodule($bundle)
|
||||
{
|
||||
$repository = "git@github.com:{$bundle['location']}.git";
|
||||
|
||||
$this->directory($bundle);
|
||||
|
||||
// We need to just extract the basename of the bundle path when
|
||||
// adding the submodule. Of course, we can't add a submodule to
|
||||
// a location outside of the Git repository, so we don't need
|
||||
// the full bundle path.
|
||||
$root = basename(path('bundle')).'/';
|
||||
|
||||
passthru('git submodule add '.$repository.' '.$root.$this->path($bundle));
|
||||
|
||||
passthru('git submodule update');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the path to the bundle's dirname.
|
||||
*
|
||||
* @param array $bundle
|
||||
* @return void
|
||||
*/
|
||||
protected function directory($bundle)
|
||||
{
|
||||
// If the installation target directory doesn't exist, we will create
|
||||
// it recursively so that we can properly install the bundle to the
|
||||
// correct path in the application.
|
||||
$target = dirname(path('bundle').$this->path($bundle));
|
||||
|
||||
if ( ! is_dir($target))
|
||||
{
|
||||
mkdir($target, 0777, true);
|
||||
}
|
||||
parent::zipball($url, $bundle, $path);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,23 +8,27 @@ abstract class Provider {
|
||||
* Install the given bundle into the application.
|
||||
*
|
||||
* @param string $bundle
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
abstract public function install($bundle);
|
||||
abstract public function install($bundle, $path);
|
||||
|
||||
/**
|
||||
* Install a bundle from by downloading a Zip.
|
||||
*
|
||||
* @param array $bundle
|
||||
* @param string $url
|
||||
* @param array $bundle
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
protected function zipball($bundle, $url)
|
||||
protected function zipball($url, $bundle, $path)
|
||||
{
|
||||
$work = path('storage').'work/';
|
||||
|
||||
// When installing a bundle from a Zip archive, we'll first clone
|
||||
// down the bundle zip into the bundles "working" directory so
|
||||
// we have a spot to do all of our bundle extration work.
|
||||
$target = path('storage').'work/laravel-bundle.zip';
|
||||
$target = $work.'laravel-bundle.zip';
|
||||
|
||||
File::put($target, file_get_contents($url));
|
||||
|
||||
@@ -36,9 +40,9 @@ abstract class Provider {
|
||||
// into the working directory. By convention, we expect the
|
||||
// archive to contain one root directory, and all of the
|
||||
// bundle contents should be stored in that directory.
|
||||
$zip->extractTo(path('storage').'work');
|
||||
$zip->extractTo($work);
|
||||
|
||||
$latest = File::latest(dirname($target))->getRealPath();
|
||||
$latest = File::latest($work)->getRealPath();
|
||||
|
||||
@chmod($latest, 0777);
|
||||
|
||||
@@ -52,15 +56,4 @@ abstract class Provider {
|
||||
@unlink($target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path for a given bundle.
|
||||
*
|
||||
* @param array $bundle
|
||||
* @return string
|
||||
*/
|
||||
protected function path($bundle)
|
||||
{
|
||||
return array_get($bundle, 'path', $bundle['name']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user