Simly remove 4byte chars from the description if those are not supported

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-07-18 22:08:35 +02:00
parent dfe6e2f216
commit 9b63e4d745
2 changed files with 16 additions and 1 deletions

View File

@@ -38,29 +38,40 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
/** @var IManager */
private $notificationManager;
private $databaseType;
private $database4ByteSupport;
public function __construct(
IDBConnection $db,
LabelMapper $labelMapper,
IUserManager $userManager,
IManager $notificationManager,
$databaseType = 'sqlite'
$databaseType = 'sqlite',
$database4ByteSupport = true
) {
parent::__construct($db, 'deck_cards', Card::class);
$this->labelMapper = $labelMapper;
$this->userManager = $userManager;
$this->notificationManager = $notificationManager;
$this->databaseType = $databaseType;
$this->database4ByteSupport = $database4ByteSupport;
}
public function insert(Entity $entity) {
$entity->setDatabaseType($this->databaseType);
$entity->setCreatedAt(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);
}
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);
if ($updateModified) {