Created
May 20, 2014 10:45
-
-
Save motin/19afc17a4e6b60308bb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Runs the command. | |
* @param array $args the command-line arguments. | |
* @return integer the return code. | |
* @throws CException if the mysqldump binary cannot be located or if the actual dump fails. | |
*/ | |
public function run($args) | |
{ | |
list($action, $options, $args) = $this->resolveRequest($args); | |
foreach ($options as $key => $value) { | |
if (property_exists($this, $key)) { | |
$this->$key = $value; | |
} | |
} | |
if (!$this->schema || $this->schema == "false") { | |
$this->options["no-create-info"] = null; | |
$this->options["skip-triggers"] = null; | |
} | |
if (!$this->data || $this->data == "false") { | |
$this->options["no-data"] = null; | |
} | |
$this->options["no-create-db"] = null; | |
$binPath = $this->resolveBinPath(); | |
$options = $this->normalizeOptions($this->options); | |
$database = $this->resolveDatabaseName(); | |
$dumpPath = $this->resolveDumpPath(); | |
return $this->process( | |
"$binPath $options $database", | |
array( | |
self::DESCRIPTOR_STDIN => array('pipe', 'r'), | |
self::DESCRIPTOR_STDOUT => array('file', $dumpPath, 'w'), | |
self::DESCRIPTOR_STDERR => array('pipe', 'w'), | |
) | |
); | |
} | |
/** | |
* Normalizes the given options to a string | |
* @param array $options the options. | |
* @return string the options. | |
*/ | |
protected function normalizeOptions($options) | |
{ | |
$result = array(); | |
foreach ($options as $name => $value) { | |
if ($value !== null) { | |
$result[] = "--$name=\"$value\""; | |
} else { | |
$result[] = "--$name"; | |
} | |
} | |
return implode(' ', $result); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment