mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 11:00:39 +00:00
added it_delete_multiple_files_hardly
This commit is contained in:
@@ -320,7 +320,7 @@ class Editor
|
|||||||
if ($item['type'] === 'file') {
|
if ($item['type'] === 'file') {
|
||||||
|
|
||||||
// Get file
|
// Get file
|
||||||
$item = UserFile::withTrashed()
|
$file = UserFile::withTrashed()
|
||||||
->find($id);
|
->find($id);
|
||||||
|
|
||||||
// Get folder shared record
|
// Get folder shared record
|
||||||
@@ -337,20 +337,24 @@ class Editor
|
|||||||
if ($item['force_delete']) {
|
if ($item['force_delete']) {
|
||||||
|
|
||||||
// Delete file
|
// Delete file
|
||||||
Storage::delete('/files/' . $item->basename);
|
Storage::delete("/files/$file->user_id/$file->basename");
|
||||||
|
|
||||||
// Delete thumbnail if exist
|
// Delete thumbnail if exist
|
||||||
if ($item->thumbnail) Storage::delete('/files/' . $item->getRawOriginal('thumbnail'));
|
if ($file->thumbnail) {
|
||||||
|
Storage::delete(
|
||||||
|
"/files/$file->user_id/{$file->getRawOriginal('thumbnail')}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Delete file permanently
|
// Delete file permanently
|
||||||
$item->forceDelete();
|
$file->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Soft delete file
|
// Soft delete file
|
||||||
if (!$item['force_delete']) {
|
if (!$item['force_delete']) {
|
||||||
|
|
||||||
// Soft delete file
|
// Soft delete file
|
||||||
$item->delete();
|
$file->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+66
-13
@@ -182,10 +182,8 @@ class FileTest extends TestCase
|
|||||||
$user = User::factory(User::class)
|
$user = User::factory(User::class)
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$file_1 = File::factory(File::class)
|
$files = File::factory(File::class)
|
||||||
->create();
|
->count(2)
|
||||||
|
|
||||||
$file_2 = File::factory(File::class)
|
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
Sanctum::actingAs($user);
|
Sanctum::actingAs($user);
|
||||||
@@ -193,30 +191,85 @@ class FileTest extends TestCase
|
|||||||
$this->postJson("/api/remove", [
|
$this->postJson("/api/remove", [
|
||||||
'items' => [
|
'items' => [
|
||||||
[
|
[
|
||||||
'id' => $file_1->id,
|
'id' => $files[0]->id,
|
||||||
'type' => 'file',
|
'type' => 'file',
|
||||||
'force_delete' => false,
|
'force_delete' => false,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => $file_2->id,
|
'id' => $files[1]->id,
|
||||||
'type' => 'file',
|
'type' => 'file',
|
||||||
'force_delete' => false,
|
'force_delete' => false,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
])->assertStatus(204);
|
])->assertStatus(204);
|
||||||
|
|
||||||
$this->assertSoftDeleted('files', [
|
$files
|
||||||
'id' => $file_1->id,
|
->each(function ($file) {
|
||||||
]);
|
$this->assertSoftDeleted('files', [
|
||||||
|
'id' => $file->id,
|
||||||
$this->assertSoftDeleted('files', [
|
]);
|
||||||
'id' => $file_2->id,
|
});
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
public function it_delete_multiple_files_hardly()
|
public function it_delete_multiple_files_hardly()
|
||||||
{
|
{
|
||||||
|
Storage::fake('local');
|
||||||
|
|
||||||
|
$this->setup->create_directories();
|
||||||
|
|
||||||
|
$user = User::factory(User::class)
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Sanctum::actingAs($user);
|
||||||
|
|
||||||
|
collect([0, 1])
|
||||||
|
->each(function ($index) {
|
||||||
|
|
||||||
|
$file = UploadedFile::fake()
|
||||||
|
->create("fake-file-$index.pdf", 1200, 'application/pdf');
|
||||||
|
|
||||||
|
$this->postJson('/api/upload', [
|
||||||
|
'file' => $file,
|
||||||
|
'folder_id' => null,
|
||||||
|
'is_last' => true,
|
||||||
|
])->assertStatus(201);
|
||||||
|
});
|
||||||
|
|
||||||
|
$file_ids = File::all()->pluck('id');
|
||||||
|
|
||||||
|
$this->postJson("/api/remove", [
|
||||||
|
'items' => [
|
||||||
|
[
|
||||||
|
'id' => $file_ids->first(),
|
||||||
|
'type' => 'file',
|
||||||
|
'force_delete' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => $file_ids->last(),
|
||||||
|
'type' => 'file',
|
||||||
|
'force_delete' => true,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
])->assertStatus(204);
|
||||||
|
|
||||||
|
$file_ids
|
||||||
|
->each(function ($id) {
|
||||||
|
$this->assertDatabaseMissing('files', [
|
||||||
|
'id' => $id,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
collect([0, 1])
|
||||||
|
->each(function ($index) use ($user) {
|
||||||
|
|
||||||
|
Storage::disk('local')
|
||||||
|
->assertMissing(
|
||||||
|
"files/$user->id/fake-file-$index.pdf"
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function it_zip_and_download_multiple_files()
|
public function it_zip_and_download_multiple_files()
|
||||||
|
|||||||
Reference in New Issue
Block a user