From d844deeb0bf7f05ad46418c56dbb27c0ed2092a5 Mon Sep 17 00:00:00 2001 From: Julio Date: Tue, 19 Oct 2021 13:41:56 +0200 Subject: [PATCH] Minor - format code --- .../Extension/SessionRelUserExtension.php | 1 + .../Schema/V200/Version20190210182615.php | 44 ++++++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/CoreBundle/DataProvider/Extension/SessionRelUserExtension.php b/src/CoreBundle/DataProvider/Extension/SessionRelUserExtension.php index 51db68824d..7aa016c79c 100644 --- a/src/CoreBundle/DataProvider/Extension/SessionRelUserExtension.php +++ b/src/CoreBundle/DataProvider/Extension/SessionRelUserExtension.php @@ -48,6 +48,7 @@ final class SessionRelUserExtension implements QueryCollectionExtensionInterface $request = $this->requestStack->getCurrentRequest(); $alias = $qb->getRootAliases()[0]; $content = $request->getContent(); + $now = new DateTime('now', new DateTimeZone('UTC')); $date = $now->format('Y-m-d H:i:s'); diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20190210182615.php b/src/CoreBundle/Migrations/Schema/V200/Version20190210182615.php index 8090f95d01..38d36d809d 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20190210182615.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20190210182615.php @@ -116,22 +116,26 @@ class Version20190210182615 extends AbstractMigrationChamilo $sessionId = (int) $item['id']; if (!empty($coachId)) { - $result = $connection->executeQuery("SELECT * FROM session_rel_user WHERE user_id = $coachId AND session_id = $sessionId AND relation_type = 3 "); - $items = $result->fetchAllAssociative(); - if (empty($items)) { - $this->addSql( - "INSERT INTO session_rel_user (relation_type, duration, registered_at, user_id, session_id) VALUES (3, 0, NOW(), $coachId, $sessionId)" - ); + $sql = "SELECT * FROM session_rel_user + WHERE user_id = $coachId AND session_id = $sessionId AND relation_type = 3 "; + $result = $connection->executeQuery($sql); + $exists = $result->fetchAllAssociative(); + if (empty($exists)) { + $sql = "INSERT INTO session_rel_user (relation_type, duration, registered_at, user_id, session_id) + VALUES (3, 0, NOW(), $coachId, $sessionId)"; + $this->addSql($sql); } } if (!empty($adminId)) { - $result = $connection->executeQuery("SELECT * FROM session_rel_user WHERE user_id = $adminId AND session_id = $sessionId AND relation_type = 4 "); - $items = $result->fetchAllAssociative(); - if (empty($items)) { - $this->addSql( - "INSERT INTO session_rel_user (relation_type, duration, registered_at, user_id, session_id) VALUES (4, 0, NOW(), $adminId, $sessionId)" - ); + $sql = "SELECT * FROM session_rel_user + WHERE user_id = $adminId AND session_id = $sessionId AND relation_type = 4 "; + $result = $connection->executeQuery($sql); + $exists = $result->fetchAllAssociative(); + if (empty($exists)) { + $sql = "INSERT INTO session_rel_user (relation_type, duration, registered_at, user_id, session_id) + VALUES (4, 0, NOW(), $adminId, $sessionId)"; + $this->addSql($sql); } } } @@ -147,14 +151,14 @@ class Version20190210182615 extends AbstractMigrationChamilo $sessionId = (int) $item['session_id']; $status = (int) $item['status']; if (!empty($userId)) { - $result = $connection->executeQuery( - "SELECT * FROM session_rel_user WHERE user_id = $userId AND session_id = $sessionId AND relation_type = $status " - ); - $items = $result->fetchAllAssociative(); - if (empty($items)) { - $this->addSql( - "INSERT INTO session_rel_user (relation_type, duration, registered_at, user_id, session_id) VALUES ($status, 0, NOW(), $userId, $sessionId)" - ); + $sql = "SELECT * FROM session_rel_user + WHERE user_id = $userId AND session_id = $sessionId AND relation_type = $status"; + $result = $connection->executeQuery($sql); + $exists = $result->fetchAllAssociative(); + if (empty($exists)) { + $sql = "INSERT INTO session_rel_user (relation_type, duration, registered_at, user_id, session_id) + VALUES ($status, 0, NOW(), $userId, $sessionId)"; + $this->addSql($sql); } } }