Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/dispatch-afte…
Browse files Browse the repository at this point in the history
…r-commit

# Conflicts:
#	src/Conversions/FileManipulator.php
  • Loading branch information
chrispage1 committed Aug 22, 2024
2 parents 194d580 + 50e9a12 commit 1c0ea67
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 3 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to `laravel-medialibrary` will be documented in this file

## 11.8.3 - 2024-08-20

### What's Changed

* Dispatch conversion jobs after database transactions have been committed by @chrispage1 in https://github.com/spatie/laravel-medialibrary/pull/3687

**Full Changelog**: https://github.com/spatie/laravel-medialibrary/compare/11.8.2...11.8.3

## 11.8.2 - 2024-08-09

### What's Changed

* Correctly remove media folders after removing all media files by @StyxUA in https://github.com/spatie/laravel-medialibrary/pull/3688

### New Contributors

* @StyxUA made their first contribution in https://github.com/spatie/laravel-medialibrary/pull/3688

**Full Changelog**: https://github.com/spatie/laravel-medialibrary/compare/11.8.1...11.8.2

## 11.8.1 - 2024-07-26

### What's Changed
Expand Down
4 changes: 2 additions & 2 deletions src/Support/FileRemover/DefaultFileRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public function removeAllFiles(Media $media): void
{

if ($media->conversions_disk && $media->disk !== $media->conversions_disk) {
$this->removeFromMediaDirectory($media, $media->conversions_disk);
$this->removeFromConversionsDirectory($media, $media->conversions_disk);
$this->removeFromResponsiveImagesDirectory($media, $media->conversions_disk);
$this->removeFromMediaDirectory($media, $media->conversions_disk);
}

$this->removeFromMediaDirectory($media, $media->disk);
$this->removeFromConversionsDirectory($media, $media->disk);
$this->removeFromResponsiveImagesDirectory($media, $media->disk);
$this->removeFromMediaDirectory($media, $media->disk);
}

public function removeFromMediaDirectory(Media $media, string $disk): void
Expand Down
106 changes: 106 additions & 0 deletions tests/Feature/FileAdder/MediaConversions/DeleteMediaFolderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

use Illuminate\Support\Facades\File;

beforeEach(function () {
foreach (range(1, 3) as $index) {
$this->testModelWithoutMediaConversions
->addMedia($this->getTestJpg())
->preservingOriginal()
->toMediaCollection();

$this->testModelWithMultipleConversions
->addMedia($this->getTestJpg())
->preservingOriginal()
->toMediaCollection();

$this->testModelWithResponsiveImages
->addMedia($this->getTestJpg())
->preservingOriginal()
->toMediaCollection();
}
});

it('will remove the media folder when deleting a media model without conversions', function () {
$ids = $this->testModelWithoutMediaConversions->getMedia()->pluck('id');

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue();
});

$this->testModelWithoutMediaConversions->clearMediaCollection();

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse();
});
});

it('will remove the media folder when deleting a subject without media conversions', function () {
$ids = $this->testModelWithoutMediaConversions->getMedia()->pluck('id');

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue();
});

$this->testModelWithoutMediaConversions->delete();

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse();
});
});

it('will remove the media folder when deleting a media model with conversions', function () {
$ids = $this->testModelWithMultipleConversions->getMedia()->pluck('id');

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue();
});

$this->testModelWithMultipleConversions->clearMediaCollection();

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse();
});
});

it('will remove the media folder when deleting a subject with media conversions', function () {
$ids = $this->testModelWithMultipleConversions->getMedia()->pluck('id');

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue();
});

$this->testModelWithMultipleConversions->delete();

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse();
});
});

it('will remove the media folder when deleting a media model with conversions and responsive images', function () {
$ids = $this->testModelWithResponsiveImages->getMedia()->pluck('id');

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue();
});

$this->testModelWithResponsiveImages->clearMediaCollection();

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse();
});
});

it('will remove the media folder when deleting a subject with media conversions and responsive images', function () {
$ids = $this->testModelWithResponsiveImages->getMedia()->pluck('id');

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue();
});

$this->testModelWithResponsiveImages->delete();

$ids->map(function ($id) {
expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse();
});
});
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class TestCase extends Orchestra

protected TestModelWithConversion $testModelWithConversion;

protected TestModelWithMultipleConversion $testModelWithMultipleConversion;
protected TestModelWithMultipleConversions $testModelWithMultipleConversions;

protected TestModelWithPreviewConversion $testModelWithPreviewConversion;

Expand Down

0 comments on commit 1c0ea67

Please sign in to comment.