init without trunk
This commit is contained in:
parent
ed24ac4994
commit
bb809e7233
14652 changed files with 177862 additions and 94817 deletions
97
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php
vendored
Normal file
97
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Filter\ODM;
|
||||
|
||||
use Doctrine\ODM\MongoDB\Query\Filter\BsonFilter;
|
||||
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
|
||||
use Gedmo\SoftDeleteable\SoftDeleteableListener;
|
||||
|
||||
class SoftDeleteableFilter extends BsonFilter
|
||||
{
|
||||
protected $listener;
|
||||
protected $documentManager;
|
||||
protected $disabled = array();
|
||||
|
||||
/**
|
||||
* Gets the criteria part to add to a query.
|
||||
*
|
||||
* @param ClassMetadata $targetEntity
|
||||
*
|
||||
* @return array The criteria array, if there is available, empty array otherwise
|
||||
*/
|
||||
public function addFilterCriteria(ClassMetadata $targetEntity)
|
||||
{
|
||||
$class = $targetEntity->getName();
|
||||
if (array_key_exists($class, $this->disabled) && $this->disabled[$class] === true) {
|
||||
return array();
|
||||
} elseif (array_key_exists($targetEntity->rootDocumentName, $this->disabled) && $this->disabled[$targetEntity->rootDocumentName] === true) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$config = $this->getListener()->getConfiguration($this->getDocumentManager(), $targetEntity->name);
|
||||
|
||||
if (!isset($config['softDeleteable']) || !$config['softDeleteable']) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$column = $targetEntity->fieldMappings[$config['fieldName']];
|
||||
|
||||
if (isset($config['timeAware']) && $config['timeAware']) {
|
||||
return array(
|
||||
'$or' => array(
|
||||
array($column['fieldName'] => null),
|
||||
array($column['fieldName'] => array('$gt' => new \DateTime('now'))),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
$column['fieldName'] => null,
|
||||
);
|
||||
}
|
||||
|
||||
protected function getListener()
|
||||
{
|
||||
if ($this->listener === null) {
|
||||
$em = $this->getDocumentManager();
|
||||
$evm = $em->getEventManager();
|
||||
|
||||
foreach ($evm->getListeners() as $listeners) {
|
||||
foreach ($listeners as $listener) {
|
||||
if ($listener instanceof SoftDeleteableListener) {
|
||||
$this->listener = $listener;
|
||||
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->listener === null) {
|
||||
throw new \RuntimeException('Listener "SoftDeleteableListener" was not added to the EventManager!');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->listener;
|
||||
}
|
||||
|
||||
protected function getDocumentManager()
|
||||
{
|
||||
if ($this->documentManager === null) {
|
||||
$refl = new \ReflectionProperty('Doctrine\ODM\MongoDB\Query\Filter\BsonFilter', 'dm');
|
||||
$refl->setAccessible(true);
|
||||
$this->documentManager = $refl->getValue($this);
|
||||
}
|
||||
|
||||
return $this->documentManager;
|
||||
}
|
||||
|
||||
public function disableForDocument($class)
|
||||
{
|
||||
$this->disabled[$class] = true;
|
||||
}
|
||||
|
||||
public function enableForDocument($class)
|
||||
{
|
||||
$this->disabled[$class] = false;
|
||||
}
|
||||
}
|
||||
126
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Filter/SoftDeleteableFilter.php
vendored
Normal file
126
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Filter/SoftDeleteableFilter.php
vendored
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Filter;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Query\Filter\SQLFilter;
|
||||
use Gedmo\SoftDeleteable\SoftDeleteableListener;
|
||||
|
||||
/**
|
||||
* The SoftDeleteableFilter adds the condition necessary to
|
||||
* filter entities which were deleted "softly"
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @author Patrik Votoček <patrik@votocek.cz>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
class SoftDeleteableFilter extends SQLFilter
|
||||
{
|
||||
/**
|
||||
* @var SoftDeleteableListener
|
||||
*/
|
||||
protected $listener;
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* @var string[bool]
|
||||
*/
|
||||
protected $disabled = array();
|
||||
|
||||
/**
|
||||
* @param ClassMetadata $targetEntity
|
||||
* @param string $targetTableAlias
|
||||
* @return string
|
||||
*/
|
||||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
|
||||
{
|
||||
$class = $targetEntity->getName();
|
||||
if (array_key_exists($class, $this->disabled) && $this->disabled[$class] === true) {
|
||||
return '';
|
||||
} elseif (array_key_exists($targetEntity->rootEntityName, $this->disabled) && $this->disabled[$targetEntity->rootEntityName] === true) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$config = $this->getListener()->getConfiguration($this->getEntityManager(), $targetEntity->name);
|
||||
|
||||
if (!isset($config['softDeleteable']) || !$config['softDeleteable']) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
$platform = $conn->getDatabasePlatform();
|
||||
$column = $targetEntity->getQuotedColumnName($config['fieldName'], $platform);
|
||||
|
||||
$addCondSql = $platform->getIsNullExpression($targetTableAlias.'.'.$column);
|
||||
if (isset($config['timeAware']) && $config['timeAware']) {
|
||||
$addCondSql = "({$addCondSql} OR {$targetTableAlias}.{$column} > {$platform->getCurrentTimestampSQL()})";
|
||||
}
|
||||
|
||||
return $addCondSql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*/
|
||||
public function disableForEntity($class)
|
||||
{
|
||||
$this->disabled[$class] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*/
|
||||
public function enableForEntity($class)
|
||||
{
|
||||
$this->disabled[$class] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SoftDeleteableListener
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function getListener()
|
||||
{
|
||||
if ($this->listener === null) {
|
||||
$em = $this->getEntityManager();
|
||||
$evm = $em->getEventManager();
|
||||
|
||||
foreach ($evm->getListeners() as $listeners) {
|
||||
foreach ($listeners as $listener) {
|
||||
if ($listener instanceof SoftDeleteableListener) {
|
||||
$this->listener = $listener;
|
||||
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->listener === null) {
|
||||
throw new \RuntimeException('Listener "SoftDeleteableListener" was not added to the EventManager!');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EntityManagerInterface
|
||||
*/
|
||||
protected function getEntityManager()
|
||||
{
|
||||
if ($this->entityManager === null) {
|
||||
$refl = new \ReflectionProperty('Doctrine\ORM\Query\Filter\SQLFilter', 'em');
|
||||
$refl->setAccessible(true);
|
||||
$this->entityManager = $refl->getValue($this);
|
||||
}
|
||||
|
||||
return $this->entityManager;
|
||||
}
|
||||
}
|
||||
59
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Driver/Annotation.php
vendored
Normal file
59
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Driver/Annotation.php
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Mapping\Driver;
|
||||
|
||||
use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
|
||||
use Gedmo\Exception\InvalidMappingException;
|
||||
use Gedmo\SoftDeleteable\Mapping\Validator;
|
||||
|
||||
/**
|
||||
* This is an annotation mapping driver for SoftDeleteable
|
||||
* behavioral extension. Used for extraction of extended
|
||||
* metadata from Annotations specifically for SoftDeleteable
|
||||
* extension.
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
class Annotation extends AbstractAnnotationDriver
|
||||
{
|
||||
/**
|
||||
* Annotation to define that this object is loggable
|
||||
*/
|
||||
const SOFT_DELETEABLE = 'Gedmo\\Mapping\\Annotation\\SoftDeleteable';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function readExtendedMetadata($meta, array &$config)
|
||||
{
|
||||
$class = $this->getMetaReflectionClass($meta);
|
||||
// class annotations
|
||||
if ($class !== null && $annot = $this->reader->getClassAnnotation($class, self::SOFT_DELETEABLE)) {
|
||||
$config['softDeleteable'] = true;
|
||||
|
||||
Validator::validateField($meta, $annot->fieldName);
|
||||
|
||||
$config['fieldName'] = $annot->fieldName;
|
||||
|
||||
$config['timeAware'] = false;
|
||||
if (isset($annot->timeAware)) {
|
||||
if (!is_bool($annot->timeAware)) {
|
||||
throw new InvalidMappingException("timeAware must be boolean. ".gettype($annot->timeAware)." provided.");
|
||||
}
|
||||
$config['timeAware'] = $annot->timeAware;
|
||||
}
|
||||
|
||||
$config['hardDelete'] = true;
|
||||
if (isset($annot->hardDelete)) {
|
||||
if (!is_bool($annot->hardDelete)) {
|
||||
throw new InvalidMappingException("hardDelete must be boolean. ".gettype($annot->hardDelete)." provided.");
|
||||
}
|
||||
$config['hardDelete'] = $annot->hardDelete;
|
||||
}
|
||||
}
|
||||
|
||||
$this->validateFullMetadata($meta, $config);
|
||||
}
|
||||
}
|
||||
59
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Driver/Xml.php
vendored
Normal file
59
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Driver/Xml.php
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Mapping\Driver;
|
||||
|
||||
use Gedmo\Mapping\Driver\Xml as BaseXml;
|
||||
use Gedmo\Exception\InvalidMappingException;
|
||||
use Gedmo\SoftDeleteable\Mapping\Validator;
|
||||
|
||||
/**
|
||||
* This is a xml mapping driver for SoftDeleteable
|
||||
* behavioral extension. Used for extraction of extended
|
||||
* metadata from xml specifically for SoftDeleteable
|
||||
* extension.
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @author Miha Vrhovnik <miha.vrhovnik@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
class Xml extends BaseXml
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function readExtendedMetadata($meta, array &$config)
|
||||
{
|
||||
/**
|
||||
* @var \SimpleXmlElement $xml
|
||||
*/
|
||||
$xml = $this->_getMapping($meta->name);
|
||||
$xmlDoctrine = $xml;
|
||||
$xml = $xml->children(self::GEDMO_NAMESPACE_URI);
|
||||
|
||||
if (in_array($xmlDoctrine->getName(), array('mapped-superclass', 'entity', 'document', 'embedded-document'))) {
|
||||
if (isset($xml->{'soft-deleteable'})) {
|
||||
$field = $this->_getAttribute($xml->{'soft-deleteable'}, 'field-name');
|
||||
|
||||
if (!$field) {
|
||||
throw new InvalidMappingException('Field name for SoftDeleteable class is mandatory.');
|
||||
}
|
||||
|
||||
Validator::validateField($meta, $field);
|
||||
|
||||
$config['softDeleteable'] = true;
|
||||
$config['fieldName'] = $field;
|
||||
|
||||
$config['timeAware'] = false;
|
||||
if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'time-aware')) {
|
||||
$config['timeAware'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'time-aware');
|
||||
}
|
||||
|
||||
$config['hardDelete'] = true;
|
||||
if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'hard-delete')) {
|
||||
$config['hardDelete'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'hard-delete');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
76
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Driver/Yaml.php
vendored
Normal file
76
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Driver/Yaml.php
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Mapping\Driver;
|
||||
|
||||
use Gedmo\Mapping\Driver\File;
|
||||
use Gedmo\Mapping\Driver;
|
||||
use Gedmo\Exception\InvalidMappingException;
|
||||
use Gedmo\SoftDeleteable\Mapping\Validator;
|
||||
|
||||
/**
|
||||
* This is a yaml mapping driver for Timestampable
|
||||
* behavioral extension. Used for extraction of extended
|
||||
* metadata from yaml specifically for Timestampable
|
||||
* extension.
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
class Yaml extends File implements Driver
|
||||
{
|
||||
/**
|
||||
* File extension
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = '.dcm.yml';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function readExtendedMetadata($meta, array &$config)
|
||||
{
|
||||
$mapping = $this->_getMapping($meta->name);
|
||||
|
||||
if (isset($mapping['gedmo'])) {
|
||||
$classMapping = $mapping['gedmo'];
|
||||
if (isset($classMapping['soft_deleteable'])) {
|
||||
$config['softDeleteable'] = true;
|
||||
|
||||
if (!isset($classMapping['soft_deleteable']['field_name'])) {
|
||||
throw new InvalidMappingException('Field name for SoftDeleteable class is mandatory.');
|
||||
}
|
||||
|
||||
$fieldName = $classMapping['soft_deleteable']['field_name'];
|
||||
|
||||
Validator::validateField($meta, $fieldName);
|
||||
|
||||
$config['fieldName'] = $fieldName;
|
||||
|
||||
$config['timeAware'] = false;
|
||||
if (isset($classMapping['soft_deleteable']['time_aware'])) {
|
||||
if (!is_bool($classMapping['soft_deleteable']['time_aware'])) {
|
||||
throw new InvalidMappingException("timeAware must be boolean. ".gettype($classMapping['soft_deleteable']['time_aware'])." provided.");
|
||||
}
|
||||
$config['timeAware'] = $classMapping['soft_deleteable']['time_aware'];
|
||||
}
|
||||
|
||||
$config['hardDelete'] = true;
|
||||
if (isset($classMapping['soft_deleteable']['hard_delete'])) {
|
||||
if (!is_bool($classMapping['soft_deleteable']['hard_delete'])) {
|
||||
throw new InvalidMappingException("hardDelete must be boolean. ".gettype($classMapping['soft_deleteable']['hard_delete'])." provided.");
|
||||
}
|
||||
$config['hardDelete'] = $classMapping['soft_deleteable']['hard_delete'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _loadMappingFile($file)
|
||||
{
|
||||
return \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
|
||||
}
|
||||
}
|
||||
17
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Event/Adapter/ORM.php
vendored
Normal file
17
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Event/Adapter/ORM.php
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Mapping\Event\Adapter;
|
||||
|
||||
use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM;
|
||||
use Gedmo\SoftDeleteable\Mapping\Event\SoftDeleteableAdapter;
|
||||
|
||||
/**
|
||||
* Doctrine event adapter for ORM adapted
|
||||
* for SoftDeleteable behavior.
|
||||
*
|
||||
* @author David Buchmann <mail@davidbu.ch>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
final class ORM extends BaseAdapterORM implements SoftDeleteableAdapter
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Mapping\Event;
|
||||
|
||||
use Gedmo\Mapping\Event\AdapterInterface;
|
||||
|
||||
/**
|
||||
* Doctrine event adapter interface
|
||||
* for SoftDeleteable behavior
|
||||
*
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
interface SoftDeleteableAdapter extends AdapterInterface
|
||||
{
|
||||
}
|
||||
52
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Validator.php
vendored
Normal file
52
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Mapping/Validator.php
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Mapping;
|
||||
|
||||
use Gedmo\Exception\InvalidMappingException;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* This class is used to validate mapping information
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
class Validator
|
||||
{
|
||||
/**
|
||||
* List of types which are valid for timestamp
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $validTypes = array(
|
||||
'date',
|
||||
'date_immutable',
|
||||
'time',
|
||||
'time_immutable',
|
||||
'datetime',
|
||||
'datetime_immutable',
|
||||
'datetimetz',
|
||||
'datetimetz_immutable',
|
||||
'timestamp',
|
||||
'zenddate',
|
||||
);
|
||||
|
||||
public static function validateField(ClassMetadata $meta, $field)
|
||||
{
|
||||
if ($meta->isMappedSuperclass) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fieldMapping = $meta->getFieldMapping($field);
|
||||
|
||||
if (!in_array($fieldMapping['type'], self::$validTypes)) {
|
||||
throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s',
|
||||
$field,
|
||||
$fieldMapping['type'],
|
||||
implode(', ', self::$validTypes),
|
||||
$meta->name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Query\TreeWalker\Exec;
|
||||
|
||||
use Doctrine\ORM\Query\Exec\MultiTableDeleteExecutor as BaseMultiTableDeleteExecutor;
|
||||
use Doctrine\ORM\Query\AST\Node;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
|
||||
/**
|
||||
* This class is used when a DELETE DQL query is called for entities
|
||||
* that are part of an inheritance tree
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
class MultiTableDeleteExecutor extends BaseMultiTableDeleteExecutor
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __construct(Node $AST, $sqlWalker, ClassMetadataInfo $meta, AbstractPlatform $platform, array $config)
|
||||
{
|
||||
parent::__construct($AST, $sqlWalker);
|
||||
|
||||
$reflProp = new \ReflectionProperty(get_class($this), '_sqlStatements');
|
||||
$reflProp->setAccessible(true);
|
||||
|
||||
$sqlStatements = $reflProp->getValue($this);
|
||||
|
||||
foreach ($sqlStatements as $index => $stmt) {
|
||||
$matches = array();
|
||||
preg_match('/DELETE FROM (\w+) .+/', $stmt, $matches);
|
||||
|
||||
if (isset($matches[1]) && $meta->getQuotedTableName($platform) === $matches[1]) {
|
||||
$sqlStatements[$index] = str_replace('DELETE FROM', 'UPDATE', $stmt);
|
||||
$sqlStatements[$index] = str_replace(
|
||||
'WHERE',
|
||||
'SET '.$config['fieldName'].' = '.$platform->getCurrentTimestampSQL().' WHERE',
|
||||
$sqlStatements[$index]
|
||||
);
|
||||
} else {
|
||||
// We have to avoid the removal of registers of child entities of a SoftDeleteable entity
|
||||
unset($sqlStatements[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
$reflProp->setValue($this, $sqlStatements);
|
||||
}
|
||||
}
|
||||
139
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Query/TreeWalker/SoftDeleteableWalker.php
vendored
Normal file
139
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Query/TreeWalker/SoftDeleteableWalker.php
vendored
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Query\TreeWalker;
|
||||
|
||||
use Doctrine\ORM\Query\SqlWalker;
|
||||
use Doctrine\ORM\Query\AST\DeleteStatement;
|
||||
use Doctrine\ORM\Query\AST\DeleteClause;
|
||||
use Doctrine\ORM\Query\Exec\SingleTableDeleteUpdateExecutor;
|
||||
use Gedmo\SoftDeleteable\SoftDeleteableListener;
|
||||
use Gedmo\SoftDeleteable\Query\TreeWalker\Exec\MultiTableDeleteExecutor;
|
||||
|
||||
/**
|
||||
* This SqlWalker is needed when you need to use a DELETE DQL query.
|
||||
* It will update the "deletedAt" field with the actual date, instead
|
||||
* of actually deleting it.
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
class SoftDeleteableWalker extends SqlWalker
|
||||
{
|
||||
protected $conn;
|
||||
protected $platform;
|
||||
protected $listener;
|
||||
protected $configuration;
|
||||
protected $alias;
|
||||
protected $deletedAtField;
|
||||
protected $meta;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __construct($query, $parserResult, array $queryComponents)
|
||||
{
|
||||
parent::__construct($query, $parserResult, $queryComponents);
|
||||
|
||||
$this->conn = $this->getConnection();
|
||||
$this->platform = $this->conn->getDatabasePlatform();
|
||||
$this->listener = $this->getSoftDeleteableListener();
|
||||
$this->extractComponents($queryComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getExecutor($AST)
|
||||
{
|
||||
switch (true) {
|
||||
case ($AST instanceof DeleteStatement):
|
||||
$primaryClass = $this->getEntityManager()->getClassMetadata($AST->deleteClause->abstractSchemaName);
|
||||
|
||||
return ($primaryClass->isInheritanceTypeJoined())
|
||||
? new MultiTableDeleteExecutor($AST, $this, $this->meta, $this->platform, $this->configuration)
|
||||
: new SingleTableDeleteUpdateExecutor($AST, $this);
|
||||
default:
|
||||
throw new \Gedmo\Exception\UnexpectedValueException('SoftDeleteable walker should be used only on delete statement');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change a DELETE clause for an UPDATE clause
|
||||
*
|
||||
* @param DeleteClause $deleteClause
|
||||
*
|
||||
* @return string The SQL.
|
||||
*/
|
||||
public function walkDeleteClause(DeleteClause $deleteClause)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$class = $em->getClassMetadata($deleteClause->abstractSchemaName);
|
||||
$tableName = $class->getTableName();
|
||||
$this->setSQLTableAlias($tableName, $tableName, $deleteClause->aliasIdentificationVariable);
|
||||
$quotedTableName = $class->getQuotedTableName($this->platform);
|
||||
$quotedColumnName = $class->getQuotedColumnName($this->deletedAtField, $this->platform);
|
||||
|
||||
$sql = 'UPDATE '.$quotedTableName.' SET '.$quotedColumnName.' = '.$this->platform->getCurrentTimestampSQL();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently used SoftDeleteableListener
|
||||
*
|
||||
* @throws \Gedmo\Exception\RuntimeException - if listener is not found
|
||||
*
|
||||
* @return SoftDeleteableListener
|
||||
*/
|
||||
private function getSoftDeleteableListener()
|
||||
{
|
||||
if (is_null($this->listener)) {
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
foreach ($em->getEventManager()->getListeners() as $event => $listeners) {
|
||||
foreach ($listeners as $hash => $listener) {
|
||||
if ($listener instanceof SoftDeleteableListener) {
|
||||
$this->listener = $listener;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($this->listener) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($this->listener)) {
|
||||
throw new \Gedmo\Exception\RuntimeException('The SoftDeleteable listener could not be found.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for components in the delete clause
|
||||
*
|
||||
* @param array $queryComponents
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function extractComponents(array $queryComponents)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
foreach ($queryComponents as $alias => $comp) {
|
||||
if (!isset($comp['metadata'])) {
|
||||
continue;
|
||||
}
|
||||
$meta = $comp['metadata'];
|
||||
$config = $this->listener->getConfiguration($em, $meta->name);
|
||||
if ($config && isset($config['softDeleteable']) && $config['softDeleteable']) {
|
||||
$this->configuration = $config;
|
||||
$this->deletedAtField = $config['fieldName'];
|
||||
$this->meta = $meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/SoftDeleteable.php
vendored
Normal file
27
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/SoftDeleteable.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable;
|
||||
|
||||
/**
|
||||
* This interface is not necessary but can be implemented for
|
||||
* Domain Objects which in some cases needs to be identified as
|
||||
* SoftDeleteable
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
interface SoftDeleteable
|
||||
{
|
||||
// this interface is not necessary to implement
|
||||
|
||||
/**
|
||||
* @gedmo:SoftDeleteable
|
||||
* to mark the class as SoftDeleteable use class annotation @gedmo:SoftDeleteable
|
||||
* this object will be able to be soft deleted
|
||||
* example:
|
||||
*
|
||||
* @gedmo:SoftDeleteable
|
||||
* class MyEntity
|
||||
*/
|
||||
}
|
||||
119
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/SoftDeleteableListener.php
vendored
Normal file
119
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/SoftDeleteableListener.php
vendored
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable;
|
||||
|
||||
use Gedmo\Mapping\MappedEventSubscriber;
|
||||
use Doctrine\Common\EventArgs;
|
||||
use Doctrine\ODM\MongoDB\UnitOfWork as MongoDBUnitOfWork;
|
||||
|
||||
/**
|
||||
* SoftDeleteable listener
|
||||
*
|
||||
* @author Gustavo Falco <comfortablynumb84@gmail.com>
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
class SoftDeleteableListener extends MappedEventSubscriber
|
||||
{
|
||||
/**
|
||||
* Pre soft-delete event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PRE_SOFT_DELETE = "preSoftDelete";
|
||||
|
||||
/**
|
||||
* Post soft-delete event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const POST_SOFT_DELETE = "postSoftDelete";
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'loadClassMetadata',
|
||||
'onFlush',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If it's a SoftDeleteable object, update the "deletedAt" field
|
||||
* and skip the removal of the object
|
||||
*
|
||||
* @param EventArgs $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onFlush(EventArgs $args)
|
||||
{
|
||||
$ea = $this->getEventAdapter($args);
|
||||
$om = $ea->getObjectManager();
|
||||
$uow = $om->getUnitOfWork();
|
||||
$evm = $om->getEventManager();
|
||||
|
||||
//getScheduledDocumentDeletions
|
||||
foreach ($ea->getScheduledObjectDeletions($uow) as $object) {
|
||||
$meta = $om->getClassMetadata(get_class($object));
|
||||
$config = $this->getConfiguration($om, $meta->name);
|
||||
|
||||
if (isset($config['softDeleteable']) && $config['softDeleteable']) {
|
||||
$reflProp = $meta->getReflectionProperty($config['fieldName']);
|
||||
$oldValue = $reflProp->getValue($object);
|
||||
$date = new \DateTime();
|
||||
|
||||
// Remove `$oldValue instanceof \DateTime` check when PHP version is bumped to >=5.5
|
||||
if (isset($config['hardDelete']) && $config['hardDelete'] && ($oldValue instanceof \DateTime || $oldValue instanceof \DateTimeInterface) && $oldValue <= $date) {
|
||||
continue; // want to hard delete
|
||||
}
|
||||
|
||||
$evm->dispatchEvent(
|
||||
self::PRE_SOFT_DELETE,
|
||||
$ea->createLifecycleEventArgsInstance($object, $om)
|
||||
);
|
||||
|
||||
|
||||
$reflProp->setValue($object, $date);
|
||||
|
||||
$om->persist($object);
|
||||
$uow->propertyChanged($object, $config['fieldName'], $oldValue, $date);
|
||||
if ($uow instanceof MongoDBUnitOfWork && !method_exists($uow, 'scheduleExtraUpdate')) {
|
||||
$ea->recomputeSingleObjectChangeSet($uow, $meta, $object);
|
||||
} else {
|
||||
$uow->scheduleExtraUpdate($object, array(
|
||||
$config['fieldName'] => array($oldValue, $date),
|
||||
));
|
||||
}
|
||||
|
||||
$evm->dispatchEvent(
|
||||
self::POST_SOFT_DELETE,
|
||||
$ea->createLifecycleEventArgsInstance($object, $om)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps additional metadata
|
||||
*
|
||||
* @param EventArgs $eventArgs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadClassMetadata(EventArgs $eventArgs)
|
||||
{
|
||||
$ea = $this->getEventAdapter($eventArgs);
|
||||
$this->loadMetadataForObjectClass($ea->getObjectManager(), $eventArgs->getClassMetadata());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getNamespace()
|
||||
{
|
||||
return __NAMESPACE__;
|
||||
}
|
||||
}
|
||||
51
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Traits/SoftDeleteable.php
vendored
Normal file
51
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Traits/SoftDeleteable.php
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Traits;
|
||||
|
||||
/**
|
||||
* SoftDeletable Trait, usable with PHP >= 5.4
|
||||
*
|
||||
* @author Wesley van Opdorp <wesley.van.opdorp@freshheads.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
trait SoftDeleteable
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $deletedAt;
|
||||
|
||||
/**
|
||||
* Sets deletedAt.
|
||||
*
|
||||
* @param \DateTime|null $deletedAt
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeletedAt(\DateTime $deletedAt = null)
|
||||
{
|
||||
$this->deletedAt = $deletedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns deletedAt.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDeletedAt()
|
||||
{
|
||||
return $this->deletedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is deleted?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeleted()
|
||||
{
|
||||
return null !== $this->deletedAt;
|
||||
}
|
||||
}
|
||||
54
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Traits/SoftDeleteableDocument.php
vendored
Normal file
54
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Traits/SoftDeleteableDocument.php
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Traits;
|
||||
|
||||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
|
||||
|
||||
/**
|
||||
* SoftDeletable Trait, usable with PHP >= 5.4
|
||||
*
|
||||
* @author Wesley van Opdorp <wesley.van.opdorp@freshheads.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
trait SoftDeleteableDocument
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @ODM\Field(type="date")
|
||||
*/
|
||||
protected $deletedAt;
|
||||
|
||||
/**
|
||||
* Sets deletedAt.
|
||||
*
|
||||
* @param \DateTime|null $deletedAt
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeletedAt(\DateTime $deletedAt = null)
|
||||
{
|
||||
$this->deletedAt = $deletedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns deletedAt.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDeletedAt()
|
||||
{
|
||||
return $this->deletedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is deleted?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeleted()
|
||||
{
|
||||
return null !== $this->deletedAt;
|
||||
}
|
||||
}
|
||||
54
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Traits/SoftDeleteableEntity.php
vendored
Normal file
54
vendor/gedmo/doctrine-extensions/lib/Gedmo/SoftDeleteable/Traits/SoftDeleteableEntity.php
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\SoftDeleteable\Traits;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* SoftDeletable Trait, usable with PHP >= 5.4
|
||||
*
|
||||
* @author Wesley van Opdorp <wesley.van.opdorp@freshheads.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
trait SoftDeleteableEntity
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
protected $deletedAt;
|
||||
|
||||
/**
|
||||
* Sets deletedAt.
|
||||
*
|
||||
* @param \DateTime|null $deletedAt
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDeletedAt(\DateTime $deletedAt = null)
|
||||
{
|
||||
$this->deletedAt = $deletedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns deletedAt.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDeletedAt()
|
||||
{
|
||||
return $this->deletedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is deleted?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeleted()
|
||||
{
|
||||
return null !== $this->deletedAt;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue