Skip to content

Commit e4d384a

Browse files
authored
Merge pull request #36 from pxthinh/tools
create command to change owner for config json files
2 parents 14c559e + ff02f90 commit e4d384a

File tree

2 files changed

+72
-20
lines changed

2 files changed

+72
-20
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace CSlant\LaravelTelegramGitNotifier\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class ChangeOwnerConfigJson extends Command
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'config-json:change-owner {--user= : user}';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'config-json';
22+
23+
/**
24+
* Execute the console command.
25+
*
26+
* @return void
27+
*/
28+
public function handle(): void
29+
{
30+
$user = $this->option('user');
31+
$jsonsPath = config('telegram-git-notifier.data_file.storage_folder');
32+
if (is_string($jsonsPath) && file_exists($jsonsPath)) {
33+
exec("chown -R $user:$user $jsonsPath");
34+
}
35+
}
36+
}

src/Providers/TelegramGitNotifierServiceProvider.php

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CSlant\LaravelTelegramGitNotifier\Providers;
44

5+
use CSlant\LaravelTelegramGitNotifier\Commands\ChangeOwnerConfigJson;
56
use Illuminate\Support\ServiceProvider;
67

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

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

28-
$configPath = __DIR__.'/../../config/telegram-git-notifier.php';
29-
$this->publishes([
30-
$configPath => config_path('telegram-git-notifier.php'),
31-
], 'config');
32-
33-
$this->publishes([
34-
__DIR__.'/../../resources/views' => config('telegram-git-notifier.defaults.paths.views'),
35-
], 'views');
36-
37-
$this->publishes([
38-
__DIR__.'/../../lang' => resource_path('lang/vendor/tg-notifier'),
39-
], 'lang');
29+
$this->registerCommands();
4030

41-
$this->publishes([
42-
__DIR__.'/../../../telegram-git-notifier/config/jsons' => config('telegram-git-notifier.data_file.storage_folder'),
43-
], 'config_jsons');
44-
45-
$jsonsPath = config('telegram-git-notifier.data_file.storage_folder');
46-
if (is_string($jsonsPath) && file_exists($jsonsPath)) {
47-
exec("chown -R www-data:www-data $jsonsPath");
48-
}
31+
$this->registerAssetPublishing();
4932
}
5033

5134
/**
@@ -68,4 +51,37 @@ public function provides(): ?array
6851
{
6952
return ['telegram-git-notifier'];
7053
}
54+
55+
/**
56+
* @return void
57+
*/
58+
protected function registerCommands(): void
59+
{
60+
$this->commands([
61+
ChangeOwnerConfigJson::class,
62+
]);
63+
}
64+
65+
/**
66+
* @return void
67+
*/
68+
protected function registerAssetPublishing(): void
69+
{
70+
$configPath = __DIR__.'/../../config/telegram-git-notifier.php';
71+
$this->publishes([
72+
$configPath => config_path('telegram-git-notifier.php'),
73+
], 'config');
74+
75+
$this->publishes([
76+
__DIR__.'/../../resources/views' => config('telegram-git-notifier.defaults.paths.views'),
77+
], 'views');
78+
79+
$this->publishes([
80+
__DIR__.'/../../lang' => resource_path('lang/vendor/tg-notifier'),
81+
], 'lang');
82+
83+
$this->publishes([
84+
__DIR__.'/../../../telegram-git-notifier/config/jsons' => config('telegram-git-notifier.data_file.storage_folder'),
85+
], 'config_jsons');
86+
}
7187
}

0 commit comments

Comments
 (0)