Skip to content

Commit

Permalink
feat: add filesize on dump log
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Apr 16, 2023
1 parent 4f71eb1 commit 9b193ef
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions App/Commands/DbDump.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
<?php namespace RockShell;
<?php

namespace RockShell;

use Symfony\Component\Console\Input\InputOption;

class DbDump extends Command {
use function ProcessWire\wireBytesStr;

class DbDump extends Command
{

const backupdir = "/site/assets/backups/database/";

public function config() {
public function config()
{
$this
->setDescription("Create a database dump using PW backup tools")
->addOption("file", "f", InputOption::VALUE_OPTIONAL,
"Filename to be used for the dump inside ".self::backupdir, "db.sql")
->addOption("delete", "d", InputOption::VALUE_NONE,
"Delete all users except guest")
;
->addOption(
"file",
"f",
InputOption::VALUE_OPTIONAL,
"Filename to be used for the dump inside " . self::backupdir,
"db.sql"
)
->addOption(
"delete",
"d",
InputOption::VALUE_NONE,
"Delete all users except guest"
);
}

public function handle() {
public function handle()
{
$wire = $this->wire();
$file = $this->option("file");

// delete all users except guest
if($this->option("delete")) {
foreach($wire->users as $user) {
if($user->name == 'guest') continue;
if ($this->option("delete")) {
foreach ($wire->users as $user) {
if ($user->name == 'guest') continue;
$this->write("Deleting user {$user->name}...");
$wire->users->delete($user);
}
Expand All @@ -34,13 +49,15 @@ public function handle() {
$backup = $wire->database->backups();
$backup->setDatabaseConfig($wire->config);
$file = $backup->backup(['filename' => $file]);
if($file) {
$this->success("Backed up to: $file\n");
if ($file) {
$this->success("Backed up to: $file");
$size = wireBytesStr($file, true);
$this->write("Filesize: $size");
$this->write("");
} else {
$this->success("Backup failed: " . implode("<br>", $backup->errors())."\n");
$this->success("Backup failed: " . implode("<br>", $backup->errors()) . "\n");
}

return self::SUCCESS;
}

}

0 comments on commit 9b193ef

Please sign in to comment.