Skip to content

Commit 39612f6

Browse files
committed
Merge pull request #78 from gwarnants/master
Added settings skip-comments and skip-dump-date
2 parents c9a23eb + f2f9787 commit 39612f6

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Refer to the [wiki](https://github.com/ifsnop/mysqldump-php/wiki/full-example) f
128128
'skip-tz-utc' => false,
129129
'no-autocommit' => true,
130130
'default-character-set' => 'utf8',
131+
'skip-comments' => false,
132+
'skip-dump-date' => false,
131133
);
132134

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

191197
The following options are now enabled by default, and there is no way to disable them since
192198
they should always be used.

src/Ifsnop/Mysqldump/Mysqldump.php

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public function __construct(
108108
'skip-tz-utz' => false,
109109
'no-autocommit' => true,
110110
'default-character-set' => Mysqldump::UTF8,
111+
'skip-comments' => false,
112+
'skip-dump-date' => false,
111113
/* deprecated */
112114
'disable-foreign-keys-check' => true
113115
);
@@ -298,18 +300,20 @@ public function start($filename = '')
298300
*/
299301
private function getDumpFileHeader()
300302
{
301-
// Some info about software, source and time
302-
$header = "-- mysqldump-php https://github.com/ifsnop/mysqldump-php" . PHP_EOL .
303-
"--" . PHP_EOL .
304-
"-- Host: {$this->host}\tDatabase: {$this->db}" . PHP_EOL .
305-
"-- ------------------------------------------------------" . PHP_EOL;
306-
307-
if (!empty($this->version)) {
308-
$header .= "-- Server version \t" . $this->version . PHP_EOL;
309-
}
303+
$header = '';
304+
if (!$this->dumpSettings['skip-comments']) {
305+
// Some info about software, source and time
306+
$header = "-- mysqldump-php https://github.com/ifsnop/mysqldump-php" . PHP_EOL .
307+
"--" . PHP_EOL .
308+
"-- Host: {$this->host}\tDatabase: {$this->db}" . PHP_EOL .
309+
"-- ------------------------------------------------------" . PHP_EOL;
310310

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

315+
$header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;
316+
}
313317
return $header;
314318
}
315319

@@ -320,7 +324,14 @@ private function getDumpFileHeader()
320324
*/
321325
private function getDumpFileFooter()
322326
{
323-
$footer = "-- Dump completed on: " . date('r') . PHP_EOL;
327+
$footer = '';
328+
if (!$this->dumpSettings['skip-comments']) {
329+
$footer .= '-- Dump completed';
330+
if (!$this->dumpSettings['skip-dump-date']) {
331+
$footer .= ' on: ' . date('r');
332+
}
333+
$footer .= PHP_EOL;
334+
}
324335

325336
return $footer;
326337
}
@@ -441,9 +452,12 @@ private function exportTriggers()
441452
private function getTableStructure($tableName)
442453
{
443454
if (!$this->dumpSettings['no-create-info']) {
444-
$ret = "--" . PHP_EOL .
445-
"-- Table structure for table `$tableName`" . PHP_EOL .
446-
"--" . PHP_EOL . PHP_EOL;
455+
$ret = '';
456+
if (!$this->dumpSettings['skip-comments']) {
457+
$ret = "--" . PHP_EOL .
458+
"-- Table structure for table `$tableName`" . PHP_EOL .
459+
"--" . PHP_EOL . PHP_EOL;
460+
}
447461
$stmt = $this->typeAdapter->show_create_table($tableName);
448462
foreach ($this->dbHandler->query($stmt) as $r) {
449463
$this->compressManager->write($ret);
@@ -486,9 +500,12 @@ private function getTableStructure($tableName)
486500
*/
487501
private function getViewStructure($viewName)
488502
{
489-
$ret = "--" . PHP_EOL .
490-
"-- Table structure for view `${viewName}`" . PHP_EOL .
491-
"--" . PHP_EOL . PHP_EOL;
503+
$ret = '';
504+
if (!$this->dumpSettings['skip-comments']) {
505+
$ret = "--" . PHP_EOL .
506+
"-- Table structure for view `${viewName}`" . PHP_EOL .
507+
"--" . PHP_EOL . PHP_EOL;
508+
}
492509
$this->compressManager->write($ret);
493510
$stmt = $this->typeAdapter->show_create_view($viewName);
494511
foreach ($this->dbHandler->query($stmt) as $r) {
@@ -615,11 +632,13 @@ private function listValues($tableName)
615632
*/
616633
function prepareListValues($tableName)
617634
{
618-
$this->compressManager->write(
619-
"--" . PHP_EOL .
620-
"-- Dumping data for table `$tableName`" . PHP_EOL .
621-
"--" . PHP_EOL . PHP_EOL
622-
);
635+
if (!$this->dumpSettings['skip-comments']) {
636+
$this->compressManager->write(
637+
"--" . PHP_EOL .
638+
"-- Dumping data for table `$tableName`" . PHP_EOL .
639+
"--" . PHP_EOL . PHP_EOL
640+
);
641+
}
623642

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

0 commit comments

Comments
 (0)