Skip to content

Commit 16eada1

Browse files
committed
Improve backups for SQLite databases using SQLite3 class
1 parent 067e4b2 commit 16eada1

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

tests/Behat/features/attachments.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Feature: Interacting with the REST API for attachments
2626
| id | 1 |
2727
| token | 1.7b962f8af22e26802b87abfa0b07b21dbd03b984ec8d6888dabd3f69cff162f8 |
2828

29-
3029
Scenario: Updating the details of an attachment
3130
Given I have a "NativeCurlClient" client
3231
And I create a project with name "Test Project" and identifier "test-project"

tests/Behat/features/version.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ Feature: Interacting with the REST API for versions
162162
| id | 1 |
163163
| name | Test Project |
164164

165-
@wip
166165
Scenario: Listing of multiple version names
167166
Given I have a "NativeCurlClient" client
168167
And I create a project with name "Test Project 1" and identifier "test-project-1"

tests/RedmineExtension/RedmineInstance.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DateTimeImmutable;
88
use InvalidArgumentException;
99
use PDO;
10+
use SQLite3;
1011

1112
final class RedmineInstance
1213
{
@@ -190,25 +191,53 @@ private function runDatabaseMigration()
190191
*/
191192
private function createDatabaseBackup()
192193
{
193-
copy($this->rootPath . $this->workingDB, $this->rootPath . $this->backupDB);
194+
$workingDB = new SQLite3($this->rootPath . $this->workingDB);
195+
196+
$backupDB = new SQLite3($this->rootPath . $this->backupDB);
197+
198+
$workingDB->backup($backupDB);
199+
200+
$workingDB->close();
201+
$backupDB->close();
194202
}
195203

196204
/**
197205
* Create backup of migrated database
198206
*/
199207
private function saveMigratedDatabase()
200208
{
201-
copy($this->rootPath . $this->workingDB, $this->rootPath . $this->migratedDB);
209+
$workingDB = new SQLite3($this->rootPath . $this->workingDB);
210+
211+
$migratedDB = new SQLite3($this->rootPath . $this->migratedDB);
212+
213+
$workingDB->backup($migratedDB);
214+
215+
$workingDB->close();
216+
$migratedDB->close();
202217
}
203218

204219
private function restoreFromMigratedDatabase(): void
205220
{
206-
copy($this->rootPath . $this->migratedDB, $this->rootPath . $this->workingDB);
221+
$workingDB = new SQLite3($this->rootPath . $this->workingDB);
222+
223+
$migratedDB = new SQLite3($this->rootPath . $this->migratedDB);
224+
225+
$migratedDB->backup($workingDB);
226+
227+
$workingDB->close();
228+
$migratedDB->close();
207229
}
208230

209231
private function restoreDatabaseFromBackup(): void
210232
{
211-
copy($this->rootPath . $this->backupDB, $this->rootPath . $this->workingDB);
233+
$workingDB = new SQLite3($this->rootPath . $this->workingDB);
234+
235+
$backupDB = new SQLite3($this->rootPath . $this->backupDB);
236+
237+
$backupDB->backup($workingDB);
238+
239+
$workingDB->close();
240+
$backupDB->close();
212241
}
213242

214243
private function removeDatabaseBackups(): void

0 commit comments

Comments
 (0)