From ceef3ee26903a8febe9488961b465afcc274b5b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20Franti=C5=A1ek=20Bu=C4=8D=C3=ADk?=
 <bucik@ics.muni.cz>
Date: Thu, 1 Sep 2022 12:33:35 +0200
Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20parameters=20orderi?=
 =?UTF-8?q?ng=20and=20duplicate=20insert?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fix1 - ordering parameters in "prepareEntitiesStructure" method call -
caused using spName as spIdentifier and vice versa
Fix2 - duplicate call for inserting the login data
---
 lib/DatabaseCommand.php | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/lib/DatabaseCommand.php b/lib/DatabaseCommand.php
index 7cb1f44..3e7674c 100644
--- a/lib/DatabaseCommand.php
+++ b/lib/DatabaseCommand.php
@@ -82,20 +82,6 @@ class DatabaseCommand
         $entities = $this->getEntities($request);
         $userId = $this->getUserId($request);
         $this->insertLogin($entities, $userId, $date);
-
-        $ids = [];
-        foreach (self::TABLE_SIDES as $side => $table) {
-            $tableId = self::TABLE_IDS[$table];
-            $ids[$tableId] = $this->getEntityDbIdFromEntityIdentifier($table, $entities[$side], $tableId);
-        }
-
-        if (!$this->writeLogin($date, $ids, $userId)) {
-            Logger::error(self::DEBUG_PREFIX . 'login record has not been inserted (data \'' . json_encode([
-                'user' => $userId,
-                'ids' => $ids,
-                'date' => $date,
-            ]) . '\'.');
-        }
     }
 
     public function insertLoginFromApi($data, DateTime $date)
@@ -407,7 +393,7 @@ class DatabaseCommand
         return $this->prepareEntitiesStructure($idpIdentifier, $idpName, $spIdentifier, $spName);
     }
 
-    private function prepareEntitiesStructure($idpIdentifier, $idpName, $spName, $spIdentifier): array
+    private function prepareEntitiesStructure($idpIdentifier, $idpName, $spIdentifier, $spName): array
     {
         $entities = [
             Config::MODE_IDP => [],
-- 
GitLab