@@ -245,52 +245,26 @@ public function fromFileInfo(
245245 ?string $ tags = null ,
246246 ?array $ linkedPageIds = null ,
247247 ): void {
248- $ this ->setId ($ fileInfo ->fileId );
249248 $ dirName = dirname ($ fileInfo ->path );
250249 $ dirName = $ dirName === '. ' ? '' : $ dirName ;
251- if ($ fileInfo ->isIndexPage ()) {
252- if ($ parentId === 0 ) {
253- // Landing page
254- $ this ->setTitle (Server::get (IFactory::class)->get ('collectives ' )->t ('Landing page ' ));
255- } else {
256- // Index page
257- $ this ->setTitle (basename ($ dirName ));
258- }
259- } else {
260- $ this ->setTitle (basename ($ fileInfo ->name , self ::SUFFIX ));
261- }
262- $ this ->setFilePath ($ dirName );
263- $ this ->setTimestamp ($ fileInfo ->mtime );
264- $ this ->setSize ($ fileInfo ->size );
265- $ this ->setFileName ($ fileInfo ->name );
266- if ($ collectivePath !== null ) {
267- $ this ->setCollectivePath ($ collectivePath );
268- }
269- if ($ lastUserId !== null ) {
270- $ this ->setLastUserId ($ lastUserId );
271- }
272- if ($ lastUserDisplayName !== null ) {
273- $ this ->setLastUserDisplayName ($ lastUserDisplayName );
274- }
275- if ($ emoji !== null ) {
276- $ this ->setEmoji ($ emoji );
277- }
278- if ($ fullWidth !== null ) {
279- $ this ->setFullWidth ($ fullWidth );
280- }
281- if ($ subpageOrder !== null ) {
282- $ this ->setSubpageOrder ($ subpageOrder );
283- }
284- if ($ slug !== null ) {
285- $ this ->setSlug ($ slug );
286- }
287- if ($ tags !== null ) {
288- $ this ->setTags ($ tags );
289- }
290- if ($ linkedPageIds !== null ) {
291- $ this ->setLinkedPageIds ($ linkedPageIds );
292- }
293- $ this ->setParentId ($ parentId );
250+ $ this ->fromData (
251+ $ fileInfo ->fileId ,
252+ $ dirName ,
253+ $ fileInfo ->isIndexPage (),
254+ $ parentId ,
255+ $ fileInfo ->name ,
256+ $ fileInfo ->mtime ,
257+ $ fileInfo ->size ,
258+ $ collectivePath ,
259+ $ lastUserId ,
260+ $ lastUserDisplayName ,
261+ $ emoji ,
262+ $ subpageOrder ,
263+ $ fullWidth ,
264+ $ slug ,
265+ $ tags ,
266+ $ linkedPageIds ,
267+ );
294268 }
295269
296270 /**
@@ -309,11 +283,51 @@ public function fromFile(
309283 ?string $ tags = null ,
310284 ?array $ linkedPageIds = null ,
311285 ): void {
312- $ this ->setId ($ file ->getId ());
313- // Set folder name as title for all index pages except the collective landing page
314286 $ dirName = dirname ($ file ->getInternalPath ());
315287 $ dirName = $ dirName === '. ' ? '' : $ dirName ;
316- if (strcmp ($ file ->getName (), self ::INDEX_PAGE_TITLE . self ::SUFFIX ) === 0 ) {
288+ $ isIndexPage = strcmp ($ file ->getName (), self ::INDEX_PAGE_TITLE . self ::SUFFIX ) === 0 ;
289+ $ mountPoint = explode ('/ ' , $ file ->getMountPoint ()->getMountPoint (), 4 );
290+ $ collectivePath = count ($ mountPoint ) >= 4 ? rtrim ($ mountPoint [3 ], '/ ' ) : null ;
291+ $ this ->fromData (
292+ $ file ->getId (),
293+ $ dirName ,
294+ $ isIndexPage ,
295+ $ parentId ,
296+ $ file ->getName (),
297+ $ file ->getMTime (),
298+ (int )$ file ->getSize (),
299+ $ collectivePath ,
300+ $ lastUserId ,
301+ $ lastUserDisplayName ,
302+ $ emoji ,
303+ $ subpageOrder ,
304+ $ fullWidth ,
305+ $ slug ,
306+ $ tags ,
307+ $ linkedPageIds ,
308+ );
309+ }
310+
311+ private function fromData (
312+ int $ id ,
313+ string $ dirName ,
314+ bool $ isIndexPage ,
315+ int $ parentId ,
316+ string $ fileName ,
317+ int $ timestamp ,
318+ int $ size ,
319+ ?string $ collectivePath = null ,
320+ ?string $ lastUserId = null ,
321+ ?string $ lastUserDisplayName = null ,
322+ ?string $ emoji = null ,
323+ ?string $ subpageOrder = null ,
324+ ?bool $ fullWidth = false ,
325+ ?string $ slug = null ,
326+ ?string $ tags = null ,
327+ ?array $ linkedPageIds = null ,
328+ ): void {
329+ $ this ->setId ($ id );
330+ if ($ isIndexPage ) {
317331 if ($ parentId === 0 ) {
318332 // Landing page
319333 $ this ->setTitle (Server::get (IFactory::class)->get ('collectives ' )->t ('Landing page ' ));
@@ -322,15 +336,14 @@ public function fromFile(
322336 $ this ->setTitle (basename ($ dirName ));
323337 }
324338 } else {
325- $ this ->setTitle (basename ($ file -> getName () , self ::SUFFIX ));
339+ $ this ->setTitle (basename ($ fileName , self ::SUFFIX ));
326340 }
327341 $ this ->setFilePath ($ dirName );
328- $ this ->setTimestamp ($ file ->getMTime ());
329- $ this ->setSize ((int )$ file ->getSize ());
330- $ this ->setFileName ($ file ->getName ());
331- $ mountPoint = explode ('/ ' , $ file ->getMountPoint ()->getMountPoint (), 4 );
332- if (count ($ mountPoint ) >= 4 ) {
333- $ this ->setCollectivePath (rtrim ($ mountPoint [3 ], '/ ' ));
342+ $ this ->setTimestamp ($ timestamp );
343+ $ this ->setSize ($ size );
344+ $ this ->setFileName ($ fileName );
345+ if ($ collectivePath !== null ) {
346+ $ this ->setCollectivePath ($ collectivePath );
334347 }
335348 if ($ lastUserId !== null ) {
336349 $ this ->setLastUserId ($ lastUserId );
0 commit comments