Plugin: XAPI: log stored statements instead of request statements - refs BT#18201

Stored statements have ID to save
pull/4376/head
Angel Fernando Quiroz Campos 3 years ago
parent 2fd3dbfb3b
commit 76eb407e4b
  1. 2
      plugin/xapi/README.md
  2. 6
      plugin/xapi/src/Entity/InternalLog.php
  3. 43
      plugin/xapi/src/Lrs/StatementsController.php

@ -85,6 +85,4 @@ ALTER TABLE xapi_internal_log ADD CONSTRAINT FK_C1C667ACA76ED395 FOREIGN KEY (us
ALTER TABLE xapi_internal_log ADD CONSTRAINT FK_C1C667ACA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;
ALTER TABLE xapi_tool_launch ADD CONSTRAINT FK_E18CB58391D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE;
ALTER TABLE xapi_tool_launch ADD CONSTRAINT FK_E18CB583613FECDF FOREIGN KEY (session_id) REFERENCES session (id) ON DELETE CASCADE;
ALTER TABLE xapi_internal_log CHANGE statement_id statement_id varchar(255) NULL;
```

@ -30,7 +30,7 @@ class InternalLog
/**
* @var string
*
* @ORM\Column(name="statement_id", type="string", nullable=true)
* @ORM\Column(name="statement_id", type="string")
*/
private $statementId;
/**
@ -105,12 +105,12 @@ class InternalLog
return $this;
}
public function getStatementId(): ?string
public function getStatementId(): string
{
return $this->statementId;
}
public function setStatementId(?string $statementId): InternalLog
public function setStatementId(string $statementId): InternalLog
{
$this->statementId = $statementId;

@ -7,6 +7,8 @@ namespace Chamilo\PluginBundle\XApi\Lrs;
use Chamilo\PluginBundle\XApi\Lrs\Util\InternalLogUtil;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Xabbuh\XApi\Common\Exception\NotFoundException;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Serializer\Symfony\ActorSerializer;
use Xabbuh\XApi\Serializer\Symfony\Serializer;
use Xabbuh\XApi\Serializer\Symfony\SerializerFactory;
@ -89,11 +91,15 @@ class StatementsController extends BaseController
)
;
InternalLogUtil::saveStatementForInternalLog($statement);
$putStatementController = new StatementPutController($this->statementRepository);
return $putStatementController->putStatement($this->httpRequest, $statement);
$response = $putStatementController->putStatement($this->httpRequest, $statement);
$this->saveLog(
[$this->httpRequest->query->get('statementId')]
);
return $response;
}
public function post(): Response
@ -109,12 +115,33 @@ class StatementsController extends BaseController
->deserializeStatements($content)
;
foreach ($statements as $statement) {
InternalLogUtil::saveStatementForInternalLog($statement);
}
$postStatementController = new StatementPostController($this->statementRepository);
return $postStatementController->postStatements($this->httpRequest, $statements);
$response = $postStatementController->postStatements($this->httpRequest, $statements);
$this->saveLog(
json_decode($response->getContent(), false)
);
return $response;
}
/**
* @param array<string> $statementsId
*
* @return void
*/
private function saveLog(array $statementsId)
{
foreach ($statementsId as $statementId) {
try {
$storedStatement = $this->statementRepository->findStatementById(
StatementId::fromString($statementId)
);
InternalLogUtil::saveStatementForInternalLog($storedStatement);
} catch (NotFoundException $e) {
}
}
}
}

Loading…
Cancel
Save