<commit_before><?php

namespace Database\Seeders;

use App\Models\Category;
use App\Models\Media;
use App\Models\Post;
use App\Models\PostBlock;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Sequence;
use Illuminate\Database\Seeder;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        $this->deleteStorageFiles();

        $admin = User::factory(['email' => '<EMAIL>', 'role' => 'admin'])
            ->create();
        $editor1 = User::factory(['email' => '<EMAIL>'])
            ->create();
        $editor2 = User::factory(['email' => '<EMAIL>'])
            ->create();

        collect([$admin, $editor1, $editor2])
            ->shuffle()
            ->each(function (User $user, int $k) {
                Media::factory([
                    'model_id' => $user->id,
                    'model_type' => User::class,
                    'model_key' => 'avatar',
                ])
                    ->withFile(
                        database_path(sprintf('seeders/files/users/%s.jpg', $k + 1)),
                        sprintf('users/%s', $user->id),
                    )
                    ->create();
            });

        $categories = Category::factory()
            ->count(8)
            ->create();

        $coverImages = glob(database_path('seeders/files/posts/*.*'));
        Post::factory()
            ->state(new Sequence(
                ['author_id' => $admin->id],
                ['author_id' => $editor1->id],
                ['author_id' => $editor2->id],
            ))
            ->count(25)
            ->create()
            ->each(function (Post $post) use ($categories, $coverImages) {
                Media::factory([
                    'model_id' => $post->id,
                    'model_type' => Post::class,
                    'model_key' => 'cover',
                ])
                    ->withFile(
                        Arr::random($coverImages),
                        sprintf('posts/%s', $post->id),
                    )
                    ->create();

                $post->categories()->attach($categories->shuffle()->take(rand(1, 3))->pluck('id'));

                if (rand(0, 1)) {
                    PostBlock::factory()->text()->create(['post_id' => $post->id]);
                }
                if (rand(0, 1)) {
                    PostBlock::factory()->video()->create(['post_id' => $post->id]);
                }
                if (rand(0, 1)) {
                    $visualsPostBlock = PostBlock::factory()->visuals()->create(['post_id' => $post->id]);
                    for ($k = 0; $k < rand(2, 5); $k++) {
                        Media::factory([
                            'model_id' => $visualsPostBlock->id,
                            'model_type' => PostBlock::class,
                            'model_key' => 'files',
                        ])
                            ->withFile(
                                Arr::random($coverImages),
                                sprintf('posts/%s/blocks/%s', $post->id, $visualsPostBlock->id),
                            )
                            ->create();
                    }
                }
            });
    }

    private function deleteStorageFiles(): void
    {
        Storage::disk('local')->deleteDirectory('data');
    }
}<commit_msg>Delete thumbnails dir as well on seed<commit_after><?php

namespace Database\Seeders;

use App\Models\Category;
use App\Models\Media;
use App\Models\Post;
use App\Models\PostBlock;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Sequence;
use Illuminate\Database\Seeder;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        $this->deleteStorageFiles();

        $admin = User::factory(['email' => '<EMAIL>', 'role' => 'admin'])
            ->create();
        $editor1 = User::factory(['email' => '<EMAIL>'])
            ->create();
        $editor2 = User::factory(['email' => '<EMAIL>'])
            ->create();

        collect([$admin, $editor1, $editor2])
            ->shuffle()
            ->each(function (User $user, int $k) {
                Media::factory([
                    'model_id' => $user->id,
                    'model_type' => User::class,
                    'model_key' => 'avatar',
                ])
                    ->withFile(
                        database_path(sprintf('seeders/files/users/%s.jpg', $k + 1)),
                        sprintf('users/%s', $user->id),
                    )
                    ->create();
            });

        $categories = Category::factory()
            ->count(8)
            ->create();

        $coverImages = glob(database_path('seeders/files/posts/*.*'));
        Post::factory()
            ->state(new Sequence(
                ['author_id' => $admin->id],
                ['author_id' => $editor1->id],
                ['author_id' => $editor2->id],
            ))
            ->count(25)
            ->create()
            ->each(function (Post $post) use ($categories, $coverImages) {
                Media::factory([
                    'model_id' => $post->id,
                    'model_type' => Post::class,
                    'model_key' => 'cover',
                ])
                    ->withFile(
                        Arr::random($coverImages),
                        sprintf('posts/%s', $post->id),
                    )
                    ->create();

                $post->categories()->attach($categories->shuffle()->take(rand(1, 3))->pluck('id'));

                if (rand(0, 1)) {
                    PostBlock::factory()->text()->create(['post_id' => $post->id]);
                }
                if (rand(0, 1)) {
                    PostBlock::factory()->video()->create(['post_id' => $post->id]);
                }
                if (rand(0, 1)) {
                    $visualsPostBlock = PostBlock::factory()->visuals()->create(['post_id' => $post->id]);
                    for ($k = 0; $k < rand(2, 5); $k++) {
                        Media::factory([
                            'model_id' => $visualsPostBlock->id,
                            'model_type' => PostBlock::class,
                            'model_key' => 'files',
                        ])
                            ->withFile(
                                Arr::random($coverImages),
                                sprintf('posts/%s/blocks/%s', $post->id, $visualsPostBlock->id),
                            )
                            ->create();
                    }
                }
            });
    }

    private function deleteStorageFiles(): void
    {
        Storage::disk('local')->deleteDirectory('data');
        Storage::disk('local')->deleteDirectory('public/thumbnails');
    }
}
{'fraction_non_alphanumeric': 0.16603882932483338, 'fraction_numerical': 0.006085192697768763, 'mean_word_length': 1.3056112224448897, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 134, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '659612', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1776, 'n_words': 295}