Beispiel #1
0
 /**
  * @Given /^the bundles have following keywords:$/
  */
 public function theBundlesHaveFollowingKeywords(TableNode $table)
 {
     $entityManager = $this->getEntityManager();
     $repository = $entityManager->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Keyword');
     foreach ($table->getHash() as $row) {
         if (isset($this->bundles[$row['bundle']])) {
             $bundle = $this->bundles[$row['bundle']];
             $keyword = $repository->findOneBy(array('value' => $row['keyword']));
             if (!$keyword) {
                 $keyword = new Entity\Keyword();
                 $keyword->setValue($row['keyword']);
             }
             $bundle->addKeyword($keyword);
             $entityManager->persist($bundle);
         }
     }
     $entityManager->flush();
 }
 /**
  * Updates bundle keywords fetched from composer.json
  *
  * @param Bundle $bundle
  * @param object $repository
  */
 private function updateKeywords(Bundle $bundle, $repository)
 {
     $keywords = $this->githubRepoApi->fetchComposerKeywords($bundle);
     foreach ($keywords as $value) {
         $keyword = $repository->findOneBy(array('value' => $value));
         if (!$keyword) {
             $keyword = new Keyword();
             $keyword->setValue($value);
         }
         $bundle->addKeyword($keyword);
     }
 }
Beispiel #3
0
 public function load(ObjectManager $manager)
 {
     $developers = array();
     $organizations = array();
     $i = 0;
     foreach ($this->orgNames as $name => $fullName) {
         $i++;
         $organization = new Entity\Organization();
         $organization->fromArray(array('name' => $name, 'fullName' => $fullName, 'email' => strtolower(str_replace(' ', '.', $fullName)) . '@foomail.bar', 'location' => $i % 2 ? 'Location ' . $i : null, 'url' => $i % 2 ? 'blog' . $i . '.com' : null, 'score' => 0, 'createdAt' => new \DateTime(sprintf('%d days ago', rand(1, 50)))));
         $manager->persist($organization);
         $organizations[] = $organization;
     }
     $i = 0;
     foreach ($this->devNames as $name => $fullName) {
         $i++;
         $developer = new Entity\Developer();
         $developer->fromArray(array('name' => $name, 'email' => strtolower(str_replace(' ', '.', $fullName)) . '@foomail.bar', 'fullName' => $fullName, 'githubId' => $name, 'company' => $i % 2 ? 'Company ' . $i : null, 'location' => $i % 2 ? 'Location ' . $i : null, 'url' => $i % 2 ? 'blog' . $i . '.com' : null, 'score' => 0, 'createdAt' => new \DateTime(sprintf('%d days ago', rand(1, 50)))));
         if (isset($organizations[$i + 1])) {
             $developer->addOrganization($organizations[$i + 1]);
         }
         $manager->persist($developer);
         $developers[] = $developer;
     }
     foreach ($developers as $i => $developer) {
         $contributors = array();
         $contributors[] = isset($developers[$i + 1]) ? $developers[$i + 1] : $developers[0];
         $contributors[] = isset($developers[$i - 1]) ? $developers[$i - 1] : $developers[count($developers) - 1];
         /* @var $contributor Entity\Developer */
         $contributor = array_pop($contributors);
         $bundle = $this->makeBundle($manager, $developer, $i, $contributor);
         if ($i % 5 == 0) {
             $bundle->setLastTweetedAt(new \DateTime());
         } else {
             $bundle->setVersionsHistory(array('symfony' => array('dev-master' => '2.1.*', '1.2.0' => '2.0.*', '1.1.0' => '2.*'), 'dependencies' => array('dev-master' => array('name' => 'friendsofsymfony/user-bundle', 'extra' => array('branch-alias' => array('dev-master' => '2.0.x-dev')), 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => array('twig/twig' => '*', 'doctrine/doctrine-bundle' => '*', 'swiftmailer/swiftmailer' => '*', 'willdurand/propel-typehintable-behavior' => 'dev-master', 'symfony/validator' => '2.1.*', 'symfony/yaml' => '2.1.*'), 'suggest' => array('doctrine/couchdb-odm-bundle' => '*', 'doctrine/doctrine-bundle' => '*', 'doctrine/mongodb-odm-bundle' => '*')), '1.2.x-dev' => array('name' => 'friendsofsymfony/user-bundle', 'require' => array('php' => '>=5.3.2', 'symfony/framework-bundle' => '>=2.1,<2.3-dev', 'symfony/security-bundle' => '>=2.1,<2.3-dev'), 'require-dev' => '', 'suggest' => ''))));
         }
         $bundle->setScore(mt_rand(10, 666));
         $bundle->addRecommender(isset($developers[$i + 2]) ? $developers[$i + 2] : ($developers[0] != $developer ? $developers[0] : $developers[1]));
         if (isset($this->keywords[$i])) {
             $keyword = new Entity\Keyword();
             $keyword->setValue($this->keywords[$i]);
             $bundle->addKeyword($keyword);
             $manager->persist($keyword);
         }
         if (isset($this->keywords[$i + 1])) {
             $keyword = new Entity\Keyword();
             $keyword->setValue($this->keywords[$i + 1]);
             $bundle->addKeyword($keyword);
             $manager->persist($keyword);
         }
         $manager->persist($bundle);
         // Add some scores for bundles
         $today = new \DateTime();
         // We add a various number of scores for a given bundle
         $daysBefore = crc32($bundle->getName() . '-days') % 50;
         $maxScore = crc32($bundle->getName()) % 50;
         $previousScore = $maxScore;
         while ($daysBefore-- > 0) {
             $date = clone $today;
             $date->sub(new \DateInterval('P' . $daysBefore . 'D'));
             $score = new Entity\Score();
             $score->setBundle($bundle);
             $score->setValue($previousScore + $daysBefore);
             $score->setDate($date);
             $manager->persist($score);
             $previousScore = $score->getValue();
         }
     }
     foreach ($organizations as $organization) {
         for ($i = 1; $i < rand(2, 7); $i++) {
             $manager->persist($this->makeBundle($manager, $organization, $i));
         }
     }
     $manager->flush();
 }