DeleteFileMessage example

$path = ImportExportFileEntity::buildPath($fileId);
            // since the file could be stored in any one directory of the available activities             foreach ($activities as $activitiy) {
                $paths[] = $activitiy . '/' . $path;
                // if file is not of an export there might be a log of invalid records                 if ($activitiy !== ImportExportLogEntity::ACTIVITY_EXPORT) {
                    $paths[] = $activitiy . '/' . $path . '_invalid';
                }
            }
        }

        $message = new DeleteFileMessage();
        $message->setFiles($paths);

        $this->messageBus->dispatch($message);
    }
}
/** * @param list<string> $paths */
    private function performFileDelete(Context $context, array $paths, string $visibility): void
    {
        if (\count($paths) <= 0) {
            return;
        }

        if ($context->hasState(self::SYNCHRONE_FILE_DELETE)) {
            $this->deleteFileHandler->__invoke(new DeleteFileMessage($paths$visibility));

            return;
        }

        $this->messageBus->dispatch(new DeleteFileMessage($paths$visibility));
    }
}
public function testItHandlesDeletes(): void
    {
        $filesystem = $this->getPublicFilesystem();

        $file1 = 'test/file1.txt';
        $file2 = 'test/file2.txt';

        $filesystem->write($file1, 'file 1 content');
        $filesystem->write($file2, 'file 2 content');

        $deleteMsg = new DeleteFileMessage();
        $deleteMsg->setFiles([$file1$file2]);

        $this->handler->__invoke($deleteMsg);

        static::assertFalse($filesystem->has($file1));
        static::assertFalse($filesystem->has($file2));
    }

    public function testItDealsWithMissingFiles(): void
    {
        $filesystem = $this->getPublicFilesystem();

        
Home | Imprint | This part of the site doesn't use cookies.