From ec5c08a7ccd7ddaf8c2f57d84443080e8a8e497e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 2 Feb 2012 15:18:36 -0600 Subject: [PATCH] added ability to install github bundles using zips. --- laravel/cli/artisan.php | 12 +++--- laravel/cli/tasks/bundle/providers/github.php | 5 ++- .../cli/tasks/bundle/providers/provider.php | 38 +++++++++++++++++++ laravel/file.php | 26 ++++++++++++- 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/laravel/cli/artisan.php b/laravel/cli/artisan.php index e91e51e0..8d4672dc 100644 --- a/laravel/cli/artisan.php +++ b/laravel/cli/artisan.php @@ -15,7 +15,9 @@ * retrieve them from the various parts of the CLI code. We can use * the Request class to access them conveniently. */ -list($arguments, $_SERVER['cli']) = Console::options($_SERVER['argv']); +list($arguments, $_SERVER['CLI']) = Console::options($_SERVER['argv']); + +$_SERVER['CLI'] = array_change_key_case($_SERVER['CLI'], CASE_UPPER); /** * The Laravel environment may be specified on the CLI using the "env" @@ -23,9 +25,9 @@ * files from the CLI since the environment is usually controlled * by server environmenet variables. */ -if (isset($_SERVER['cli']['env'])) +if (isset($_SERVER['CLI']['ENV'])) { - $_SERVER['LARAVEL_ENV'] = $_SERVER['cli']['env']; + $_SERVER['LARAVEL_ENV'] = $_SERVER['CLI']['ENV']; } /** @@ -33,9 +35,9 @@ * for the "database" CLI option. This allows migrations to be run * conveniently for a test or staging database. */ -if (isset($_SERVER['cli']['db'])) +if (isset($_SERVER['CLI']['DB'])) { - Config::set('database.default', $_SERVER['cli']['db']); + Config::set('database.default', $_SERVER['CLI']['DB']); } /** diff --git a/laravel/cli/tasks/bundle/providers/github.php b/laravel/cli/tasks/bundle/providers/github.php index da0f27a0..52269deb 100644 --- a/laravel/cli/tasks/bundle/providers/github.php +++ b/laravel/cli/tasks/bundle/providers/github.php @@ -25,9 +25,9 @@ public function install($bundle) */ protected function zipball($bundle) { - $zip = "https://github.com/{$bundle['location']}/zipball/master"; + $url = "http://nodeload.github.com/{$bundle['location']}/zipball/master"; - parent::zipball($zip, true); + parent::zipball($bundle, $url, true); } /** @@ -38,6 +38,7 @@ protected function zipball($bundle) */ protected function submodule($bundle) { + die('here'); $repository = "git@github.com:{$bundle['location']}.git"; $this->directory($bundle); diff --git a/laravel/cli/tasks/bundle/providers/provider.php b/laravel/cli/tasks/bundle/providers/provider.php index 4080aa56..a7879480 100644 --- a/laravel/cli/tasks/bundle/providers/provider.php +++ b/laravel/cli/tasks/bundle/providers/provider.php @@ -1,5 +1,7 @@ open($target); + + // Once we have the Zip archive, we can open it and extract it + // 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/bundles'); + + $latest = File::latest(dirname($target)); + + // Once we have the latest modified directory, we should be + // able to move its contents over into the bundles folder + // so the bundle will be usable by the develoepr. + $path = $this->path($bundle); + + File::cpdir($latest->getRealPath(), path('bundle').$path); + } + /** * Create the path to the bundle's dirname. * diff --git a/laravel/file.php b/laravel/file.php index 627c5933..6f82c771 100644 --- a/laravel/file.php +++ b/laravel/file.php @@ -191,7 +191,7 @@ public static function cpdir($source, $destination, $delete = false) // from the installed bundle's source directory. if ( ! is_dir($destination)) { - mkdir($destination); + mkdir($destination, 0777, true); } $items = new FilesystemIterator($source, FilesystemIterator::SKIP_DOTS); @@ -227,4 +227,28 @@ public static function cpdir($source, $destination, $delete = false) if ($delete) rmdir($source); } + /** + * Get the most recently modified file in a directory. + * + * @param string $directory + * @return SplFileInfo + */ + public static function latest($directory) + { + $time = 0; + + $items = new FilesystemIterator($directory, FilesystemIterator::SKIP_DOTS); + + // To get the latest created file, we'll simply spin through the + // directory, setting the latest file if we encounter a file + // with a UNIX timestamp greater than the latest one we + // have encountered thus far in the loop. + foreach ($items as $item) + { + if ($item->getMTime() > $time) $latest = $item; + } + + return $latest; + } + } \ No newline at end of file