Better exception handling for if username does not exist

Created on 16 July 2020, about 4 years ago
Updated 24 September 2023, about 1 year ago

Thanks to CI experimenting ( ✨ Add-Improve Gitlab CI testing Active ) I saw the \Exception parameters are wrong.

Thinking about adding: src/Exception/UsernameNotExistException.php :

namespace Drupal\wordpress_migrate\Exception;
/**
 * Class UsernameNotExistException.
 *
 * @package Drupal\wordpresss_migrate\Exception
 */
class UsernameNotExistException extends \Exception {}

and in WordPressMigrationGenerator.php:

class WordPressMigrationGenerator {

  // This is necessary to use $this->t on UsernameNotExistException message.
  use StringTranslationTrait;

and adjust the exception like so:

    // Determine the uid mappings, creating an author migration if needed.
    if ($this->configuration['default_author']) {
      $account = user_load_by_name($this->configuration['default_author']);
      if ($account) {
        $this->uidMapping = [
          'plugin' => 'default_value',
          'default_value' => $account->id(),
        ];
      }
      else {
        throw new UsernameNotExistException($this->t('Username @name does not exist.',
          ['@name' => $this->configuration['default_author']]));
      }
    }
As of alpha6 still seem to be getting this with non existent users in the system when it initially parses but then it still imports ok.
πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States HongPong Philadelphia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024