Skip to content

Commit

Permalink
Move presoftdeletable methods
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Oct 31, 2023
1 parent c8f4639 commit 9e3c725
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 77 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ a release.
---

## [Unreleased]
## Added
- SoftDeleteable: `Gedmo\SoftDeleteable\Mapping\Event::createPreSoftDeleteEventArgs()` and `Gedmo\SoftDeleteable\Mapping\Event::createPostSoftDeleteEventArgs()` methods.

### Changed
- Dropped support for PHP < 7.4
- Dropped support for Symfony < 5.4

### Deprecated
- Calling `Gedmo\Mapping\Event\Adapter\ORM::getObjectManager()` and `getObject()` on EventArgs that do not implement `getObjectManager()` and `getObject()` (such as old EventArgs implementing `getEntityManager()` and `getEntity()`)
- Calling `Gedmo\Uploadable\Event\UploadableBaseEventArgs::getEntityManager()` and `getEntity()`. Call `getObjectManager()` and `getObject()` instead.
- Calling `Gedmo\Uploadable\Event\UploadableBaseEventArgs::getEntityManager()` and `getEntity()`. Call `getObjectManager()` and `getObject()` instead.
- `Gedmo\Mapping\Event\AdapterInterface::createLifecycleEventArgsInstance()` method.

## [3.13.0] - 2023-09-06
### Fixed
- References: fixed condition in `XML` Driver that did not allow to retrieve from the entity definition the `mappedBy` and `inversedBy` fields.
- Fix bug collecting metadata for inherited mapped classes

### Deprecated
- SoftDeleteable: function `createLifecycleEventArgsInstance` is deprecated. Use `createPreSoftDeleteEventArgs` and `createPostSoftDeleteEventArgs` instead.

## [3.12.0] - 2023-07-08
### Added
- Tree: `setSibling()` and `getSibling()` methods in the `Node` interface through the BC `@method` annotation
Expand Down
36 changes: 5 additions & 31 deletions src/Mapping/Event/Adapter/ODM.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Exception\RuntimeException;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\SoftDeleteable\Event\ODM\PostSoftDeleteEventArgs;
use Gedmo\SoftDeleteable\Event\ODM\PreSoftDeleteEventArgs;

/**
* Doctrine event adapter for ODM specific
Expand Down Expand Up @@ -155,36 +152,13 @@ public function clearObjectChangeSet($uow, $object)
/**
* Creates a ODM specific LifecycleEventArgs.
*
* @param DocumentManager $manager
* @param object $document
* @param DocumentManager $documentManager
*
* @deprecated Use createPreSoftDeleteEventArgs() or createPostSoftDeleteEventArgs() instead
* @return LifecycleEventArgs
*/
public function createLifecycleEventArgsInstance(object $object, ObjectManager $manager): LifecycleEventArgs
public function createLifecycleEventArgsInstance($document, $documentManager)
{
return new LifecycleEventArgs($object, $manager);
}

/**
* Creates a ODM specific PreSoftDeleteEventArgs.
*
* @param DocumentManager $manager
*
* @return PreSoftDeleteEventArgs
*/
public function createPreSoftDeleteEventArgs(object $object, ObjectManager $manager): LifecycleEventArgs
{
return new PreSoftDeleteEventArgs($object, $manager);
}

/**
* Creates a ODM specific PostSoftDeleteEventArgs.
*
* @param DocumentManager $manager
*
* @return PostSoftDeleteEventArgs
*/
public function createPostSoftDeleteEventArgs(object $object, ObjectManager $manager): LifecycleEventArgs
{
return new PostSoftDeleteEventArgs($object, $manager);
return new LifecycleEventArgs($document, $documentManager);
}
}
40 changes: 7 additions & 33 deletions src/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@

use Doctrine\Common\EventArgs;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Exception\RuntimeException;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\SoftDeleteable\Event\ORM\PostSoftDeleteEventArgs;
use Gedmo\SoftDeleteable\Event\ORM\PreSoftDeleteEventArgs;

/**
* Doctrine event adapter for ORM specific
Expand Down Expand Up @@ -183,38 +180,15 @@ public function clearObjectChangeSet($uow, $object)
}

/**
* Creates a ORM specific LifecycleEventArgs.
* Creates an ORM specific LifecycleEventArgs.
*
* @param EntityManagerInterface $manager
* @param object $object
* @param EntityManagerInterface $entityManager
*
* @deprecated Use createPreSoftDeleteEventArgs() or createPostSoftDeleteEventArgs() instead
* @return LifecycleEventArgs
*/
public function createLifecycleEventArgsInstance(object $object, ObjectManager $manager): LifecycleEventArgs
public function createLifecycleEventArgsInstance($object, $entityManager)

Check warning on line 190 in src/Mapping/Event/Adapter/ORM.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Event/Adapter/ORM.php#L190

Added line #L190 was not covered by tests
{
return new LifecycleEventArgs($object, $manager);
}

/**
* Creates a ORM specific PreSoftDeleteEventArgs.
*
* @param EntityManagerInterface $manager
*
* @return PreSoftDeleteEventArgs
*/
public function createPreSoftDeleteEventArgs(object $object, ObjectManager $manager): LifecycleEventArgs
{
return new PreSoftDeleteEventArgs($object, $manager);
}

/**
* Creates a ORM specific PostSoftDeleteEventArgs.
*
* @param EntityManagerInterface $manager
*
* @return PostSoftDeleteEventArgs
*/
public function createPostSoftDeleteEventArgs(object $object, ObjectManager $manager): LifecycleEventArgs
{
return new PostSoftDeleteEventArgs($object, $manager);
return new LifecycleEventArgs($object, $entityManager);

Check warning on line 192 in src/Mapping/Event/Adapter/ORM.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Event/Adapter/ORM.php#L192

Added line #L192 was not covered by tests
}
}
4 changes: 1 addition & 3 deletions src/Mapping/Event/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*
* @method LifecycleEventArgs createLifecycleEventArgsInstance(object $object, ObjectManager $manager) @deprecated Use createPreSoftDeleteEventArgs() or createPostSoftDeleteEventArgs() instead
* @method LifecycleEventArgs createPreSoftDeleteEventArgs(object $object, ObjectManager $manager)
* @method LifecycleEventArgs createPostSoftDeleteEventArgs(object $object, ObjectManager $manager)
* @method LifecycleEventArgs createLifecycleEventArgsInstance(object $object, ObjectManager $manager) @deprecated
* @method object getObject()
*/
interface AdapterInterface
Expand Down
13 changes: 11 additions & 2 deletions src/SoftDeleteable/Event/ORM/PostSoftDeleteEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@

namespace Gedmo\SoftDeleteable\Event\ORM;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\Persistence\Event\LifecycleEventArgs as PersistenceLifecycleEventArgs;

final class PostSoftDeleteEventArgs extends LifecycleEventArgs
{
if (!class_exists(LifecycleEventArgs::class)) {
/** @template-extends PersistenceLifecycleEventArgs<EntityManagerInterface> */
final class PostSoftDeleteEventArgs extends PersistenceLifecycleEventArgs
{
}
} else {
final class PostSoftDeleteEventArgs extends LifecycleEventArgs
{
}
}
13 changes: 11 additions & 2 deletions src/SoftDeleteable/Event/ORM/PreSoftDeleteEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@

namespace Gedmo\SoftDeleteable\Event\ORM;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\Persistence\Event\LifecycleEventArgs as PersistenceLifecycleEventArgs;

final class PreSoftDeleteEventArgs extends LifecycleEventArgs
{
if (!class_exists(LifecycleEventArgs::class)) {
/** @template-extends PersistenceLifecycleEventArgs<EntityManagerInterface> */
final class PreSoftDeleteEventArgs extends PersistenceLifecycleEventArgs
{
}
} else {
final class PreSoftDeleteEventArgs extends LifecycleEventArgs
{
}
}
20 changes: 20 additions & 0 deletions src/SoftDeleteable/Mapping/Event/Adapter/ODM.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

namespace Gedmo\SoftDeleteable\Mapping\Event\Adapter;

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Mapping\Event\Adapter\ODM as BaseAdapterODM;
use Gedmo\SoftDeleteable\Event\ODM\PostSoftDeleteEventArgs;
use Gedmo\SoftDeleteable\Event\ODM\PreSoftDeleteEventArgs;
use Gedmo\SoftDeleteable\Mapping\Event\SoftDeleteableAdapter;

/**
Expand Down Expand Up @@ -40,4 +44,20 @@ public function getDateValue($meta, $field)

return $datetime;
}

/**
* @param DocumentManager $manager
*/
public function createPreSoftDeleteEventArgs(object $object, ObjectManager $manager): PreSoftDeleteEventArgs
{
return new PreSoftDeleteEventArgs($object, $manager);
}

/**
* @param DocumentManager $manager
*/
public function createPostSoftDeleteEventArgs(object $object, ObjectManager $manager): PostSoftDeleteEventArgs
{
return new PostSoftDeleteEventArgs($object, $manager);
}
}
20 changes: 20 additions & 0 deletions src/SoftDeleteable/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM;
use Gedmo\SoftDeleteable\Event\ORM\PostSoftDeleteEventArgs;
use Gedmo\SoftDeleteable\Event\ORM\PreSoftDeleteEventArgs;
use Gedmo\SoftDeleteable\Mapping\Event\SoftDeleteableAdapter;

/**
Expand All @@ -35,6 +39,22 @@ public function getDateValue($meta, $field)
return $converter->convertToPHPValue($this->getRawDateValue($mapping), $platform);
}

/**
* @param EntityManagerInterface $manager
*/
public function createPreSoftDeleteEventArgs(object $object, ObjectManager $manager): PreSoftDeleteEventArgs
{
return new PreSoftDeleteEventArgs($object, $manager);
}

/**
* @param EntityManagerInterface $manager
*/
public function createPostSoftDeleteEventArgs(object $object, ObjectManager $manager): PostSoftDeleteEventArgs
{
return new PostSoftDeleteEventArgs($object, $manager);
}

/**
* Generates current timestamp for the specified mapping
*
Expand Down
5 changes: 5 additions & 0 deletions src/SoftDeleteable/Mapping/Event/SoftDeleteableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@

namespace Gedmo\SoftDeleteable\Mapping\Event;

use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Mapping\Event\AdapterInterface;

/**
* Doctrine event adapter for the SoftDeleteable extension.
*
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
*
* @method LifecycleEventArgs createPreSoftDeleteEventArgs(object $object, ObjectManager $manager)
* @method LifecycleEventArgs createPostSoftDeleteEventArgs(object $object, ObjectManager $manager)
*/
interface SoftDeleteableAdapter extends AdapterInterface
{
Expand Down
14 changes: 12 additions & 2 deletions src/SoftDeleteable/SoftDeleteableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ public function onFlush(EventArgs $args)
continue; // want to hard delete
}

// @todo: in the next major remove check and call createPreSoftDeleteEventArgs
$preSoftDeleteEventArgs = method_exists($ea, 'createPreSoftDeleteEventArgs')
? $ea->createPreSoftDeleteEventArgs($object, $om)
: $ea->createLifecycleEventArgsInstance($object, $om);

$evm->dispatchEvent(
self::PRE_SOFT_DELETE,
$ea->createPreSoftDeleteEventArgs($object, $om)
$preSoftDeleteEventArgs
);

$reflProp->setValue($object, $date);
Expand All @@ -98,9 +103,14 @@ public function onFlush(EventArgs $args)
]);
}

// @todo: in the next major remove check and call createPostSoftDeleteEventArgs
$postSoftDeleteEventArgs = method_exists($ea, 'createPostSoftDeleteEventArgs')
? $ea->createPostSoftDeleteEventArgs($object, $om)
: $ea->createLifecycleEventArgsInstance($object, $om);

$evm->dispatchEvent(
self::POST_SOFT_DELETE,
$ea->createPostSoftDeleteEventArgs($object, $om)
$postSoftDeleteEventArgs
);
}
}
Expand Down

0 comments on commit 9e3c725

Please sign in to comment.