Created
January 25, 2019 15:02
-
-
Save mjordan/cd73d31bebb2d3db9271c4e5a5e63abc to your computer and use it in GitHub Desktop.
Symfony 4 fixtures generator for Riprap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/DataFixtures/AppFixtures.php | |
namespace App\DataFixtures; | |
use App\Entity\FixityCheckEvent; | |
use Doctrine\Bundle\FixturesBundle\Fixture; | |
use Doctrine\Common\Persistence\ObjectManager; | |
use Ramsey\Uuid\Uuid; | |
class AppFixtures extends Fixture | |
{ | |
public function load(ObjectManager $manager) | |
{ | |
$ids = range(0, 1000); | |
$data = array(); | |
foreach ($ids as $id) { | |
$uuid4 = Uuid::uuid4(); | |
$uuid = $uuid4->toString(); | |
$data[$id] = array('uuid' => $uuid, 'SHA-1' => sha1($id)); | |
$event = new FixityCheckEvent(); | |
$event->setEventUuid($data[$id]['uuid']); | |
$event->setEventType('fix'); | |
$event->setResourceId('http://localhost:8000/mockrepository/rest/' . $id); | |
// Only the days and months are "random", within specificed ranges of values. | |
$month = str_pad(rand(7, 12), 2, '0', STR_PAD_LEFT); | |
$day = str_pad(rand(1,28), 2, '0', STR_PAD_LEFT); | |
$rand_date = '2018-' . $month . '-' . $day . 'T19:04:20-0800'; | |
$event->setTimestamp($rand_date); | |
$event->setDigestAlgorithm('SHA-1'); | |
$event->setDigestValue($data[$id]['SHA-1']); | |
$event->setEventOutcome('success'); | |
$event->setEventDetail(''); | |
$event->setEventOutcomeDetailNote(''); | |
$manager->persist($event); | |
} | |
$manager->flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment