-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/maven/fixes/9.1' into maven/rele…
…ase/9.1
- Loading branch information
Showing
14 changed files
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
service/src/main/php/func/classes.new/ESRender/Plugin/Sodix.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
require_once(dirname(__FILE__) . '/../../../../vendor/autoload.php'); | ||
|
||
use GuzzleHttp\RequestOptions; | ||
use GuzzleHttp\Exception\RequestException; | ||
use GuzzleHttp\Exception\TransferException; | ||
use GuzzleHttp\Psr7; | ||
|
||
class ESRender_Plugin_Sodix extends ESRender_Plugin_Abstract | ||
{ | ||
protected String $url; | ||
protected String $user; | ||
protected String $password; | ||
|
||
public function __construct(array $properties = [ | ||
"url" => "", | ||
"user" => "", | ||
"password" => "" | ||
]) { | ||
parent::__construct($properties); | ||
} | ||
|
||
public function postRetrieveObjectProperties(&$data): void { | ||
$esObject = new ESObject($data); | ||
$logger = $this->getLogger(); | ||
if ($esObject->getNodeProperty('ccm:replicationsource') !== 'SODIX') { | ||
return; | ||
} | ||
if (empty($esObject->getNodeProperty('ccm:replicationsourceid'))) { | ||
$logger->error("No SODIX ID found for"); | ||
} | ||
$isPayedMedia = $esObject->getNodeProperty('ccm:editorial_state') === 'restricted_mz'; | ||
$logger->info("Started communication with SODIX API for node" . ($isPayedMedia ? ' (payed media)' : '')); | ||
$repId = $esObject->getNodeProperty('ccm:replicationsourceid'); | ||
$token = $this->getToken(); | ||
if (empty($token)) { | ||
$logger->error("Token could not be retrieved, aborting"); | ||
return; | ||
} | ||
$logger->info("Successfully retrieved token."); | ||
if (!$isPayedMedia) { | ||
$body = [ | ||
"operationName" => "getPlayoutWindow", | ||
"query" => "query getPlayoutWindow { getPlayoutWindow(mediaId: \"$repId\") { playoutUrl } }" | ||
]; | ||
} else { | ||
$body = [ | ||
"operationName" => "paidMediaLinks", | ||
"query" => "query paidMediaLinks { paidMediaLinks(id: \"$repId\") { links { href linkType } } }" | ||
]; | ||
} | ||
$response = $this->getGraphQL($token, $body); | ||
if (empty($response)) { | ||
return; | ||
} | ||
$this->handlePlayOut($response, $data, $isPayedMedia); | ||
} | ||
|
||
private function getToken(): String { | ||
$logger = $this->getLogger(); | ||
$uri = substr($this->url, 0, -8) . '/auth/login'; | ||
$client = GuzzleHelper::getClient(); | ||
try { | ||
$result = $client->post($uri, [ | ||
GuzzleHttp\RequestOptions::JSON =>["login" => $this->user, "password" => $this->password], | ||
'http_errors' => true | ||
]); | ||
} catch (GuzzleHttp\Exception\ClientException | GuzzleHttp\Exception\TransferException $exception) { | ||
$logger->error(GuzzleHttp\Psr7\Message::toString($exception->getResponse())); | ||
return ""; | ||
} | ||
|
||
return json_decode($result->getBody(), true)["access_token"] ?? ""; | ||
} | ||
|
||
private function getGraphQL(String $token, array $body): array { | ||
$logger = $this->getLogger(); | ||
$client = GuzzleHelper::getClient(); | ||
try { | ||
$result = $client->post($this->url, [ | ||
'headers' => [ | ||
'Authorization' => 'Bearer ' . $token, | ||
'Content-Type' => 'application/json' | ||
], | ||
GuzzleHttp\RequestOptions::JSON => $body, | ||
'http_errors' => true | ||
]); | ||
} catch (GuzzleHttp\Exception\ClientException | GuzzleHttp\Exception\TransferException $exception) { | ||
$logger->error(GuzzleHttp\Psr7\Message::toString($exception->getResponse())); | ||
return []; | ||
} | ||
|
||
return json_decode($result->getBody(), true); | ||
} | ||
|
||
private function handlePlayOut(array $response, &$data, bool $isPayedMedia): void { | ||
$logger = $this->getLogger(); | ||
if ($response["errors"][0]["extensions"]["classification"] ?? "" === "DataFetchingException") { | ||
$logger->error("SODIX content contains errors. Url could not be found or retrieved."); | ||
return; | ||
} | ||
if ($isPayedMedia) { | ||
$playOutLinkEntry = array_filter($response['data']['paidMediaLinks']['links'] ?? [], fn($link) => $link['linkType'] === 'direct'); | ||
$playOutUrl = reset($playOutLinkEntry)['href'] ?? ''; | ||
$downloadLinkEntry = array_filter($response['data']['paidMediaLinks']['links'] ?? [], fn($link) => $link['linkType'] === 'download'); | ||
if (!empty($downloadLinkEntry)) { | ||
Config::set('downloadUrl', reset($downloadLinkEntry)['href'] ?? ''); | ||
} | ||
} else { | ||
$playOutUrl = $response["data"]["getPlayoutWindow"]["playoutUrl"] ?? ""; | ||
} | ||
if (empty($playOutUrl)) { | ||
$logger->error("SODIX response does not contain expected url: " . json_encode($response)); | ||
} | ||
$logger->info("SODIX url successfully retrieved."); | ||
$data->node->properties->{'ccm:wwwurl'} = $playOutUrl; | ||
$unique = uniqid(); | ||
Config::set('urlEmbedding', '<iframe id="'.$unique.'" src="'. $playOutUrl . '" width="100%" height="800" border="0"></iframe>'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters