@@ -315,34 +315,49 @@ protected function init(): void
315
315
/**
316
316
* Perform import from filesystem.
317
317
*/
318
- public function importFromFilesystem ($ path , $ isSub = false )
318
+ public function importFromFilesystem (string $ path , bool $ isSub = false ): void
319
319
{
320
320
if (!$ isSub ) {
321
+ if ($ this ->isEntity ()) {
322
+ $ this ->getModel ()->importFromFilesystem ($ path );
323
+
324
+ return ;
325
+ }
326
+
327
+ if (!$ this ->persistence ->connection ->inTransaction ()) {
328
+ $ this ->atomic (function () use ($ path ) {
329
+ $ this ->importFromFilesystem ($ path );
330
+ });
331
+
332
+ return ;
333
+ }
334
+
335
+ foreach ($ this as $ entity ) {
336
+ $ entity ->delete ();
337
+ }
338
+
321
339
$ path = __DIR__ . '/../ ' . $ path ;
322
340
}
323
341
324
- $ dir = new \DirectoryIterator ($ path );
325
- foreach ($ dir as $ fileinfo ) {
326
- $ name = $ fileinfo ->getFilename ();
327
-
328
- if ($ name === '. ' || $ name [0 ] === '. ' ) {
342
+ foreach (new \DirectoryIterator ($ path ) as $ fileinfo ) {
343
+ if ($ fileinfo ->isDot () || in_array ($ fileinfo ->getFilename (), ['.git ' , 'vendor ' , 'js ' ])) {
329
344
continue ;
330
345
}
331
346
332
- if ($ name === 'src ' || $ name === ' demos ' || $ isSub ) {
333
- $ entity = $ this ->getModel ( true )-> createEntity ();
347
+ if (in_array ( $ fileinfo -> getFilename (), [ ' demos ' , 'src ' , ' tests ' ], true ) || $ isSub ) {
348
+ $ entity = $ this ->createEntity ();
334
349
335
350
/*
336
351
// Disabling saving file in db
337
- $m ->save([
352
+ $entity ->save([
338
353
$this->fieldName()->name => $fileinfo->getFilename(),
339
354
$this->fieldName()->is_folder => $fileinfo->isDir(),
340
355
$this->fieldName()->type => pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION),
341
356
]);
342
357
*/
343
358
344
359
if ($ fileinfo ->isDir ()) {
345
- $ entity ->SubFolder ->importFromFilesystem ($ dir ->getPath () . '/ ' . $ name , true );
360
+ $ entity ->SubFolder ->importFromFilesystem ($ fileinfo ->getPath () . '/ ' . $ fileinfo -> getFilename () , true );
346
361
}
347
362
}
348
363
}
0 commit comments