<commit_before><?php
class Vps_Controller_Action_Cli_ImportController extends Vps_Controller_Action_Cli_Abstract
{
    protected $_mysqlDir = '';
    public function indexAction()
    {
        $dbConfig = new Zend_Config_Ini('application/config.db.ini', 'database');
        $dbConfig = $dbConfig->web;
        $mysqlLocalOptions = "--host={$dbConfig->host} --user={$dbConfig->username} --password={$dbConfig->password} ";

        $config = new Zend_Config_Ini('application/config.ini', $this->_getParam('server'));

        $this->_sshHost = $config->server->user.'@'.$config->server->host;
        if ($config->server->host == 'vivid-planet.com') {
            $this->_mysqlDir = '/usr/local/mysql/bin/';
        }

        $onlineRevision = false;
        try {
            $info = new SimpleXMLElement(`ssh {$this->_sshHost} "cd {$config->server->dir} && svn info --xml"`);
            $onlineRevision = (int)$info->entry['revision'];
        } catch (Exception $e) {}
        if (!$onlineRevision) {
            throw new Vps_ClientException("Can't detect online revision");
        }

        echo "ermittle db optionen...\n";
        $dbConfigIni = tempnam('/tmp', 'vpsimport');
        $this->_systemCheckRet("scp {$this->_sshHost}:{$config->server->dir}/application/config.db.ini $dbConfigIni");
        $onlineDbConfig = new Zend_Config_Ini($dbConfigIni, 'database');
        unlink($dbConfigIni);
        $onlineDbConfig = $onlineDbConfig->web;
        $mysqlOnlineOptions = "--host={$onlineDbConfig->host} --user={$onlineDbConfig->username} --password={$onlineDbConfig->password} ";

        echo "kopiere uploads...\n";
        $this->_systemCheckRet("rsync --progress --delete --update --exclude=cache/ ".
            "--recursive {$this->_sshHost}:{$config->uploads}/ ".Vps_Registry::get('config')->uploads."/");

        $p = "/var/backups/vpsimport/".date("Y-m-d_H:i:s_U")."_{$dbConfig->dbname}.sql";
        echo "erstelle datenbank-backup in $p...\n";
        $this->_systemCheckRet("mysqldump $mysqlLocalOptions {$dbConfig->dbname} > $p");

        $dumpname = tempnam('/tmp', 'vpsimport');
        echo "erstelle datenbank dump (online) - $dumpname...\n";
        exec("ssh {$this->_sshHost} \"echo 'SHOW TABLES' | {$this->_mysqlDir}mysql $mysqlOnlineOptions {$onlineDbConfig->dbname}\"", $tables);

        $this->_systemSsh("{$this->_mysqlDir}mysqldump --ignore-table={$onlineDbConfig->dbname}.cache_component $mysqlOnlineOptions {$onlineDbConfig->dbname} > $dumpname");
        if (in_array('cache_component', $tables)) {
            $this->_systemSsh("{$this->_mysqlDir}mysqldump --no-data $mysqlOnlineOptions {$onlineDbConfig->dbname} cache_component >> $dumpname");
        }

        $this->_systemSsh("bzip2 $dumpname");
        $this->_systemSsh("ls -lh $dumpname.bz2");

        echo "kopiere datenbank dump...\n";
        $this->_systemCheckRet("scp {$this->_sshHost}:{$dumpname}.bz2 {$dumpname}.bz2");

        echo "loesche datenbank dump online...\n";
        $this->_systemSsh("rm $dumpname.bz2");

        echo "loesche lokale datenbank...\n";
        $this->_systemCheckRet("echo \"DROP DATABASE \`{$dbConfig->dbname}\`\" | mysql $mysqlLocalOptions");

        echo "erstelle neue datenbank...\n";
        $this->_systemCheckRet("echo \"CREATE DATABASE \`{$dbConfig->dbname}\`\" | mysql $mysqlLocalOptions");

        echo "spiele dump in lokale datenbank ein...\n";
        $this->_systemCheckRet("rm {$dumpname}");
        $this->_systemCheckRet("bunzip2 {$dumpname}.bz2");
        $this->_systemCheckRet("mysql $mysqlLocalOptions {$dbConfig->dbname} < $dumpname");

        echo "loesche datebank dump lokal...\n";
        $this->_systemCheckRet("rm $dumpname");

        echo "writing application/update ($onlineRevision)...\n";
        file_put_contents('application/update', $onlineRevision);

        echo "fertig!\n";

        exit();
    }
    private function _systemSsh($cmd)
    {
        return $this->_systemCheckRet("ssh {$this->_sshHost} \"nice ".$cmd."\"");
    }

    public static function getHelp()
    {
        return "import uploads+database";
    }
    public static function getHelpOptions()
    {
        return array(
            array(
                'param'=> 'server',
                'value'=> self::_getConfigSections(),
                'valueOptional' => true,
                'help' => 'what to import'
            )
        );
    }
}<commit_msg>verbesserungen bei import, nocht nicht fertig<commit_after><?php
class Vps_Controller_Action_Cli_ImportController extends Vps_Controller_Action_Cli_Abstract
{
    public function indexAction()
    {
        if (Vps_Registry::get('config')->server->host != 'vivid') {
            throw new Vps_ClientException("Import is only possible on vivid server");
        }
        $dbConfig = new Zend_Config_Ini('application/config.db.ini', 'database');
        $dbConfig = $dbConfig->web;
        $mysqlLocalOptions = "--host={$dbConfig->host} --user={$dbConfig->username} --password={$dbConfig->password} ";

        $config = new Zend_Config_Ini('application/config.ini', $this->_getParam('server'));
        $this->_sshHost = $config->server->user.'@'.$config->server->host;
        $this->_sshDir = $config->server->dir;

        $onlineRevision = $this->_systemSshVps('import get-update-revision');

        echo "kopiere uploads...\n";
        $this->_systemSshVps('copy-uploads '.Vps_Registry::get('config')->uploads.'/', $config->uploads);
        //$this->_systemCheckRet("rsync --progress --delete --update --exclude=cache/ ".
        //    "--recursive {$this->_sshHost}:{$config->uploads}/ ".Vps_Registry::get('config')->uploads."/");


        $p = "/var/backups/vpsimport/".date("Y-m-d_H:i:s_U")."_{$dbConfig->dbname}.sql";
        echo "erstelle datenbank-backup in $p...\n";
        $this->_systemCheckRet("mysqldump $mysqlLocalOptions {$dbConfig->dbname} > $p");

        echo "erstelle datenbank dump (online)...\n";
        $dumpname = $this->_systemSshVps('import create-dump');

        echo "kopiere datenbank dump...\n";
        $dumpname = $this->_systemSshVps('copy-dump '.$dumpname);
        //$this->_systemCheckRet("scp {$this->_sshHost}:{$dumpname} {$dumpname}");

        echo "loesche lokale datenbank...\n";
        $this->_systemCheckRet("echo \"DROP DATABASE \`{$dbConfig->dbname}\`\" | mysql $mysqlLocalOptions");

        echo "erstelle neue datenbank...\n";
        $this->_systemCheckRet("echo \"CREATE DATABASE \`{$dbConfig->dbname}\`\" | mysql $mysqlLocalOptions");

        echo "spiele dump in lokale datenbank ein...\n";
        $this->_systemCheckRet("bunzip2 {$dumpname}");
        $dumpname = substr($dumpname, 0, -4);
        $this->_systemCheckRet("mysql $mysqlLocalOptions {$dbConfig->dbname} < $dumpname");

        echo "loesche datebank dump lokal...\n";
        $this->_systemCheckRet("rm $dumpname");

        echo "writing application/update ($onlineRevision)...\n";
        file_put_contents('application/update', $onlineRevision);

        echo "fertig!\n";

        exit();
    }
    private function _systemSsh($cmd)
    {
        return $this->_systemCheckRet("ssh {$this->_sshHost} \"nice ".$cmd."\"");
    }
    private function _systemSshVps($cmd, $dir = null)
    {
        if (!$dir) $dir = $this->_sshDir;
        $cmd = "sshvps $this->_sshHost $dir $cmd";
        $cmd = "sudo -u www-data $cmd";
        return $this->_systemCheckRet($cmd);
    }
    public static function getHelp()
    {
        return "import uploads+database";
    }
    public static function getHelpOptions()
    {
        return array(
            array(
                'param'=> 'server',
                'value'=> self::_getConfigSections(),
                'valueOptional' => true,
                'help' => 'what to import'
            )
        );
    }

    public function createDumpAction()
    {
        $dbConfig = new Zend_Config_Ini('application/config.db.ini', 'database');
        $dbConfig = $dbConfig->web;
        $mysqlOptions = "--host={$dbConfig->host} --user={$dbConfig->username} --password={$dbConfig->password} ";
        $config = Zend_Registry::get('config');

        $mysqlDir = '';
        if ($config->server->host == 'vivid-planet.com') {
            $mysqlDir = '/usr/local/mysql/bin/';
        }

        $dumpname = tempnam('/tmp', 'vpsimport');

        $tables = Zend_Registry::get('db')->fetchCol('SHOW TABLES');


        $this->_systemCheckRet("{$mysqlDir}mysqldump --ignore-table={$dbConfig->dbname}.cache_component $mysqlOptions {$dbConfig->dbname} > $dumpname");
        if (in_array('cache_component', $tables)) {
            $this->_systemCheckRet("{$mysqlDir}mysqldump --no-data $mysqlOptions {$dbConfig->dbname} cache_component >> $dumpname");
        }

        $this->_systemCheckRet("bzip2 $dumpname");

        echo $dumpname.".bz2";

        $this->_helper->viewRenderer->setNoRender(true);
    }

    public function getUpdateRevisionAction()
    {
        if (file_exists('application/update')) {
            echo file_get_contents('application/update');
        } else {
            try {
                $info = new SimpleXMLElement(`svn info --xml"`);
                $onlineRevision = (int)$info->entry['revision'];
            } catch (Exception $e) {}
            if (!$onlineRevision) {
                throw new Vps_ClientException("Can't detect online revision");
            }
        }
        $this->_helper->viewRenderer->setNoRender(true);
    }
}
{'fraction_non_alphanumeric': 0.17602956705385428, 'fraction_numerical': 0.0012671594508975714, 'mean_word_length': 2.7538644470868014, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 140, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 2}, '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': '4144273', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2825, 'n_words': 502}