| 422 | | foreach($file = file($dir2 . '/mysql-db.sql') as $num => $line) { |
|---|
| 423 | | if (in_array(substr($line, 0, 2), array('--', '/*'))) { |
|---|
| 424 | | unset($file[$num]); |
|---|
| 425 | | } |
|---|
| 426 | | } |
|---|
| 427 | | |
|---|
| 428 | | file_put_contents($dir2 . '/mysql-db.sql', $file); |
|---|
| 429 | | } |
|---|
| 430 | | |
|---|
| 431 | | if (is_file($dir2 . '/asteriskcdr.sql')) { |
|---|
| 432 | | rename($dir2 . '/asteriskcdr.sql', $dir2 . '/mysql-cdr.sql'); |
|---|
| | 424 | |
|---|
| | 425 | // remove SET and comments that later break restores when using pear |
|---|
| | 426 | $cmd[] = fpbx_which('grep'); |
|---|
| | 427 | $cmd[] = "-v '^\/\*\|^SET\|^--'"; |
|---|
| | 428 | $cmd[] = $src; |
|---|
| | 429 | $cmd[] = ' > ' . $dst; |
|---|
| | 430 | exec(implode(' ', $cmd), $file, $status); |
|---|
| | 431 | if ($status) { |
|---|
| | 432 | // The grep failed, if there is a $dst file remove it and either way rename the $src |
|---|
| | 433 | freepbx_log(FPBX_LOG_ERROR, _("Failed converting asterisk.sql to proper format, renaming to mysql-db.sql in current state")); |
|---|
| | 434 | if (is_file($dst)) { |
|---|
| | 435 | unlink($dst); |
|---|
| | 436 | } |
|---|
| | 437 | rename($src,$dst); |
|---|
| | 438 | } else { |
|---|
| | 439 | unlink($src); |
|---|
| | 440 | } |
|---|
| | 441 | unset($cmd, $file); |
|---|
| | 442 | } |
|---|
| | 443 | |
|---|
| | 444 | $src = $dir2 . '/asteriskcdr.sql'; |
|---|
| | 445 | if (is_file($src)) { |
|---|
| | 446 | $dst = $dir2 . '/mysql-cdr.sql'; |
|---|
| 436 | | foreach($file = file($dir2 . '/mysql-cdr.sql') as $num => $line) { |
|---|
| 437 | | if (in_array(substr($line, 0, 2), array('--', '/*'))) { |
|---|
| 438 | | unset($file[$num]); |
|---|
| 439 | | } |
|---|
| 440 | | } |
|---|
| 441 | | file_put_contents($dir2 . '/mysql-cdr.sql', $file); |
|---|
| | 450 | |
|---|
| | 451 | |
|---|
| | 452 | // remove SET and comments that later break restores when using pear |
|---|
| | 453 | $cmd[] = fpbx_which('grep'); |
|---|
| | 454 | $cmd[] = "-v '^\/\*\|^SET\|^--'"; |
|---|
| | 455 | $cmd[] = $src; |
|---|
| | 456 | $cmd[] = ' > ' . $dst; |
|---|
| | 457 | exec(implode(' ', $cmd), $file, $status); |
|---|
| | 458 | if ($status) { |
|---|
| | 459 | // The grep failed, if there is a $dst file remove it and either way rename the $src |
|---|
| | 460 | freepbx_log(FPBX_LOG_ERROR, _("Failed converting asteriskcdr.sql to proper format, renaming to mysql-cdr.sql in current state")); |
|---|
| | 461 | if (is_file($dst)) { |
|---|
| | 462 | unlink($dst); |
|---|
| | 463 | } |
|---|
| | 464 | rename($src,$dst); |
|---|
| | 465 | } else { |
|---|
| | 466 | unlink($src); |
|---|
| | 467 | } |
|---|
| | 468 | unset($cmd, $file); |
|---|