Skip to content

Commit 7f52c20

Browse files
Merge pull request #94 from mirko-pagliai/develop
Develop
2 parents bedbd57 + c2ce210 commit 7f52c20

39 files changed

+928
-883
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
# 2.x branch
2+
## 2.12 branch
3+
### 2.12.0
4+
* added `AbstractBackupUtility::timeout()` method, so now `BackupExport`/`BackupImport` utilities have a method to set the
5+
timeout for shell commands at runtime. Added `--timeout` option (short: `-t`) for `ExportCommand`/`ImportCommand`;
6+
* the events (`Backup.beforeExport`, `Backup.afterExport`, `Backup.beforeImport`, `Backup.afterImport`, which remain
7+
implemented by the driver classes) are directly dispatched by the `BackupExport::export()` and `BackupImport::import()`
8+
methods, and no longer by the drivers themselves;
9+
* added the `AbstractBackupUtility` abstract class that provides the code common to `BackupExport` and `BackupImport`,
10+
with the new `AbstractBackupUtility::__get()` magic method for reading `BackupExport`/`BackupImport` properties;
11+
* removed `$Driver` public property for `BackupExport`/`BackupImport` and added `AbstractBackupUtility::getDriver()` method;
12+
* the abstract `Driver` class has become `AbstractDriver` and no longer takes a connection as constructor argument, but
13+
directly uses the one set by the configuration. The old `Driver::_exec()` method has been moved and has become
14+
`AbstractBackupUtility::getProcess()`. The old `Driver::export()` and `Driver::import()` methods no longer exist and
15+
their code has been "absorbed" into the `BackupExport::export()` and `BackupImport::import()` methods;
16+
* `BackupTrait::getDriver()` method has become `AbstractBackupUtility::getDriver()`;
17+
* `BackupTrait::getDriverName()` and `AbstractBackupUtility::getDriver()` no longer accept a connection as argument, but
18+
directly use the one set by the configuration;
19+
* the `BackupExport::export()` and `BackupImport::import()` methods can return the filename path on success or `false`
20+
if the `Backup.beforeExport`/`Backup.beforeImport` events are stopped;
21+
* `Driver::_getExecutable()`, `Driver::_getExportExecutable()` and `Driver::_getImportExecutable()` have become
22+
`Driver::getExecutable()`, `Driver::getExportExecutable()` and `Driver::getImportExecutable()`;
23+
* the `Driver::getConfig()` method no longer accepts `null` as argument, but only a string as key, since there is no
24+
need to return the whole configuration;
25+
* `MySql::getAuthFile()` method has become `getAuthFilePath()`, to be more understandable;
26+
* `MySql::deleteAuthFile()` method returns void (there is no need for it to return anything);
27+
* removed useless `TestCase::getMockForAbstractDriver()` method;
28+
* removed useless `BackupExport::$config` property;
29+
* improved the `ExportCommand` class;
30+
* completely improved the `BackupImportTest` tests.
31+
232
## 2.11 branch
333
### 2.11.1
434
* added the `DatabaseBackup.processTimeout` configuration, which allows you to set a timeout for commands that will be

config/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838

