2021-08-14 20:43:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\DataFixtures;
|
|
|
|
|
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Core\GSFile;
|
2021-08-19 12:54:06 +01:00
|
|
|
use App\Util\TemporaryFile;
|
2021-08-14 20:43:35 +01:00
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
|
|
use Doctrine\Persistence\ObjectManager;
|
2021-08-19 01:44:03 +01:00
|
|
|
use Exception;
|
2021-08-14 21:46:44 +01:00
|
|
|
use Functional as F;
|
2021-08-14 20:43:35 +01:00
|
|
|
|
|
|
|
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) {
|
2021-08-19 12:54:06 +01:00
|
|
|
$file = new TemporaryFile();
|
|
|
|
$file->write(file_get_contents($filepath));
|
2021-08-14 21:46:44 +01:00
|
|
|
try {
|
2021-09-22 15:04:45 +01:00
|
|
|
GSFile::storeFileAsAttachment($file);
|
2021-08-19 01:44:03 +01:00
|
|
|
} catch (Exception $e) {
|
2021-08-19 12:54:06 +01:00
|
|
|
echo "Could not save file {$filepath}, failed with {$e}\n";
|
|
|
|
} finally {
|
|
|
|
unset($file);
|
2021-08-14 21:46:44 +01:00
|
|
|
}
|
|
|
|
});
|
2021-08-14 20:43:35 +01:00
|
|
|
$manager->flush();
|
|
|
|
}
|
|
|
|
}
|