Skip to content

Commit 82f0d6c

Browse files
committed
remove write/delete action
1 parent b687fd5 commit 82f0d6c

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

demos/collection/multitable.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ public function setModel(Model $model, $route = []): void
7575
$model->addCondition($model->fieldName()->parent_folder_id, null);
7676
$model->setOrder([$model->fieldName()->is_folder => 'desc', $model->fieldName()->name]);
7777

78-
\Atk4\Ui\Header::addTo($app, ['MacOS File Finder', 'subHeader' => 'Component built around Table, Columns and JsReload']);
78+
\Atk4\Ui\Header::addTo($app, ['File Finder', 'subHeader' => 'Component built around Table, Columns and JsReload']);
7979

8080
$vp = \Atk4\Ui\VirtualPage::addTo($app)->set(function (\Atk4\Ui\VirtualPage $vp) use ($model) {
81-
$model->action('delete')->execute();
8281
$model->importFromFilesystem('.');
8382
\Atk4\Ui\Button::addTo($vp, ['Import Complete', 'big green fluid'])->link('multitable.php');
8483
$vp->js(true)->closest('.modal')->find('.header')->remove();

demos/init-db.php

+25-10
Original file line numberDiff line numberDiff line change
@@ -315,34 +315,49 @@ protected function init(): void
315315
/**
316316
* Perform import from filesystem.
317317
*/
318-
public function importFromFilesystem($path, $isSub = false)
318+
public function importFromFilesystem(string $path, bool $isSub = false): void
319319
{
320320
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+
321339
$path = __DIR__ . '/../' . $path;
322340
}
323341

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'])) {
329344
continue;
330345
}
331346

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();
334349

335350
/*
336351
// Disabling saving file in db
337-
$m->save([
352+
$entity->save([
338353
$this->fieldName()->name => $fileinfo->getFilename(),
339354
$this->fieldName()->is_folder => $fileinfo->isDir(),
340355
$this->fieldName()->type => pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION),
341356
]);
342357
*/
343358

344359
if ($fileinfo->isDir()) {
345-
$entity->SubFolder->importFromFilesystem($dir->getPath() . '/' . $name, true);
360+
$entity->SubFolder->importFromFilesystem($fileinfo->getPath() . '/' . $fileinfo->getFilename(), true);
346361
}
347362
}
348363
}

phpstan.neon.dist

-9
Original file line numberDiff line numberDiff line change
@@ -889,15 +889,6 @@ parameters:
889889
-
890890
path: 'demos/init-db.php'
891891
message: '~^Property Atk4\\Ui\\Demos\\Stat::\$title has no type specified\.$~'
892-
-
893-
path: 'demos/init-db.php'
894-
message: '~^Method Atk4\\Ui\\Demos\\File::importFromFilesystem\(\) has no return type specified\.$~'
895-
-
896-
path: 'demos/init-db.php'
897-
message: '~^Method Atk4\\Ui\\Demos\\File::importFromFilesystem\(\) has parameter \$isSub with no type specified\.$~'
898-
-
899-
path: 'demos/init-db.php'
900-
message: '~^Method Atk4\\Ui\\Demos\\File::importFromFilesystem\(\) has parameter \$path with no type specified\.$~'
901892
-
902893
path: 'demos/interactive/console.php'
903894
message: '~^Method class@anonymous/demos/interactive/console\.php:\d+::generateReport\(\) has no return type specified\.$~'

0 commit comments

Comments
 (0)