From 8c5a41eae7d694f9e2376f001cfa20815230fee7 Mon Sep 17 00:00:00 2001 From: mirko-pagliai Date: Sat, 2 Sep 2017 10:24:39 +0200 Subject: [PATCH 1/5] when a backup is sent by mail, the mimetype is forced --- CHANGELOG.md | 3 +++ src/Utility/BackupManager.php | 5 ++++- version | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 745c5797..f10466e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # 2.x branch ## 2.1 branch +### 2.1.4 +* when a backup is sent by mail, the mimetype is forced. + ### 2.1.3 * added `createBackup()` and `createSomeBackups()` to the `TestCase` class; * `BackupManager::_send()` has become `getEmailInstance()`. diff --git a/src/Utility/BackupManager.php b/src/Utility/BackupManager.php index 3880086e..3a2275ab 100644 --- a/src/Utility/BackupManager.php +++ b/src/Utility/BackupManager.php @@ -142,7 +142,10 @@ protected function getEmailInstance($backup, $recipient) ->setFrom($sender) ->setTo($recipient) ->setSubject(__d('database_backup', 'Database backup {0} from {1}', basename($backup), env('SERVER_NAME', 'localhost'))) - ->setAttachments($backup); + ->setAttachments([basename($backup) => [ + 'file' => $backup, + 'mimetype' => mime_content_type($backup), + ]]); } /** diff --git a/version b/version index ac2cdeba..7d2ed7c7 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.1.3 +2.1.4 From 14cbff08a54091b96b675778b547b581f19d70f4 Mon Sep 17 00:00:00 2001 From: mirko-pagliai Date: Sat, 2 Sep 2017 10:27:30 +0200 Subject: [PATCH 2/5] fixed some tests --- CHANGELOG.md | 3 ++- src/TestSuite/DriverTestCase.php | 1 + tests/TestCase/Shell/BackupShellTest.php | 9 +++------ tests/bootstrap.php | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f10466e1..fc8d2444 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # 2.x branch ## 2.1 branch ### 2.1.4 -* when a backup is sent by mail, the mimetype is forced. +* when a backup is sent by mail, the mimetype is forced; +* fixed some tests. ### 2.1.3 * added `createBackup()` and `createSomeBackups()` to the `TestCase` class; diff --git a/src/TestSuite/DriverTestCase.php b/src/TestSuite/DriverTestCase.php index 50b30421..8d498724 100644 --- a/src/TestSuite/DriverTestCase.php +++ b/src/TestSuite/DriverTestCase.php @@ -62,6 +62,7 @@ public function setUp() $connection = $this->getConnection(); + TableRegistry::clear(); $this->Articles = TableRegistry::get('Articles', compact('connection')); $this->Comments = TableRegistry::get('Comments', compact('connection')); diff --git a/tests/TestCase/Shell/BackupShellTest.php b/tests/TestCase/Shell/BackupShellTest.php index ba2113b4..28494e1f 100644 --- a/tests/TestCase/Shell/BackupShellTest.php +++ b/tests/TestCase/Shell/BackupShellTest.php @@ -86,11 +86,8 @@ public function testWelcome() { $this->invokeMethod($this->BackupShell, '_welcome'); - $messages = $this->out->messages(); - - $this->assertRegExp('/^Connection: test/', $messages[6]); - $this->assertEquals('Driver: Mysql', $messages[7]); - $this->assertRegExp('/^\-+$/', $messages[8]); + $this->assertContains('Connection: test', $this->out->messages()); + $this->assertContains('Driver: Mysql', $this->out->messages()); } /** @@ -371,7 +368,7 @@ public function testGetOptionParser() $this->assertInstanceOf('Cake\Console\ConsoleOptionParser', $parser); $this->assertEquals([ - 'deleteAll', + 'delete_all', 'export', 'import', 'index', diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 2300d472..6e32fcb3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -91,7 +91,7 @@ ]); ConnectionManager::setConfig('test', ['url' => 'mysql://travis@localhost/test']); -ConnectionManager::setConfig('test_sqlite', ['url' => 'sqlite:\\' . TMP . 'example.sq3']); +ConnectionManager::setConfig('test_sqlite', ['url' => 'sqlite:///' . TMP . 'example.sq3']); ConnectionManager::setConfig('test_postgres', ['url' => 'postgres://postgres@localhost/travis_ci_test']); Configure::write('DatabaseBackup.connection', 'test'); From e35e0c2864fd20473f6e320f16a505fa81b48f4b Mon Sep 17 00:00:00 2001 From: mirko-pagliai Date: Sat, 2 Sep 2017 10:28:23 +0200 Subject: [PATCH 3/5] updated --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 561a3ccb..d883a6e8 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,19 @@ *DatabaseBackup* is a CakePHP plugin to export, import and manage database backups. Currently, the plugin supports *MySql*, *Postgres* and *Sqlite* databases. -**NOTE**: this plugin requires at least version 3.4 of CakePHP. - ## Installation You can install the plugin via composer: $ composer require --prefer-dist mirko-pagliai/cakephp-database-backup + +**NOTE**: the package may require one of the latest versions version of CakePHP. +Instead, the [cakephp3.2](//github.com/mirko-pagliai/cakephp-database-backup/tree/cakephp3.2) +branch is compatible with CakePHP versions from 3.2 onwards. +In this case, you can install the package as well: + + $ composer require --prefer-dist mirko-pagliai/cakephp-database-backup:dev-cakephp3.2 -Then you have to edit `APP/config/bootstrap.php` to load the plugin: +After installation, you have to edit `APP/config/bootstrap.php` to load the plugin: Plugin::load('DatabaseBackup', ['bootstrap' => true]); From c6a59d375fdebad45e4482475f15753cdd906f63 Mon Sep 17 00:00:00 2001 From: mirko-pagliai Date: Sat, 2 Sep 2017 10:37:07 +0200 Subject: [PATCH 4/5] fixed test --- tests/TestCase/Driver/MysqlTest.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/TestCase/Driver/MysqlTest.php b/tests/TestCase/Driver/MysqlTest.php index 3e43e215..b5786966 100644 --- a/tests/TestCase/Driver/MysqlTest.php +++ b/tests/TestCase/Driver/MysqlTest.php @@ -12,6 +12,7 @@ */ namespace DatabaseBackup\Test\TestCase\Driver; +use Cake\Datasource\ConnectionManager; use DatabaseBackup\BackupTrait; use DatabaseBackup\Driver\Mysql; use DatabaseBackup\TestSuite\DriverTestCase; @@ -122,7 +123,10 @@ public function testBeforeExport() $this->Driver->beforeExport(); - $expected = '[mysqldump]' . PHP_EOL . 'user=travis' . PHP_EOL . 'password=""' . PHP_EOL . 'host=localhost'; + $expected = '[mysqldump]' . PHP_EOL . + 'user=' . ConnectionManager::config('test')['username'] . PHP_EOL . + 'password=""' . PHP_EOL . + 'host=localhost'; $auth = $this->getProperty($this->Driver, 'auth'); $this->assertFileExists($auth); $this->assertEquals($expected, file_get_contents($auth)); @@ -140,7 +144,10 @@ public function testBeforeImport() $this->Driver->beforeImport(); - $expected = '[client]' . PHP_EOL . 'user=travis' . PHP_EOL . 'password=""' . PHP_EOL . 'host=localhost'; + $expected = '[client]' . PHP_EOL . + 'user=' . ConnectionManager::config('test')['username'] . PHP_EOL . + 'password=""' . PHP_EOL . + 'host=localhost'; $auth = $this->getProperty($this->Driver, 'auth'); $this->assertFileExists($auth); $this->assertEquals($expected, file_get_contents($auth)); From 1f5d02387bcb1356e1774e00ee6d4f3a04c3ea33 Mon Sep 17 00:00:00 2001 From: mirko-pagliai Date: Sat, 2 Sep 2017 10:43:16 +0200 Subject: [PATCH 5/5] fixed --- tests/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6e32fcb3..4f40bc7d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -90,7 +90,7 @@ ], ]); -ConnectionManager::setConfig('test', ['url' => 'mysql://travis@localhost/test']); +ConnectionManager::setConfig('test', ['url' => 'mysql://root@localhost/test']); ConnectionManager::setConfig('test_sqlite', ['url' => 'sqlite:///' . TMP . 'example.sq3']); ConnectionManager::setConfig('test_postgres', ['url' => 'postgres://postgres@localhost/travis_ci_test']);