Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
IntegrationService Class Reference
Inheritance diagram for IntegrationService:
IntegrationServiceInterface

Public Member Functions

 __construct (IntegrationFactory $integrationFactory, IntegrationOauthService $oauthService)
 
 create (array $integrationData)
 
 update (array $integrationData)
 
 delete ($integrationId)
 
 get ($integrationId)
 
 findByName ($name)
 
 findByConsumerId ($consumerId)
 
 findActiveIntegrationByConsumerId ($consumerId)
 
 getSelectedResources ($integrationId)
 

Protected Member Functions

 _loadIntegrationById ($integrationId)
 
 _addOauthConsumerData (IntegrationModel $integration)
 
 _addOauthTokenData (IntegrationModel $integration)
 

Protected Attributes

 $_integrationFactory
 
 $_oauthService
 

Detailed Description

Integration Service.

This service is used to interact with integrations.

Definition at line 19 of file IntegrationService.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( IntegrationFactory  $integrationFactory,
IntegrationOauthService  $oauthService 
)

Construct and initialize Integration Factory

Parameters
IntegrationFactory$integrationFactory
IntegrationOauthService$oauthService

Definition at line 37 of file IntegrationService.php.

38  {
39  $this->_integrationFactory = $integrationFactory;
40  $this->_oauthService = $oauthService;
41  }

Member Function Documentation

◆ _addOauthConsumerData()

_addOauthConsumerData ( IntegrationModel  $integration)
protected

Add oAuth consumer key and secret.

Parameters
IntegrationModel$integration
Returns
void

Definition at line 159 of file IntegrationService.php.

160  {
161  if ($integration->getId()) {
162  $consumer = $this->_oauthService->loadConsumer($integration->getConsumerId());
163  $integration->setData('consumer_key', $consumer->getKey());
164  $integration->setData('consumer_secret', $consumer->getSecret());
165  }
166  }

◆ _addOauthTokenData()

_addOauthTokenData ( IntegrationModel  $integration)
protected

Add oAuth token and token secret.

Parameters
IntegrationModel$integration
Returns
void

Definition at line 174 of file IntegrationService.php.

175  {
176  if ($integration->getId()) {
177  $accessToken = $this->_oauthService->getAccessToken($integration->getConsumerId());
178  if ($accessToken) {
179  $integration->setData('token', $accessToken->getToken());
180  $integration->setData('token_secret', $accessToken->getSecret());
181  }
182  }
183  }

◆ _loadIntegrationById()

_loadIntegrationById (   $integrationId)
protected

Load integration by id.

Parameters
int$integrationId
Returns
IntegrationModel
Exceptions

Definition at line 144 of file IntegrationService.php.

145  {
146  $integration = $this->_integrationFactory->create()->load($integrationId);
147  if (!$integration->getId()) {
148  throw new IntegrationException(__('The integration with ID "%1" doesn\'t exist.', $integrationId));
149  }
150  return $integration;
151  }
__()
Definition: __.php:13

◆ create()

create ( array  $integrationData)

{Create a new Integration

Parameters
array$integrationData
Returns
IntegrationModel
Exceptions
}

Implements IntegrationServiceInterface.

Definition at line 46 of file IntegrationService.php.

47  {
48  $this->_checkIntegrationByName($integrationData['name']);
49  $integration = $this->_integrationFactory->create()->setData($integrationData);
50  $integration->save();
51  $consumerName = 'Integration' . $integration->getId();
52  $consumer = $this->_oauthService->createConsumer(['name' => $consumerName]);
53  $integration->setConsumerId($consumer->getId());
54  $integration->save();
55  return $integration;
56  }

◆ delete()

delete (   $integrationId)

{Delete an Integration.

Parameters
int$integrationId
Returns
array Integration data
Exceptions
}

Implements IntegrationServiceInterface.

Definition at line 76 of file IntegrationService.php.

77  {
78  $integration = $this->_loadIntegrationById($integrationId);
79  $data = $integration->getData();
80  $integration->delete();
81  return $data;
82  }

◆ findActiveIntegrationByConsumerId()

findActiveIntegrationByConsumerId (   $consumerId)

{Get the details of an active Integration by consumer_id.

Parameters
int$consumerId
Returns
IntegrationModel
}

Implements IntegrationServiceInterface.

Definition at line 116 of file IntegrationService.php.

117  {
118  $integration = $this->_integrationFactory->create()->loadActiveIntegrationByConsumerId($consumerId);
119  return $integration;
120  }

◆ findByConsumerId()

findByConsumerId (   $consumerId)

{Get the details of an Integration by consumer_id.

Parameters
int$consumerId
Returns
IntegrationModel
}

Implements IntegrationServiceInterface.

Definition at line 107 of file IntegrationService.php.

108  {
109  $integration = $this->_integrationFactory->create()->load($consumerId, 'consumer_id');
110  return $integration;
111  }

◆ findByName()

findByName (   $name)

{Find Integration by name.

Parameters
string$integrationName
Returns
IntegrationModel
}

Implements IntegrationServiceInterface.

Definition at line 98 of file IntegrationService.php.

99  {
100  $integration = $this->_integrationFactory->create()->load($name, 'name');
101  return $integration;
102  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ get()

get (   $integrationId)

{Get the details of a specific Integration.

Parameters
int$integrationId
Returns
IntegrationModel
Exceptions
}

Implements IntegrationServiceInterface.

Definition at line 87 of file IntegrationService.php.

88  {
89  $integration = $this->_loadIntegrationById($integrationId);
92  return $integration;
93  }
_addOauthTokenData(IntegrationModel $integration)
_addOauthConsumerData(IntegrationModel $integration)

◆ getSelectedResources()

getSelectedResources (   $integrationId)

{Return an array of selected resources for an integration.

Parameters
int$integrationId
Returns
array
}

Implements IntegrationServiceInterface.

Definition at line 188 of file IntegrationService.php.

189  {
190  $integration = $this->get($integrationId);
191  $data = $integration->getData();
192 
193  $selectedResourceIds = [];
194  if ($data && isset($data['resource']) && is_array($data['resource'])) {
195  $selectedResourceIds = $data['resource'];
196  }
197  return $selectedResourceIds;
198  }

◆ update()

update ( array  $integrationData)

{Update an Integration.

Parameters
array$integrationData
Returns
IntegrationModel
Exceptions
}

Implements IntegrationServiceInterface.

Definition at line 61 of file IntegrationService.php.

62  {
63  $integration = $this->_loadIntegrationById($integrationData['integration_id']);
64  //If name has been updated check if it conflicts with an existing integration
65  if ($integration->getName() != $integrationData['name']) {
66  $this->_checkIntegrationByName($integrationData['name']);
67  }
68  $integration->addData($integrationData);
69  $integration->save();
70  return $integration;
71  }

Field Documentation

◆ $_integrationFactory

$_integrationFactory
protected

Definition at line 24 of file IntegrationService.php.

◆ $_oauthService

$_oauthService
protected

Definition at line 29 of file IntegrationService.php.


The documentation for this class was generated from the following file: