3
3
namespace BookStack \Entities \Repos ;
4
4
5
5
use BookStack \Activity \TagRepo ;
6
- use BookStack \Entities \Models \Book ;
7
6
use BookStack \Entities \Models \BookChild ;
8
- use BookStack \Entities \Models \Chapter ;
9
7
use BookStack \Entities \Models \Entity ;
10
8
use BookStack \Entities \Models \EntityContainerData ;
11
9
use BookStack \Entities \Queries \PageQueries ;
@@ -31,9 +29,13 @@ public function __construct(
31
29
32
30
/**
33
31
* Create a new entity in the system.
32
+ * @template T of Entity
33
+ * @param T $entity
34
+ * @return T
34
35
*/
35
- public function create (Entity $ entity , array $ input ): void
36
+ public function create (Entity $ entity , array $ input ): Entity
36
37
{
38
+ $ entity = $ entity ->clone ()->refresh ();
37
39
$ entityInput = array_intersect_key ($ input , ['name ' , 'priority ' ]);
38
40
$ entity ->forceFill ($ entityInput );
39
41
$ entity ->forceFill ([
@@ -59,13 +61,19 @@ public function create(Entity $entity, array $input): void
59
61
$ entity ->indexForSearch ();
60
62
61
63
$ this ->referenceStore ->updateForEntity ($ entity );
64
+
65
+ return $ entity ;
62
66
}
63
67
64
68
/**
65
69
* Update the given entity.
70
+ * @template T of Entity
71
+ * @param T $entity
72
+ * @return T
66
73
*/
67
- public function update (Entity $ entity , array $ input ): void
74
+ public function update (Entity $ entity , array $ input ): Entity
68
75
{
76
+ $ entity = $ entity ->clone ()->refresh ();
69
77
$ oldUrl = $ entity ->getUrl ();
70
78
71
79
$ entity ->fill ($ input );
@@ -78,6 +86,7 @@ public function update(Entity $entity, array $input): void
78
86
$ entity ->save ();
79
87
if ($ entity ->shouldHaveContainerData () && $ entity ->containerData ) {
80
88
$ this ->updateContainerDescription ($ entity ->containerData , $ input );
89
+ $ entity ->containerData ->save ();
81
90
}
82
91
83
92
if (isset ($ input ['tags ' ])) {
@@ -91,6 +100,8 @@ public function update(Entity $entity, array $input): void
91
100
if ($ oldUrl !== $ entity ->getUrl ()) {
92
101
$ this ->referenceUpdater ->updateEntityReferences ($ entity , $ oldUrl );
93
102
}
103
+
104
+ return $ entity ;
94
105
}
95
106
96
107
/**
@@ -147,7 +158,7 @@ public function updateDefaultTemplate(EntityContainerData $containerData, int $t
147
158
}
148
159
149
160
/**
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.
151
162
* Typically ran during create/update/insert events.
152
163
*/
153
164
public function sortParent (Entity $ entity ): void
@@ -158,6 +169,9 @@ public function sortParent(Entity $entity): void
158
169
}
159
170
}
160
171
172
+ /**
173
+ * Update the description of the given container data from input data.
174
+ */
161
175
protected function updateContainerDescription (EntityContainerData $ data , array $ input ): void
162
176
{
163
177
if (isset ($ input ['description_html ' ])) {
0 commit comments