Skip to content
Snippets Groups Projects
Commit 46924143 authored by Aaron Bauman's avatar Aaron Bauman
Browse files

Merge branch '5.0.x' into 3349963-pushpull-revisions

parents 8837a0ce 2766e865
No related branches found
No related tags found
1 merge request!44Issue #3349963: Push/Pull Revisions
Showing
with 82 additions and 54 deletions
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
"consolidation/output-formatters": "^3.2.0 || ^4.1", "consolidation/output-formatters": "^3.2.0 || ^4.1",
"lusitanian/oauth": "^0.8.11", "lusitanian/oauth": "^0.8.11",
"firebase/php-jwt": "^5.0 || ^6.0", "firebase/php-jwt": "^5.0 || ^6.0",
"drupal/address": "^1.8", "drupal/address": "^1.8 || ^2.0",
"drupal/key": "^1.14", "drupal/key": "^1.14",
"drupal/dynamic_entity_reference": "^1.9 || ^2.0 || ^3 || ^4", "drupal/dynamic_entity_reference": "^1.9 || ^2.0 || ^3 || ^4",
"drupal/typed_data": "^1.0-beta2", "drupal/typed_data": "^1.0-beta2",
......
...@@ -194,7 +194,7 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface { ...@@ -194,7 +194,7 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface {
// Attach the new file id to the user entity. // Attach the new file id to the user entity.
/* var \Drupal\file\FileInterface */ /* var \Drupal\file\FileInterface */
if ($file = file_save_data($file_data, $destination, FileSystemInterface::EXISTS_REPLACE)) { if ($file = \Drupal::service('file.repository')->writeData($file_data, $destination, FileSystemInterface::EXISTS_REPLACE)) {
$account->user_picture->target_id = $file->id(); $account->user_picture->target_id = $file->id();
} }
else { else {
......
...@@ -51,9 +51,9 @@ class SalesforceJWTPlugin extends SalesforceAuthProviderPluginBase { ...@@ -51,9 +51,9 @@ class SalesforceJWTPlugin extends SalesforceAuthProviderPluginBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct(array $configuration, $plugin_id, $plugin_definition, ClientInterface $httpClient, SalesforceAuthTokenStorageInterface $storage, ConfigFactoryInterface $configFactory, KeyRepositoryInterface $keyRepository, TimeInterface $time) { public function __construct(array $configuration, $plugin_id, $plugin_definition, ClientInterface $httpClient, SalesforceAuthTokenStorageInterface $storage, ConfigFactoryInterface $configFactory, KeyRepositoryInterface $keyRepository, TimeInterface $time) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $httpClient, $storage, $configFactory);
$this->keyRepository = $keyRepository; $this->keyRepository = $keyRepository;
$this->time = $time; $this->time = $time;
parent::__construct($configuration, $plugin_id, $plugin_definition, $httpClient, $storage, $configFactory);
} }
/** /**
...@@ -195,8 +195,9 @@ class SalesforceJWTPlugin extends SalesforceAuthProviderPluginBase { ...@@ -195,8 +195,9 @@ class SalesforceJWTPlugin extends SalesforceAuthProviderPluginBase {
* JWT Assertion. * JWT Assertion.
*/ */
protected function generateAssertion() { protected function generateAssertion() {
$key = $this->keyRepository->getKey($this->getCredentials()->getKeyId()) $key = $this->keyRepository->getKey($this->getCredentials()->getKeyId()) ?
->getKeyValue(); $this->keyRepository->getKey($this->getCredentials()->getKeyId())
->getKeyValue() : '';
$token = $this->generateAssertionClaim(); $token = $this->generateAssertionClaim();
return JWT::encode($token, $key, 'RS256'); return JWT::encode($token, $key, 'RS256');
} }
......
...@@ -31,7 +31,7 @@ class SalesforceLoggerSubscriber implements EventSubscriberInterface { ...@@ -31,7 +31,7 @@ class SalesforceLoggerSubscriber implements EventSubscriberInterface {
* *
* @var \Drupal\Core\Config\ConfigFactoryInterface * @var \Drupal\Core\Config\ConfigFactoryInterface
*/ */
protected $configFactory; protected $config;
/** /**
* Create a new Salesforce Logger Subscriber. * Create a new Salesforce Logger Subscriber.
......
...@@ -87,30 +87,30 @@ salesforce_mapping.salesforce_mapping.*: ...@@ -87,30 +87,30 @@ salesforce_mapping.salesforce_mapping.*:
type: sequence type: sequence
label: 'Field Mappings' label: 'Field Mappings'
sequence: sequence:
- type: mapping type: mapping
label: 'Field Mapping' label: 'Field Mapping'
mapping: mapping:
drupal_field_type: drupal_field_type:
type: string type: string
label: 'Fieldmap Type' label: 'Fieldmap Type'
drupal_field_value: drupal_field_value:
type: string type: string
label: 'Fieldmap Value' label: 'Fieldmap Value'
direction: direction:
type: string type: string
label: 'Direction' label: 'Direction'
salesforce_field: salesforce_field:
type: string type: string
label: 'Salesforce Field Name' label: 'Salesforce Field Name'
id: id:
type: integer type: integer
label: 'Field Id' label: 'Field Id'
drupal_constant: drupal_constant:
type: string type: string
label: 'Drupal Constant' label: 'Drupal Constant'
description: description:
type: text type: text
label: 'Description' label: 'Description'
# Schema / Config API requires that we add these: # Schema / Config API requires that we add these:
status: status:
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\salesforce_mapping\Plugin\Validation\Constraint; namespace Drupal\salesforce_mapping\Plugin\Validation\Constraint;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
...@@ -10,7 +11,7 @@ use Symfony\Component\Validator\ConstraintValidator; ...@@ -10,7 +11,7 @@ use Symfony\Component\Validator\ConstraintValidator;
/** /**
* Validates that a set of fields are unique for the given entity type. * Validates that a set of fields are unique for the given entity type.
*/ */
class UniqueFieldsConstraintValidator extends ConstraintValidator { class UniqueFieldsConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/** /**
* The entity type manager. * The entity type manager.
......
...@@ -45,7 +45,8 @@ class MappedObjectList extends EntityListBuilder { ...@@ -45,7 +45,8 @@ class MappedObjectList extends EntityListBuilder {
return new static( return new static(
$entity_type, $entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()), $container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('url_generator') $container->get('url_generator'),
$container->get('date.formatter')
); );
} }
......
...@@ -12,8 +12,6 @@ use Drupal\Tests\BrowserTestBase; ...@@ -12,8 +12,6 @@ use Drupal\Tests\BrowserTestBase;
*/ */
class SalesforceMappingCrudFormTest extends BrowserTestBase { class SalesforceMappingCrudFormTest extends BrowserTestBase {
use StringTranslationTrait;
/** /**
* Default theme required for D9. * Default theme required for D9.
* *
...@@ -73,9 +71,9 @@ class SalesforceMappingCrudFormTest extends BrowserTestBase { ...@@ -73,9 +71,9 @@ class SalesforceMappingCrudFormTest extends BrowserTestBase {
'drupal_bundle' => 'salesforce_mapping_test_content', 'drupal_bundle' => 'salesforce_mapping_test_content',
'salesforce_object_type' => 'Contact', 'salesforce_object_type' => 'Contact',
]; ];
$this->submitForm($post, $this->t('Save')); $this->submitForm($post, 'Save');
$this->assertSession() $this->assertSession()
->pageTextContainsOnce($this->t('The mapping has been successfully saved.')); ->pageTextContainsOnce('The mapping has been successfully saved.');
$mapping = $mappingStorage->load($mapping_name); $mapping = $mappingStorage->load($mapping_name);
// Make sure mapping was saved correctly. // Make sure mapping was saved correctly.
...@@ -92,7 +90,7 @@ class SalesforceMappingCrudFormTest extends BrowserTestBase { ...@@ -92,7 +90,7 @@ class SalesforceMappingCrudFormTest extends BrowserTestBase {
'drupal_bundle' => 'salesforce_mapping_test_content', 'drupal_bundle' => 'salesforce_mapping_test_content',
'salesforce_object_type' => 'Contact', 'salesforce_object_type' => 'Contact',
]; ];
$this->submitForm($post, $this->t('Save')); $this->submitForm($post, 'Save');
$this->assertSession()->fieldValueEquals('label', $post['label']); $this->assertSession()->fieldValueEquals('label', $post['label']);
// Test simply adding a field plugin of every possible type. This is not // Test simply adding a field plugin of every possible type. This is not
...@@ -108,7 +106,7 @@ class SalesforceMappingCrudFormTest extends BrowserTestBase { ...@@ -108,7 +106,7 @@ class SalesforceMappingCrudFormTest extends BrowserTestBase {
if (call_user_func([$definition['class'], 'isAllowed'], $mapping)) { if (call_user_func([$definition['class'], 'isAllowed'], $mapping)) {
// Add a new field: // Add a new field:
$post['buttons[field_type]'] = $definition['id']; $post['buttons[field_type]'] = $definition['id'];
$this->submitForm($post, $this->t('Add a field mapping')); $this->submitForm($post, 'Add a field mapping');
// Confirm that the new field shows up: // Confirm that the new field shows up:
$this->assertSession()->pageTextContains($definition['label']); $this->assertSession()->pageTextContains($definition['label']);
...@@ -141,9 +139,9 @@ class SalesforceMappingCrudFormTest extends BrowserTestBase { ...@@ -141,9 +139,9 @@ class SalesforceMappingCrudFormTest extends BrowserTestBase {
} }
// Confirm that form saves correctly. // Confirm that form saves correctly.
$this->submitForm($post, $this->t('Save')); $this->submitForm($post, 'Save');
$this->assertSession() $this->assertSession()
->pageTextContainsOnce($this->t('The mapping has been successfully saved.')); ->pageTextContainsOnce('The mapping has been successfully saved.');
// Confirm that the changes are stored properly by reloading and counting // Confirm that the changes are stored properly by reloading and counting
// the fields. // the fields.
......
...@@ -17,16 +17,16 @@ class SalesforceAuthListBuilder extends ConfigEntityListBuilder { ...@@ -17,16 +17,16 @@ class SalesforceAuthListBuilder extends ConfigEntityListBuilder {
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
/** @var \Drupal\salesforce\SalesforceAuthProviderInterface $plugin */ /** @var \Drupal\salesforce\SalesforceAuthProviderInterface $plugin */
$plugin = $entity->getPlugin(); $plugin = $entity->getPlugin();
$row['default'] = $entity->authManager() $row['default'] = $entity->authManager()->getConfig()?->id == $entity->id()
->getConfig() && $entity->authManager() ? $this->t('Default')
->getConfig() : '';
->id() == $entity->id()
? $this->t('Default') : '';
$row['label'] = $entity->label(); $row['label'] = $entity->label();
$row['url'] = $plugin->getCredentials()->getLoginUrl(); $row['url'] = $plugin?->getCredentials()?->getLoginUrl();
$row['key'] = substr($plugin->getCredentials()->getConsumerKey(), 0, 16) . '...'; $row['key'] = $plugin?->getCredentials()?->getConsumerKey()
$row['type'] = $plugin->label(); ? substr($plugin?->getCredentials()?->getConsumerKey(), 0, 16) . '...'
$row['status'] = $plugin->hasAccessToken() ? 'Authorized' : 'Missing'; : NULL;
$row['type'] = $plugin?->label();
$row['status'] = $plugin?->hasAccessToken() ? 'Authorized' : 'Missing';
return $row + parent::buildRow($entity); return $row + parent::buildRow($entity);
} }
...@@ -40,8 +40,8 @@ class SalesforceAuthListBuilder extends ConfigEntityListBuilder { ...@@ -40,8 +40,8 @@ class SalesforceAuthListBuilder extends ConfigEntityListBuilder {
// Add a "revoke" action if we have a token. // Add a "revoke" action if we have a token.
$operations['edit']['url'] = $entity->toUrl('edit-form'); $operations['edit']['url'] = $entity->toUrl('edit-form');
if (!$entity instanceof SalesforceAuthConfig if (!$entity instanceof SalesforceAuthConfig
|| !$entity->getPlugin()->hasAccessToken() || !$entity->getPlugin()?->hasAccessToken()
|| !$entity->hasLinkTemplate('revoke')) { || !$entity->hasLinkTemplate('revoke')) {
return $operations; return $operations;
} }
// Add a "revoke" action if we have a token. // Add a "revoke" action if we have a token.
......
...@@ -7,6 +7,7 @@ use Drupal\Component\Serialization\Json; ...@@ -7,6 +7,7 @@ use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelTrait;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\salesforce\IdentityNotFoundException; use Drupal\salesforce\IdentityNotFoundException;
...@@ -25,6 +26,7 @@ use GuzzleHttp\Exception\RequestException; ...@@ -25,6 +26,7 @@ use GuzzleHttp\Exception\RequestException;
class RestClient implements RestClientInterface { class RestClient implements RestClientInterface {
use StringTranslationTrait; use StringTranslationTrait;
use LoggerChannelTrait;
/** /**
* Response object. * Response object.
...@@ -207,8 +209,14 @@ class RestClient implements RestClientInterface { ...@@ -207,8 +209,14 @@ class RestClient implements RestClientInterface {
} }
// If authToken is not set, try refreshing it before failing init. // If authToken is not set, try refreshing it before failing init.
if (!$this->authToken) { if (!$this->authToken) {
$this->authToken = $this->authManager->refreshToken(); try {
return isset($this->authToken); $this->authToken = $this->authManager->refreshToken();
return isset($this->authToken);
}
catch (\Exception $e) {
$this->getLogger('salesforce')->error('@e', ['@e' => $e->getMessage()]);
return FALSE;
}
} }
return TRUE; return TRUE;
} }
......
...@@ -122,6 +122,12 @@ class RestResponseDescribe extends RestResponse { ...@@ -122,6 +122,12 @@ class RestResponseDescribe extends RestResponse {
protected array $urls; protected array $urls;
protected bool $hasSubtypes;
protected ?string $listviewable;
protected ?string $lookupLayoutable;
// phpcs:enable // phpcs:enable
/** /**
......
...@@ -51,6 +51,13 @@ class SelectQuery implements SelectQueryInterface { ...@@ -51,6 +51,13 @@ class SelectQuery implements SelectQueryInterface {
*/ */
public $offset; public $offset;
/**
* The operator used to combine conditions, defaults to 'AND'.
*
* @var string
*/
public $conjunction;
/** /**
* SelectQuery constructor. * SelectQuery constructor.
* *
...@@ -59,11 +66,15 @@ class SelectQuery implements SelectQueryInterface { ...@@ -59,11 +66,15 @@ class SelectQuery implements SelectQueryInterface {
*/ */
public function __construct($object_type = '') { public function __construct($object_type = '') {
$this->objectType = $object_type; $this->objectType = $object_type;
$this->conjunction = 'AND';
} }
/** /**
* Add a condition to the query. * Add a condition to the query.
* *
* Conditions will be combined with the conjunction defined by
* $this->conjunction. Defaults to 'AND'.
*
* @param string $field * @param string $field
* Field name. * Field name.
* @param mixed $value * @param mixed $value
...@@ -100,6 +111,8 @@ class SelectQuery implements SelectQueryInterface { ...@@ -100,6 +111,8 @@ class SelectQuery implements SelectQueryInterface {
* Implements PHP's magic toString(). * Implements PHP's magic toString().
* *
* Function to convert the query to a string to pass to the SF API. * Function to convert the query to a string to pass to the SF API.
* Conditions will be combined with the conjunction defined by
* $this->conjunction. Defaults to 'AND'.
* *
* @return string * @return string
* SOQL query ready to be executed the SF API. * SOQL query ready to be executed the SF API.
...@@ -116,7 +129,7 @@ class SelectQuery implements SelectQueryInterface { ...@@ -116,7 +129,7 @@ class SelectQuery implements SelectQueryInterface {
foreach ($this->conditions as $condition) { foreach ($this->conditions as $condition) {
$where[] = implode('+', $condition); $where[] = implode('+', $condition);
} }
$query .= '+WHERE+' . implode('+AND+', $where); $query .= '+WHERE+' . implode('+' . $this->conjunction . '+', $where);
} }
if ($this->order) { if ($this->order) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment