init without trunk
This commit is contained in:
parent
ed24ac4994
commit
bb809e7233
14652 changed files with 177862 additions and 94817 deletions
27
vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity/LogEntry.php
vendored
Normal file
27
vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity/LogEntry.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\Loggable\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Gedmo\Loggable\Entity\LogEntry
|
||||
*
|
||||
* @ORM\Table(
|
||||
* name="ext_log_entries",
|
||||
* options={"row_format":"DYNAMIC"},
|
||||
* indexes={
|
||||
* @ORM\Index(name="log_class_lookup_idx", columns={"object_class"}),
|
||||
* @ORM\Index(name="log_date_lookup_idx", columns={"logged_at"}),
|
||||
* @ORM\Index(name="log_user_lookup_idx", columns={"username"}),
|
||||
* @ORM\Index(name="log_version_lookup_idx", columns={"object_id", "object_class", "version"})
|
||||
* }
|
||||
* )
|
||||
* @ORM\Entity(repositoryClass="Gedmo\Loggable\Entity\Repository\LogEntryRepository")
|
||||
*/
|
||||
class LogEntry extends MappedSuperclass\AbstractLogEntry
|
||||
{
|
||||
/**
|
||||
* All required columns are mapped through inherited superclass
|
||||
*/
|
||||
}
|
||||
219
vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity/MappedSuperclass/AbstractLogEntry.php
vendored
Normal file
219
vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity/MappedSuperclass/AbstractLogEntry.php
vendored
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\Loggable\Entity\MappedSuperclass;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Gedmo\Loggable\Entity\AbstractLog
|
||||
*
|
||||
* @ORM\MappedSuperclass
|
||||
*/
|
||||
abstract class AbstractLogEntry
|
||||
{
|
||||
/**
|
||||
* @var integer $id
|
||||
*
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string $action
|
||||
*
|
||||
* @ORM\Column(type="string", length=8)
|
||||
*/
|
||||
protected $action;
|
||||
|
||||
/**
|
||||
* @var \DateTime $loggedAt
|
||||
*
|
||||
* @ORM\Column(name="logged_at", type="datetime")
|
||||
*/
|
||||
protected $loggedAt;
|
||||
|
||||
/**
|
||||
* @var string $objectId
|
||||
*
|
||||
* @ORM\Column(name="object_id", length=64, nullable=true)
|
||||
*/
|
||||
protected $objectId;
|
||||
|
||||
/**
|
||||
* @var string $objectClass
|
||||
*
|
||||
* @ORM\Column(name="object_class", type="string", length=255)
|
||||
*/
|
||||
protected $objectClass;
|
||||
|
||||
/**
|
||||
* @var integer $version
|
||||
*
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* @var array $data
|
||||
*
|
||||
* @ORM\Column(type="array", nullable=true)
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @var string $data
|
||||
*
|
||||
* @ORM\Column(length=255, nullable=true)
|
||||
*/
|
||||
protected $username;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAction()
|
||||
{
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set action
|
||||
*
|
||||
* @param string $action
|
||||
*/
|
||||
public function setAction($action)
|
||||
{
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getObjectClass()
|
||||
{
|
||||
return $this->objectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set object class
|
||||
*
|
||||
* @param string $objectClass
|
||||
*/
|
||||
public function setObjectClass($objectClass)
|
||||
{
|
||||
$this->objectClass = $objectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getObjectId()
|
||||
{
|
||||
return $this->objectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set object id
|
||||
*
|
||||
* @param string $objectId
|
||||
*/
|
||||
public function setObjectId($objectId)
|
||||
{
|
||||
$this->objectId = $objectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get username
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set username
|
||||
*
|
||||
* @param string $username
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get loggedAt
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getLoggedAt()
|
||||
{
|
||||
return $this->loggedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set loggedAt to "now"
|
||||
*/
|
||||
public function setLoggedAt()
|
||||
{
|
||||
$this->loggedAt = new \DateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set data
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current version
|
||||
*
|
||||
* @param integer $version
|
||||
*/
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current version
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
}
|
||||
164
vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity/Repository/LogEntryRepository.php
vendored
Normal file
164
vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity/Repository/LogEntryRepository.php
vendored
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
namespace Gedmo\Loggable\Entity\Repository;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Query;
|
||||
use Gedmo\Loggable\Entity\LogEntry;
|
||||
use Gedmo\Tool\Wrapper\EntityWrapper;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Gedmo\Loggable\LoggableListener;
|
||||
|
||||
/**
|
||||
* The LogEntryRepository has some useful functions
|
||||
* to interact with log entries.
|
||||
*
|
||||
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
class LogEntryRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
* Currently used loggable listener
|
||||
*
|
||||
* @var LoggableListener
|
||||
*/
|
||||
private $listener;
|
||||
|
||||
/**
|
||||
* Loads all log entries for the given entity
|
||||
*
|
||||
* @param object $entity
|
||||
*
|
||||
* @return LogEntry[]
|
||||
*/
|
||||
public function getLogEntries($entity)
|
||||
{
|
||||
$q = $this->getLogEntriesQuery($entity);
|
||||
|
||||
return $q->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query for loading of log entries
|
||||
*
|
||||
* @param object $entity
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
public function getLogEntriesQuery($entity)
|
||||
{
|
||||
$wrapped = new EntityWrapper($entity, $this->_em);
|
||||
$objectClass = $wrapped->getMetadata()->name;
|
||||
$meta = $this->getClassMetadata();
|
||||
$dql = "SELECT log FROM {$meta->name} log";
|
||||
$dql .= " WHERE log.objectId = :objectId";
|
||||
$dql .= " AND log.objectClass = :objectClass";
|
||||
$dql .= " ORDER BY log.version DESC";
|
||||
|
||||
$objectId = (string) $wrapped->getIdentifier();
|
||||
$q = $this->_em->createQuery($dql);
|
||||
$q->setParameters(compact('objectId', 'objectClass'));
|
||||
|
||||
return $q;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts given $entity to $revision by
|
||||
* restoring all fields from that $revision.
|
||||
* After this operation you will need to
|
||||
* persist and flush the $entity.
|
||||
*
|
||||
* @param object $entity
|
||||
* @param integer $version
|
||||
*
|
||||
* @throws \Gedmo\Exception\UnexpectedValueException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function revert($entity, $version = 1)
|
||||
{
|
||||
$wrapped = new EntityWrapper($entity, $this->_em);
|
||||
$objectMeta = $wrapped->getMetadata();
|
||||
$objectClass = $objectMeta->name;
|
||||
$meta = $this->getClassMetadata();
|
||||
$dql = "SELECT log FROM {$meta->name} log";
|
||||
$dql .= " WHERE log.objectId = :objectId";
|
||||
$dql .= " AND log.objectClass = :objectClass";
|
||||
$dql .= " AND log.version <= :version";
|
||||
$dql .= " ORDER BY log.version ASC";
|
||||
|
||||
$objectId = (string) $wrapped->getIdentifier();
|
||||
$q = $this->_em->createQuery($dql);
|
||||
$q->setParameters(compact('objectId', 'objectClass', 'version'));
|
||||
$logs = $q->getResult();
|
||||
|
||||
if ($logs) {
|
||||
$config = $this->getLoggableListener()->getConfiguration($this->_em, $objectMeta->name);
|
||||
$fields = $config['versioned'];
|
||||
$filled = false;
|
||||
while (($log = array_pop($logs)) && !$filled) {
|
||||
if ($data = $log->getData()) {
|
||||
foreach ($data as $field => $value) {
|
||||
if (in_array($field, $fields)) {
|
||||
$this->mapValue($objectMeta, $field, $value);
|
||||
$wrapped->setPropertyValue($field, $value);
|
||||
unset($fields[array_search($field, $fields)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$filled = count($fields) === 0;
|
||||
}
|
||||
/*if (count($fields)) {
|
||||
throw new \Gedmo\Exception\UnexpectedValueException('Could not fully revert the entity to version: '.$version);
|
||||
}*/
|
||||
} else {
|
||||
throw new \Gedmo\Exception\UnexpectedValueException('Could not find any log entries under version: '.$version);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMetadata $objectMeta
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function mapValue(ClassMetadata $objectMeta, $field, &$value)
|
||||
{
|
||||
if (!$objectMeta->isSingleValuedAssociation($field)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mapping = $objectMeta->getAssociationMapping($field);
|
||||
$value = $value ? $this->_em->getReference($mapping['targetEntity'], $value) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently used LoggableListener
|
||||
*
|
||||
* @throws \Gedmo\Exception\RuntimeException - if listener is not found
|
||||
*
|
||||
* @return LoggableListener
|
||||
*/
|
||||
private function getLoggableListener()
|
||||
{
|
||||
if (is_null($this->listener)) {
|
||||
foreach ($this->_em->getEventManager()->getListeners() as $event => $listeners) {
|
||||
foreach ($listeners as $hash => $listener) {
|
||||
if ($listener instanceof LoggableListener) {
|
||||
$this->listener = $listener;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($this->listener) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($this->listener)) {
|
||||
throw new \Gedmo\Exception\RuntimeException('The loggable listener could not be found');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->listener;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue