<commit_before><?php

namespace Gradcracker\Console\Command;

use League\CLImate\CLImate;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

class mysqldumper extends Command
{
    protected $cli;
 
    protected $config;

    protected $localAdapter;

    protected $db;

    public function __construct(CLImate $cli)
    {
        parent::__construct();
        $this->cli = $cli;
        $this->dump_folder = getcwd().'/dump';
        $this->loadConfig();
        $this->databaseSetup();
        $this->setLocalAdapter();
    }

    protected function configure()
    {
        $this->setName('dump')->setDescription('Dump the data');
        // ->addArgument(
        //     'env',
        //     InputArgument::REQUIRED,
        //     'Required option'
        // )->addArgument(
        //     'destination',
        //     InputArgument::OPTIONAL,
        //     'optional argument?'
        // );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->mysqldumper();
    }

    public function mysqldumper()
    {
        if($this->mysqldumpExists()) {
            $start_dump = date('YmdHi');
       
            $this->localAdapter->createDir('/'.$start_dump);

            $table_list = $this->listTables();

            $table_count = count($table_list);

           $this->cli->dump($table_list);

            $progress = $this->cli->progress()->total($table_count);

            for($i = 0; $i < $table_count; $i++) {
                //$this->cli->out($i, 'error');
                $progress->advance(1, '<light_green>('.$i.' of '.$table_count.') Dumping '.$table_list[$i]['Tables_in_'.$this->config->db].'</light_green>');
                exec($this->config->mysqldump.' --user='.$this->config->user.' --password='.$this->config->pass.' --host='.$this->config->host.' '.$this->config->db.' '.$table_list[$i]['Tables_in_'.$this->config->db].' | gzip > "'.$this->dump_folder.'/'.$start_dump.'/'.$table_list[$i]['Tables_in_'.$this->config->db].'.sql.gz"');
             }

            $this->cli->br();
            $this->out('Completed', 'success');
        } else {
            $this->out('mysqldump not found. Please check your path.', 'error');
        }
    }

    public function out($message, $style = 'info')
    {
        switch ($style) {
            case 'info':
                $this->cli->blue($message);
                break;
            case 'success':
                $this->cli->green($message);
                break;
            case 'error':
                $this->cli->red($message);
                break;
        }
    }

    public function loadConfig()
    {
        $this->config = json_decode(file_get_contents('config.json'));
    }

    public function databaseSetup()
    {
        try {
            $conn = new \PDO("mysql:host=".$this->config->host.";dbname=".$this->config->db, $this->config->user, $this->config->pass);
            $conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            
            $this->db = $conn;
        }
        catch(PDOException $e) {
            echo "Error: " . $e->getMessage();
        }
    }

    public function listTables()
    {
        $stmt = $this->db->prepare('SHOW TABLES'); 
        $stmt->setFetchMode(\PDO::FETCH_ASSOC); // set the resulting array to associative
        $stmt->execute();
            
        return $stmt->fetchAll();
    }

    public function mysqldumpExists()
    {
        return file_exists($this->config->mysqldump);
    }

    public function setLocalAdapter()
    {
        $this->localAdapter = new Filesystem(new Local($this->dump_folder));
    }
}<commit_msg>PSR-2 fixes<commit_after><?php

namespace Gradcracker\Console\Command;

use League\CLImate\CLImate;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

class mysqldumper extends Command
{
    protected $cli;
 
    protected $config;

    protected $localAdapter;

    protected $db;

    public function __construct(CLImate $cli)
    {
        parent::__construct();
        $this->cli = $cli;
        $this->dump_folder = getcwd().'/dump';
        $this->loadConfig();
        $this->databaseSetup();
        $this->setLocalAdapter();
    }

    protected function configure()
    {
        $this->setName('dump')->setDescription('Dump the data');
        // ->addArgument(
        //     'env',
        //     InputArgument::REQUIRED,
        //     'Required option'
        // )->addArgument(
        //     'destination',
        //     InputArgument::OPTIONAL,
        //     'optional argument?'
        // );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->mysqldumper();
    }

    public function mysqldumper()
    {
        if ($this->mysqldumpExists()) {
            $start_dump = date('YmdHi');
       
            $this->localAdapter->createDir('/'.$start_dump);

            $table_list = $this->listTables();

            $table_count = count($table_list);

            $this->cli->dump($table_list);

            $progress = $this->cli->progress()->total($table_count);

            for ($i = 0; $i < $table_count; $i++) {
                //$this->cli->out($i, 'error');
                $progress->advance(1, '<light_green>('.$i.' of '.$table_count.') Dumping '.$table_list[$i]['Tables_in_'.$this->config->db].'</light_green>');
                exec($this->config->mysqldump.' --user='.$this->config->user.' --password='.$this->config->pass.' --host='.$this->config->host.' '.$this->config->db.' '.$table_list[$i]['Tables_in_'.$this->config->db].' | gzip > "'.$this->dump_folder.'/'.$start_dump.'/'.$table_list[$i]['Tables_in_'.$this->config->db].'.sql.gz"');
            }

            $this->cli->br();
            $this->out('Completed', 'success');
        } else {
            $this->out('mysqldump not found. Please check your path.', 'error');
        }
    }

    public function out($message, $style = 'info')
    {
        switch ($style) {
            case 'info':
                $this->cli->blue($message);
                break;
            case 'success':
                $this->cli->green($message);
                break;
            case 'error':
                $this->cli->red($message);
                break;
        }
    }

    public function loadConfig()
    {
        $this->config = json_decode(file_get_contents('config.json'));
    }

    public function databaseSetup()
    {
        try {
            $conn = new \PDO("mysql:host=".$this->config->host.";dbname=".$this->config->db, $this->config->user, $this->config->pass);
            $conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            
            $this->db = $conn;
        } catch (PDOException $e) {
            echo "Error: " . $e->getMessage();
        }
    }

    public function listTables()
    {
        $stmt = $this->db->prepare('SHOW TABLES');
        $stmt->setFetchMode(\PDO::FETCH_ASSOC); // set the resulting array to associative
        $stmt->execute();
            
        return $stmt->fetchAll();
    }

    public function mysqldumpExists()
    {
        return file_exists($this->config->mysqldump);
    }

    public function setLocalAdapter()
    {
        $this->localAdapter = new Filesystem(new Local($this->dump_folder));
    }
}
{'fraction_non_alphanumeric': 0.17385131646876614, 'fraction_numerical': 0.0006453278265358802, 'mean_word_length': 2.0934131736526944, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '615788', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2271, 'n_words': 366}