Example #1
0
 public function load(ObjectManager $manager)
 {
     /*
             $connection = $manager->getConnection();
             $dbPlatform = $connection->getDatabasePlatform();
     #        $connection->query('SET FOREIGN_KEY_CHECKS=0');
             $q = $dbPlatform->getTruncateTableSql('documents');
             $connection->executeUpdate($q);
             $q = $dbPlatform->getTruncateTableSql('files');
             $connection->executeUpdate($q);
      #       $connection->query('SET FOREIGN_KEY_CHECKS=1');
     */
     for ($i = 0; $i <= 10; $i++) {
         $document = new Document();
         $document->setTitle('Der Titel Nr. ' . $i);
         $document->setDocDate(new \Datetime());
         $document->setPath('/home/jacek/dir');
         $document->setCreated(new \Datetime());
         $document->setTags('tag1 tag2 tag3');
         $r = mt_rand(1, 2);
         for ($j = 0; $j <= $r; $j++) {
             $file = new File();
             $file->setTitle('Titel der Datei Nr. ' . $j);
             $file->setFilename('Dateiname.ext');
             $file->setPath('/home/jacek/dir');
             $file->setFiletype('ext');
             $file->setContent('blablabla');
             $file->setCreated(new \Datetime());
             $file->setDocument($document);
             $manager->persist($file);
             print "File angelegt: {$file->getTitle()} \n";
         }
         $manager->persist($document);
         print "Doc angelegt: {$document->getTitle()} \n";
     }
     $manager->flush();
 }