Skip to content

Commit

Permalink
DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Lindecke committed Sep 27, 2019
1 parent ef72a8c commit 45da647
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
65 changes: 65 additions & 0 deletions src/Command/CliManDBCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace lindesbs\climan\Command;

use Contao\System;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\VarDumper\VarDumper;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;


class CliManDBCommand extends Command
{


protected function configure(): void
{
$this->setName('climan:db');
$this->setDescription('db stuff');

$this->addArgument("generate");
$this->addOption('gzip', null, InputOption::VALUE_NONE, 'gzip');
$this->addOption('gi', null, InputOption::VALUE_NONE, 'add generation info to filename');

}


protected function execute(InputInterface $input, OutputInterface $output)
{

if ($input->getArgument("generate"))
{

$param = System::getContainer()->get('database_connection')->getParams();


$db = new \mysqli($param['host'], $param['user'], $param['password'], $param['dbname'], $param['port']);
$dump = new \MySQLDump($db);

$strFilename = "export.sql";


if ($input->getOption("gi"))
{
$strFilename = sprintf("export_%s.sql", date("Y-m-d_H-i-s"));
}

if ($input->getOption("gzip"))
{
$strFilename.=".gz";
}

$dump->save(TL_ROOT . '/'.$strFilename);

return;
}

}


}
7 changes: 1 addition & 6 deletions src/Command/CliManFrontendUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace lindesbs\climan\Command;

use Contao\System;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -76,12 +77,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$objFeUser->disable = 0;
$objFeUser->save();


$objDB = \Database::getInstance();

$dump = new \MySQLDump($objDB);
$dump->save(TL_ROOT . '/export.sql');

return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ services:
lindesbs.climan.frontenduser.command:
class: lindesbs\climan\Command\CliManFrontendUserCommand
tags: ['console.command']
lindesbs.climan.db.command:
class: lindesbs\climan\Command\CliManDBCommand
tags: ['console.command']

0 comments on commit 45da647

Please sign in to comment.