Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mirko-pagliai committed Dec 15, 2018
2 parents 244642f + cbb0864 commit e770753
Show file tree
Hide file tree
Showing 38 changed files with 1,117 additions and 836 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 7.0
- 7.1
- 7.2
- 7.3

matrix:
fast_finish: true
Expand All @@ -16,12 +17,6 @@ matrix:
- php: 7.0
env: COVERAGE=1

- php: 7.0
env: CAKEPHP_VERSION="3.5.*"

- php: 7.0
env: CAKEPHP_VERSION="3.6.*"

services:
- mysql
- postgresql
Expand All @@ -32,7 +27,6 @@ addons:
install:
- composer self-update
- composer install --prefer-dist --no-interaction
- if [[ ! -z "$CAKEPHP_VERSION" ]]; then composer require --update-with-dependencies cakephp/cakephp:${CAKEPHP_VERSION}; fi

before_script:
- mysql -e 'create database test;'
Expand Down
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# 2.x branch
## 2.6 branch
### 2.6.0
* `BackupShell` has been replaced with console commands. Every method of the
previous class is now a `Command` class;
* `BackupManager::index()` returns a collection of backups;
* `ConsoleIntegrationTestCase` has been replaced by `ConsoleIntegrationTestTrait`.
`TestCaseTrait` has been removed and its methods moved to `TestCase`;
* removed `DATABASE_BACKUP` constant;
* updated for CakePHP 3.7.

## 2.5 branch
### 2.5.1
* added `Plugin` class for CakePHP 3.6.
* updated for CakePHP 3.6 and 3.7. Added `Plugin` class;
* many small code fixes.

### 2.5.0
* now it uses the `mirko-pagliai/php-tools` package. This also replaces
Expand All @@ -15,7 +26,7 @@
* `VALID_COMPRESSIONS` and `VALID_EXTENSIONS` constants have been replaced by
`getValidCompressions()` and `getValidExtensions()` methods provided by the
`BackupTrait` class;
* replaced `InternalErrorException` with `InvalidArgumentException` and
* replaced `InternalErrorException` with `InvalidArgumentException` and
`RuntimeException`. This allows compatibility with CakePHP 3.6 branch.

## 2.3 branch
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
Currently, the plugin supports *MySql*, *Postgres* and *Sqlite* databases.

