working on bundle upgrade routine.

This commit is contained in:
Taylor Otwell
2012-02-03 14:54:23 -06:00
parent b1f12b19bf
commit ea42fe75f2
4 changed files with 113 additions and 90 deletions

View File

@@ -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);
}
}

View File

@@ -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']);
}
}