2021-08-14 20:43:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\DataFixtures;
|
|
|
|
|
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Core\GSFile;
|
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
|
|
use Doctrine\Persistence\ObjectManager;
|
2021-08-14 21:46:44 +01:00
|
|
|
use Functional as F;
|
2021-08-14 20:43:35 +01:00
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
|
|
|
|
|
|
|
class MediaFixtures extends Fixture
|
|
|
|
{
|
|
|
|
public function load(ObjectManager $manager)
|
|
|
|
{
|
|
|
|
DB::setManager($manager);
|
2021-08-14 21:46:44 +01:00
|
|
|
F\map(glob(INSTALLDIR . '/tests/sample-uploads/*'),
|
|
|
|
function (string $filepath) {
|
|
|
|
$copy_filepath = str_replace('.', '.copy.', $filepath);
|
|
|
|
copy($filepath, $copy_filepath);
|
|
|
|
$file = new File($copy_filepath, checkPath: true);
|
|
|
|
try {
|
|
|
|
GSFile::sanitizeAndStoreFileAsAttachment($file);
|
|
|
|
} catch (\Jcupitt\Vips\Exception $e) {
|
2021-08-16 17:09:02 +01:00
|
|
|
echo "Could not save file {$copy_filepath}\n";
|
2021-08-14 21:46:44 +01:00
|
|
|
}
|
2021-08-16 17:09:02 +01:00
|
|
|
@unlink($copy_filepath);
|
2021-08-14 21:46:44 +01:00
|
|
|
});
|
2021-08-14 20:43:35 +01:00
|
|
|
$manager->flush();
|
|
|
|
}
|
|
|
|
}
|