Did you like this plugin? Its development requires a lot of time for me.
Please consider the possibility of making [a donation](//paypal.me/mirkopagliai): even a coffee is enough! Thank you.
Please consider the possibility of making [a donation](//paypal.me/mirkopagliai):
even a coffee is enough! Thank you.

[![Make a donation](https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_carte.jpg)](//paypal.me/mirkopagliai)

Expand All @@ -18,7 +19,7 @@ You can install the plugin via composer:

$ composer require --prefer-dist mirko-pagliai/cakephp-database-backup

**NOTE: the latest version available requires at least CakePHP 3.5**.
**NOTE: the latest version available requires at least CakePHP 3.7**.

Instead, the [cakephp3.2](//github.com/mirko-pagliai/cakephp-database-backup/tree/cakephp3.2)
branch is compatible with all previous versions of CakePHP from version 3.2.
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ before_test:

install:
- cd c:\
- curl -fsS -o php.zip https://windows.php.net/downloads/releases/php-5.6.38-nts-Win32-VC11-x86.zip
- curl -fsS -o php.zip https://windows.php.net/downloads/releases/php-5.6.39-nts-Win32-VC11-x86.zip
- 7z x php.zip -oc:\php > nul
- cd c:\php
- copy php.ini-production php.ini
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}],
"require": {
"php": ">=5.5.9",
"cakephp/cakephp": "^3.5",
"mirko-pagliai/php-tools": "^1.0"
"cakephp/cakephp": "^3.7",
"mirko-pagliai/php-tools": "^1.1"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^3.0",
Expand All @@ -24,6 +24,7 @@
},
"autoload-dev": {
"psr-4": {
"App\\": "tests/test_app/TestApp/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests",
"DatabaseBackup\\Test\\": "tests"
}
Expand Down
32 changes: 12 additions & 20 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,42 @@
*/
use Cake\Core\Configure;

//Sets the default DatabaseBackup name
if (!defined('DATABASE_BACKUP')) {
define('DATABASE_BACKUP', 'DatabaseBackup');
}

//Sets the redirect to `/dev/null`. This string can be concatenated to shell commands
if (!defined('REDIRECT_TO_DEV_NULL')) {
define('REDIRECT_TO_DEV_NULL', is_win() ? ' 2>nul' : ' 2>/dev/null');
}

//Binaries
foreach (['bzip2', 'gzip', 'mysql', 'mysqldump', 'pg_dump', 'pg_restore', 'sqlite3'] as $binary) {
if (!Configure::check(DATABASE_BACKUP . '.binaries.' . $binary)) {
Configure::write(DATABASE_BACKUP . '.binaries.' . $binary, which($binary));
if (!Configure::check('DatabaseBackup.binaries.' . $binary)) {
Configure::write('DatabaseBackup.binaries.' . $binary, which($binary));
}
}

//Chmod for backups.
//This works only on Unix
if (!Configure::check(DATABASE_BACKUP . '.chmod')) {
Configure::write(DATABASE_BACKUP . '.chmod', 0664);
if (!Configure::check('DatabaseBackup.chmod')) {
Configure::write('DatabaseBackup.chmod', 0664);
}

//Database connection
if (!Configure::check(DATABASE_BACKUP . '.connection')) {
Configure::write(DATABASE_BACKUP . '.connection', 'default');
if (!Configure::check('DatabaseBackup.connection')) {
Configure::write('DatabaseBackup.connection', 'default');
}

//Redirects stderr to `/dev/null`. This suppresses the output of executed commands
if (!Configure::check(DATABASE_BACKUP . '.redirectStderrToDevNull')) {
Configure::write(DATABASE_BACKUP . '.redirectStderrToDevNull', true);
if (!Configure::check('DatabaseBackup.redirectStderrToDevNull')) {
Configure::write('DatabaseBackup.redirectStderrToDevNull', true);
}

//Default target directory
if (!Configure::check(DATABASE_BACKUP . '.target')) {
Configure::write(DATABASE_BACKUP . '.target', ROOT . DS . 'backups');
if (!Configure::check('DatabaseBackup.target')) {
Configure::write('DatabaseBackup.target', ROOT . DS . 'backups');
}

//Checks for the target directory
$target = Configure::read(DATABASE_BACKUP . '.target');

if (!file_exists($target)) {
safe_mkdir($target);
}
$target = Configure::read('DatabaseBackup.target');
safe_mkdir($target);

if (!is_writeable($target)) {
trigger_error(sprintf('Directory %s not writeable', $target), E_USER_ERROR);
Expand Down
6 changes: 5 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
<ruleset>
<arg value="p"/>
<file>.</file>

<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>

<rule ref="Generic.Commenting.Todo">
<severity>0</severity>
</rule>

<rule ref="Internal.NoCodeFound">
<severity>0</severity>
</rule>
Expand Down
8 changes: 4 additions & 4 deletions src/BackupTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getAbsolutePath($path)
*/
public function getBinary($name)
{
return Configure::readOrFail(DATABASE_BACKUP . '.binaries.' . $name);
return Configure::readOrFail('DatabaseBackup.binaries.' . $name);
}

/**
Expand Down Expand Up @@ -79,7 +79,7 @@ public function getCompression($filename)
*/
public function getConnection($name = null)
{
return ConnectionManager::get($name ?: Configure::readOrFail(DATABASE_BACKUP . '.connection'));
return ConnectionManager::get($name ?: Configure::readOrFail('DatabaseBackup.connection'));
}

/**
Expand All @@ -95,7 +95,7 @@ public function getDriver(ConnectionInterface $connection = null)
{
$connection = $connection ?: $this->getConnection();
$className = get_class_short_name($connection->getDriver());
$driver = App::classname(sprintf('%s.%s', DATABASE_BACKUP, $className), 'Driver');
$driver = App::classname(sprintf('%s.%s', 'DatabaseBackup', $className), 'Driver');

if (!$driver) {
throw new InvalidArgumentException(__d('database_backup', 'The `{0}` driver does not exist', $className));
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getExtension($filename)
*/
public function getTarget()
{
return Configure::read(DATABASE_BACKUP . '.target');
return Configure::read('DatabaseBackup.target');
}

/**
Expand Down
65 changes: 65 additions & 0 deletions src/Command/DeleteAllCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* This file is part of cakephp-database-backup.
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Mirko Pagliai
* @link https://github.com/mirko-pagliai/cakephp-database-backup
* @license https://opensource.org/licenses/mit-license.php MIT License
* @since 2.6.0
*/
namespace DatabaseBackup\Command;

use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use DatabaseBackup\Console\Command;
use DatabaseBackup\Utility\BackupManager;

/**
* Deletes all backup files
*/
class DeleteAllCommand extends Command
{
/**
* Hook method for defining this command's option parser
* @param ConsoleOptionParser $parser The parser to be defined
* @return ConsoleOptionParser
*/
protected function buildOptionParser(ConsoleOptionParser $parser)
{
$parser->setDescription(__d('database_backup', 'Deletes all database backups'));

return $parser;
}

/**
* Deletes all backup files
* @param Arguments $args The command arguments
* @param ConsoleIo $io The console io
* @return null|int The exit code or null for success
* @see https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupShell#delete_all
* @uses DatabaseBackup\Utility\BackupManager::deleteAll()
*/
public function execute(Arguments $args, ConsoleIo $io)
{
parent::execute($args, $io);

$deleted = (new BackupManager)->deleteAll();

if (!$deleted) {
$io->verbose(__d('database_backup', 'No backup has been deleted'));

return null;
}

foreach ($deleted as $file) {
$io->verbose(__d('database_backup', 'Backup `{0}` has been deleted', rtr($file)));
}

$io->success(__d('database_backup', 'Deleted backup files: {0}', count($deleted)));
}
}
Loading

0 comments on commit e770753

Please sign in to comment.