diff --git a/application/Espo/Core/Utils/Authentication/LDAP.php b/application/Espo/Core/Utils/Authentication/LDAP.php index 5d7b146aa0..9e9ab4e1d0 100644 --- a/application/Espo/Core/Utils/Authentication/LDAP.php +++ b/application/Espo/Core/Utils/Authentication/LDAP.php @@ -99,6 +99,22 @@ class LDAP extends Espo return $this->utils; } + protected function getContainer() + { + return $this->getInjection('container'); + } + + protected function useSystemUser() + { + $systemUser = $this->getEntityManager()->getEntity('User', 'system'); + if (!$systemUser) { + throw new Error("System user is not found."); + } + + $this->getContainer()->setUser($systemUser); + $this->getEntityManager()->setUser($systemUser); + } + protected function getLdapClient() { if (!isset($this->ldapClient)) { @@ -183,7 +199,12 @@ class LDAP extends Espo ] ]); - if (!isset($user) && $this->getUtils()->getOption('createEspoUser')) { + if (!isset($user)) { + if (!$this->getUtils()->getOption('createEspoUser')) { + $this->useSystemUser(); + throw new Error($this->getContainer()->get('language')->translate('ldapUserInEspoNotFound', 'messages', 'User')); + } + $userData = $ldapClient->getEntry($userDn); $user = $this->createUser($userData, $isPortal); } @@ -283,18 +304,11 @@ class LDAP extends Espo $data[$fieldName] = $fieldValue; } - $entityManager = $this->getEntityManager(); + $this->useSystemUser(); - $systemUser = $entityManager->getEntity('User', 'system'); - if (!$systemUser) { - throw new Error("System user is not found"); - } - $this->getInjection('container')->setUser($systemUser); - $entityManager->setUser($systemUser); - - $user = $entityManager->getEntity('User'); + $user = $this->getEntityManager()->getEntity('User'); $user->set($data); - $entityManager->saveEntity($user); + $this->getEntityManager()->saveEntity($user); return $this->getEntityManager()->getEntity('User', $user->id); } diff --git a/application/Espo/Core/Utils/Database/Schema/Converter.php b/application/Espo/Core/Utils/Database/Schema/Converter.php index c1010dbef4..f0d9522da2 100644 --- a/application/Espo/Core/Utils/Database/Schema/Converter.php +++ b/application/Espo/Core/Utils/Database/Schema/Converter.php @@ -282,6 +282,9 @@ class Converter protected function prepareManyMany($entityName, $relationParams, $tables) { $tableName = Util::toUnderScore($relationParams['relationName']); + $GLOBALS['log']->debug('DBAL: prepareManyMany invoked for ' . $entityName, [ + 'tableName' => $tableName, 'parameters' => $relationParams + ]); if ($this->getSchema()->hasTable($tableName)) { $GLOBALS['log']->debug('DBAL: Table ['.$tableName.'] exists.'); @@ -297,17 +300,22 @@ class Converter //add midKeys to a schema $uniqueIndex = array(); - foreach($relationParams['midKeys'] as $index => $midKey) { - - $columnName = Util::toUnderScore($midKey); - $table->addColumn($columnName, $this->idParams['dbType'], $this->getDbFieldParams(array( - 'type' => 'foreignId', - 'len' => $this->idParams['len'], - ))); - $table->addIndex(array($columnName), SchemaUtils::generateIndexName($columnName)); - - $uniqueIndex[] = $columnName; - } + if (empty($relationParams['midKeys'])) { + $GLOBALS['log']->debug('REBUILD: midKeys are empty!', [ + 'scope' => $entityName, 'tableName' => $tableName, + 'parameters' => $relationParams + ]); + } else { + foreach($relationParams['midKeys'] as $index => $midKey) { + $columnName = Util::toUnderScore($midKey); + $table->addColumn($columnName, $this->idParams['dbType'], $this->getDbFieldParams(array( + 'type' => 'foreignId', + 'len' => $this->idParams['len'], + ))); + $table->addIndex(array($columnName), SchemaUtils::generateIndexName($columnName)); + $uniqueIndex[] = $columnName; + } + } //END: add midKeys to a schema //add additionalColumns diff --git a/application/Espo/Resources/i18n/en_US/User.json b/application/Espo/Resources/i18n/en_US/User.json index 4f85f0d9c1..56ee8dec10 100644 --- a/application/Espo/Resources/i18n/en_US/User.json +++ b/application/Espo/Resources/i18n/en_US/User.json @@ -109,7 +109,8 @@ "enterTotpCode": "Enter a code from your authenticator app.", "verifyTotpCode": "Scan the QR-code with your mobile authenticator app. If you have a trouble with scanning, you can enter the secret manually. After that you will see a 6-digit code in your application. Enter this code in the field below.", "generateAndSendNewPassword": "A new password will be generated and sent to the user's email address.", - "security2FaResetConfimation": "Are you sure you want to reset the current 2FA settings?" + "security2FaResetConfimation": "Are you sure you want to reset the current 2FA settings?", + "ldapUserInEspoNotFound": "User is not found in EspoCRM. Contact your administrator to create the user." }, "options": { "gender": {