Minor: Format code

pull/5520/head
Angel Fernando Quiroz Campos 1 year ago
parent 11547fc082
commit 3d21289aa3
  1. 6
      src/CoreBundle/EventListener/CidReqListener.php
  2. 5
      src/CoreBundle/EventListener/CourseAccessListener.php
  3. 21
      src/CoreBundle/Migrations/Schema/V200/Version20240515124400.php
  4. 8
      src/CoreBundle/Repository/TrackECourseAccessRepository.php
  5. 4
      src/CoreBundle/State/UserSessionSubscriptionsStateProvider.php

@ -18,7 +18,6 @@ use Chamilo\CoreBundle\Security\Authorization\Voter\SessionVoter;
use Chamilo\CourseBundle\Controller\CourseControllerInterface; use Chamilo\CourseBundle\Controller\CourseControllerInterface;
use Chamilo\CourseBundle\Entity\CGroup; use Chamilo\CourseBundle\Entity\CGroup;
use ChamiloSession; use ChamiloSession;
use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\ControllerEvent;
@ -273,14 +272,15 @@ class CidReqListener
$courseId = $sessionHandler->get('cid', 0); $courseId = $sessionHandler->get('cid', 0);
$sessionId = $sessionHandler->get('sid', 0); $sessionId = $sessionHandler->get('sid', 0);
$ip = $request->getClientIp(); $ip = $request->getClientIp();
if ($courseId !== 0) { if (0 !== $courseId) {
$token = $this->tokenStorage->getToken(); $token = $this->tokenStorage->getToken();
if (null !== $token) { if (null !== $token) {
/** @var User $user */ /** @var User $user */
$user = $token->getUser(); $user = $token->getUser();
if ($user instanceof UserInterface) { if ($user instanceof UserInterface) {
$this->entityManager->getRepository(TrackECourseAccess::class) $this->entityManager->getRepository(TrackECourseAccess::class)
->logoutAccess($user, $courseId, $sessionId, $ip); ->logoutAccess($user, $courseId, $sessionId, $ip)
;
} }
} }
} }

@ -10,11 +10,8 @@ use Chamilo\CoreBundle\Entity\TrackECourseAccess;
use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\ServiceHelper\CidReqHelper; use Chamilo\CoreBundle\ServiceHelper\CidReqHelper;
use Chamilo\CoreBundle\ServiceHelper\UserHelper; use Chamilo\CoreBundle\ServiceHelper\UserHelper;
use DateTime;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
/** /**
* In and outs of a course * In and outs of a course

@ -4,12 +4,13 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Migrations\Schema\V200; namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\ResourceFile;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\TrackEDownloads;
use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Chamilo\CoreBundle\Entity\TrackEDownloads; use Exception;
use Chamilo\CoreBundle\Entity\ResourceFile;
use Chamilo\CoreBundle\Entity\ResourceNode;
final class Version20240515124400 extends AbstractMigrationChamilo final class Version20240515124400 extends AbstractMigrationChamilo
{ {
@ -35,7 +36,8 @@ final class Version20240515124400 extends AbstractMigrationChamilo
->setFirstResult($offset) ->setFirstResult($offset)
->setMaxResults($batchSize) ->setMaxResults($batchSize)
->getQuery() ->getQuery()
->getResult(); ->getResult()
;
if (empty($downloads)) { if (empty($downloads)) {
break; break;
@ -67,17 +69,18 @@ final class Version20240515124400 extends AbstractMigrationChamilo
$url = $resourceNode->getResourceFile()->getOriginalName(); $url = $resourceNode->getResourceFile()->getOriginalName();
echo "Resource link $resourceLinkId Down id {$download->getDownId()} for $url: user ".$user->getFullname()."\n"; echo "Resource link $resourceLinkId Down id {$download->getDownId()} for $url: user ".$user->getFullname()."\n";
$this->connection->executeUpdate("UPDATE track_e_downloads SET resource_link_id = ? WHERE down_id = ?", [$resourceLinkId, $download->getDownId()]); $this->connection->executeUpdate('UPDATE track_e_downloads SET resource_link_id = ? WHERE down_id = ?', [$resourceLinkId, $download->getDownId()]);
} }
} }
} }
} }
$this->entityManager->commit(); $this->entityManager->commit();
} catch (\Exception $e) { } catch (Exception $e) {
$this->entityManager->rollback(); $this->entityManager->rollback();
$success = false; $success = false;
echo "Failed for download ID {$download->getDownId()}: ".$e->getMessage()."\n"; echo "Failed for download ID {$download->getDownId()}: ".$e->getMessage()."\n";
break; break;
} finally { } finally {
$this->entityManager->clear(); $this->entityManager->clear();
@ -88,13 +91,11 @@ final class Version20240515124400 extends AbstractMigrationChamilo
// Only delete if all updates were successful // Only delete if all updates were successful
if ($success) { if ($success) {
$this->connection->executeUpdate("DELETE FROM track_e_downloads WHERE resource_link_id IS NULL"); $this->connection->executeUpdate('DELETE FROM track_e_downloads WHERE resource_link_id IS NULL');
} else { } else {
echo "Process failed. No records were deleted.\n"; echo "Process failed. No records were deleted.\n";
} }
} }
public function down(Schema $schema): void public function down(Schema $schema): void {}
{
}
} }

@ -9,6 +9,7 @@ namespace Chamilo\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\TrackECourseAccess; use Chamilo\CoreBundle\Entity\TrackECourseAccess;
use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Entity\User;
use DateTime; use DateTime;
use DateTimeZone;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
@ -79,7 +80,7 @@ class TrackECourseAccessRepository extends ServiceEntityRepository
$access->setCId($courseId); $access->setCId($courseId);
$access->setSessionId($sessionId); $access->setSessionId($sessionId);
$access->setUserIp($ip); $access->setUserIp($ip);
$access->setLoginCourseDate(new \DateTime()); $access->setLoginCourseDate(new DateTime());
$access->setCounter(1); $access->setCounter(1);
$this->_em->persist($access); $this->_em->persist($access);
$this->_em->flush(); $this->_em->flush();
@ -90,7 +91,7 @@ class TrackECourseAccessRepository extends ServiceEntityRepository
*/ */
public function logoutAccess(User $user, int $courseId, int $sessionId, string $ip): void public function logoutAccess(User $user, int $courseId, int $sessionId, string $ip): void
{ {
$now = new DateTime("now", new \DateTimeZone("UTC")); $now = new DateTime('now', new DateTimeZone('UTC'));
$sessionLifetime = 3600; $sessionLifetime = 3600;
$limitTime = (new DateTime())->setTimestamp(time() - $sessionLifetime); $limitTime = (new DateTime())->setTimestamp(time() - $sessionLifetime);
@ -106,7 +107,8 @@ class TrackECourseAccessRepository extends ServiceEntityRepository
->orderBy('a.loginCourseDate', 'DESC') ->orderBy('a.loginCourseDate', 'DESC')
->setMaxResults(1) ->setMaxResults(1)
->getQuery() ->getQuery()
->getOneOrNullResult(); ->getOneOrNullResult()
;
if ($access) { if ($access) {
$access->setLogoutCourseDate($now); $access->setLogoutCourseDate($now);

@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\State;
use ApiPlatform\Metadata\Operation; use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface; use ApiPlatform\State\ProviderInterface;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\Node\UserRepository; use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\Repository\SessionRepository; use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper; use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
@ -16,6 +17,9 @@ use Exception;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* @template-implements ProviderInterface<Session>
*/
class UserSessionSubscriptionsStateProvider implements ProviderInterface class UserSessionSubscriptionsStateProvider implements ProviderInterface
{ {
public function __construct( public function __construct(

Loading…
Cancel
Save