gnu-social/src/DataFixtures/MediaFixtures.php

33 lines
914 B
PHP
Raw Normal View History

<?php
namespace App\DataFixtures;
use App\Core\DB\DB;
use App\Core\GSFile;
use App\Util\TemporaryFile;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Exception;
2021-08-15 05:46:44 +09:00
use Functional as F;
class MediaFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
DB::setManager($manager);
2021-08-15 05:46:44 +09:00
F\map(glob(INSTALLDIR . '/tests/sample-uploads/*'),
function (string $filepath) {
$file = new TemporaryFile();
$file->write(file_get_contents($filepath));
2021-08-15 05:46:44 +09:00
try {
2021-09-22 23:04:45 +09:00
GSFile::storeFileAsAttachment($file);
} catch (Exception $e) {
echo "Could not save file {$filepath}, failed with {$e}\n";
} finally {
unset($file);
2021-08-15 05:46:44 +09:00
}
});
$manager->flush();
}
}