Skip to content

Commit

Permalink
Merge pull request #36 from pxthinh/tools
Browse files Browse the repository at this point in the history
create command to change owner for config json files
  • Loading branch information
tanhongit authored Nov 24, 2023
2 parents 14c559e + ff02f90 commit e4d384a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 20 deletions.
36 changes: 36 additions & 0 deletions src/Commands/ChangeOwnerConfigJson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace CSlant\LaravelTelegramGitNotifier\Commands;

use Illuminate\Console\Command;

class ChangeOwnerConfigJson extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'config-json:change-owner {--user= : user}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'config-json';

/**
* Execute the console command.
*
* @return void
*/
public function handle(): void
{
$user = $this->option('user');
$jsonsPath = config('telegram-git-notifier.data_file.storage_folder');
if (is_string($jsonsPath) && file_exists($jsonsPath)) {
exec("chown -R $user:$user $jsonsPath");
}
}
}
56 changes: 36 additions & 20 deletions src/Providers/TelegramGitNotifierServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CSlant\LaravelTelegramGitNotifier\Providers;

use CSlant\LaravelTelegramGitNotifier\Commands\ChangeOwnerConfigJson;
use Illuminate\Support\ServiceProvider;

class TelegramGitNotifierServiceProvider extends ServiceProvider
Expand All @@ -25,27 +26,9 @@ public function boot(): void

$this->loadTranslationsFrom(__DIR__.'/../../lang', 'tg-notifier');

$configPath = __DIR__.'/../../config/telegram-git-notifier.php';
$this->publishes([
$configPath => config_path('telegram-git-notifier.php'),
], 'config');

$this->publishes([
__DIR__.'/../../resources/views' => config('telegram-git-notifier.defaults.paths.views'),
], 'views');

$this->publishes([
__DIR__.'/../../lang' => resource_path('lang/vendor/tg-notifier'),
], 'lang');
$this->registerCommands();

$this->publishes([
__DIR__.'/../../../telegram-git-notifier/config/jsons' => config('telegram-git-notifier.data_file.storage_folder'),
], 'config_jsons');

$jsonsPath = config('telegram-git-notifier.data_file.storage_folder');
if (is_string($jsonsPath) && file_exists($jsonsPath)) {
exec("chown -R www-data:www-data $jsonsPath");
}
$this->registerAssetPublishing();
}

/**
Expand All @@ -68,4 +51,37 @@ public function provides(): ?array
{
return ['telegram-git-notifier'];
}

/**
* @return void
*/
protected function registerCommands(): void
{
$this->commands([
ChangeOwnerConfigJson::class,
]);
}

/**
* @return void
*/
protected function registerAssetPublishing(): void
{
$configPath = __DIR__.'/../../config/telegram-git-notifier.php';
$this->publishes([
$configPath => config_path('telegram-git-notifier.php'),
], 'config');

$this->publishes([
__DIR__.'/../../resources/views' => config('telegram-git-notifier.defaults.paths.views'),
], 'views');

$this->publishes([
__DIR__.'/../../lang' => resource_path('lang/vendor/tg-notifier'),
], 'lang');

$this->publishes([
__DIR__.'/../../../telegram-git-notifier/config/jsons' => config('telegram-git-notifier.data_file.storage_folder'),
], 'config_jsons');
}
}

0 comments on commit e4d384a

Please sign in to comment.