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