fixed restart timesheet with tags with active record (#1622)
This commit is contained in:
@@ -434,7 +434,7 @@ class TimesheetController extends BaseApiController
|
|||||||
return $this->viewHandler->handle($view);
|
return $this->viewHandler->handle($view);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->repository->save($timesheet);
|
$this->service->updateTimesheet($timesheet);
|
||||||
|
|
||||||
$view = new View($timesheet, Response::HTTP_OK);
|
$view = new View($timesheet, Response::HTTP_OK);
|
||||||
$view->getContext()->setGroups(['Default', 'Entity', 'Timesheet']);
|
$view->getContext()->setGroups(['Default', 'Entity', 'Timesheet']);
|
||||||
@@ -759,7 +759,7 @@ class TimesheetController extends BaseApiController
|
|||||||
|
|
||||||
$timesheet->setExported(!$timesheet->isExported());
|
$timesheet->setExported(!$timesheet->isExported());
|
||||||
|
|
||||||
$this->repository->save($timesheet);
|
$this->service->updateTimesheet($timesheet);
|
||||||
|
|
||||||
$view = new View($timesheet, 200);
|
$view = new View($timesheet, 200);
|
||||||
$view->getContext()->setGroups(['Default', 'Entity', 'Timesheet']);
|
$view->getContext()->setGroups(['Default', 'Entity', 'Timesheet']);
|
||||||
@@ -812,7 +812,7 @@ class TimesheetController extends BaseApiController
|
|||||||
|
|
||||||
$meta->setValue($value);
|
$meta->setValue($value);
|
||||||
|
|
||||||
$this->repository->save($timesheet);
|
$this->service->updateTimesheet($timesheet);
|
||||||
|
|
||||||
$view = new View($timesheet, 200);
|
$view = new View($timesheet, 200);
|
||||||
$view->getContext()->setGroups(['Default', 'Entity', 'Timesheet']);
|
$view->getContext()->setGroups(['Default', 'Entity', 'Timesheet']);
|
||||||
|
|||||||
@@ -91,6 +91,25 @@ class TimesheetRepository extends EntityRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function add(Timesheet $timesheet, int $maxRunningEntries)
|
||||||
|
{
|
||||||
|
$em = $this->getEntityManager();
|
||||||
|
$em->beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (null === $timesheet->getEnd()) {
|
||||||
|
$this->stopActiveEntries($timesheet->getUser(), $maxRunningEntries, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$em->persist($timesheet);
|
||||||
|
$em->flush();
|
||||||
|
$em->commit();
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
$em->rollback();
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Timesheet $timesheet
|
* @param Timesheet $timesheet
|
||||||
* @throws \Doctrine\ORM\ORMException
|
* @throws \Doctrine\ORM\ORMException
|
||||||
@@ -126,12 +145,13 @@ class TimesheetRepository extends EntityRepository
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Timesheet $entry
|
* @param Timesheet $entry
|
||||||
|
* @param bool $flush
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
* @throws \Doctrine\ORM\ORMException
|
* @throws \Doctrine\ORM\ORMException
|
||||||
* @throws \Doctrine\ORM\OptimisticLockException
|
* @throws \Doctrine\ORM\OptimisticLockException
|
||||||
*/
|
*/
|
||||||
public function stopRecording(Timesheet $entry)
|
public function stopRecording(Timesheet $entry, bool $flush = true)
|
||||||
{
|
{
|
||||||
if (null !== $entry->getEnd()) {
|
if (null !== $entry->getEnd()) {
|
||||||
throw new RepositoryException('Timesheet entry already stopped');
|
throw new RepositoryException('Timesheet entry already stopped');
|
||||||
@@ -146,7 +166,9 @@ class TimesheetRepository extends EntityRepository
|
|||||||
|
|
||||||
$entityManager = $this->getEntityManager();
|
$entityManager = $this->getEntityManager();
|
||||||
$entityManager->persist($entry);
|
$entityManager->persist($entry);
|
||||||
|
if ($flush) {
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -486,12 +508,13 @@ class TimesheetRepository extends EntityRepository
|
|||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param int $hardLimit
|
* @param int $hardLimit
|
||||||
|
* @param bool $flush
|
||||||
* @return int
|
* @return int
|
||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
* @throws \Doctrine\ORM\ORMException
|
* @throws \Doctrine\ORM\ORMException
|
||||||
* @throws \Doctrine\ORM\OptimisticLockException
|
* @throws \Doctrine\ORM\OptimisticLockException
|
||||||
*/
|
*/
|
||||||
public function stopActiveEntries(User $user, int $hardLimit)
|
public function stopActiveEntries(User $user, int $hardLimit, bool $flush = true)
|
||||||
{
|
{
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
$activeEntries = $this->getActiveEntries($user);
|
$activeEntries = $this->getActiveEntries($user);
|
||||||
@@ -509,7 +532,7 @@ class TimesheetRepository extends EntityRepository
|
|||||||
throw new \Exception('timesheet.start.exceeded_limit');
|
throw new \Exception('timesheet.start.exceeded_limit');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->stopRecording($activeEntry);
|
$this->stopRecording($activeEntry, $flush);
|
||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ final class TimesheetService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls prepareNewTimesheet() automatically.
|
* Calls prepareNewTimesheet() automatically if $request is not null.
|
||||||
*
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param Request|null $request
|
* @param Request|null $request
|
||||||
@@ -96,21 +96,20 @@ final class TimesheetService
|
|||||||
throw new \InvalidArgumentException('Cannot create timesheet, already persisted');
|
throw new \InvalidArgumentException('Cannot create timesheet, already persisted');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $timesheet->getEnd()) {
|
if (null === $timesheet->getEnd() && !$this->auth->isGranted('start', $timesheet)) {
|
||||||
if (!$this->auth->isGranted('start', $timesheet)) {
|
|
||||||
throw new AccessDeniedHttpException('You are not allowed to start this timesheet record');
|
throw new AccessDeniedHttpException('You are not allowed to start this timesheet record');
|
||||||
}
|
}
|
||||||
$this->repository->stopActiveEntries(
|
|
||||||
$timesheet->getUser(),
|
|
||||||
$this->configuration->getActiveEntriesHardLimit()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->repository->save($timesheet);
|
$this->repository->add($timesheet, $this->configuration->getActiveEntriesHardLimit());
|
||||||
|
|
||||||
return $timesheet;
|
return $timesheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateTimesheet(Timesheet $timesheet)
|
||||||
|
{
|
||||||
|
return $this->repository->save($timesheet);
|
||||||
|
}
|
||||||
|
|
||||||
public function stopTimesheet(Timesheet $timesheet)
|
public function stopTimesheet(Timesheet $timesheet)
|
||||||
{
|
{
|
||||||
return $this->repository->stopRecording($timesheet);
|
return $this->repository->stopRecording($timesheet);
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ class HtmlRendererFactoryTest extends TestCase
|
|||||||
$this->createMock(ProjectRepository::class)
|
$this->createMock(ProjectRepository::class)
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @var HtmlRenderer $renderer */
|
|
||||||
$renderer = $sut->create('foo', 'bar.html.twig');
|
$renderer = $sut->create('foo', 'bar.html.twig');
|
||||||
|
|
||||||
self::assertInstanceOf(HtmlRenderer::class, $renderer);
|
self::assertInstanceOf(HtmlRenderer::class, $renderer);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
namespace App\Tests\Export\Renderer;
|
namespace App\Tests\Export\Renderer;
|
||||||
|
|
||||||
use App\Export\Renderer\HtmlRenderer;
|
|
||||||
use App\Export\Renderer\PDFRenderer;
|
use App\Export\Renderer\PDFRenderer;
|
||||||
use App\Export\Renderer\PdfRendererFactory;
|
use App\Export\Renderer\PdfRendererFactory;
|
||||||
use App\Repository\ProjectRepository;
|
use App\Repository\ProjectRepository;
|
||||||
@@ -32,7 +31,6 @@ class PdfRendererFactoryTest extends TestCase
|
|||||||
$this->createMock(ProjectRepository::class)
|
$this->createMock(ProjectRepository::class)
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @var HtmlRenderer $renderer */
|
|
||||||
$renderer = $sut->create('foo', 'bar.pdf.twig');
|
$renderer = $sut->create('foo', 'bar.pdf.twig');
|
||||||
|
|
||||||
self::assertInstanceOf(PDFRenderer::class, $renderer);
|
self::assertInstanceOf(PDFRenderer::class, $renderer);
|
||||||
|
|||||||
Reference in New Issue
Block a user