Skip to content

Commit

Permalink
feat: make commands run as sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Jan 15, 2024
1 parent 0770cb3 commit 02df9ae
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions App/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
$this->sudo(true);
return $this->handle();
}

Expand Down Expand Up @@ -370,6 +371,22 @@ public function success($str)
$this->info($this->str($str));
}

/**
* Change to the first superuser
* @return void
*/
public function sudo($silent = false): void
{
if (!$this->wire()) return;
$role = $this->wire()->roles->get('superuser');
$su = $this->wire()->users->get("sort=id,roles=$role");
if (!$su->id and !$silent) {
$this->log("No superuser found");
return;
}
$this->wire()->users->setCurrentUser($su);
}

/**
* Enforce trailing slash and normalize separators
* @param string $path
Expand Down

0 comments on commit 02df9ae

Please sign in to comment.