/** * @param array $tables * @param $mysqldump * * @return Symfony_Process_ProcessBuilder */ protected function createProcessBuilder(array $tables, $mysqldump) { $processBuilder = Symfony_Process_ProcessBuilder::create()->setWorkingDirectory(untrailingslashit(ABSPATH))->setTimeout(3600)->setPrefix($mysqldump)->add('--force')->add('--user='******'--password='******'--add-drop-table'); if ($this->options->isSkipLockTables()) { // Don't lock all tables for read. $processBuilder->add('--lock-tables=false'); } if ($this->options->isSkipExtendedInsert()) { $processBuilder->add('--extended-insert=false'); } $processBuilder->add($this->configuration->getDatabase()); // Dump only specific tables foreach ($tables as $table) { $processBuilder->add($table); } if ($this->configuration->isSocket()) { $processBuilder->add('--socket=' . $this->configuration->getSocketPath()); } else { $processBuilder->add('--host=' . $this->configuration->getHost()); if (($port = $this->configuration->getPort()) !== null) { $processBuilder->add('--port=' . $port); } } return $processBuilder; }
public function createExportTableStream($length, $tableName) { $stream = new MWP_Stream_Append(); $columns = $this->getConnection()->query("SHOW COLUMNS IN `{$tableName}`;")->fetchAll(); if (is_array($columns)) { $columns = $this->repack($columns, 'Field'); } $query = $this->selectAllDataQuery($tableName, $columns); $statement = $this->getConnection()->query($query, true); // Go through row by row if (!$this->options->isSkipLockTables()) { $stream->addStream(MWP_Stream_Stream::factory("LOCK TABLES `{$tableName}` WRITE;\n")); } $stream->addStream(MWP_Stream_Stream::factory("/*!40000 ALTER TABLE `{$tableName}` DISABLE KEYS */;\n")); $stream->addStream(new MWP_Stream_Callable(array($this, 'createExportRowStream'), array($statement, $tableName, $columns))); $stream->addStream(MWP_Stream_Stream::factory("\n")); $stream->addStream(MWP_Stream_Stream::factory("/*!40000 ALTER TABLE `{$tableName}` ENABLE KEYS */;\n")); if (!$this->options->isSkipLockTables()) { $stream->addStream(MWP_Stream_Stream::factory("UNLOCK TABLES;\n")); } return $stream; }