Release 2.9.0 (#4526)

* added fix to work around bc break in new phpword version
* fix phpoffice deprecations
* mark unused option as deprecated
* support for DateTimeInterface and DateTimeImmutable where possible
* use TRUSTED_PROXIES setting - fixes #4533
* re-enable Kimai test in docker test build script (#4541)
* bump dependencies
This commit is contained in:
Kevin Papst
2024-01-10 12:43:07 +01:00
committed by GitHub
parent c6a651456e
commit 6531e7fe52
46 changed files with 487 additions and 485 deletions

View File

@@ -16,7 +16,8 @@ use App\Model\ActivityBudgetStatisticModel;
use App\Model\ActivityStatistic;
use App\Repository\TimesheetRepository;
use App\Timesheet\DateTimeFactory;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -26,19 +27,15 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class ActivityStatisticService
{
public function __construct(private TimesheetRepository $timesheetRepository, private EventDispatcherInterface $dispatcher)
public function __construct(private readonly TimesheetRepository $timesheetRepository, private readonly EventDispatcherInterface $dispatcher)
{
}
/**
* WARNING: this method does not respect the budget type. Your results will always be wither the "full lifetime data" or the "selected date-range".
*
* @param Activity $activity
* @param DateTime|null $begin
* @param DateTime|null $end
* @return ActivityStatistic
* WARNING: this method does not respect the budget type.
* Your results will always be with the "full lifetime data" or the "selected date-range".
*/
public function getActivityStatistics(Activity $activity, ?DateTime $begin = null, ?DateTime $end = null): ActivityStatistic
public function getActivityStatistics(Activity $activity, ?DateTimeInterface $begin = null, ?DateTimeInterface $end = null): ActivityStatistic
{
$statistics = $this->getBudgetStatistic([$activity], $begin, $end);
$event = new ActivityStatisticEvent($activity, array_pop($statistics), $begin, $end);
@@ -47,7 +44,7 @@ class ActivityStatisticService
return $event->getStatistic();
}
public function getBudgetStatisticModel(Activity $activity, DateTime $today): ActivityBudgetStatisticModel
public function getBudgetStatisticModel(Activity $activity, DateTimeInterface $today): ActivityBudgetStatisticModel
{
$stats = new ActivityBudgetStatisticModel($activity);
$stats->setStatisticTotal($this->getActivityStatistics($activity));
@@ -68,10 +65,9 @@ class ActivityStatisticService
/**
* @param Activity[] $activities
* @param DateTime $today
* @return ActivityBudgetStatisticModel[]
*/
public function getBudgetStatisticModelForActivities(array $activities, DateTime $today): array
public function getBudgetStatisticModelForActivities(array $activities, DateTimeInterface $today): array
{
$models = [];
$monthly = [];
@@ -121,11 +117,9 @@ class ActivityStatisticService
/**
* @param Activity[] $activities
* @param DateTime|null $begin
* @param DateTime|null $end
* @return array<int, ActivityStatistic>
*/
private function getBudgetStatistic(array $activities, ?DateTime $begin = null, ?DateTime $end = null): array
private function getBudgetStatistic(array $activities, ?DateTimeInterface $begin = null, ?DateTimeInterface $end = null): array
{
$statistics = [];
foreach ($activities as $activity) {
@@ -139,25 +133,25 @@ class ActivityStatisticService
if (null !== $result) {
foreach ($result as $resultRow) {
$statistic = $statistics[$resultRow['id']];
$statistic->setDuration($statistic->getDuration() + $resultRow['duration']);
$statistic->setRate($statistic->getRate() + $resultRow['rate']);
$statistic->setInternalRate($statistic->getInternalRate() + $resultRow['internalRate']);
$statistic->setCounter($statistic->getCounter() + $resultRow['counter']);
$statistic->addDuration((int) $resultRow['duration']);
$statistic->addRate((float) $resultRow['rate']);
$statistic->addInternalRate((float) $resultRow['internalRate']);
$statistic->addCounter((int) $resultRow['counter']);
if ($resultRow['billable']) {
$statistic->setDurationBillable($statistic->getDurationBillable() + $resultRow['duration']);
$statistic->setRateBillable($statistic->getRateBillable() + $resultRow['rate']);
$statistic->setInternalRateBillable($statistic->getInternalRateBillable() + $resultRow['internalRate']);
$statistic->setCounterBillable($statistic->getCounterBillable() + $resultRow['counter']);
$statistic->addDurationBillable((int) $resultRow['duration']);
$statistic->addRateBillable((float) $resultRow['rate']);
$statistic->addInternalRateBillable((float) $resultRow['internalRate']);
$statistic->addCounterBillable((int) $resultRow['counter']);
if ($resultRow['exported']) {
$statistic->setDurationBillableExported($statistic->getDurationBillableExported() + $resultRow['duration']);
$statistic->setRateBillableExported($statistic->getRateBillableExported() + $resultRow['rate']);
$statistic->addDurationBillableExported((int) $resultRow['duration']);
$statistic->addRateBillableExported((float) $resultRow['rate']);
}
}
if ($resultRow['exported']) {
$statistic->setDurationExported($statistic->getDurationExported() + $resultRow['duration']);
$statistic->setRateExported($statistic->getRateExported() + $resultRow['rate']);
$statistic->setInternalRateExported($statistic->getInternalRateExported() + $resultRow['internalRate']);
$statistic->setCounterExported($statistic->getCounterExported() + $resultRow['counter']);
$statistic->addDurationExported((int) $resultRow['duration']);
$statistic->addRateExported((float) $resultRow['rate']);
$statistic->addInternalRateExported((float) $resultRow['internalRate']);
$statistic->addCounterExported((int) $resultRow['counter']);
}
}
}
@@ -165,7 +159,7 @@ class ActivityStatisticService
return $statistics;
}
private function createStatisticQueryBuilder(array $activities, DateTime $begin = null, ?DateTime $end = null): QueryBuilder
private function createStatisticQueryBuilder(array $activities, \DateTimeInterface $begin = null, ?\DateTimeInterface $end = null): QueryBuilder
{
$qb = $this->timesheetRepository->createQueryBuilder('t');
$qb
@@ -187,14 +181,14 @@ class ActivityStatisticService
if ($begin !== null) {
$qb
->andWhere($qb->expr()->gte('t.begin', ':begin'))
->setParameter('begin', $begin, Types::DATETIME_MUTABLE)
->setParameter('begin', DateTimeImmutable::createFromInterface($begin), Types::DATETIME_IMMUTABLE)
;
}
if ($end !== null) {
$qb
->andWhere($qb->expr()->lte('t.begin', ':end'))
->setParameter('end', $end, Types::DATETIME_MUTABLE)
->setParameter('end', DateTimeImmutable::createFromInterface($end), Types::DATETIME_IMMUTABLE)
;
}