Skip to content

Commit

Permalink
chore: Use DI to fetch services from ConcurringSessionService
Browse files Browse the repository at this point in the history
  • Loading branch information
hectoras committed May 17, 2024
1 parent 9c69e78 commit 024d5dd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 37 deletions.
8 changes: 5 additions & 3 deletions model/Container/TestQtiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2021-2023 (original work) Open Assessment Technologies SA;
*
* @author Ricardo Quintanilha <[email protected]>
* Copyright (c) 2021-2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);
Expand Down Expand Up @@ -47,7 +45,9 @@
use oat\taoQtiTest\model\Service\StoreTraceVariablesService;
use oat\taoQtiTest\model\Service\TimeoutService;
use oat\taoQtiTest\models\runner\QtiRunnerService;
use oat\taoQtiTest\models\runner\time\TimerAdjustmentServiceInterface;
use oat\taoQtiTest\models\TestModelService;
use oat\taoQtiTest\models\TestSessionService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
Expand Down Expand Up @@ -172,6 +172,8 @@ public function __invoke(ContainerConfigurator $configurator): void
service(DeliveryExecutionService::SERVICE_ID),
service(FeatureFlagChecker::class),
service(StateServiceInterface::SERVICE_ID),
service(TestSessionService::SERVICE_ID),
service(TimerAdjustmentServiceInterface::SERVICE_ID),
]
);
}
Expand Down
44 changes: 10 additions & 34 deletions model/Service/ConcurringSessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
namespace oat\taoQtiTest\model\Service;

use common_Exception;
use oat\oatbox\service\ServiceManager;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\taoDelivery\model\execution\DeliveryExecution;
use oat\taoDelivery\model\execution\DeliveryExecutionInterface;
Expand All @@ -44,6 +43,7 @@
class ConcurringSessionService
{
private const PAUSE_REASON_CONCURRENT_TEST = 'PAUSE_REASON_CONCURRENT_TEST';

/**
* @var string Controls whether a delivery execution state should be kept as is or reset each time it starts.
* `false` – the state will be reset on each restart.
Expand All @@ -58,9 +58,9 @@ class ConcurringSessionService
private DeliveryExecutionService $deliveryExecutionService;
private FeatureFlagCheckerInterface $featureFlagChecker;
private StateServiceInterface $stateService;
private TestSessionService $testSessionService;
private TimerAdjustmentServiceInterface $timerAdjustmentService;
private ?PHPSession $currentSession;
private ?TestSessionService $testSessionService;
private ?TimerAdjustmentServiceInterface $timerAdjustmentService;

public function __construct(
LoggerInterface $logger,
Expand All @@ -69,19 +69,19 @@ public function __construct(
DeliveryExecutionService $deliveryExecutionService,
FeatureFlagCheckerInterface $featureFlagChecker,
StateServiceInterface $stateService,
PHPSession $currentSession = null,
TestSessionService $testSessionService = null,
TimerAdjustmentServiceInterface $timerAdjustmentService = null
TestSessionService $testSessionService,
TimerAdjustmentServiceInterface $timerAdjustmentService,
PHPSession $currentSession = null
) {
$this->logger = $logger;
$this->qtiRunnerService = $qtiRunnerService;
$this->runtimeService = $runtimeService;
$this->deliveryExecutionService = $deliveryExecutionService;
$this->featureFlagChecker = $featureFlagChecker;
$this->stateService = $stateService;
$this->currentSession = $currentSession ?? PHPSession::singleton();
$this->testSessionService = $testSessionService;
$this->timerAdjustmentService = $timerAdjustmentService;
$this->currentSession = $currentSession ?? PHPSession::singleton();
}

public function pauseActiveDeliveryExecutionsForUser($activeExecution): void
Expand Down Expand Up @@ -172,7 +172,7 @@ public function adjustTimers(DeliveryExecution $execution): void
)
);

$testSession = $this->getTestSessionService()->getTestSession($execution);
$testSession = $this->testSessionService->getTestSession($execution);

if ($testSession && $testSession->getCurrentAssessmentItemRef()) {
$duration = $testSession->getTimerDuration(
Expand Down Expand Up @@ -216,14 +216,14 @@ public function adjustTimers(DeliveryExecution $execution): void
if ($delta > 0) {
$this->logger->debug(sprintf('Adjusting timers by %d s', $delta));

$this->getTimerAdjustmentService()->increase(
$this->timerAdjustmentService->increase(
$testSession,
$delta,
TimerAdjustmentServiceInterface::TYPE_TIME_ADJUSTMENT
);

$testSession->suspend();
$this->getTestSessionService()->persist($testSession);
$this->testSessionService->persist($testSession);
}
}
}
Expand Down Expand Up @@ -307,28 +307,4 @@ private function getContextByDeliveryExecution(DeliveryExecutionInterface $execu
$execution->getUserIdentifier()
);
}

private function getTimerAdjustmentService(): TimerAdjustmentServiceInterface
{
if (!$this->timerAdjustmentService instanceof TimerAdjustmentServiceInterface) {
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->timerAdjustmentService = ServiceManager::getServiceManager()->get(
TimerAdjustmentServiceInterface::SERVICE_ID
);
}

return $this->timerAdjustmentService;
}

private function getTestSessionService(): TestSessionService
{
if (!$this->testSessionService instanceof TestSessionService) {
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->testSessionService = ServiceManager::getServiceManager()->get(
TestSessionService::SERVICE_ID
);
}

return $this->testSessionService;
}
}

0 comments on commit 024d5dd

Please sign in to comment.