MediaFixtures.php 943 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. declare(strict_types = 1);
  3. namespace App\DataFixtures;
  4. use App\Core\DB\DB;
  5. use App\Core\GSFile;
  6. use App\Util\TemporaryFile;
  7. use Doctrine\Bundle\FixturesBundle\Fixture;
  8. use Doctrine\Persistence\ObjectManager;
  9. use Exception;
  10. use Functional as F;
  11. class MediaFixtures extends Fixture
  12. {
  13. public function load(ObjectManager $manager)
  14. {
  15. DB::setManager($manager);
  16. F\map(
  17. glob(INSTALLDIR . '/tests/sample-uploads/*'),
  18. function (string $filepath) {
  19. $file = new TemporaryFile();
  20. $file->write(file_get_contents($filepath));
  21. try {
  22. GSFile::storeFileAsAttachment($file);
  23. } catch (Exception $e) {
  24. echo "Could not save file {$filepath}, failed with {$e}\n";
  25. } finally {
  26. unset($file);
  27. }
  28. },
  29. );
  30. $manager->flush();
  31. }
  32. }