diff --git a/ldap_authentication/ldap_authentication.install b/ldap_authentication/ldap_authentication.install index 12e3c20..4605c11 100644 --- a/ldap_authentication/ldap_authentication.install +++ b/ldap_authentication/ldap_authentication.install @@ -5,13 +5,15 @@ * Install, update and uninstall functions for the LDAP authentication module. */ +use Drupal\Core\Database\Database; + /** * Implements hook_requirements(). */ function ldap_authentication_requirements($phase) { $requirements = []; - if ($phase != "install" && db_table_exists('ldapauth')) { + if ($phase != "install" && Database::getConnection()->schema()->tableExists('ldapauth')) { $requirements['ldap_authentication_ldap_integration'] = [ 'title' => t('LDAP Integration LDAP Auth Upgrade Concern'), 'severity' => REQUIREMENT_WARNING, diff --git a/ldap_authentication/src/Controller/LoginValidatorBase.php b/ldap_authentication/src/Controller/LoginValidatorBase.php index aed48b7..5886b3f 100644 --- a/ldap_authentication/src/Controller/LoginValidatorBase.php +++ b/ldap_authentication/src/Controller/LoginValidatorBase.php @@ -2,6 +2,7 @@ namespace Drupal\ldap_authentication\Controller; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManager; @@ -661,7 +662,7 @@ abstract class LoginValidatorBase implements LdapUserAttributesInterface { $template = $this->config->get('emailTemplate'); } $this->ldapEntry->setAttribute($this->serverDrupalUser->get('mail_attr'), [ - SafeMarkup::format($template, $this->emailTemplateTokens) + (new FormattableMarkup($template, $this->emailTemplateTokens)) ->__toString(), ]); } diff --git a/ldap_authorization/tests/src/Kernel/LdapAuthorizationProviderIntegrationTests.php b/ldap_authorization/tests/src/Kernel/LdapAuthorizationProviderIntegrationTests.php index 8b6c95d..cad3b6c 100644 --- a/ldap_authorization/tests/src/Kernel/LdapAuthorizationProviderIntegrationTests.php +++ b/ldap_authorization/tests/src/Kernel/LdapAuthorizationProviderIntegrationTests.php @@ -1,6 +1,6 @@ 4, + 0 => 'cn=hpotter', + 1 => 'ou=Gryffindor', + 2 => 'ou=student', + 3 => 'ou=people', + 4 => 'dc=hogwarts', + 5 => 'dc=edu', + ]; + } + +} diff --git a/ldap_servers/tests/src/Unit/TokenTests.php b/ldap_servers/tests/src/Unit/TokenTests.php index a519dcf..1e9ed33 100644 --- a/ldap_servers/tests/src/Unit/TokenTests.php +++ b/ldap_servers/tests/src/Unit/TokenTests.php @@ -6,31 +6,6 @@ use Drupal\ldap_servers\Helper\ConversionHelper; use Drupal\Tests\UnitTestCase; use Symfony\Component\Ldap\Entry; -/** - * Helper class to make it possible to simulate ldap_explode_dn(). - */ -class LdapExplodeDnMock { - - /** - * Simulate explode_dn. - * - * @return array - * DN exploded, input ignored. - */ - public static function ldapExplodeDn($input) { - return [ - 'count' => 4, - 0 => 'cn=hpotter', - 1 => 'ou=Gryffindor', - 2 => 'ou=student', - 3 => 'ou=people', - 4 => 'dc=hogwarts', - 5 => 'dc=edu', - ]; - } - -} - /** * @coversDefaultClass \Drupal\ldap_servers\Processor\TokenProcessor * @group ldap diff --git a/ldap_user/ldap_user.install b/ldap_user/ldap_user.install index 1ededa7..6f1f301 100644 --- a/ldap_user/ldap_user.install +++ b/ldap_user/ldap_user.install @@ -5,8 +5,10 @@ * Install, update and uninstall functions for the LDAP User module. */ +use Drupal\Core\Database\Database; use Drupal\Core\Url; -use Drupal\Component\Utility\SafeMarkup; +use Drupal\Component\Utility\Html; +use Drupal\Core\Link; use Drupal\Core\Utility\UpdateException; use Drupal\ldap_servers\LdapUserAttributesInterface; @@ -30,7 +32,7 @@ function ldap_user_update_8301(&$sandbox) { // Check for externalauth module (which has been a dependency for ages). if (!\Drupal::moduleHandler()->moduleExists('externalauth')) { $external_link = Url::fromUri('https://drupal.org/project/externalauth'); - $message = t('Please install the 8301 %external_link module.', ['%external_link' => \Drupal::l('External Auth', $external_link)]); + $message = t('Please install the 8301 %external_link module.', ['%external_link' => Link::fromTextAndUrl('External Auth', $external_link)]); \Drupal::messenger()->addError($message); throw new UpdateException($message); } @@ -38,11 +40,11 @@ function ldap_user_update_8301(&$sandbox) { if (empty($sandbox)) { $sandbox['progress'] = 0; $sandbox['current_id'] = 0; - $sandbox['max'] = db_query('SELECT COUNT(DISTINCT aid) FROM {ldap_user_identities}')->fetchField(); + $sandbox['max'] = Database::getConnection()->query('SELECT COUNT(DISTINCT aid) FROM {ldap_user_identities}')->fetchField(); } $limit = 25; - $result = db_select('ldap_user_identities') + $result = Database::getConnection()->select('ldap_user_identities') ->fields('ldap_user_identities', ['aid', 'uid', 'identifier']) ->condition('aid', $sandbox['current_id'], '>') ->orderBy('aid') @@ -52,17 +54,17 @@ function ldap_user_update_8301(&$sandbox) { // Iterate over the old table and create entries in the new table. foreach ($result as $identity) { // Load the user as the service expects an account. - $account = user_load($identity->uid); + $account = \Drupal::entityTypeManager()->getStorage('user')->load($identity->uid); $authmap = \Drupal::service('externalauth.authmap'); $authmap->save($account, 'ldap_user', $identity->identifier); // Delete the row if successful. - db_query("DELETE FROM {ldap_user_identities} WHERE aid = :aid", [':aid' => $identity->aid]); + Database::getConnection()->query("DELETE FROM {ldap_user_identities} WHERE aid = :aid", [':aid' => $identity->aid]); - $sandbox['results'][] = $identity->aid . ' : ' . SafeMarkup::checkPlain($identity->identifier); + $sandbox['results'][] = $identity->aid . ' : ' . Html::escape($identity->identifier); $sandbox['progress']++; $sandbox['current_id'] = $identity->aid; - $sandbox['message'] = SafeMarkup::checkPlain($identity->identifier); + $sandbox['message'] = Html::escape($identity->identifier); } if ($sandbox['progress'] != $sandbox['max']) { $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max']; @@ -76,13 +78,13 @@ function ldap_user_update_8302(&$sandbox) { // Check for externalauth module (which has been a dependency for ages). if (!\Drupal::moduleHandler()->moduleExists('externalauth')) { $external_link = Url::fromUri('https://drupal.org/project/externalauth'); - $message = t('Please install the 8301 %external_link module.', ['%external_link' => \Drupal::l('External Auth', $external_link)]); + $message = t('Please install the 8301 %external_link module.', ['%external_link' => Link::fromTextAndUrl('External Auth', $external_link)]); \Drupal::messenger()->addError($message); throw new UpdateException($message); } // Drop the table if it exists. try { - db_query("DROP TABLE {ldap_user_identities}"); + Database::getConnection()->query("DROP TABLE {ldap_user_identities}"); } catch (Exception $e) { \Drupal::messenger()->addWarning(t("Couldn't drop the table 'ldap_user_identities'. Maybe it's been dropped already?")); diff --git a/ldap_user/tests/src/Kernel/FieldProviderTests.php b/ldap_user/tests/src/Kernel/FieldProviderTests.php index ab400bb..350a74d 100644 --- a/ldap_user/tests/src/Kernel/FieldProviderTests.php +++ b/ldap_user/tests/src/Kernel/FieldProviderTests.php @@ -1,6 +1,6 @@