File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -35,18 +35,33 @@ public function handle(): void
3535 return ;
3636 }
3737
38- $ user = ( string ) ( $ this ->argument ('user ' ) ?? ' ' );
39- $ group = ( string ) ( $ this ->argument ('group ' ) ?? $ user) ;
38+ $ user = $ this ->argument ('user ' );
39+ $ group = $ this ->argument ('group ' ) ?? $ user ;
4040
41- if (empty ($ user ) || empty ($ group )) {
42- $ group = $ user = ( string ) exec ( ' ps aux | egrep "(apache|httpd|nginx)" | grep -v "root" | head -n1 | cut -d\ -f1 ' );
41+ if (! is_string ($ user ) || ! is_string ($ group )) {
42+ $ user = $ group = $ this -> getDefaultUserGroup ( );
4343 }
4444
4545 $ jsonsPath = config ('telegram-git-notifier.data_file.storage_folder ' );
4646 if (is_string ($ jsonsPath ) && file_exists ($ jsonsPath )) {
47- shell_exec ("chown -R " . escapeshellarg ($ user ) . ": " . escapeshellarg ($ group ) . " " . escapeshellarg ($ jsonsPath ));
47+ shell_exec ("chown -R " . escapeshellarg ($ user ). ": " . escapeshellarg ($ group ). " " . escapeshellarg ($ jsonsPath ));
4848 } else {
4949 $ this ->error ('The path to the jsons folder is not valid ' );
5050 }
5151 }
52+
53+ /**
54+ * Get the default user and group for the chown command.
55+ *
56+ * @return string
57+ */
58+ private function getDefaultUserGroup (): string
59+ {
60+ $ defaultUserGroup = exec ('ps aux | egrep "(apache|httpd|nginx)" | grep -v "root" | head -n1 | cut -d\ -f1 ' );
61+ if ($ defaultUserGroup === false ) {
62+ $ this ->error ('Failed to retrieve default user and group ' );
63+ return '' ;
64+ }
65+ return $ defaultUserGroup ;
66+ }
5267}
You can’t perform that action at this time.
0 commit comments