Skip to content

Commit

Permalink
Merge pull request ifsnop#78 from gwarnants/master
Browse files Browse the repository at this point in the history
Added settings skip-comments and skip-dump-date
  • Loading branch information
ifsnop committed Mar 15, 2015
2 parents c9a23eb + f2f9787 commit 39612f6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ Refer to the [wiki](https://github.com/ifsnop/mysqldump-php/wiki/full-example) f
'skip-tz-utc' => false,
'no-autocommit' => true,
'default-character-set' => 'utf8',
'skip-comments' => false,
'skip-dump-date' => false,
);

$pdoSettingsDefaults = array(
Expand Down Expand Up @@ -187,6 +189,10 @@ Refer to the [wiki](https://github.com/ifsnop/mysqldump-php/wiki/full-example) f
- Could be specified using the declared consts: IMysqldump\Mysqldump::UTF8 or IMysqldump\Mysqldump::UTF8MB4BZIP2
- http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
- https://mathiasbynens.be/notes/mysql-utf8mb4
- **skip-comments**
- http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_comments
- **skip-dump-date**
- http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_dump-date

The following options are now enabled by default, and there is no way to disable them since
they should always be used.
Expand Down
63 changes: 41 additions & 22 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public function __construct(
'skip-tz-utz' => false,
'no-autocommit' => true,
'default-character-set' => Mysqldump::UTF8,
'skip-comments' => false,
'skip-dump-date' => false,
/* deprecated */
'disable-foreign-keys-check' => true
);
Expand Down Expand Up @@ -298,18 +300,20 @@ public function start($filename = '')
*/
private function getDumpFileHeader()
{
// Some info about software, source and time
$header = "-- mysqldump-php https://github.com/ifsnop/mysqldump-php" . PHP_EOL .
"--" . PHP_EOL .
"-- Host: {$this->host}\tDatabase: {$this->db}" . PHP_EOL .
"-- ------------------------------------------------------" . PHP_EOL;

if (!empty($this->version)) {
$header .= "-- Server version \t" . $this->version . PHP_EOL;
}
$header = '';
if (!$this->dumpSettings['skip-comments']) {
// Some info about software, source and time
$header = "-- mysqldump-php https://github.com/ifsnop/mysqldump-php" . PHP_EOL .
"--" . PHP_EOL .
"-- Host: {$this->host}\tDatabase: {$this->db}" . PHP_EOL .
"-- ------------------------------------------------------" . PHP_EOL;

$header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;
if (!empty($this->version)) {
$header .= "-- Server version \t" . $this->version . PHP_EOL;
}

$header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;
}
return $header;
}

Expand All @@ -320,7 +324,14 @@ private function getDumpFileHeader()
*/
private function getDumpFileFooter()
{
$footer = "-- Dump completed on: " . date('r') . PHP_EOL;
$footer = '';
if (!$this->dumpSettings['skip-comments']) {
$footer .= '-- Dump completed';
if (!$this->dumpSettings['skip-dump-date']) {
$footer .= ' on: ' . date('r');
}
$footer .= PHP_EOL;
}

return $footer;
}
Expand Down Expand Up @@ -441,9 +452,12 @@ private function exportTriggers()
private function getTableStructure($tableName)
{
if (!$this->dumpSettings['no-create-info']) {
$ret = "--" . PHP_EOL .
"-- Table structure for table `$tableName`" . PHP_EOL .
"--" . PHP_EOL . PHP_EOL;
$ret = '';
if (!$this->dumpSettings['skip-comments']) {
$ret = "--" . PHP_EOL .
"-- Table structure for table `$tableName`" . PHP_EOL .
"--" . PHP_EOL . PHP_EOL;
}
$stmt = $this->typeAdapter->show_create_table($tableName);
foreach ($this->dbHandler->query($stmt) as $r) {
$this->compressManager->write($ret);
Expand Down Expand Up @@ -486,9 +500,12 @@ private function getTableStructure($tableName)
*/
private function getViewStructure($viewName)
{
$ret = "--" . PHP_EOL .
"-- Table structure for view `${viewName}`" . PHP_EOL .
"--" . PHP_EOL . PHP_EOL;
$ret = '';
if (!$this->dumpSettings['skip-comments']) {
$ret = "--" . PHP_EOL .
"-- Table structure for view `${viewName}`" . PHP_EOL .
"--" . PHP_EOL . PHP_EOL;
}
$this->compressManager->write($ret);
$stmt = $this->typeAdapter->show_create_view($viewName);
foreach ($this->dbHandler->query($stmt) as $r) {
Expand Down Expand Up @@ -615,11 +632,13 @@ private function listValues($tableName)
*/
function prepareListValues($tableName)
{
$this->compressManager->write(
"--" . PHP_EOL .
"-- Dumping data for table `$tableName`" . PHP_EOL .
"--" . PHP_EOL . PHP_EOL
);
if (!$this->dumpSettings['skip-comments']) {
$this->compressManager->write(
"--" . PHP_EOL .
"-- Dumping data for table `$tableName`" . PHP_EOL .
"--" . PHP_EOL . PHP_EOL
);
}

if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->setup_transaction());
Expand Down

0 comments on commit 39612f6

Please sign in to comment.