Merge pull request #4441 from AngelFQC/BT18160

Xapi: Allow cron process use alternative LRS
pull/4448/head
Nicolas Ducoulombier 3 years ago committed by GitHub
commit 244b9f2810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      plugin/xapi/cron/send_statements.php
  2. 6
      plugin/xapi/lang/english.php
  3. 6
      plugin/xapi/lang/french.php
  4. 6
      plugin/xapi/lang/spanish.php
  5. 28
      plugin/xapi/src/XApiPlugin.php

@ -34,7 +34,7 @@ $countNotSent = count($notSentSharedStatements);
if ($countNotSent > 0) { if ($countNotSent > 0) {
echo '['.time().'] Trying to send '.$countNotSent.' statements to LRS'.PHP_EOL; echo '['.time().'] Trying to send '.$countNotSent.' statements to LRS'.PHP_EOL;
$client = XApiPlugin::create()->getXApiStatementClient(); $client = XApiPlugin::create()->getXapiStatementCronClient();
/** @var SharedStatement $notSentSharedStatement */ /** @var SharedStatement $notSentSharedStatement */
foreach ($notSentSharedStatements as $notSentSharedStatement) { foreach ($notSentSharedStatements as $notSentSharedStatement) {

@ -14,6 +14,12 @@ $strings['lrs_auth_username'] = 'LRS user';
$strings['lrs_auth_username_help'] = 'Username for basic HTTP authentication'; $strings['lrs_auth_username_help'] = 'Username for basic HTTP authentication';
$strings['lrs_auth_password'] = 'LRS password'; $strings['lrs_auth_password'] = 'LRS password';
$strings['lrs_auth_password_help'] = 'Password for basic HTTP authentication'; $strings['lrs_auth_password_help'] = 'Password for basic HTTP authentication';
$strings['cron_lrs_url'] = 'Cron: LRS endpoint';
$strings['cron_lrs_url_help'] = 'Alternative base URL of the LRS for the cron process';
$strings['cron_lrs_auth_username'] = 'Cron: LRS user';
$strings['cron_lrs_auth_username_help'] = 'Alternative username for basic HTTP authentication for the cron process';
$strings['cron_lrs_auth_password'] = 'Cron: LRS password';
$strings['cron_lrs_auth_password_help'] = 'Alternative password for basic HTTP authentication for the cron process';
$strings['lrs_lp_item_viewed_active'] = 'Learning path item viewed'; $strings['lrs_lp_item_viewed_active'] = 'Learning path item viewed';
$strings['lrs_lp_end_active'] = 'Learning path ended'; $strings['lrs_lp_end_active'] = 'Learning path ended';
$strings['lrs_quiz_active'] = 'Quiz ended'; $strings['lrs_quiz_active'] = 'Quiz ended';

@ -14,6 +14,12 @@ $strings['lrs_auth_username'] = 'Utilisateur LRS';
$strings['lrs_auth_username_help'] = 'Nom d\'utilisateur pour l\'authentification HTTP de base'; $strings['lrs_auth_username_help'] = 'Nom d\'utilisateur pour l\'authentification HTTP de base';
$strings['lrs_auth_password'] = 'Mot de passe LRS'; $strings['lrs_auth_password'] = 'Mot de passe LRS';
$strings['lrs_auth_password_help'] = 'Mot de passe pour l\'authentification HTTP de base'; $strings['lrs_auth_password_help'] = 'Mot de passe pour l\'authentification HTTP de base';
$strings['cron_lrs_url'] = 'Cron: LRS endpoint';
$strings['cron_lrs_url_help'] = 'Alternative base URL of the LRS for the cron process';
$strings['cron_lrs_auth_username'] = 'Cron: LRS user';
$strings['cron_lrs_auth_username_help'] = 'Alternative username for basic HTTP authentication for the cron process';
$strings['cron_lrs_auth_password'] = 'Cron: LRS password';
$strings['cron_lrs_auth_password_help'] = 'Alternative password for basic HTTP authentication for the cron process';
$strings['lrs_lp_item_viewed_active'] = 'Élément de parcours visionné'; $strings['lrs_lp_item_viewed_active'] = 'Élément de parcours visionné';
$strings['lrs_lp_end_active'] = 'Parcours terminé'; $strings['lrs_lp_end_active'] = 'Parcours terminé';
$strings['lrs_quiz_active'] = 'Exercice terminé'; $strings['lrs_quiz_active'] = 'Exercice terminé';

@ -14,6 +14,12 @@ $strings['lrs_auth_username'] = 'Usuario del LRS';
$strings['lrs_auth_username_help'] = 'Usuario para autenticación con HTTP básica'; $strings['lrs_auth_username_help'] = 'Usuario para autenticación con HTTP básica';
$strings['lrs_auth_password'] = 'Contraseña del LRS'; $strings['lrs_auth_password'] = 'Contraseña del LRS';
$strings['lrs_auth_password_help'] = 'Contraseña para autenticación con HTTP básica'; $strings['lrs_auth_password_help'] = 'Contraseña para autenticación con HTTP básica';
$strings['cron_lrs_url'] = 'Cron: LRS endpoint';
$strings['cron_lrs_url_help'] = 'Opcional. Base de la URL alternativa del LRS del proceso cron.';
$strings['cron_lrs_auth_username'] = 'Cron: Usuario del LRS';
$strings['cron_lrs_auth_username_help'] = 'Opcional. Usuario alternativo para autenticación con HTTP básica del proceso cron';
$strings['cron_lrs_auth_password'] = 'Cron: Contraseña del LRS';
$strings['cron_lrs_auth_password_help'] = 'Opcional. Contraseña alternativa para autenticación con HTTP básica del proceso cron';
$strings['lrs_lp_item_viewed_active'] = 'Visualización de contenido de lección'; $strings['lrs_lp_item_viewed_active'] = 'Visualización de contenido de lección';
$strings['lrs_lp_end_active'] = 'Finalización de lección'; $strings['lrs_lp_end_active'] = 'Finalización de lección';
$strings['lrs_quiz_active'] = 'Finalización de ejercicio'; $strings['lrs_quiz_active'] = 'Finalización de ejercicio';

@ -17,6 +17,7 @@ use GuzzleHttp\RequestOptions;
use Http\Adapter\Guzzle6\Client; use Http\Adapter\Guzzle6\Client;
use Http\Message\MessageFactory\GuzzleMessageFactory; use Http\Message\MessageFactory\GuzzleMessageFactory;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Xabbuh\XApi\Client\Api\StatementsApiClientInterface;
use Xabbuh\XApi\Client\XApiClientBuilder; use Xabbuh\XApi\Client\XApiClientBuilder;
use Xabbuh\XApi\Model\Agent; use Xabbuh\XApi\Model\Agent;
use Xabbuh\XApi\Model\IRI; use Xabbuh\XApi\Model\IRI;
@ -30,6 +31,9 @@ class XApiPlugin extends Plugin implements HookPluginInterface
public const SETTING_LRS_URL = 'lrs_url'; public const SETTING_LRS_URL = 'lrs_url';
public const SETTING_LRS_AUTH_USERNAME = 'lrs_auth_username'; public const SETTING_LRS_AUTH_USERNAME = 'lrs_auth_username';
public const SETTING_LRS_AUTH_PASSWORD = 'lrs_auth_password'; public const SETTING_LRS_AUTH_PASSWORD = 'lrs_auth_password';
public const SETTING_CRON_LRS_URL = 'cron_lrs_url';
public const SETTING_CRON_LRS_AUTH_USERNAME = 'cron_lrs_auth_username';
public const SETTING_CRON_LRS_AUTH_PASSWORD = 'cron_lrs_auth_password';
public const SETTING_UUID_NAMESPACE = 'uuid_namespace'; public const SETTING_UUID_NAMESPACE = 'uuid_namespace';
public const SETTING_LRS_LP_ITEM_ACTIVE = 'lrs_lp_item_viewed_active'; public const SETTING_LRS_LP_ITEM_ACTIVE = 'lrs_lp_item_viewed_active';
public const SETTING_LRS_LP_ACTIVE = 'lrs_lp_end_active'; public const SETTING_LRS_LP_ACTIVE = 'lrs_lp_end_active';
@ -56,6 +60,10 @@ class XApiPlugin extends Plugin implements HookPluginInterface
self::SETTING_LRS_AUTH_USERNAME => 'text', self::SETTING_LRS_AUTH_USERNAME => 'text',
self::SETTING_LRS_AUTH_PASSWORD => 'text', self::SETTING_LRS_AUTH_PASSWORD => 'text',
self::SETTING_CRON_LRS_URL => 'text',
self::SETTING_CRON_LRS_AUTH_USERNAME => 'text',
self::SETTING_CRON_LRS_AUTH_PASSWORD => 'text',
self::SETTING_LRS_LP_ITEM_ACTIVE => 'boolean', self::SETTING_LRS_LP_ITEM_ACTIVE => 'boolean',
self::SETTING_LRS_LP_ACTIVE => 'boolean', self::SETTING_LRS_LP_ACTIVE => 'boolean',
self::SETTING_LRS_QUIZ_ACTIVE => 'boolean', self::SETTING_LRS_QUIZ_ACTIVE => 'boolean',
@ -199,14 +207,26 @@ class XApiPlugin extends Plugin implements HookPluginInterface
->getStateApiClient(); ->getStateApiClient();
} }
/** public function getXApiStatementClient(): StatementsApiClientInterface
* @return \Xabbuh\XApi\Client\Api\StatementsApiClientInterface
*/
public function getXApiStatementClient()
{ {
return $this->createXApiClient()->getStatementsApiClient(); return $this->createXApiClient()->getStatementsApiClient();
} }
public function getXapiStatementCronClient(): StatementsApiClientInterface
{
$lrsUrl = $this->get(self::SETTING_CRON_LRS_URL);
$lrsUsername = $this->get(self::SETTING_CRON_LRS_AUTH_USERNAME);
$lrsPassword = $this->get(self::SETTING_CRON_LRS_AUTH_PASSWORD);
return $this
->createXApiClient(
empty($lrsUrl) ? null : $lrsUrl,
empty($lrsUsername) ? null : $lrsUsername,
empty($lrsPassword) ? null : $lrsPassword
)
->getStatementsApiClient();
}
/** /**
* Perform actions after save the plugin configuration. * Perform actions after save the plugin configuration.
* *

Loading…
Cancel
Save