33namespace BookStack \Entities \Repos ;
44
55use BookStack \Activity \TagRepo ;
6- use BookStack \Entities \Models \Book ;
76use BookStack \Entities \Models \BookChild ;
8- use BookStack \Entities \Models \Chapter ;
97use BookStack \Entities \Models \Entity ;
108use BookStack \Entities \Models \EntityContainerData ;
119use BookStack \Entities \Queries \PageQueries ;
@@ -31,9 +29,13 @@ public function __construct(
3129
3230 /**
3331 * Create a new entity in the system.
32+ * @template T of Entity
33+ * @param T $entity
34+ * @return T
3435 */
35- public function create (Entity $ entity , array $ input ): void
36+ public function create (Entity $ entity , array $ input ): Entity
3637 {
38+ $ entity = $ entity ->clone ()->refresh ();
3739 $ entityInput = array_intersect_key ($ input , ['name ' , 'priority ' ]);
3840 $ entity ->forceFill ($ entityInput );
3941 $ entity ->forceFill ([
@@ -59,13 +61,19 @@ public function create(Entity $entity, array $input): void
5961 $ entity ->indexForSearch ();
6062
6163 $ this ->referenceStore ->updateForEntity ($ entity );
64+
65+ return $ entity ;
6266 }
6367
6468 /**
6569 * Update the given entity.
70+ * @template T of Entity
71+ * @param T $entity
72+ * @return T
6673 */
67- public function update (Entity $ entity , array $ input ): void
74+ public function update (Entity $ entity , array $ input ): Entity
6875 {
76+ $ entity = $ entity ->clone ()->refresh ();
6977 $ oldUrl = $ entity ->getUrl ();
7078
7179 $ entity ->fill ($ input );
@@ -78,6 +86,7 @@ public function update(Entity $entity, array $input): void
7886 $ entity ->save ();
7987 if ($ entity ->shouldHaveContainerData () && $ entity ->containerData ) {
8088 $ this ->updateContainerDescription ($ entity ->containerData , $ input );
89+ $ entity ->containerData ->save ();
8190 }
8291
8392 if (isset ($ input ['tags ' ])) {
@@ -91,6 +100,8 @@ public function update(Entity $entity, array $input): void
91100 if ($ oldUrl !== $ entity ->getUrl ()) {
92101 $ this ->referenceUpdater ->updateEntityReferences ($ entity , $ oldUrl );
93102 }
103+
104+ return $ entity ;
94105 }
95106
96107 /**
@@ -147,7 +158,7 @@ public function updateDefaultTemplate(EntityContainerData $containerData, int $t
147158 }
148159
149160 /**
150- * Sort the parent of the given entity, if any auto sort actions are set for it.
161+ * Sort the parent of the given entity if any auto sort actions are set for it.
151162 * Typically ran during create/update/insert events.
152163 */
153164 public function sortParent (Entity $ entity ): void
@@ -158,6 +169,9 @@ public function sortParent(Entity $entity): void
158169 }
159170 }
160171
172+ /**
173+ * Update the description of the given container data from input data.
174+ */
161175 protected function updateContainerDescription (EntityContainerData $ data , array $ input ): void
162176 {
163177 if (isset ($ input ['description_html ' ])) {
0 commit comments