Merge pull request #398 from cachethq/permissions-command
Add FixPermissionsCommand. Closes #397
This commit is contained in:
+1
-1
@@ -64,7 +64,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"post-install-cmd": [
|
"post-install-cmd": [
|
||||||
"php artisan optimize",
|
"php artisan optimize",
|
||||||
"chmod -R 777 app/storage public",
|
"php artisan cachet:chmod",
|
||||||
"php artisan cachet:one-click-deploy"
|
"php artisan cachet:one-click-deploy"
|
||||||
],
|
],
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace CachetHQ\Cachet\Console\Commands;
|
||||||
|
|
||||||
|
use DirectoryIterator;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class FixPermissionsCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The console command name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $name = 'cachet:chmod';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Fixes file and directory permissions. Ensures SQLite database is writeable.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path to the storage directory.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $storageDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path of the database directory.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $databaseDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path of the SQLite database file.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $databasePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which database connection are we using?
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $databaseDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new fix permissions command instance.
|
||||||
|
*
|
||||||
|
* @param string $storageDirectory
|
||||||
|
* @param string $databaseDirectory
|
||||||
|
* @param string $databasePath
|
||||||
|
* @param string $databaseDefault
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($storageDirectory, $databaseDirectory, $databasePath, $databaseDefault)
|
||||||
|
{
|
||||||
|
$this->storageDirectory = $storageDirectory;
|
||||||
|
$this->databaseDirectory = $databaseDirectory;
|
||||||
|
$this->databasePath = $databasePath;
|
||||||
|
$this->databaseDefault = $databaseDefault;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function fire()
|
||||||
|
{
|
||||||
|
$this->recursiveChmod($this->storageDirectory);
|
||||||
|
|
||||||
|
if ($this->databaseDefault === 'sqlite') {
|
||||||
|
chmod($this->databaseDirectory, 755);
|
||||||
|
chmod($this->databasePath, 755);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively sets a paths file permissions.
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @param string $mode
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function recursiveChmod($path, $mode = '0755')
|
||||||
|
{
|
||||||
|
$dir = new DirectoryIterator($path);
|
||||||
|
foreach ($dir as $item) {
|
||||||
|
if (!$item->isDot()) {
|
||||||
|
chmod($item->getPathname(), $mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($item->isDir() && !$item->isDot()) {
|
||||||
|
$this->recursiveChmod($item->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace CachetHQ\Cachet\Providers;
|
namespace CachetHQ\Cachet\Providers;
|
||||||
|
|
||||||
|
use CachetHQ\Cachet\Console\Commands\FixPermissionsCommand;
|
||||||
use CachetHQ\Cachet\Console\Commands\OneClickDeployCommand;
|
use CachetHQ\Cachet\Console\Commands\OneClickDeployCommand;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ class ConsoleServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
|
$this->commands('CachetHQ\Cachet\Console\Commands\FixPermissionsCommand');
|
||||||
$this->commands('CachetHQ\Cachet\Console\Commands\OneClickDeployCommand');
|
$this->commands('CachetHQ\Cachet\Console\Commands\OneClickDeployCommand');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +26,15 @@ class ConsoleServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
|
$this->app->singleton('CachetHQ\Cachet\Console\Commands\FixPermissionsCommand', function ($app) {
|
||||||
|
$storageDirectory = $app->path['storage'];
|
||||||
|
$databaseDirectory = $app->path['database'];
|
||||||
|
$databasePath = $app->config->get('database.connections.sqlite.database');
|
||||||
|
$databaseDefault = $app->config->get('database.default');
|
||||||
|
|
||||||
|
return new FixPermissionsCommand($storageDirectory, $databaseDirectory, $databasePath, $databaseDefault);
|
||||||
|
});
|
||||||
|
|
||||||
$this->app->singleton('CachetHQ\Cachet\Console\Commands\OneClickDeployCommand', function ($app) {
|
$this->app->singleton('CachetHQ\Cachet\Console\Commands\OneClickDeployCommand', function ($app) {
|
||||||
return new OneClickDeployCommand($app->environment('heroku'));
|
return new OneClickDeployCommand($app->environment('heroku'));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user