Skip to content

Commit

Permalink
Merge branch 'MDL-78002_402' of https://github.com/stronk7/moodle int…
Browse files Browse the repository at this point in the history
…o MOODLE_402_STABLE
  • Loading branch information
snake committed May 4, 2023
2 parents 97f6672 + c6ff4c5 commit 2138619
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/classes/moodlenet/moodlenet_client.php
Expand Up @@ -72,16 +72,23 @@ public function create_resource_from_stored_file(

$moodleneturl = $this->oauthclient->get_issuer()->get('baseurl');
$apiurl = rtrim($moodleneturl, '/') . self::API_CREATE_RESOURCE_URI;
$stream = $file->get_psr_stream();

$requestdata = $this->prepare_file_share_request_data(
$file->get_filename(),
$file->get_mimetype(),
$file->get_psr_stream(),
$stream,
$resourcename,
$resourcedescription,
);

return $this->httpclient->request('POST', $apiurl, $requestdata);
try {
$response = $this->httpclient->request('POST', $apiurl, $requestdata);
} finally {
$stream->close(); // Always close the request stream ASAP. Or it will remain open till shutdown/destruct.
}

return $response;
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/filestorage/tests/file_system_test.php
Expand Up @@ -1093,6 +1093,7 @@ public function test_get_psr_stream(): void {
$this->assertInstanceOf(\Psr\Http\Message\StreamInterface::class, $stream);
$this->assertEquals(file_get_contents(__FILE__), $stream->getContents());
$this->assertFalse($stream->isWritable());
$stream->close();
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/filestorage/tests/stored_file_test.php
Expand Up @@ -118,6 +118,7 @@ public function test_get_psr_stream(): void {
$this->assertInstanceOf(\Psr\Http\Message\StreamInterface::class, $stream);
$this->assertEquals(file_get_contents($filepath), $stream->getContents());
$this->assertFalse($stream->isWritable());
$stream->close();
}

}

0 comments on commit 2138619

Please sign in to comment.