Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/8.0' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/8.0
  • Loading branch information
metaventis-build committed Sep 21, 2023
2 parents e7760f7 + 63af3ab commit 343fbed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 14 additions & 2 deletions service/src/main/php/src/lib/EduRestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace connector\lib;

use connector\tools\h5p\H5PFramework;

define('APPID', 'educonnector');

class EduRestClient
Expand Down Expand Up @@ -93,7 +95,7 @@ public function unlockNode($nodeId) {
throw new \Exception('Error unlocking node ' . $nodeId, $httpcode);
}

public function getContent($node, $downloadUrl=NULL){
public function getContent($node, $downloadUrl = null, $isH5p = false){
if ($node->node->contentUrl){
$contentUrl = $node->node->contentUrl; //repo-version 5.0 or older
}else{
Expand Down Expand Up @@ -122,14 +124,24 @@ public function getContent($node, $downloadUrl=NULL){
$url = $contentUrl . '&ticket=' . $_SESSION[$this->connectorId]['ticket'] . '&params=display%3Ddownload';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (! $isH5p) {
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
} else {
$h5pFramework = new H5PFramework();
$path = $h5pFramework->getUploadedH5pPath();
$filePath = fopen($path, 'wb');
curl_setopt($curl,CURLOPT_FILE, $filePath);
}
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeader);
$data = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($isH5p) {
fclose($filePath);
}
if ($httpcode >= 200 && $httpcode < 308) {
return $data;
}else{
Expand Down
6 changes: 1 addition & 5 deletions service/src/main/php/src/tools/h5p/H5P.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,7 @@ public function setNode() {
}
} else {
$client = new EduRestClient($this->connectorId);
$data = $client->getContent($node);

$fp = fopen($this->H5PFramework->getUploadedH5pPath(), 'w');
fwrite($fp, $data);
fclose($fp);
$client->getContent($node, null, true);
}
$_SESSION[$this->connectorId]['node'] = $node;
}
Expand Down

0 comments on commit 343fbed

Please sign in to comment.