Skip to content

Commit a5cfb76

Browse files
Develop (#44)
* improved exception message when no binary file is found * no longer uses the `Folder` class * updated * fixed * Develop dependencies (#42) added tests for lower dependencies * updated * come back * fixed * fixed * updated * little fixes for `BackupManager` and `BackupExport` classes * test * fixed typo * little fixes * fixed * updated * fixed * added badge * some fixes * uses `Filesystem` class * come back * fixed
1 parent 08e90b5 commit a5cfb76

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ matrix:
2929
services:
3030
- mysql
3131
- postgresql
32-
32+
3333
addons:
3434
postgresql: "9.4"
3535

@@ -42,12 +42,12 @@ install:
4242
before_script:
4343
- mysql -e 'create database test;'
4444
- psql -c 'create database travis_ci_test;' -U postgres
45-
45+
4646
script:
4747
- if [[ $PHPCS != '1' && $COVERAGE != '1' ]]; then vendor/bin/phpunit --exclude-group=onlyWindows; fi
4848
- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs --standard=phpcs.xml.dist; fi
4949
- if [[ $COVERAGE = 1 ]]; then vendor/bin/phpunit --exclude-group=onlyWindows --coverage-clover=clover.xml; fi
50-
50+
5151
after_success:
5252
- if [[ $COVERAGE = 1 ]]; then bash <(curl -s https://codecov.io/bash); fi
5353

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Build Status](https://api.travis-ci.org/mirko-pagliai/cakephp-database-backup.svg?branch=master)](https://travis-ci.org/mirko-pagliai/cakephp-database-backup)
55
[![Build status](https://ci.appveyor.com/api/projects/status/imerokwpvy0r51fj/branch/master?svg=true)](https://ci.appveyor.com/project/mirko-pagliai/cakephp-database-backup/branch/master)
66
[![codecov](https://codecov.io/gh/mirko-pagliai/cakephp-database-backup/branch/master/graph/badge.svg)](https://codecov.io/gh/mirko-pagliai/cakephp-database-backup)
7+
[![CodeFactor](https://www.codefactor.io/repository/github/mirko-pagliai/cakephp-database-backup/badge/develop)](https://www.codefactor.io/repository/github/mirko-pagliai/cakephp-database-backup/overview/develop)
78

89
*DatabaseBackup* is a CakePHP plugin to export, import and manage database backups.
910
Currently, the plugin supports *MySql*, *Postgres* and *Sqlite* databases.
@@ -51,9 +52,9 @@ If you want to use a different directory, read below.
5152

5253
## Requirements
5354
*DatabaseBackup* requires:
54-
* `mysql` and `mysqldump` for *MySql* databases;
55-
* `pg_dump` and `pg_restore` for *Postgres* databases;
56-
* `sqlite3` for *Sqlite* databases.
55+
* `mysql` and `mysqldump` for *MySql* databases;
56+
* `pg_dump` and `pg_restore` for *Postgres* databases;
57+
* `sqlite3` for *Sqlite* databases.
5758

5859
**Optionally**, if you want to handle compressed backups, `bzip2` and `gzip` are
5960
also required.
@@ -66,19 +67,19 @@ permission).
6667

6768
## Configuration
6869
The plugin uses some configuration parameters. See our wiki:
69-
* [Configuration](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/Configuration)
70+
* [Configuration](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/Configuration)
7071

7172
If you want to send backup files by email, remember to set up your application
7273
correctly so that it can send emails. For more information on how to configure
7374
your application, see the [Cookbook](https://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports).
7475

7576
## How to use
7677
See our wiki:
77-
* [Export backups as cron jobs](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/Export-backups-as-cron-jobs)
78-
* [How to use the BackupExport utility](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupExport-utility)
79-
* [How to use the BackupImport utility](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupImport-utility)
80-
* [How to use the BackupManager utility](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupManager-utility)
81-
* [How to use the BackupShell](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupShell)
78+
* [Export backups as cron jobs](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/Export-backups-as-cron-jobs)
79+
* [How to use the BackupExport utility](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupExport-utility)
80+
* [How to use the BackupImport utility](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupImport-utility)
81+
* [How to use the BackupManager utility](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupManager-utility)
82+
* [How to use the BackupShell](https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupShell)
8283

8384
And refer to our [API](//mirko-pagliai.github.io/cakephp-database-backup).
8485

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ before_test:
2727

2828
install:
2929
- cd c:\
30-
- curl -fsS -o php.zip https://windows.php.net/downloads/releases/php-7.2.21-nts-Win32-VC15-x86.zip
30+
- curl -fsS -o php.zip https://windows.php.net/downloads/releases/php-7.2.22-nts-Win32-VC15-x86.zip
3131
- 7z x php.zip -oc:\php > nul
3232
- cd c:\php
3333
- copy php.ini-production php.ini

src/BackupTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Cake\Datasource\ConnectionManager;
1919
use InvalidArgumentException;
2020
use RuntimeException;
21+
use Symfony\Component\Filesystem\Filesystem;
2122

2223
/**
2324
* A trait that provides some methods used by all other classes
@@ -39,7 +40,7 @@ trait BackupTrait
3940
*/
4041
public function getAbsolutePath($path)
4142
{
42-
return is_absolute($path) ? $path : $this->getTarget() . DS . $path;
43+
return (new Filesystem())->isAbsolutePath($path) ? $path : $this->getTarget() . DS . $path;
4344
}
4445

4546
/**

src/Driver/Driver.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,12 @@ protected function _exportExecutableWithCompression($filename)
145145
*/
146146
protected function _importExecutableWithCompression($filename)
147147
{
148-
$executable = $this->_importExecutable();
149148
$compression = $this->getCompression($filename);
150149
$filename = escapeshellarg($filename);
151150

151+
$executable = $this->_importExecutable() . ' < ' . $filename;
152152
if ($compression) {
153-
$executable = sprintf('%s -dc %s | ', $this->getBinary($compression), $filename) . $executable;
154-
} else {
155-
$executable .= ' < ' . $filename;
153+
$executable = sprintf('%s -dc %s | ', $this->getBinary($compression), $filename) . $this->_importExecutable();
156154
}
157155

158156
if (Configure::read('DatabaseBackup.redirectStderrToDevNull')) {

tests/TestCase/Utility/BackupManagerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ public function testRotate()
143143
$this->assertEquals(['gzip', 'bzip2'], $filesAfterRotate->extract('compression')->toList());
144144

145145
//Gets the difference
146-
$diff = array_udiff($initialFiles->toList(), $filesAfterRotate->toList(), function ($a, $b) {
147-
return strcmp($a->filename, $b->filename);
146+
$diff = array_udiff($initialFiles->toList(), $filesAfterRotate->toList(), function ($first, $second) {
147+
return strcmp($first->filename, $second->filename);
148148
});
149149

150150
//Again, only 1 backup was deleted
@@ -167,17 +167,17 @@ public function testSend()
167167
{
168168
$file = $this->createBackup();
169169
$mimetype = mime_content_type($file);
170-
$to = 'recipient@example.com';
170+
$recipient = 'recipient@example.com';
171171

172172
$instance = new BackupManager();
173-
$this->_email = $this->invokeMethod($instance, 'getEmailInstance', [$file, $to]);
173+
$this->_email = $this->invokeMethod($instance, 'getEmailInstance', [$file, $recipient]);
174174
$this->assertInstanceof(Email::class, $this->_email);
175175

176176
$this->assertEmailFrom(Configure::read('DatabaseBackup.mailSender'));
177-
$this->assertEmailTo($to);
177+
$this->assertEmailTo($recipient);
178178
$this->assertEmailSubject('Database backup ' . basename($file) . ' from localhost');
179179
$this->assertEmailAttachmentsContains(basename($file), compact('file', 'mimetype'));
180-
$this->assertArrayKeysEqual(['headers', 'message'], $this->BackupManager->send($file, $to));
180+
$this->assertArrayKeysEqual(['headers', 'message'], $this->BackupManager->send($file, $recipient));
181181

182182
//With an invalid sender
183183
@unlink($file);

tests/test_app/TestApp/Application.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public function bootstrap()
4040
*/
4141
public function middleware($middlewareQueue)
4242
{
43-
$middlewareQueue->add(new RoutingMiddleware($this));
44-
45-
return $middlewareQueue;
43+
return $middlewareQueue->add(new RoutingMiddleware($this));
4644
}
4745

4846
/**

0 commit comments

Comments
 (0)