From 893136966581610bc0388ef5ff552163c80b6120 Mon Sep 17 00:00:00 2001 From: vtalbot Date: Thu, 20 Sep 2012 22:15:29 -0400 Subject: [PATCH 1/2] Add task bundle:uninstall, bundle:unpublish, migrate:rollback bundle, migrate:reset bundle. --- laravel/cli/tasks/bundle/bundler.php | 50 ++++++++++++++++++++++++++ laravel/cli/tasks/bundle/publisher.php | 20 +++++++++++ laravel/cli/tasks/help.json | 8 +++++ laravel/cli/tasks/migrate/migrator.php | 18 ++++++++-- 4 files changed, 94 insertions(+), 2 deletions(-) diff --git a/laravel/cli/tasks/bundle/bundler.php b/laravel/cli/tasks/bundle/bundler.php index 7af60e07..d7e5dcda 100644 --- a/laravel/cli/tasks/bundle/bundler.php +++ b/laravel/cli/tasks/bundle/bundler.php @@ -61,6 +61,43 @@ public function install($bundles) } } + /** + * Uninstall the given bundles from the application. + * + * @param array $bundles + * @return void + */ + public function uninstall($bundles) + { + if (count($bundles) == 0) + { + throw new \Exception("Tell me what bundle to uninstall."); + } + + foreach ($bundles as $name) + { + if ( ! Bundle::exists($name)) + { + echo "Bundle [{$name}] is not installed."; + continue; + } + + echo "Uninstalling [{$name}]...".PHP_EOL; + $migrator = IoC::resolve('task: migrate'); + $migrator->reset($name); + + $publisher = IoC::resolve('bundle.publisher'); + $publisher->unpublish($name); + + $location = Bundle::path($name); + File::rmdir($location); + + echo "Bundle [{$name}] has been uninstalled!".PHP_EOL; + } + + echo "Now, you have to remove those bundle from your application/bundles.php".PHP_EOL; + } + /** * Upgrade the given bundles for the application. * @@ -159,6 +196,19 @@ public function publish($bundles) array_walk($bundles, array(IoC::resolve('bundle.publisher'), 'publish')); } + /** + * Delete bundle assets from the public directory. + * + * @param array $bundles + * @return void + */ + public function unpublish($bundles) + { + if (count($bundles) == 0) $bundles = Bundle::names(); + + array_walk($bundles, array(IoC::resolve('bundle.publisher'), 'unpublish')); + } + /** * Install a bundle using a provider. * diff --git a/laravel/cli/tasks/bundle/publisher.php b/laravel/cli/tasks/bundle/publisher.php index 12527b08..5beb4fb4 100644 --- a/laravel/cli/tasks/bundle/publisher.php +++ b/laravel/cli/tasks/bundle/publisher.php @@ -28,6 +28,26 @@ public function publish($bundle) echo "Assets published for bundle [$bundle].".PHP_EOL; } + /** + * Delete a bundle's assets from the public directory + * + * @param string $bundle + * @return void + */ + public function unpublish($bundle) + { + if ( ! Bundle::exists($bundle)) + { + echo "Bundle [$bundle] is not registered."; + + return; + } + + File::rmdir(path('public').'bundles'.DS.$bundle); + + echo "Assets deleted for bundle [$bundle].".PHP_EOL; + } + /** * Copy the contents of a bundle's assets to the public folder. * diff --git a/laravel/cli/tasks/help.json b/laravel/cli/tasks/help.json index 3f614ad1..d89a0b2a 100644 --- a/laravel/cli/tasks/help.json +++ b/laravel/cli/tasks/help.json @@ -38,6 +38,10 @@ "description": "Install a bundle.", "command": "php artisan bundle:install swiftmailer" }, + "bundle:uninstall": { + "description": "Uninstall a bundle, delete its public, rollback its migrations.", + "command": "php artisan bundle:uninstall swiftmailer" + }, "bundle:upgrade": { "description": "Upgrade a bundle.", "command": "php artisan bundle:upgrade swiftmailer" @@ -45,6 +49,10 @@ "bundle:publish": { "description": "Publish all bundles' assets.", "command": "php artisan bundle:publish" + }, + "bundle:unpublish": { + "description": "Delete all bundles' assets from the public directory.", + "command": "php artisan bundle:unpublish" } }, "Unit Testing": { diff --git a/laravel/cli/tasks/migrate/migrator.php b/laravel/cli/tasks/migrate/migrator.php index 4ab2ef05..521dff98 100644 --- a/laravel/cli/tasks/migrate/migrator.php +++ b/laravel/cli/tasks/migrate/migrator.php @@ -103,9 +103,23 @@ public function rollback($arguments = array()) { $migrations = $this->resolver->last(); + // If bundles supplied, filter migrations to rollback only bundles' + // migrations. + if (count($arguments) > 0) + { + $bundles = $arguments; + + if ( ! is_array($bundles)) $bundles = array($bundles); + + $migrations = array_filter($migrations, function($migration) use ($bundles) + { + return in_array($migration['bundle'], $bundles); + }); + } + if (count($migrations) == 0) { - echo "Nothing to rollback."; + echo "Nothing to rollback.".PHP_EOL; return false; } @@ -136,7 +150,7 @@ public function rollback($arguments = array()) */ public function reset($arguments = array()) { - while ($this->rollback()) {}; + while ($this->rollback($arguments)) {}; } /** From c55a8f49dd4bed2ce47e3d84ea956355cf6c4c82 Mon Sep 17 00:00:00 2001 From: Vincent Talbot Date: Thu, 27 Sep 2012 11:57:34 -0300 Subject: [PATCH 2/2] Update laravel/cli/tasks/migrate/migrator.php --- laravel/cli/tasks/migrate/migrator.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/laravel/cli/tasks/migrate/migrator.php b/laravel/cli/tasks/migrate/migrator.php index 521dff98..d38f6ab2 100644 --- a/laravel/cli/tasks/migrate/migrator.php +++ b/laravel/cli/tasks/migrate/migrator.php @@ -105,17 +105,17 @@ public function rollback($arguments = array()) // If bundles supplied, filter migrations to rollback only bundles' // migrations. - if (count($arguments) > 0) - { - $bundles = $arguments; - - if ( ! is_array($bundles)) $bundles = array($bundles); - - $migrations = array_filter($migrations, function($migration) use ($bundles) - { - return in_array($migration['bundle'], $bundles); - }); - } + if (count($arguments) > 0) + { + $bundles = $arguments; + + if ( ! is_array($bundles)) $bundles = array($bundles); + + $migrations = array_filter($migrations, function($migration) use ($bundles) + { + return in_array($migration['bundle'], $bundles); + }); + } if (count($migrations) == 0) {