- $chapter->changeBook($parent->id);
- $chapter->rebuildPermissions();
- Activity::add(ActivityType::CHAPTER_MOVE, $chapter);
-
- return $parent;
- }
-
- /**
- * Update the default page template used for this chapter.
- * Checks that, if changing, the provided value is a valid template and the user
- * has visibility of the provided page template id.
- */
- protected function updateChapterDefaultTemplate(Chapter $chapter, int $templateId): void
- {
- $changing = $templateId !== intval($chapter->default_template_id);
- if (!$changing) {
- return;
- }
-
- if ($templateId === 0) {
- $chapter->default_template_id = null;
- $chapter->save();
- return;
- }
-
- $templateExists = Page::query()->visible()
- ->where('template', '=', true)
- ->where('id', '=', $templateId)
- ->exists();
-
- $chapter->default_template_id = $templateExists ? $templateId : null;
- $chapter->save();
- }
-
- /**
- * Find a page parent entity via an identifier string in the format:
- * {type}:{id}
- * Example: (book:5).
- *
- * @throws MoveOperationException
- */
- public function findParentByIdentifier(string $identifier): ?Book
- {
- $stringExploded = explode(':', $identifier);
- $entityType = $stringExploded[0];
- $entityId = intval($stringExploded[1]);
+ return (new DatabaseTransaction(function () use ($chapter, $parent) {
+ $chapter->changeBook($parent->id);
+ $chapter->rebuildPermissions();
+ Activity::add(ActivityType::CHAPTER_MOVE, $chapter);