Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions social_post.post_update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* Update encryption tokens in Social Post.
*/
function social_post_post_update_add_encryption_to_access_tokens(&$sandbox = NULL) {
$entity = \Drupal::entityTypeManager()
->getStorage('social_post');

foreach($entity as $user) {
$token = $user->get('token');
$user->setToken($token);
$user->save();
$result = t('Token %nid saved', [
'%nid' => $user
->id(),
]);
}

}
3 changes: 2 additions & 1 deletion src/Entity/SocialPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\social_api\Entity\SocialApi;

/**
* Defines the Social Post entity.
Expand Down Expand Up @@ -37,7 +38,7 @@
* }
* )
*/
class SocialPost extends ContentEntityBase implements ContentEntityInterface {
class SocialPost extends SocialApi implements ContentEntityInterface {
use EntityChangedTrait;

/**
Expand Down
10 changes: 2 additions & 8 deletions src/SocialPostManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public function addRecord($name, $provider_user_id, $token, $additional_data = N
];

$user_info = $this->entityTypeManager->getStorage('social_post')->create($values);
$user_info->setToken($token);

// Save the entity.
$user_info->save();
Expand Down Expand Up @@ -269,14 +270,7 @@ public function getToken($provider_user_id) {
])
);

if (!$user_data) {
return FALSE;
}
else {
// Get token and decrypt it.
return $this->decryptToken($user_data->get('token')->getValue()[0]['value']);
}

return $this->decryptToken($user_data->get('token')->getValue()[0]['value']);
}

/**
Expand Down