/**
  * @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;
 }
Example #2
0
 /**
  * @param MWP_IncrementalBackup_Database_Configuration $configuration
  *
  * @return string
  */
 private static function getDsn(MWP_IncrementalBackup_Database_Configuration $configuration)
 {
     $pdoParameters = array('dbname' => $configuration->getDatabase(), 'charset' => $configuration->getCharset());
     if ($configuration->isSocket()) {
         $pdoParameters['unix_socket'] = $configuration->getSocketPath();
     } else {
         $pdoParameters['host'] = $configuration->getHost();
         if (($port = $configuration->getPort()) !== null) {
             $pdoParameters['port'] = $configuration->getPort();
         }
     }
     $parameters = array();
     foreach ($pdoParameters as $name => $value) {
         $parameters[] = $name . '=' . $value;
     }
     $dsn = sprintf("mysql:%s", implode(';', $parameters));
     return $dsn;
 }
 /**
  * @param string $method
  *
  * @param array  $options
  *
  * @throws MWP_Worker_Exception
  * @return MWP_IncrementalBackup_Database_DumperInterface
  */
 protected function createDumper($method, array $options = array())
 {
     $dumperOptions = MWP_IncrementalBackup_Database_DumpOptions::createFromArray($options);
     switch ($method) {
         case self::METHOD_MYSQLDUMP:
             $configuration = MWP_IncrementalBackup_Database_Configuration::createFromWordPressContext(mwp_context());
             $dumper = new MWP_IncrementalBackup_Database_MysqlDumpDumper($configuration, $dumperOptions);
             return $dumper;
         case self::METHOD_PHPDUMPER:
             $configuration = MWP_IncrementalBackup_Database_Configuration::createFromWordPressContext(mwp_context());
             $dumper = new MWP_IncrementalBackup_Database_PhpDumper($configuration, mwp_container()->getSystemEnvironment(), $dumperOptions);
             return $dumper;
         default:
             throw new MWP_Worker_Exception(MWP_Worker_Exception::BACKUP_DATABASE_METHOD_NOT_AVAILABLE);
             break;
     }
 }
 public function __construct(MWP_IncrementalBackup_Database_Configuration $configuration)
 {
     $this->configuration = $configuration;
     if (!extension_loaded('mysql')) {
         throw new MWP_IncrementalBackup_Database_Exception_ConnectionException("Mysql extension is not loaded.");
     }
     if ($configuration->isSocket()) {
         $this->connection = @mysql_connect(':' . $configuration->getSocketPath(), $configuration->getUsername(), $configuration->getPassword());
     } else {
         $host = $configuration->getHost();
         if ($configuration->getPort() !== null) {
             $host .= ':' . $configuration->getPort();
         }
         $this->connection = @mysql_connect($host, $configuration->getUsername(), $configuration->getPassword());
     }
     if (!is_resource($this->connection)) {
         throw new MWP_IncrementalBackup_Database_Exception_ConnectionException(mysql_error(), mysql_errno());
     }
     @mysql_set_charset($configuration->getCharset(), $this->connection);
     mysql_select_db($configuration->getDatabase(), $this->connection);
 }