Commit 1824b0b2 authored by Taylor Otwell's avatar Taylor Otwell

Merge pull request #1257 from vtalbot/develop

Add bundle:uninstall, bundle:unpublish, migrate:rollback and migrate:reset for bundles
parents b8ed8060 6a14705a
......@@ -61,6 +61,43 @@ class Bundler extends Task {
}
}
/**
* 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 @@ class Bundler extends Task {
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.
*
......
......@@ -28,6 +28,26 @@ class Publisher {
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.
*
......
......@@ -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": {
......
......@@ -103,9 +103,23 @@ class Migrator extends Task {
{
$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 @@ class Migrator extends Task {
*/
public function reset($arguments = array())
{
while ($this->rollback()) {};
while ($this->rollback($arguments)) {};
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment