Fixed coding style.

This commit is contained in:
Jan Böhmer 2020-03-15 13:56:31 +01:00
parent 24939f2342
commit fd61c8d9e2
129 changed files with 962 additions and 1091 deletions

View file

@ -49,8 +49,6 @@ use App\Entity\LogSystem\ElementCreatedLogEntry;
use App\Entity\LogSystem\ElementDeletedLogEntry;
use App\Entity\LogSystem\ElementEditedLogEntry;
use App\Entity\UserSystem\User;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
class LogEntryRepository extends DBElementRepository
{
@ -72,9 +70,9 @@ class LogEntryRepository extends DBElementRepository
* Find log entries associated with the given element (the history of the element).
*
* @param AbstractDBElement $element The element for which the history should be generated
* @param string $order By default newest entries are shown first. Change this to ASC to show oldest entries first.
* @param null $limit
* @param null $offset
* @param string $order By default newest entries are shown first. Change this to ASC to show oldest entries first.
* @param null $limit
* @param null $offset
*
* @return AbstractLogEntry[]
*/
@ -84,9 +82,11 @@ class LogEntryRepository extends DBElementRepository
}
/**
* Try to get a log entry that contains the information to undete a given element
* @param string $class The class of the element that should be undeleted
* @param int $id The ID of the element that should be deleted
* Try to get a log entry that contains the information to undete a given element.
*
* @param string $class The class of the element that should be undeleted
* @param int $id The ID of the element that should be deleted
*
* @return ElementDeletedLogEntry
*/
public function getUndeleteDataForElement(string $class, int $id): ElementDeletedLogEntry
@ -94,31 +94,34 @@ class LogEntryRepository extends DBElementRepository
$qb = $this->createQueryBuilder('log');
$qb->select('log')
//->where('log INSTANCE OF App\Entity\LogSystem\ElementEditedLogEntry')
->where('log INSTANCE OF ' . ElementDeletedLogEntry::class)
->where('log INSTANCE OF '.ElementDeletedLogEntry::class)
->andWhere('log.target_type = :target_type')
->andWhere('log.target_id = :target_id')
->orderBy('log.timestamp', 'DESC')
->setMaxResults(1);
$qb->setParameters([
'target_type' => AbstractLogEntry::targetTypeClassToID($class),
'target_id' => $id,
]);
'target_type' => AbstractLogEntry::targetTypeClassToID($class),
'target_id' => $id,
]);
$query = $qb->getQuery();
$query = $qb->getQuery();
$results = $query->execute();
if (empty($results)) {
throw new \RuntimeException("No undelete data could be found for this element");
throw new \RuntimeException('No undelete data could be found for this element');
}
return $results[0];
}
/**
* Gets all log entries that are related to time travelling
* @param AbstractDBElement $element The element for which the time travel data should be retrieved
* @param \DateTime $until Back to which timestamp should the data be get (including the timestamp)
* Gets all log entries that are related to time travelling.
*
* @param AbstractDBElement $element The element for which the time travel data should be retrieved
* @param \DateTime $until Back to which timestamp should the data be get (including the timestamp)
*
* @return AbstractLogEntry[]
*/
public function getTimetravelDataForElement(AbstractDBElement $element, \DateTime $until): array
@ -126,48 +129,49 @@ class LogEntryRepository extends DBElementRepository
$qb = $this->createQueryBuilder('log');
$qb->select('log')
//->where('log INSTANCE OF App\Entity\LogSystem\ElementEditedLogEntry')
->where('log INSTANCE OF ' . ElementEditedLogEntry::class)
->orWhere('log INSTANCE OF ' . CollectionElementDeleted::class)
->where('log INSTANCE OF '.ElementEditedLogEntry::class)
->orWhere('log INSTANCE OF '.CollectionElementDeleted::class)
->andWhere('log.target_type = :target_type')
->andWhere('log.target_id = :target_id')
->andWhere('log.timestamp >= :until')
->orderBy('log.timestamp', 'DESC');
$qb->setParameters([
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_id' => $element->getID(),
'until' => $until
]);
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_id' => $element->getID(),
'until' => $until,
]);
$query = $qb->getQuery();
return $query->execute();
}
/**
* Check if the given element has existed at the given timestamp
* @param AbstractDBElement $element
* @param \DateTime $timestamp
* Check if the given element has existed at the given timestamp.
*
* @return bool True if the element existed at the given timestamp
*/
public function getElementExistedAtTimestamp(AbstractDBElement $element, \DateTime $timestamp): bool
{
$qb = $this->createQueryBuilder('log');
$qb->select('count(log)')
->where('log INSTANCE OF ' . ElementCreatedLogEntry::class)
->where('log INSTANCE OF '.ElementCreatedLogEntry::class)
->andWhere('log.target_type = :target_type')
->andWhere('log.target_id = :target_id')
->andWhere('log.timestamp >= :until')
->orderBy('log.timestamp', 'DESC');
$qb->setParameters([
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_id' => $element->getID(),
'until' => $timestamp
]);
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_id' => $element->getID(),
'until' => $timestamp,
]);
$query = $qb->getQuery();
$count = $query->getSingleScalarResult();
return !($count > 0);
return ! ($count > 0);
}
/**
@ -187,9 +191,9 @@ class LogEntryRepository extends DBElementRepository
/**
* Gets the target element associated with the logentry.
*
* @param AbstractLogEntry $logEntry
* @return AbstractDBElement|null Returns the associated DBElement or null if the log either has no target or the element
* was deleted from DB.
* was deleted from DB.
*
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
@ -206,34 +210,9 @@ class LogEntryRepository extends DBElementRepository
return $this->getEntityManager()->find($class, $id);
}
protected function getLastUser(AbstractDBElement $element, string $class)
{
$qb = $this->createQueryBuilder('log');
$qb->select('log')
//->where('log INSTANCE OF App\Entity\LogSystem\ElementEditedLogEntry')
->where('log INSTANCE OF ' . $class)
->andWhere('log.target_type = :target_type')
->andWhere('log.target_id = :target_id')
->orderBy('log.timestamp', 'DESC');
$qb->setParameters([
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_id' => $element->getID()
]);
$query = $qb->getQuery();
$query->setMaxResults(1);
/** @var AbstractLogEntry[] $results */
$results = $query->execute();
if (isset($results[0])) {
return $results[0]->getUser();
}
return null;
}
/**
* Returns the last user that has edited the given element.
* @param AbstractDBElement $element
*
* @return User|null A user object, or null if no user could be determined.
*/
public function getLastEditingUser(AbstractDBElement $element): ?User
@ -243,11 +222,37 @@ class LogEntryRepository extends DBElementRepository
/**
* Returns the user that has created the given element.
* @param AbstractDBElement $element
*
* @return User|null A user object, or null if no user could be determined.
*/
public function getCreatingUser(AbstractDBElement $element): ?User
{
return $this->getLastUser($element, ElementCreatedLogEntry::class);
}
protected function getLastUser(AbstractDBElement $element, string $class)
{
$qb = $this->createQueryBuilder('log');
$qb->select('log')
//->where('log INSTANCE OF App\Entity\LogSystem\ElementEditedLogEntry')
->where('log INSTANCE OF '.$class)
->andWhere('log.target_type = :target_type')
->andWhere('log.target_id = :target_id')
->orderBy('log.timestamp', 'DESC');
$qb->setParameters([
'target_type' => AbstractLogEntry::targetTypeClassToID(get_class($element)),
'target_id' => $element->getID(),
]);
$query = $qb->getQuery();
$query->setMaxResults(1);
/** @var AbstractLogEntry[] $results */
$results = $query->execute();
if (isset($results[0])) {
return $results[0]->getUser();
}
return null;
}
}