protected function dump_base(base $base, InputInterface $input, OutputInterface $output) { $date_obj = new DateTime(); $filename = sprintf('%s%s_%s.sql', p4string::addEndSlash($input->getArgument('directory')), $base->get_dbname(), $date_obj->format('Y_m_d_H_i_s')); $command = sprintf('mysqldump %s %s %s %s %s %s --default-character-set=utf8', '--host=' . escapeshellarg($base->get_host()), '--port=' . escapeshellarg($base->get_port()), '--user='******'--password='******'--databases', escapeshellarg($base->get_dbname())); if ($input->getOption('gzip')) { $filename .= '.gz'; $command .= ' | gzip -9'; } elseif ($input->getOption('bzip')) { $filename .= '.bz2'; $command .= ' | bzip2 -9'; } $output->write(sprintf('Generating <info>%s</info> ... ', $filename)); $command .= ' > ' . escapeshellarg($filename); $process = new Process($command); $process->setTimeout((int) $input->getOption('timeout')); $process->run(); if (!$process->isSuccessful()) { $output->writeln('<error>Failed</error>'); return 1; } if (file_exists($filename) && filesize($filename) > 0) { $output->writeln('OK'); return 0; } else { $output->writeln('<error>Failed</error>'); return 1; } }
public function upgradeDatabase(\base $base, $applyPatches) { $recommends = []; $allTables = []; $schema = $base->get_schema(); foreach ($schema->tables->table as $table) { $allTables[(string) $table['name']] = $table; } $foundTables = $this->connection->fetchAll("SHOW TABLE STATUS"); foreach ($foundTables as $foundTable) { $tableName = $foundTable["Name"]; if (isset($allTables[$tableName])) { $engine = strtolower(trim($allTables[$tableName]->engine)); $ref_engine = strtolower($foundTable['Engine']); if ($engine != $ref_engine && in_array($engine, ['innodb', 'myisam'])) { $recommends = $this->alterTableEngine($tableName, $engine, $recommends); } $ret = $this->upgradeTable($allTables[$tableName]); $recommends = array_merge($recommends, $ret); unset($allTables[$tableName]); } elseif (!in_array($tableName, self::$ormTables)) { $recommends[] = ['message' => 'Une table pourrait etre supprime', 'sql' => 'DROP TABLE ' . $base->get_dbname() . '.`' . $tableName . '`;']; } } foreach ($allTables as $tableName => $table) { $this->createTable($table); } $current_version = $base->get_version(); if ($applyPatches) { $this->applyPatches($base, $current_version, $this->app['phraseanet.version']->getNumber(), false, $this->app); } return $recommends; }