Skip to content

Commit 3be4e2a

Browse files
authored
Added deletion check when updating or deleting records (#13)
1 parent f4ac959 commit 3be4e2a

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor/
22
.idea/
3+
.phpunit.result.cache

phpunit.xml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
forceCoversAnnotation="true"
6-
beStrictAboutCoversAnnotation="true"
5+
forceCoversAnnotation="false"
6+
beStrictAboutCoversAnnotation="false"
77
beStrictAboutOutputDuringTests="true"
88
beStrictAboutTodoAnnotatedTests="true"
99
verbose="true">
10-
<testsuite name="default">
11-
<directory suffix="Test.php">tests</directory>
12-
</testsuite>
13-
14-
<filter>
15-
<whitelist processUncoveredFilesFromWhitelist="true">
16-
<directory suffix=".php">src</directory>
17-
</whitelist>
18-
</filter>
10+
<coverage processUncoveredFiles="true">
11+
<include>
12+
<directory suffix=".php">src</directory>
13+
</include>
14+
</coverage>
15+
<testsuite name="default">
16+
<directory suffix="Test.php">tests</directory>
17+
</testsuite>
1918
</phpunit>

src/Mapping.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ private function replace(array $data, array $original, array $deleteIds = [])
304304
}
305305
}
306306

307+
if ($this->definition->getDeletionTimestamp()) {
308+
$query->isNull($this->definition->getDeletionTimestamp());
309+
}
310+
307311
$base = $this->getBaseData($data);
308312
$originalBase = $this->getBaseData($original);
309313

@@ -432,7 +436,7 @@ private function delete($ids = [])
432436
$query->in($primary, array_values($primaryValues));
433437
$query->closeOr();
434438

435-
$result = $deletion ? $query->update([$deletion => gmdate('Y-m-d H:i:s')]) : $query->remove();
439+
$result = $deletion ? $query->isNull($deletion)->update([$deletion => gmdate('Y-m-d H:i:s')]) : $query->remove();
436440
if (!$result) {
437441
throw new \Exception('Failed to delete records.');
438442
}

tests/MappingTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ public function getMapping()
303303
->withColumns('id', 'description', 'amount', 'modified')
304304
->withModificationData(['modified' => '2019-01-02 03:04:05']);
305305

306-
307306
$order = (new Definition('orders'))
308307
->withColumns('id', 'date_created')
309308
->withOne($discount, 'discount', 'order_id')

0 commit comments

Comments
 (0)