Skip to content

Commit 7413760

Browse files
authored
Merge branch 'v2.4.x' into fix-softdelete-in-future
2 parents 7398ca1 + cac89be commit 7413760

File tree

52 files changed

+371
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+371
-106
lines changed

.travis.yml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,41 @@ language: php
22

33
sudo: false
44

5-
php:
6-
- 5.4
7-
- 5.5
8-
- 5.6
9-
- 7.0
5+
matrix:
6+
include:
7+
- php: 5.4
8+
env: phpunit_exclude_groups=datetimeinterface
9+
- php: 5.5
10+
- php: 5.6
11+
- php: 7.0
12+
- php: 7.1
13+
- php: 7.2
14+
15+
cache:
16+
directories:
17+
- $HOME/.composer/cache
1018

1119
services: mongodb
1220

1321
before_install:
14-
- if [[ "$TRAVIS_PHP_VERSION" = 5.* ]]; then echo 'extension=mongo.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
15-
- if [[ "$TRAVIS_PHP_VERSION" != 5.* ]]; then echo 'extension=mongodb.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
16-
- if [[ "$TRAVIS_PHP_VERSION" != 5.* ]]; then cp composer7.json composer.json; fi
22+
- if [[ "$TRAVIS_PHP_VERSION" = 5.* ]]; then echo 'extension=mongo.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
23+
- if [[ "$TRAVIS_PHP_VERSION" != 5.* ]]; then echo 'extension=mongodb.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
24+
- if [[ "$TRAVIS_PHP_VERSION" != 5.* ]]; then cp composer7.json composer.json; fi
1725

1826
install:
19-
- composer install --prefer-dist
27+
- composer install --prefer-dist
2028

2129
script:
22-
- bin/phpunit -c tests/
30+
- |
31+
if [[ ! $phpunit_exclude_groups ]]; then
32+
echo "Debug: 'bin/phpunit -c tests/'"
33+
bin/phpunit -c tests/
34+
else
35+
echo "Debug: 'bin/phpunit -c tests/ --exclude-group $phpunit_exclude_groups'"
36+
bin/phpunit -c tests/ --exclude-group $phpunit_exclude_groups
37+
fi
2338
2439
notifications:
25-
email:
26-
27-
40+
email:
41+
42+

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"doctrine/orm": ">=2.5.0",
4848
"doctrine/common": ">=2.5.0",
4949
"symfony/yaml": "~2.6|~3.0|~4.0",
50-
"phpunit/phpunit": "*"
50+
"phpunit/phpunit": "^4.8|^5.7|^6.5"
5151
},
5252
"suggest": {
5353
"doctrine/mongodb-odm": "to use the extensions with the MongoDB ODM",

composer7.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
},
4848
"require-dev": {
4949
"alcaeus/mongo-php-adapter": "~1.0.4",
50-
"doctrine/mongodb-odm": "~1.0",
50+
"doctrine/mongodb-odm": ">=1.0.2",
5151
"doctrine/orm": ">=2.5.0",
5252
"doctrine/common": ">=2.5.0",
53-
"symfony/yaml": "~2.6|~3.0",
54-
"phpunit/phpunit": "*"
53+
"symfony/yaml": "~2.6|~3.0|~4.0",
54+
"phpunit/phpunit": "^4.8|^5.7|^6.5"
5555
},
5656
"suggest": {
5757
"doctrine/mongodb-odm": "to use the extensions with the MongoDB ODM",

lib/Gedmo/Mapping/Event/Adapter/ORM.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Gedmo\Mapping\Event\Adapter;
44

5+
use Doctrine\ORM\EntityManagerInterface;
56
use Gedmo\Mapping\Event\AdapterInterface;
67
use Gedmo\Exception\RuntimeException;
78
use Doctrine\Common\EventArgs;
8-
use Doctrine\ORM\EntityManager;
99
use Doctrine\ORM\Event\LifecycleEventArgs;
1010

1111
/**
@@ -23,7 +23,7 @@ class ORM implements AdapterInterface
2323
private $args;
2424

2525
/**
26-
* @var \Doctrine\ORM\EntityManager
26+
* @var \Doctrine\ORM\EntityManagerInterface
2727
*/
2828
private $em;
2929

@@ -75,9 +75,9 @@ public function __call($method, $args)
7575
/**
7676
* Set the entity manager
7777
*
78-
* @param \Doctrine\ORM\EntityManager $em
78+
* @param \Doctrine\ORM\EntityManagerInterface $em
7979
*/
80-
public function setEntityManager(EntityManager $em)
80+
public function setEntityManager(EntityManagerInterface $em)
8181
{
8282
$this->em = $em;
8383
}

lib/Gedmo/References/Mapping/Event/Adapter/ODM.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Doctrine\ODM\MongoDB\DocumentManager;
66
use Doctrine\ODM\MongoDB\Proxy\Proxy as MongoDBProxy;
7-
use Doctrine\ORM\EntityManager;
7+
use Doctrine\ORM\EntityManagerInterface;
88
use Doctrine\ORM\Proxy\Proxy as ORMProxy;
99
use Gedmo\Mapping\Event\Adapter\ODM as BaseAdapterODM;
1010
use Gedmo\References\Mapping\Event\ReferencesAdapter;
@@ -28,7 +28,7 @@ public function getIdentifier($om, $object, $single = true)
2828
return $this->extractIdentifier($om, $object, $single);
2929
}
3030

