Merge pull request #541 from nextcloud/bugfix/532/4byte-description
Simly remove 4byte chars from the description if those are not supported
This commit is contained in:
@@ -61,6 +61,10 @@ class Application extends App {
|
|||||||
return $container->getServer()->getConfig()->getSystemValue('dbtype', 'sqlite');
|
return $container->getServer()->getConfig()->getSystemValue('dbtype', 'sqlite');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$container->registerService('database4ByteSupport', function($container) {
|
||||||
|
return $container->getServer()->getDatabaseConnection()->supports4ByteText();
|
||||||
|
});
|
||||||
|
|
||||||
// Delete user/group acl entries when they get deleted
|
// Delete user/group acl entries when they get deleted
|
||||||
/** @var IUserManager $userManager */
|
/** @var IUserManager $userManager */
|
||||||
$userManager = $server->getUserManager();
|
$userManager = $server->getUserManager();
|
||||||
|
|||||||
@@ -38,29 +38,40 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
|||||||
/** @var IManager */
|
/** @var IManager */
|
||||||
private $notificationManager;
|
private $notificationManager;
|
||||||
private $databaseType;
|
private $databaseType;
|
||||||
|
private $database4ByteSupport;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IDBConnection $db,
|
IDBConnection $db,
|
||||||
LabelMapper $labelMapper,
|
LabelMapper $labelMapper,
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
IManager $notificationManager,
|
IManager $notificationManager,
|
||||||
$databaseType = 'sqlite'
|
$databaseType = 'sqlite',
|
||||||
|
$database4ByteSupport = true
|
||||||
) {
|
) {
|
||||||
parent::__construct($db, 'deck_cards', Card::class);
|
parent::__construct($db, 'deck_cards', Card::class);
|
||||||
$this->labelMapper = $labelMapper;
|
$this->labelMapper = $labelMapper;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
$this->notificationManager = $notificationManager;
|
$this->notificationManager = $notificationManager;
|
||||||
$this->databaseType = $databaseType;
|
$this->databaseType = $databaseType;
|
||||||
|
$this->database4ByteSupport = $database4ByteSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert(Entity $entity) {
|
public function insert(Entity $entity) {
|
||||||
$entity->setDatabaseType($this->databaseType);
|
$entity->setDatabaseType($this->databaseType);
|
||||||
$entity->setCreatedAt(time());
|
$entity->setCreatedAt(time());
|
||||||
$entity->setLastModified(time());
|
$entity->setLastModified(time());
|
||||||
|
if (!$this->database4ByteSupport) {
|
||||||
|
$description = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $entity->getDescription());
|
||||||
|
$entity->setDescription($description);
|
||||||
|
}
|
||||||
return parent::insert($entity);
|
return parent::insert($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Entity $entity, $updateModified = true) {
|
public function update(Entity $entity, $updateModified = true) {
|
||||||
|
if (!$this->database4ByteSupport) {
|
||||||
|
$description = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $entity->getDescription());
|
||||||
|
$entity->setDescription($description);
|
||||||
|
}
|
||||||
$entity->setDatabaseType($this->databaseType);
|
$entity->setDatabaseType($this->databaseType);
|
||||||
|
|
||||||
if ($updateModified) {
|
if ($updateModified) {
|
||||||
|
|||||||
Reference in New Issue
Block a user