Skip to content

Commit 0b20fc3

Browse files
committed
fix: Wrap renaming of notes through autotile in locking context
Signed-off-by: Julius Härtl <[email protected]>
1 parent 1bbe5ff commit 0b20fc3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/Controller/NotesController.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,44 @@
1212
use OCP\AppFramework\Http\JSONResponse;
1313
use OCP\AppFramework\Http\StreamResponse;
1414
use OCP\Files\IMimeTypeDetector;
15+
use OCP\Files\Lock\ILock;
16+
use OCP\Files\Lock\ILockManager;
17+
use OCP\Files\Lock\LockContext;
1518
use OCP\IConfig;
1619
use OCP\IL10N;
1720
use OCP\IRequest;
1821

1922
class NotesController extends Controller {
2023
private NotesService $notesService;
2124
private SettingsService $settingsService;
25+
private ILockManager $lockManager;
2226
private Helper $helper;
2327
private IConfig $settings;
2428
private IL10N $l10n;
2529
private IMimeTypeDetector $mimeTypeDetector;
30+
private string $userId;
2631

2732
public function __construct(
2833
string $AppName,
2934
IRequest $request,
3035
NotesService $notesService,
36+
ILockManager $lockManager,
3137
SettingsService $settingsService,
3238
Helper $helper,
3339
IConfig $settings,
3440
IL10N $l10n,
35-
IMimeTypeDetector $mimeTypeDetector
41+
IMimeTypeDetector $mimeTypeDetector,
42+
string $userId
3643
) {
3744
parent::__construct($AppName, $request);
3845
$this->notesService = $notesService;
3946
$this->settingsService = $settingsService;
47+
$this->lockManager = $lockManager;
4048
$this->helper = $helper;
4149
$this->settings = $settings;
4250
$this->l10n = $l10n;
4351
$this->mimeTypeDetector = $mimeTypeDetector;
52+
$this->userId = $userId;
4453
}
4554

4655
/**
@@ -208,7 +217,15 @@ public function autotitle(int $id) : JSONResponse {
208217
$oldTitle = $note->getTitle();
209218
$newTitle = $this->notesService->getTitleFromContent($note->getContent());
210219
if ($oldTitle !== $newTitle) {
211-
$note->setTitle($newTitle);
220+
$isRichText = $this->settingsService->get($this->userId, 'noteMode') === 'rich';
221+
$lockContext = new LockContext(
222+
$note->getFile(),
223+
$isRichText ? ILock::TYPE_APP : ILock::TYPE_USER,
224+
$isRichText ? 'text' : $this->userId
225+
);
226+
$this->lockManager->runInScope($lockContext, function () use ($note, $newTitle) {
227+
$note->setTitle($newTitle);
228+
});
212229
}
213230
return $note->getTitle();
214231
});

lib/Service/Note.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,8 @@ public function setFavorite(bool $favorite) : void {
179179
$this->noteUtil->getTagService()->setFavorite($this->getId(), $favorite);
180180
}
181181
}
182+
183+
public function getFile(): File {
184+
return $this->file;
185+
}
182186
}

0 commit comments

Comments
 (0)