31-
if ($om instanceof EntityManager) {
31+
if ($om instanceof EntityManagerInterface) {
3232
if ($object instanceof ORMProxy) {
3333
$id = $om->getUnitOfWork()->getEntityIdentifier($object);
3434
} else {
@@ -88,7 +88,7 @@ public function extractIdentifier($om, $object, $single = true)
8888
/**
8989
* Override so we don't get an exception. We want to allow this.
9090
*/
91-
private function throwIfNotEntityManager(EntityManager $em)
91+
private function throwIfNotEntityManager(EntityManagerInterface $em)
9292
{
9393
}
9494
}

lib/Gedmo/References/Mapping/Event/Adapter/ORM.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Doctrine\ODM\MongoDB\DocumentManager as MongoDocumentManager;
66
use Doctrine\ODM\MongoDB\Proxy\Proxy as MongoDBProxy;
77
use Doctrine\ODM\PHPCR\DocumentManager as PhpcrDocumentManager;
8-
use Doctrine\ORM\EntityManager;
8+
use Doctrine\ORM\EntityManagerInterface;
99
use Doctrine\ORM\Proxy\Proxy as ORMProxy;
1010
use Gedmo\Exception\InvalidArgumentException;
1111
use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM;
@@ -26,7 +26,7 @@ final class ORM extends BaseAdapterORM implements ReferencesAdapter
2626
*/
2727
public function getIdentifier($om, $object, $single = true)
2828
{
29-
if ($om instanceof EntityManager) {
29+
if ($om instanceof EntityManagerInterface) {
3030
return $this->extractIdentifier($om, $object, $single);
3131
}
3232

lib/Gedmo/Sluggable/Mapping/Driver/Annotation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private function retrieveSlug($meta, array &$config, $property, $fieldNamePrefix
148148
if ($slug->unique_base && !$meta->hasField($slug->unique_base) && !$meta->hasAssociation($slug->unique_base)) {
149149
throw new InvalidMappingException("Unable to find [{$slug->unique_base}] as mapped property in entity - {$meta->name}");
150150
}
151-
$sluggableFields = [];
151+
$sluggableFields = array();
152152
foreach ($slug->fields as $field) {
153153
$sluggableFields[] = $fieldNamePrefix ? ($fieldNamePrefix . '.' . $field) : $field;
154154
}

lib/Gedmo/Sluggable/SluggableListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ private function generateSlug(SluggableAdapter $ea, $object)
298298
$needToChangeSlug = true;
299299
}
300300
$value = $meta->getReflectionProperty($sluggableField)->getValue($object);
301-
$slug .= ($value instanceof \DateTime) ? $value->format($options['dateFormat']) : $value;
301+
// Remove `$value instanceof \DateTime` check when PHP version is bumped to >=5.5
302+
$slug .= ($value instanceof \DateTime || $value instanceof \DateTimeInterface) ? $value->format($options['dateFormat']) : $value;
302303
$slug .= ' ';
303304
}
304305
// trim generated slug as it will have unnecessary trailing space

lib/Gedmo/SoftDeleteable/SoftDeleteableListener.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class SoftDeleteableListener extends MappedEventSubscriber
2929
*/
3030
const POST_SOFT_DELETE = "postSoftDelete";
3131

32+
/**
33+
* Objects soft-deleted on flush.
34+
*
35+
* @var array
36+
*/
37+
private $softDeletedObjects = array();
38+
3239
/**
3340
* {@inheritdoc}
3441
*/
@@ -37,6 +44,7 @@ public function getSubscribedEvents()
3744
return array(
3845
'loadClassMetadata',
3946
'onFlush',
47+
'postFlush'
4048
);
4149
}
4250

@@ -64,7 +72,9 @@ public function onFlush(EventArgs $args)
6472
$reflProp = $meta->getReflectionProperty($config['fieldName']);
6573
$oldValue = $reflProp->getValue($object);
6674
$date = new \DateTime();
67-
if (isset($config['hardDelete']) && $config['hardDelete'] && $oldValue instanceof \DateTimeInterface && $oldValue <= $date) {
75+
76+
// Remove `$oldValue instanceof \DateTime` check when PHP version is bumped to >=5.5
77+
if (isset($config['hardDelete']) && $config['hardDelete'] && ($oldValue instanceof \DateTime || $oldValue instanceof \DateTimeInterface) && $oldValue <= $date) {
6878
continue; // want to hard delete
6979
}
7080

@@ -90,10 +100,32 @@ public function onFlush(EventArgs $args)
90100
self::POST_SOFT_DELETE,
91101
$ea->createLifecycleEventArgsInstance($object, $om)
92102
);
103+
104+
$this->softDeletedObjects[] = $object;
93105
}
94106
}
95107
}
96108

109+
/**
110+
* Detach soft-deleted objects from object manager.
111+
*
112+
* @param \Doctrine\Common\EventArgs $args
113+
*
114+
* @return void
115+
*
116+
* @throws \Gedmo\Exception\InvalidArgumentException
117+
*/
118+
public function postFlush(EventArgs $args)
119+
{
120+
$ea = $this->getEventAdapter($args);
121+
$om = $ea->getObjectManager();
122+
123+
foreach ($this->softDeletedObjects as $index => $object) {
124+
$om->detach($object);
125+
unset($this->softDeletedObjects[$index]);
126+
}
127+
}
128+
97129
/**
98130
* Maps additional metadata
99131
*

lib/Gedmo/SoftDeleteable/Traits/SoftDeleteable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait SoftDeleteable
1818
/**
1919
* Sets deletedAt.
2020
*
21-
* @param \Datetime|null $deletedAt
21+
* @param \DateTime|null $deletedAt
2222
*
2323
* @return $this
2424
*/

0 commit comments

Comments
 (0)