3939
//Writes default configuration values
4040
$defaults = [
41-
'DatabaseBackup.connection' => 'default',
4241
'DatabaseBackup.chmod' => 0664,
42+
'DatabaseBackup.connection' => 'default',
43+
'DatabaseBackup.processTimeout' => 60,
4344
'DatabaseBackup.target' => ROOT . 'backups',
4445
'DatabaseBackup.mysql.export' => '{{BINARY}} --defaults-file={{AUTH_FILE}} {{DB_NAME}}',
4546
'DatabaseBackup.mysql.import' => '{{BINARY}} --defaults-extra-file={{AUTH_FILE}} {{DB_NAME}}',

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ parameters:
55
count: 1
66
path: tests/TestCase/BackupTraitTest.php
77

8+
-
9+
message: "#^Access to an undefined property DatabaseBackup\\\\Utility\\\\BackupExport\\:\\:\\$noExistingProperty\\.$#"
10+
count: 1
11+
path: tests/TestCase/Utility/BackupExportAndImportTest.php
12+
13+
-
14+
message: "#^Expression \"\\$this\\-\\>BackupExport\\-\\>noExistingProperty\" on a separate line does not do anything\\.$#"
15+
count: 1
16+
path: tests/TestCase/Utility/BackupExportAndImportTest.php
17+

psalm-baseline.xml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<files psalm-version="4.x-dev@">
3+
<file src="src/Driver/Mysql.php">
4+
<RedundantPropertyInitializationCheck occurrences="2">
5+
<code>$this-&gt;auth</code>
6+
<code>TMP . uniqid('auth')</code>
7+
</RedundantPropertyInitializationCheck>
8+
</file>
39
<file src="src/TestSuite/DriverTestCase.php">
410
<TypeDoesNotContainType occurrences="1">
511
<code>empty($this-&gt;Driver)</code>
612
</TypeDoesNotContainType>
713
</file>
8-
<file src="src/Utility/BackupExport.php">
9-
<RedundantPropertyInitializationCheck occurrences="2">
10-
<code>$this-&gt;defaultExtension</code>
11-
<code>$this-&gt;extension</code>
12-
</RedundantPropertyInitializationCheck>
14+
<file src="src/Utility/AbstractBackupUtility.php">
15+
<TypeDoesNotContainType occurrences="1">
16+
<code>empty($this-&gt;Driver)</code>
17+
</TypeDoesNotContainType>
1318
</file>
1419
<file src="src/Utility/BackupManager.php">
1520
<TooManyTemplateParams occurrences="1">

resources/locales/database_backup.pot

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,161 +4,177 @@
44
#, fuzzy
55
msgid ""
66
msgstr ""
7-
"POT-Creation-Date: 2019-12-18 16:44+0100\n"
7+
"POT-Creation-Date: 2023-06-06 16:05+0200\n"
88
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
99
"Last-Translator: NAME <EMAIL@ADDRESS>\n"
1010
"MIME-Version: 1.0\n"
1111
"Content-Type: text/plain; charset=utf-8\n"
1212
"Content-Transfer-Encoding: 8bit\n"
1313
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
1414

15-
#: BackupTrait.php:56
16-
msgid "Binary for `{0}` could not be found. You have to set its path manually"
17-
msgstr ""
18-
19-
#: BackupTrait.php:104
20-
msgid "The `{0}` driver does not exist"
21-
msgstr ""
22-
23-
#: Command/DeleteAllCommand.php:34
15+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/DeleteAllCommand.php:36
2416
msgid "Deletes all database backups"
2517
msgstr ""
2618

27-
#: Command/DeleteAllCommand.php:52
28-
#: Command/RotateCommand.php:62
19+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/DeleteAllCommand.php:53
20+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/RotateCommand.php:64
2921
msgid "No backup has been deleted"
3022
msgstr ""
3123

32-
#: Command/DeleteAllCommand.php:58
33-
#: Command/RotateCommand.php:68
24+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/DeleteAllCommand.php:59
25+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/RotateCommand.php:70
3426
msgid "Backup `{0}` has been deleted"
3527
msgstr ""
3628

37-
#: Command/DeleteAllCommand.php:61
38-
#: Command/RotateCommand.php:71
29+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/DeleteAllCommand.php:62
30+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/RotateCommand.php:73
3931
msgid "Deleted backup files: {0}"
4032
msgstr ""
4133

42-
#: Command/ExportCommand.php:37
34+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ExportCommand.php:39
4335
msgid "Exports a database backup"
4436
msgstr ""
4537

46-
#: Command/ExportCommand.php:41
38+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ExportCommand.php:43
4739
msgid "Compression type. By default, no compression will be used"
4840
msgstr ""
4941

50-
#: Command/ExportCommand.php:45
51-
msgid "Filename. It can be an absolute path and may contain patterns. The compression type will be automatically setted"
42+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ExportCommand.php:47
43+
msgid "Filename. It can be an absolute path and may contain patterns. The compression type will be automatically set"
5244
msgstr ""
5345

54-
#: Command/ExportCommand.php:50
46+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ExportCommand.php:52
5547
msgid "Rotates backups. You have to indicate the number of backups you want to keep. So, it will delete all backups that are older. By default, no backup will be deleted"
5648
msgstr ""
5749

58-
#: Command/ExportCommand.php:56
50+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ExportCommand.php:58
5951
msgid "Sends the backup file via email. You have to indicate the recipient's email address"
6052
msgstr ""
6153

62-
#: Command/ExportCommand.php:94
54+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ExportCommand.php:63
55+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ImportCommand.php:45
56+
msgid "Timeout for shell commands. Default value: {0} seconds"
57+
msgstr ""
58+
59+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ExportCommand.php:101
60+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ImportCommand.php:74
61+
msgid "The `{0}` event stopped the operation"
62+
msgstr ""
63+
64+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ExportCommand.php:102
6365
msgid "Backup `{0}` has been exported"
6466
msgstr ""
6567

66-
#: Command/ImportCommand.php:35
68+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ImportCommand.php:39
6769
msgid "Imports a database backup"
6870
msgstr ""
6971

70-
#: Command/ImportCommand.php:37
71-
#: Command/SendCommand.php:38
72+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ImportCommand.php:41
73+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/SendCommand.php:40
7274
msgid "Filename. It can be an absolute path"
7375
msgstr ""
7476

75-
#: Command/ImportCommand.php:57
77+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/ImportCommand.php:75
7678
msgid "Backup `{0}` has been imported"
7779
msgstr ""
7880

79-
#: Command/IndexCommand.php:36
81+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/IndexCommand.php:38
8082
msgid "Lists database backups"
8183
msgstr ""
8284

83-
#: Command/IndexCommand.php:53
85+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/IndexCommand.php:54
8486
msgid "Backup files found: {0}"
8587
msgstr ""
8688

87-
#: Command/IndexCommand.php:60
89+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/IndexCommand.php:60
8890
msgid "Filename"
8991
msgstr ""
9092

91-
#: Command/IndexCommand.php:61
93+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/IndexCommand.php:61
9294
msgid "Extension"
9395
msgstr ""
9496

95-
#: Command/IndexCommand.php:62
97+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/IndexCommand.php:62
9698
msgid "Compression"
9799
msgstr ""
98100

99-
#: Command/IndexCommand.php:63
101+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/IndexCommand.php:63
100102
msgid "Size"
101103
msgstr ""
102104

103-
#: Command/IndexCommand.php:64
105+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/IndexCommand.php:64
104106
msgid "Datetime"
105107
msgstr ""
106108

107-
#: Command/RotateCommand.php:35
109+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/RotateCommand.php:37
108110
msgid "Rotates backups"
109111
msgstr ""
110112

111-
#: Command/RotateCommand.php:37
113+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/RotateCommand.php:39
112114
msgid "Number of backups you want to keep. So, it will delete all backups that are older"
113115
msgstr ""
114116

115-
#: Command/SendCommand.php:35
117+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/SendCommand.php:37
116118
msgid "Send a database backup via mail"
117119
msgstr ""
118120

119-
#: Command/SendCommand.php:42
121+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/SendCommand.php:44
120122
msgid "Recipient's email address"
121123
msgstr ""
122124

123-
#: Command/SendCommand.php:62
125+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Command/SendCommand.php:64
124126
msgid "Backup `{0}` was sent via mail"
125127
msgstr ""
126128

127-
#: Console/Command.php:38
129+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Console/Command.php:39
128130
msgid "Connection: {0}"
129131
msgstr ""
130132

131-
#: Console/Command.php:39
133+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Console/Command.php:40
132134
msgid "Driver: {0}"
133135
msgstr ""
134136

135-
#: Driver/Driver.php:185
136-
#: Driver/Driver.php:228
137-
msgid "Failed with exit code `{0}`"
137+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Console/Command.php:43
138+
msgid "Timeout for shell commands: {0} seconds"
138139
msgstr ""
139140

140-
#: Utility/BackupExport.php:119
141+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/AbstractBackupUtility.php:83
142+
msgid "The `{0}` driver does not exist"
143+
msgstr ""
144+
145+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupExport.php:75
141146
msgid "Invalid compression type"
142147
msgstr ""
143148

144-
#: Utility/BackupExport.php:155
149+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupExport.php:106
145150
msgid "File `{0}` already exists"
146151
msgstr ""
147152

148-
#: Utility/BackupExport.php:160
149-
#: Utility/BackupImport.php:66
153+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupExport.php:109
154+
msgid "Invalid `{0}` file extension"
155+
msgstr ""
156+
157+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupExport.php:176
158+
msgid "Export failed with error message: `{0}`"
159+
msgstr ""
160+
161+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupImport.php:38
150162
msgid "Invalid file extension"
151163
msgstr ""
152164

153-
#: Utility/BackupImport.php:87
165+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupImport.php:59
154166
msgid "You must first set the filename"
155167
msgstr ""
156168

157-
#: Utility/BackupManager.php:100
169+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupImport.php:73
170+
msgid "Import failed with error message: `{0}`"
171+
msgstr ""
172+
173+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupManager.php:94
158174
msgid "Invalid rotate value"
159175
msgstr ""
160176

161-
#: Utility/BackupManager.php:128
177+
#: ./home/mirko/Libs/Plugins/cakephp-database-backup/src/Utility/BackupManager.php:117
162178
msgid "Database backup {0} from {1}"
163179
msgstr ""
164180

0 commit comments

Comments
 (0)