-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Clean up unused profile pictures (#2887)
Co-authored-by: Kristian Stöckel <[email protected]>
- Loading branch information
1 parent
c184e41
commit 4298b96
Showing
21 changed files
with
38 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
|
||
class CleanUpProfilePictures extends Command | ||
{ | ||
|
||
protected $signature = 'app:clean-up-profilepictures'; | ||
protected $description = 'Clean up profile pictures that somehow didn\'t get deleted when the user was deleted'; | ||
|
||
public function handle(): void { | ||
$usedPictures = User::select('avatar')->distinct()->get()->pluck('avatar')->filter()->toArray(); | ||
|
||
$profilePictures = new \FilesystemIterator(public_path("uploads/avatars")); | ||
foreach ($profilePictures as $profilePicture) { | ||
if (!in_array(basename($profilePicture), $usedPictures)) { | ||
File::delete($profilePicture); | ||
$this->info('Deleted profile picture ' . basename($profilePicture)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes