Skip to content

Commit

Permalink
8.1.19
Browse files Browse the repository at this point in the history
- Removed migrate_tools patch that has been fixed
- D8CORE-4677 Migrate process plugin to get the OAuth token for use CAP (#42)
- If the last name is empty, but a first name is parsed, move the first name to the last name. (#41)
  • Loading branch information
pookmish authored Nov 18, 2021
2 parents eeeccbf + 6422fca commit cd19bc2
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Stanford Migrate


8.x-1.19
--------------------------------------------------------------------------------
_Release Date: 2021-11-18_

- Removed migrate_tools patch that has been fixed
- D8CORE-4677 Migrate process plugin to get the OAuth token for use CAP (#42)
- If the last name is empty, but a first name is parsed, move the first name to the last name. (#41)


8.x-1.18
--------------------------------------------------------------------------------
_Release Date: 2021-10-20_
Expand Down
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
"drupal/migrate_plus": {
"https://www.drupal.org/project/migrate_plus/issues/2837684": "https://www.drupal.org/files/issues/2837684-8-migrate-plus-xml-return-as-xml.patch",
"https://www.drupal.org/project/migrate_plus/issues/3050058": "https://www.drupal.org/files/issues/2019-05-17/migrate_plus-no_selector-3050058-3.patch"
},
"drupal/migrate_tools": {
"https://www.drupal.org/project/migrate_tools/issues/2894708": "https://www.drupal.org/files/issues/2019-02-28/disabled-migrations-list-2894708-17.patch"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/migrate/process/ImageDimensionSkip.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function isImageBigger($value) {
return FALSE;
}
try {
[$width, $height] = getimagesize($value);
[$width, $height] = @getimagesize($value);
}
catch (\Exception $e) {
return FALSE;
Expand Down
8 changes: 6 additions & 2 deletions src/Plugin/migrate/process/NameField.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ class NameField extends ProcessPluginBase {
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$name = FullNameParser::parse($value);
return [
$name = [
'title' => $name['salutation'],
'given' => !empty($name['fname']) ? $name['fname'] : $name['initials'],
'family' => trim($name['lname'] . ' ' . $name['suffix']),
];

if (empty($name['family']) && $name['given']) {
$name['family'] = $name['given'];
$name['given'] = '';
}
return $name;
}

}
84 changes: 84 additions & 0 deletions src/Plugin/migrate/process/OauthAccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Drupal\stanford_migrate\Plugin\migrate\process;

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\migrate_plus\AuthenticationPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Migrate process plugin that will return the bearer token for OAuth2 auth.
*
* This requires the migration to be configured for oauth2 authentication, or
* pass the oauth2 credentials into the process plugin. The schema for both
* are exactly the same.
*
* @see \Drupal\migrate_plus\Plugin\migrate_plus\authentication\OAuth2
*
* @MigrateProcessPlugin(
* id = "oauth2_access_token"
* )
*/
class OauthAccessToken extends ProcessPluginBase implements ContainerFactoryPluginInterface {

/**
* Authentication plugin manager service.
*
* @var \Drupal\migrate_plus\AuthenticationPluginManager
*/
protected $authPluginManager;

/**
* Authentication plugin.
*
* @var \Drupal\migrate_plus\AuthenticationPluginInterface
*/
protected $authenticationPlugin;

/**
* {@inheritDoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.migrate_plus.authentication')
);
}

/**
* {@inheritDoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AuthenticationPluginManager $auth_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->authPluginManager = $auth_manager;
}

/**
* {@inheritDoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$this->configuration += $row->getSource();
$options = $this->getAuthenticationPlugin()->getAuthenticationOptions();
preg_match('/ .*$/', $options['headers']['Authorization'], $bearer_match);
return trim(reset($bearer_match));
}

/**
* Returns the initialized authentication plugin.
*
* @return \Drupal\migrate_plus\AuthenticationPluginInterface
* The authentication plugin.
*/
public function getAuthenticationPlugin() {
if (!isset($this->authenticationPlugin)) {
$this->authenticationPlugin = $this->authPluginManager->createInstance($this->configuration['authentication']['plugin'], $this->configuration['authentication']);
}
return $this->authenticationPlugin;
}

}
2 changes: 1 addition & 1 deletion stanford_migrate.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Adds more functionality to migrate and migrate plus modules'
type: module
core_version_requirement: ^8.8 || ^9
package: 'Stanford'
version: 8.x-1.18
version: 8.x-1.19
dependencies:
- drupal:migrate
- migrate_plus:migrate_plus
Expand Down
8 changes: 8 additions & 0 deletions tests/src/Unit/Plugin/migrate/process/NameFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public function testTranform() {
'family' => 'Doe',
];
$this->assertEquals($expected, $name_info);

$name_info = $plugin->transform('Drupal', $migrate_executable, $row, 'field_stuff');
$expected = [
'title' => '',
'given' => '',
'family' => 'Drupal',
];
$this->assertEquals($expected, $name_info);
}

}
53 changes: 53 additions & 0 deletions tests/src/Unit/Plugin/migrate/process/OauthAccessTokenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Drupal\Tests\stanford_migrate\Unit\Plugin\migrate\process;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\migrate_plus\AuthenticationPluginInterface;
use Drupal\migrate_plus\AuthenticationPluginManager;
use Drupal\stanford_migrate\Plugin\migrate\process\OauthAccessToken;
use Drupal\Tests\UnitTestCase;

/**
* class OauthAccessTokenTest.
*
* @coversDefaultClass \Drupal\stanford_migrate\Plugin\migrate\process\OauthAccessToken
*/
class OauthAccessTokenTest extends UnitTestCase {

/**
* Migrate process plugin.
*
* @var \Drupal\stanford_migrate\Plugin\migrate\process\OauthAccessToken
*/
protected $processPlugin;

/**
* {@inheritDoc}
*/
public function setUp() {
parent::setUp();
$auth_headers = ['headers' => ['Authorization' => 'Bearer foo-bar-baz']];
$auth_plugin = $this->createMock(AuthenticationPluginInterface::class);
$auth_plugin->method('getAuthenticationOptions')->willReturn($auth_headers);

$auth_manager = $this->createMock(AuthenticationPluginManager::class);
$auth_manager->method('createInstance')->willReturn($auth_plugin);
$container = new ContainerBuilder();
$container->set('plugin.manager.migrate_plus.authentication', $auth_manager);
$this->processPlugin = OauthAccessToken::create($container, [], '', []);
}

/**
* The process plugin returns the correct string.
*/
public function testTransform() {
$migration = $this->createMock(MigrateExecutableInterface::class);
$row = new Row();
$row->setSourceProperty('authentication', ['plugin' => 'oauth2']);
$this->assertEquals('foo-bar-baz', $this->processPlugin->transform('', $migration, $row, ''));
}

}

0 comments on commit cd19bc2

Please sign in to comment.