Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2022-07-26 10:44:15 +0300
committerGitHub <noreply@github.com>2022-07-26 10:44:15 +0300
commit339dfb871263106e68c5c077336d57d066e18087 (patch)
tree910bfc5b587c4e10534c6869388b450fa46aa6c2
parent9896c7f002dfc10a174853f2a8ad67153559522e (diff)
parent1c0342af58a9b4040fe7e7976df9a532311e952d (diff)
Merge pull request #33344 from nextcloud/backport/33129/stable23
[stable23] Fix reading blob data as resource
-rw-r--r--lib/public/AppFramework/Db/Entity.php3
-rw-r--r--tests/lib/AppFramework/Db/EntityTest.php17
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/public/AppFramework/Db/Entity.php b/lib/public/AppFramework/Db/Entity.php
index b7ddc6dc5f7..c40bbb0d22c 100644
--- a/lib/public/AppFramework/Db/Entity.php
+++ b/lib/public/AppFramework/Db/Entity.php
@@ -113,6 +113,9 @@ abstract class Entity {
$type = $this->_fieldTypes[$name];
if ($type === 'blob') {
// (B)LOB is treated as string when we read from the DB
+ if (is_resource($args[0])) {
+ $args[0] = stream_get_contents($args[0]);
+ }
$type = 'string';
}
diff --git a/tests/lib/AppFramework/Db/EntityTest.php b/tests/lib/AppFramework/Db/EntityTest.php
index 17234849a2d..d76a8ccfe06 100644
--- a/tests/lib/AppFramework/Db/EntityTest.php
+++ b/tests/lib/AppFramework/Db/EntityTest.php
@@ -43,6 +43,8 @@ use PHPUnit\Framework\Constraint\IsType;
* @method bool getAnotherBool()
* @method bool isAnotherBool()
* @method void setAnotherBool(bool $anotherBool)
+ * @method string getLongText()
+ * @method void setLongText(string $longText)
*/
class TestEntity extends Entity {
protected $name;
@@ -51,11 +53,13 @@ class TestEntity extends Entity {
protected $preName;
protected $trueOrFalse;
protected $anotherBool;
+ protected $longText;
public function __construct($name = null) {
$this->addType('testId', 'integer');
$this->addType('trueOrFalse', 'bool');
$this->addType('anotherBool', 'boolean');
+ $this->addType('longText', 'blob');
$this->name = $name;
}
}
@@ -210,6 +214,18 @@ class EntityTest extends \Test\TestCase {
$this->assertSame(null, $entity->getId());
}
+ public function testSetterConvertsResourcesToStringProperly() {
+ $string = 'Definitely a string';
+ $stream = fopen('php://memory', 'r+');
+ fwrite($stream, $string);
+ rewind($stream);
+
+ $entity = new TestEntity();
+ $entity->setLongText($stream);
+ fclose($stream);
+ $this->assertSame($string, $entity->getLongText());
+ }
+
public function testGetFieldTypes() {
$entity = new TestEntity();
@@ -218,6 +234,7 @@ class EntityTest extends \Test\TestCase {
'testId' => 'integer',
'trueOrFalse' => 'bool',
'anotherBool' => 'boolean',
+ 'longText' => 'blob',
], $entity->getFieldTypes());
}