-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,044 additions
and
814 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\MbtBundle\Repository; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\DBAL\LockMode; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use Tienvx\Bundle\MbtBundle\Entity\Bug; | ||
use Tienvx\Bundle\MbtBundle\Model\BugInterface; | ||
|
||
class BugRepository extends ServiceEntityRepository implements BugRepositoryInterface | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Bug::class); | ||
} | ||
|
||
public function updateSteps(BugInterface $bug, array $newSteps): void | ||
{ | ||
$this->getEntityManager()->wrapInTransaction(function () use ($bug, $newSteps): void { | ||
// Refresh the bug for the latest steps's length. | ||
$this->getEntityManager()->refresh($bug); | ||
|
||
if (count($newSteps) <= count($bug->getSteps())) { | ||
$this->getEntityManager()->lock($bug, LockMode::PESSIMISTIC_WRITE); | ||
$bug->getProgress()->setTotal(0); | ||
$bug->getProgress()->setProcessed(0); | ||
$bug->setSteps($newSteps); | ||
} | ||
}); | ||
} | ||
|
||
public function increaseProcessed(BugInterface $bug, int $processed = 1): void | ||
{ | ||
$this->getEntityManager()->wrapInTransaction(function () use ($bug, $processed): void { | ||
// Refresh the bug for the latest progress. | ||
$this->getEntityManager()->refresh($bug); | ||
|
||
$this->getEntityManager()->lock($bug, LockMode::PESSIMISTIC_WRITE); | ||
$bug->getProgress()->increase($processed); | ||
}); | ||
} | ||
|
||
public function increaseTotal(BugInterface $bug, int $total): void | ||
{ | ||
$this->getEntityManager()->wrapInTransaction(function () use ($bug, $total): void { | ||
// Refresh the bug for the latest progress. | ||
$this->getEntityManager()->refresh($bug); | ||
|
||
$this->getEntityManager()->lock($bug, LockMode::PESSIMISTIC_WRITE); | ||
$bug->getProgress()->setTotal($bug->getProgress()->getTotal() + $total); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\MbtBundle\Repository; | ||
|
||
use Doctrine\Persistence\ObjectRepository; | ||
use Tienvx\Bundle\MbtBundle\Model\BugInterface; | ||
|
||
interface BugRepositoryInterface extends ObjectRepository | ||
{ | ||
public function updateSteps(BugInterface $bug, array $newSteps): void; | ||
|
||
public function increaseProcessed(BugInterface $bug, int $processed = 1): void; | ||
|
||
public function increaseTotal(BugInterface $bug, int $total): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\MbtBundle\Repository; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use Tienvx\Bundle\MbtBundle\Entity\Task; | ||
use Tienvx\Bundle\MbtBundle\Model\TaskInterface; | ||
|
||
class TaskRepository extends ServiceEntityRepository implements TaskRepositoryInterface | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Task::class); | ||
} | ||
|
||
public function startRunning(TaskInterface $task): void | ||
{ | ||
$task->setRunning(true); | ||
$this->getEntityManager()->flush(); | ||
} | ||
|
||
public function stopRunning(TaskInterface $task): void | ||
{ | ||
$task->setRunning(false); | ||
// Running task take long time. Reconnect to flush changes. | ||
$this->getEntityManager()->getConnection()->connect(); | ||
$this->getEntityManager()->flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\MbtBundle\Repository; | ||
|
||
use Doctrine\Persistence\ObjectRepository; | ||
use Tienvx\Bundle\MbtBundle\Model\TaskInterface; | ||
|
||
interface TaskRepositoryInterface extends ObjectRepository | ||
{ | ||
public function startRunning(TaskInterface $task): void; | ||
|
||
public function stopRunning(TaskInterface $task): void; | ||
} |
Oops, something went wrong.