Skip to content
Browse files

Merge pull request #239 from cursedcoder/feature/OrgsAndDevs

Split developers and organizations
  • Loading branch information...
2 parents c502910 + f91441f commit 07d6b22d75177476a22c9823b95aa94dce0dba50 @stloyd stloyd committed
Showing with 2,450 additions and 1,599 deletions.
  1. +1 −0 behat.yml.dist
  2. +2 −2 src/Knp/Bundle/KnpBundlesBundle/Badge/BadgeGenerator.php
  3. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Command/KbGenerateBadgesCommand.php
  4. +0 −1 src/Knp/Bundle/KnpBundlesBundle/Command/KbPopulateCommand.php
  5. +2 −2 src/Knp/Bundle/KnpBundlesBundle/Command/KbSolrIndexCommand.php
  6. +0 −41 src/Knp/Bundle/KnpBundlesBundle/Command/KbUpdateUsersCommand.php
  7. +141 −0 src/Knp/Bundle/KnpBundlesBundle/Command/MigrateUsersCommand.php
  8. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Consumer/GithubHookConsumer.php
  9. +12 −12 src/Knp/Bundle/KnpBundlesBundle/Consumer/UpdateBundleConsumer.php
  10. +3 −3 src/Knp/Bundle/KnpBundlesBundle/Controller/BadgeController.php
  11. +0 −10 src/Knp/Bundle/KnpBundlesBundle/Controller/BaseController.php
  12. +30 −29 src/Knp/Bundle/KnpBundlesBundle/Controller/BundleController.php
  13. +24 −20 src/Knp/Bundle/KnpBundlesBundle/Controller/{UserController.php → DeveloperController.php}
  14. +108 −0 src/Knp/Bundle/KnpBundlesBundle/Controller/OrganizationController.php
  15. +133 −90 src/Knp/Bundle/KnpBundlesBundle/DataFixtures/ORM/Data.php
  16. +47 −47 src/Knp/Bundle/KnpBundlesBundle/Entity/Bundle.php
  17. +290 −0 src/Knp/Bundle/KnpBundlesBundle/Entity/Developer.php
  18. +105 −0 src/Knp/Bundle/KnpBundlesBundle/Entity/Organization.php
  19. +355 −0 src/Knp/Bundle/KnpBundlesBundle/Entity/Owner.php
  20. +115 −0 src/Knp/Bundle/KnpBundlesBundle/Entity/OwnerManager.php
  21. +0 −621 src/Knp/Bundle/KnpBundlesBundle/Entity/User.php
  22. +0 −89 src/Knp/Bundle/KnpBundlesBundle/Entity/UserManager.php
  23. +66 −24 src/Knp/Bundle/KnpBundlesBundle/Features/Context/FeatureContext.php
  24. +1 −0 src/Knp/Bundle/KnpBundlesBundle/Features/bundleSearch.feature
  25. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Features/bundleShow.feature
  26. +17 −0 src/Knp/Bundle/KnpBundlesBundle/Features/organizationList.feature
  27. +24 −0 src/Knp/Bundle/KnpBundlesBundle/Features/organizationShow.feature
  28. +6 −6 src/Knp/Bundle/KnpBundlesBundle/Git/RepoManager.php
  29. +100 −0 src/Knp/Bundle/KnpBundlesBundle/Github/Developer.php
  30. +103 −0 src/Knp/Bundle/KnpBundlesBundle/Github/Organization.php
  31. +90 −0 src/Knp/Bundle/KnpBundlesBundle/Github/Owner.php
  32. +8 −0 src/Knp/Bundle/KnpBundlesBundle/Github/OwnerInterface.php
  33. +12 −12 src/Knp/Bundle/KnpBundlesBundle/Github/Repo.php
  34. +0 −184 src/Knp/Bundle/KnpBundlesBundle/Github/User.php
  35. +2 −2 src/Knp/Bundle/KnpBundlesBundle/Indexer/SolrIndexer.php
  36. +2 −1 src/Knp/Bundle/KnpBundlesBundle/Menu/MenuBuilder.php
  37. +16 −16 src/Knp/Bundle/KnpBundlesBundle/Repository/BundleRepository.php
  38. +52 −0 src/Knp/Bundle/KnpBundlesBundle/Repository/DeveloperRepository.php
  39. +50 −0 src/Knp/Bundle/KnpBundlesBundle/Repository/OrganizationRepository.php
  40. +33 −0 src/Knp/Bundle/KnpBundlesBundle/Repository/OwnerRepository.php
  41. +6 −25 src/Knp/Bundle/KnpBundlesBundle/Resources/config/routing.yml
  42. +4 −4 src/Knp/Bundle/KnpBundlesBundle/Resources/config/routing/bundles.yml
  43. +14 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/config/routing/developers.yml
  44. +19 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/config/routing/organizations.yml
  45. +17 −10 src/Knp/Bundle/KnpBundlesBundle/Resources/config/services.yml
  46. +12 −12 src/Knp/Bundle/KnpBundlesBundle/Resources/public/css/styles.css
  47. +3 −3 src/Knp/Bundle/KnpBundlesBundle/Resources/solr/conf/schema.xml
  48. +31 −5 src/Knp/Bundle/KnpBundlesBundle/Resources/translations/messages.en.yml
  49. +3 −3 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Bundle/add.html.twig
  50. +4 −4 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Bundle/bigList.html.twig
  51. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Bundle/evolution.html.twig
  52. +5 −5 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Bundle/list.html.twig
  53. +3 −3 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Bundle/listLatest.atom.twig
  54. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Bundle/mediumList.html.twig
  55. +4 −4 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Bundle/searchBigList.html.twig
  56. +18 −18 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Bundle/show.html.twig
  57. +61 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Developer/list.html.twig
  58. +5 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Developer/list.js.twig
  59. +5 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Developer/list.json.twig
  60. +68 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Developer/show.html.twig
  61. +1 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Developer/show.js.twig
  62. +1 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Developer/show.json.twig
  63. +2 −2 src/Knp/Bundle/KnpBundlesBundle/Resources/views/{User → Developer}/userbar.html.twig
  64. +61 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Organization/list.html.twig
  65. +5 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Organization/list.js.twig
  66. +5 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Organization/list.json.twig
  67. +58 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Organization/show.html.twig
  68. +1 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Organization/show.js.twig
  69. +1 −0 src/Knp/Bundle/KnpBundlesBundle/Resources/views/Organization/show.json.twig
  70. +0 −17 src/Knp/Bundle/KnpBundlesBundle/Resources/views/User/bundles.js.twig
  71. +0 −17 src/Knp/Bundle/KnpBundlesBundle/Resources/views/User/bundles.json.twig
  72. +0 −61 src/Knp/Bundle/KnpBundlesBundle/Resources/views/User/list.html.twig
  73. +0 −5 src/Knp/Bundle/KnpBundlesBundle/Resources/views/User/list.js.twig
  74. +0 −5 src/Knp/Bundle/KnpBundlesBundle/Resources/views/User/list.json.twig
  75. +0 −68 src/Knp/Bundle/KnpBundlesBundle/Resources/views/User/show.html.twig
  76. +0 −1 src/Knp/Bundle/KnpBundlesBundle/Resources/views/User/show.js.twig
  77. +0 −1 src/Knp/Bundle/KnpBundlesBundle/Resources/views/User/show.json.twig
  78. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Resources/views/layout.html.twig
  79. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Resources/views/layout/timeline.html.twig
  80. +9 −10 src/Knp/Bundle/KnpBundlesBundle/Security/Core/User/UserProvider.php
  81. +6 −6 src/Knp/Bundle/KnpBundlesBundle/Tests/Commands/KbUpdateTrendsCommandTest.php
  82. +2 −2 src/Knp/Bundle/KnpBundlesBundle/Tests/EventListener/Scoring/GlobalScoreTest.php
  83. +2 −2 src/Knp/Bundle/KnpBundlesBundle/Tests/EventListener/Scoring/KnpBundlesListenerTest.php
  84. +2 −2 src/Knp/Bundle/KnpBundlesBundle/Tests/Git/RepoManagerTest.php
  85. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Tests/Git/RepoTest.php
  86. +19 −19 src/Knp/Bundle/KnpBundlesBundle/Tests/Github/{UserTest.php → DeveloperTest.php}
  87. +4 −4 src/Knp/Bundle/KnpBundlesBundle/Tests/Security/Core/User/UserProviderTest.php
  88. +4 −4 src/Knp/Bundle/KnpBundlesBundle/Tests/Travis/TravisTest.php
  89. +3 −3 src/Knp/Bundle/KnpBundlesBundle/Tests/Updater/UpdaterTest.php
  90. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Travis/Travis.php
  91. +2 −2 src/Knp/Bundle/KnpBundlesBundle/Twig/Extension/BundleUtilsExtension.php
  92. +1 −1 src/Knp/Bundle/KnpBundlesBundle/Twitterer/TrendingBundleTwitterer.php
  93. +20 −50 src/Knp/Bundle/KnpBundlesBundle/Updater/Updater.php
View
1 behat.yml.dist
@@ -11,6 +11,7 @@ default:
bootstrap: ""
env: test
debug: true
+ bootstrap: ''
Behat\MinkExtension\Extension:
base_url: 'http://knpbundles.local/app_test.php'
default_session: symfony2
View
4 src/Knp/Bundle/KnpBundlesBundle/Badge/BadgeGenerator.php
@@ -108,7 +108,7 @@ public function show(Bundle $bundle, $type = 'long', $regenerate = false)
$this->cacheDir
);
- $filename = sprintf('%s/badges/%s/%s-%s.png', $relativePath, $type, $bundle->getUsername(), $bundle->getName());
+ $filename = sprintf('%s/badges/%s/%s-%s.png', $relativePath, $type, $bundle->getOwnerName(), $bundle->getName());
if (!$this->filesystem->exists($filename) || false !== $regenerate) {
$this->generate($bundle);
}
@@ -206,7 +206,7 @@ protected function setFont(ImagineInterface $imagine, $font, $size, $color = '8c
*/
protected function getBadgeFile(Bundle $bundle, $type = self::LONG)
{
- return $this->cacheDir.'/badges/'.$type.'/'.$bundle->getUsername().'-'.$bundle->getName().'.png';
+ return $this->cacheDir.'/badges/'.$type.'/'.$bundle->getOwnerName().'-'.$bundle->getName().'.png';
}
/**
View
2 src/Knp/Bundle/KnpBundlesBundle/Command/KbGenerateBadgesCommand.php
@@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$badgeGenerator->generate($bundle);
++$badgesCount;
} catch (ImageNotSavedException $e) {
- $output->writeln('<error>Error occured during an image saving for '.$bundle->getUsername().'-'.$bundle->getName().' </error>');
+ $output->writeln('<error>Error occured during an image saving for '.$bundle->getOwnerName().'-'.$bundle->getName().' </error>');
}
}
View
1 src/Knp/Bundle/KnpBundlesBundle/Command/KbPopulateCommand.php
@@ -48,6 +48,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
$bundles = $updater->searchNewBundles();
$updater->createMissingBundles($bundles);
$updater->updateBundlesData();
- $updater->updateUsers();
}
}
View
4 src/Knp/Bundle/KnpBundlesBundle/Command/KbSolrIndexCommand.php
@@ -50,8 +50,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$indexer = $this->getContainer()->get('knp_bundles.indexer.solr');
if ($bundleName) {
- list($username, $name) = explode('/', $bundleName);
- $bundles = array($doctrine->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle')->findOneByUsernameAndName($username, $name));
+ list($ownerName, $name) = explode('/', $bundleName);
+ $bundles = array($doctrine->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle')->findOneByOwnerNameAndName($ownerName, $name));
} elseif ($force) {
$bundles = $doctrine->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle')->findAll();
} else {
View
41 src/Knp/Bundle/KnpBundlesBundle/Command/KbUpdateUsersCommand.php
@@ -1,41 +0,0 @@
-<?php
-
-namespace Knp\Bundle\KnpBundlesBundle\Command;
-
-use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Output\OutputInterface;
-use Knp\Bundle\KnpBundlesBundle\Updater\Updater;
-
-class KbUpdateUsersCommand extends ContainerAwareCommand
-{
- /**
- * {@inheritdoc}
- */
- protected function configure()
- {
- $this
- ->setDefinition(array())
- ->setName('kb:update:users')
- ;
- }
-
- /**
- * {@inheritdoc}
- *
- * @throws \InvalidArgumentException When the target directory does not exist
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- /* @var $updater Updater */
- $updater = $this->getContainer()->get('knp_bundles.updater');
- $updater->setOutput($output);
- $updater->setUp();
-
- $updater->updateUsers();
-
- $em = $this->getContainer()->get('knp_bundles.entity_manager');
- $em->flush();
- }
-}
View
141 src/Knp/Bundle/KnpBundlesBundle/Command/MigrateUsersCommand.php
@@ -0,0 +1,141 @@
+<?php
+
+namespace Knp\Bundle\KnpBundlesBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+use Github\Exception\ApiLimitExceedException;
+
+/**
+ * @todo Remove this command on next week or so
+ */
+class MigrateUsersCommand extends ContainerAwareCommand
+{
+ private $owners;
+ private $github;
+
+ private $ownerTable = <<<EOF
+CREATE TABLE owner (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(127) NOT NULL, fullName VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, avatarUrl VARCHAR(255) DEFAULT NULL, url VARCHAR(255) DEFAULT NULL, location VARCHAR(255) DEFAULT NULL, createdAt DATETIME NOT NULL, score INT NOT NULL, discriminator VARCHAR(255) NOT NULL, company VARCHAR(255) DEFAULT NULL, UNIQUE INDEX name_unique (name), PRIMARY KEY(id)) ENGINE = InnoDB;
+CREATE TABLE organization_developer (organization_id INT NOT NULL, developer_id INT NOT NULL, INDEX IDX_5DCC519C32C8A3DE (organization_id), INDEX IDX_5DCC519C64DD9267 (developer_id), PRIMARY KEY(organization_id, developer_id)) ENGINE = InnoDB;
+ALTER TABLE organization_developer ADD CONSTRAINT FK_5DCC519C32C8A3DE FOREIGN KEY (organization_id) REFERENCES owner (id) ON DELETE CASCADE;
+ALTER TABLE organization_developer ADD CONSTRAINT FK_5DCC519C64DD9267 FOREIGN KEY (developer_id) REFERENCES owner (id) ON DELETE CASCADE;
+ALTER TABLE bundle DROP FOREIGN KEY bundle_ibfk_1;
+EOF;
+
+ private $afterMigration = <<<EOF
+ALTER TABLE contribution DROP FOREIGN KEY FK_EA351E15A76ED395;
+ALTER TABLE bundles_usage DROP FOREIGN KEY FK_1351C3D1D9BF196B;
+DROP INDEX IDX_1351C3D1D9BF196B ON bundles_usage;
+DROP INDEX user_id ON contribution;
+DROP INDEX user_id ON bundle;
+DROP INDEX full_name_unique ON bundle;
+DROP TABLE user;
+ALTER TABLE bundle CHANGE user_id owner_id INT NOT NULL, CHANGE username ownerName VARCHAR(127) NOT NULL;
+ALTER TABLE bundle ADD CONSTRAINT FK_A57B32FD7E3C61F9 FOREIGN KEY (owner_id) REFERENCES owner (id);
+CREATE INDEX IDX_A57B32FD7E3C61F9 ON bundle (owner_id);
+CREATE UNIQUE INDEX full_name_unique ON bundle (ownerName, name);
+ALTER TABLE bundles_usage DROP PRIMARY KEY;
+ALTER TABLE bundles_usage CHANGE knpbundles_user_id knpbundles_owner_id INT NOT NULL;
+ALTER TABLE bundles_usage ADD CONSTRAINT FK_1351C3D124476F28 FOREIGN KEY (knpbundles_owner_id) REFERENCES owner (id);
+CREATE INDEX IDX_1351C3D124476F28 ON bundles_usage (knpbundles_owner_id);
+ALTER TABLE bundles_usage ADD PRIMARY KEY (bundle_id, knpbundles_owner_id);
+ALTER TABLE contribution DROP PRIMARY KEY;
+ALTER TABLE contribution CHANGE user_id developer_id INT NOT NULL;
+ALTER TABLE contribution ADD CONSTRAINT FK_EA351E1564DD9267 FOREIGN KEY (developer_id) REFERENCES owner (id) ON DELETE CASCADE;
+CREATE INDEX IDX_EA351E1564DD9267 ON contribution (developer_id);
+ALTER TABLE contribution ADD PRIMARY KEY (bundle_id, developer_id);
+EOF;
+
+ protected function configure()
+ {
+ $this
+ ->setDefinition(array())
+ ->setName('kb:migrate:users')
+ ->addOption('users', 'u', InputOption::VALUE_OPTIONAL, 'how many users migrate per one cycle', 10)
+ ->addOption('remove-not-existing', 'rne', InputOption::VALUE_OPTIONAL, 'remove users which are not exist on github', false)
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ /**
+ * @var $connection \Doctrine\DBAL\Connection
+ * @var $github \Github\Client
+ */
+ $connection = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection();
+ $this->github = $github = $this->getContainer()->get('knp_bundles.github_client');
+
+ $usersPerCycle = $input->getOption('users');
+
+ $testFetch = $connection->fetchAssoc('SELECT * FROM user LIMIT 1');
+
+ if (!isset($testFetch['is_migrated'])) {
+ $connection->executeQuery($this->ownerTable);
+ $connection->executeQuery('ALTER TABLE user ADD is_migrated VARCHAR(10) NULL;');
+ }
+
+ do {
+ $oldUsers = $connection->fetchAll(sprintf('SELECT * FROM user WHERE is_migrated IS NULL LIMIT %d', $usersPerCycle));
+
+ foreach ($oldUsers as $oldUser) {
+ try {
+ $ghUser = $github->api('user')->show($oldUser['name']);
+ } catch (ApiLimitExceedException $e) {
+ throw $e;
+ } catch (\RuntimeException $e) {
+ sleep(10);
+ continue;
+ }
+
+ if (isset($ghUser['message']) && $ghUser['message'] == 'Not Found') {
+ if ($input->getOption('remove-not-existing')) {
+ $connection->executeQuery('DELETE user WHERE id = :user_id', array('user_id' => $oldUser['id']));
+ } else {
+ $connection->executeQuery('UPDATE user SET is_migrated = 1 WHERE id = :user_id', array('user_id' => $oldUser['id']));
+ }
+ continue;
+ }
+
+ $data = $oldUser;
+ $data['discriminator'] = $ghUser['type'] == 'Organization' ? 'organization' : 'developer';
+ $data = $this->migrateColumns($data, $ghUser);
+
+ $this->owners[] = $data;
+ }
+
+ $connection->beginTransaction();
+ try {
+ foreach ($this->owners as $ownerData) {
+ $connection->insert('owner', $ownerData);
+ $connection->executeQuery('UPDATE user SET is_migrated = 1 WHERE id = :user_id', array('user_id' => $ownerData['id']));
+ }
+
+ $connection->commit();
+
+ $output->writeln(sprintf('%d users has been successfully migrated', $usersPerCycle));
+ } catch (\Exception $e) {
+ $connection->rollback();
+ $connection->close();
+
+ throw $e;
+ }
+
+ $this->owners = array();
+ } while (count($oldUsers) > 0);
+
+ $connection->executeQuery($this->afterMigration);
+ }
+
+ private function migrateColumns($data, $ghUser)
+ {
+ $data['url'] = $data['blog'];
+ $data['avatarUrl'] = isset($ghUser['avatar_url']) ? $ghUser['avatar_url'] : null;
+
+ unset($data['blog'], $data['gravatarHash'], $data['is_migrated']);
+
+ return $data;
+ }
+}
View
2 src/Knp/Bundle/KnpBundlesBundle/Consumer/GithubHookConsumer.php
@@ -56,7 +56,7 @@ public function execute($msg)
$payload = $message->payload;
$bundle = $this->manager->getRepository('KnpBundlesBundle:Bundle')->findOneBy(array(
'name' => $payload->repository->name,
- 'username' => $payload->repository->owner->name
+ 'ownerName' => $payload->repository->owner->name
));
if (!$bundle) {
View
24 src/Knp/Bundle/KnpBundlesBundle/Consumer/UpdateBundleConsumer.php
@@ -6,8 +6,8 @@
use Knp\Bundle\KnpBundlesBundle\Git;
use Knp\Bundle\KnpBundlesBundle\Entity\Bundle;
use Knp\Bundle\KnpBundlesBundle\Entity\Score;
-use Knp\Bundle\KnpBundlesBundle\Entity\User;
-use Knp\Bundle\KnpBundlesBundle\Entity\UserManager;
+use Knp\Bundle\KnpBundlesBundle\Entity\Owner;
+use Knp\Bundle\KnpBundlesBundle\Entity\OwnerManager;
use Knp\Bundle\KnpBundlesBundle\Indexer\SolrIndexer;
use Knp\Bundle\KnpBundlesBundle\Travis\Travis;
@@ -43,9 +43,9 @@ class UpdateBundleConsumer implements ConsumerInterface
private $em;
/**
- * @var Knp\Bundle\KnpBundlesBundle\Entity\UserManager
+ * @var Knp\Bundle\KnpBundlesBundle\Entity\OwnerManager
*/
- private $users;
+ private $ownerManager;
/**
* @var Knp\Bundle\KnpBundlesBundle\Indexer\SolrIndexer
@@ -64,18 +64,18 @@ class UpdateBundleConsumer implements ConsumerInterface
/**
* @param ObjectManager $em
- * @param UserManager $users
+ * @param OwnerManager $ownerManager
* @param Repo $githubRepoApi
* @param Travis $travis
* @param SolrIndexer $indexer
*/
- public function __construct(ObjectManager $em, UserManager $users, Repo $githubRepoApi, Travis $travis, SolrIndexer $indexer)
+ public function __construct(ObjectManager $em, OwnerManager $ownerManager, Repo $githubRepoApi, Travis $travis, SolrIndexer $indexer)
{
$this->em = $em;
- $this->users = $users;
+ $this->ownerManager = $ownerManager;
$this->githubRepoApi = $githubRepoApi;
$this->travis = $travis;
- $this->users = $users;
+ $this->ownerManager = $ownerManager;
$this->indexer = $indexer;
}
@@ -187,7 +187,7 @@ private function updateContributors(Bundle $bundle)
$contributors = array();
foreach ($contributorNames as $contributorName) {
- $contributors[] = $this->users->getOrCreate($contributorName);
+ $contributors[] = $this->ownerManager->getOrCreate($contributorName);
}
$bundle->setContributors($contributors);
@@ -220,9 +220,9 @@ private function updateKeywords(Bundle $bundle)
*/
protected function removeBundle(Bundle $bundle)
{
- $user = $bundle->getUser();
- if ($user instanceof User) {
- $user->removeBundle($bundle);
+ $owner = $bundle->getOwner();
+ if ($owner instanceof Owner) {
+ $owner->removeBundle($bundle);
}
// remove bundle from search index
View
6 src/Knp/Bundle/KnpBundlesBundle/Controller/BadgeController.php
@@ -11,11 +11,11 @@
*/
class BadgeController extends BaseController
{
- public function showAction($username, $name, $type = 'long')
+ public function showAction($ownerName, $name, $type = 'long')
{
- $bundle = $this->getBundleRepository()->findOneByUsernameAndName($username, $name);
+ $bundle = $this->getBundleRepository()->findOneByOwnerNameAndName($ownerName, $name);
if (!$bundle) {
- throw new NotFoundHttpException(sprintf('The bundle "%s/%s" does not exist', $username, $name));
+ throw new NotFoundHttpException(sprintf('The bundle "%s/%s" does not exist', $ownerName, $name));
}
return $this->container->get('knp_bundles.badge_generator')->show($bundle, $type);
View
10 src/Knp/Bundle/KnpBundlesBundle/Controller/BaseController.php
@@ -57,16 +57,6 @@ protected function getPaginator(Query $query, $page, $limit = 10)
return $paginator;
}
- protected function getBundleRepository()
- {
- return $this->getRepository('Bundle');
- }
-
- protected function getUserRepository()
- {
- return $this->getRepository('User');
- }
-
protected function getRepository($class)
{
return $this->container->get('knp_bundles.entity_manager')->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\'.$class);
View
59 src/Knp/Bundle/KnpBundlesBundle/Controller/BundleController.php
@@ -16,7 +16,7 @@
use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\SolariumAdapter;
use Knp\Bundle\KnpBundlesBundle\Entity\Bundle;
-use Knp\Bundle\KnpBundlesBundle\Entity\User;
+use Knp\Bundle\KnpBundlesBundle\Entity\Developer;
use Knp\Menu\MenuItem;
use Knp\Bundle\KnpBundlesBundle\Updater\Exception\UserNotFoundException;
@@ -58,7 +58,8 @@ public function searchAction(Request $request)
}
$dismax = $select->getDisMax();
- $dismax->setQueryFields(array('name^2', 'username', 'fullName^1.5', 'description', 'keywords', 'text', 'text_ngram'));
+
+ $dismax->setQueryFields(array('name^2', 'ownerName', 'fullName^1.5', 'description', 'keywords', 'text', 'text_ngram'));
$dismax->setPhraseFields(array('description^30'));
$dismax->setQueryParser('edismax');
@@ -73,7 +74,7 @@ public function searchAction(Request $request)
if ('html' === $format && count($bundles) === 1) {
$first = $bundles->current();
if (strtolower($first['name']) == strtolower($query)) {
- return $this->redirect($this->generateUrl('bundle_show', array('username' => $first['username'], 'name' => $first['name'])));
+ return $this->redirect($this->generateUrl('bundle_show', array('ownerName' => $first['ownerName'], 'name' => $first['name'])));
}
}
@@ -85,19 +86,19 @@ public function searchAction(Request $request)
));
}
- public function showAction(Request $request, $username, $name)
+ public function showAction(Request $request, $ownerName, $name)
{
/* @var $bundle Bundle */
- $bundle = $this->getRepository('Bundle')->findOneByUsernameAndName($username, $name);
+ $bundle = $this->getRepository('Bundle')->findOneByOwnerNameAndName($ownerName, $name);
if (!$bundle) {
- throw new NotFoundHttpException(sprintf('The bundle "%s/%s" does not exist', $username, $name));
+ throw new NotFoundHttpException(sprintf('The bundle "%s/%s" does not exist', $ownerName, $name));
}
$format = $this->recognizeRequestFormat($request);
$this->highlightMenu('bundles');
- $user = $this->get('security.context')->getToken()->getUser();
+ $owner = $this->get('security.context')->getToken()->getUser();
return $this->render('KnpBundlesBundle:Bundle:show.'.$format.'.twig', array(
'series' => array(
@@ -106,10 +107,10 @@ public function showAction(Request $request, $username, $name)
'data' => $bundle->getScores(),
)
),
- 'bundle' => $bundle,
- 'score_details' => $bundle->getScoreDetails(),
- 'isUsedByUser' => $user instanceof User && $user->isUsingBundle($bundle),
- 'callback' => $request->query->get('callback')
+ 'bundle' => $bundle,
+ 'score_details' => $bundle->getScoreDetails(),
+ 'isUsedByDeveloper' => $owner instanceof Owner && $owner->isUsingBundle($bundle),
+ 'callback' => $request->query->get('callback')
));
}
@@ -123,9 +124,9 @@ public function listAction(Request $request, $sort)
$sortField = $this->sortFields[$sort];
- $query = $this->getRepository('Bundle')->queryAllWithUsersAndContributorsSortedBy($sortField);
+ $query = $this->getRepository('Bundle')->queryAllWithOwnersAndContributorsSortedBy($sortField);
$bundles = $this->getPaginator($query, $request->query->get('page', 1));
- $users = $this->getRepository('User')->findAllSortedBy('createdAt', 20);
+ $owners = $this->getRepository('Developer')->findAllSortedBy('createdAt', 20);
$this->highlightMenu('bundles');
@@ -137,7 +138,7 @@ public function listAction(Request $request, $sort)
)
),
'bundles' => $bundles,
- 'users' => $users,
+ 'developers' => $owners,
'sort' => $sort,
'sortLegends' => $this->sortLegends,
'callback' => $request->query->get('callback')
@@ -156,7 +157,7 @@ public function evolutionAction()
'series' => array(
array(
'name' => 'Developers',
- 'data' => $this->getRepository('User')->getUsersCountEvolution(),
+ 'data' => $this->getRepository('Developer')->getUsersCountEvolution(),
),
array(
'name' => 'Bundles updated',
@@ -164,7 +165,7 @@ public function evolutionAction()
)
),
'bundles' => $this->getRepository('Bundle')->count(),
- 'users' => $this->getRepository('User')->count()
+ 'developers' => $this->getRepository('Developer')->count()
));
}
@@ -192,10 +193,10 @@ public function addAction(Request $request)
if (!$error) {
$bundle = trim(str_replace(array('http://github.com', 'https://github.com', '.git'), '', $bundle), '/');
if (preg_match('/^[a-z0-9-]+\/[a-z0-9-\.]+$/i', $bundle)) {
- list($username, $name) = explode('/', $bundle);
+ list($ownerName, $name) = explode('/', $bundle);
- $url = $this->generateUrl('bundle_show', array('username' => $username, 'name' => $name));
- if ($this->getRepository('Bundle')->findOneByUsernameAndName($username, $name)) {
+ $url = $this->generateUrl('bundle_show', array('ownerName' => $ownerName, 'name' => $name));
+ if ($this->getRepository('Bundle')->findOneByOwnerNameAndName($ownerName, $name)) {
if (!$request->isXmlHttpRequest()) {
return $this->redirect($url);
} else {
@@ -241,29 +242,29 @@ public function addAction(Request $request)
), $error ? 400 : 201);
}
- public function changeUsageStatusAction($username, $name)
+ public function changeUsageStatusAction($ownerName, $name)
{
/* @var $bundle Bundle */
- $bundle = $this->getRepository('Bundle')->findOneByUsernameAndName($username, $name);
+ $bundle = $this->getRepository('Bundle')->findOneByOwnerNameAndName($ownerName, $name);
if (!$bundle) {
- throw new NotFoundHttpException(sprintf('The bundle "%s/%s" does not exist', $username, $name));
+ throw new NotFoundHttpException(sprintf('The bundle "%s/%s" does not exist', $ownerName, $name));
}
- $params = array('username' => $username, 'name' => $name);
+ $params = array('ownerName' => $ownerName, 'name' => $name);
- if (!$user = $this->get('security.context')->getToken()->getUser()) {
+ if (!$owner = $this->get('security.context')->getToken()->getUser()) {
return $this->redirect($this->generateUrl('bundle_show', $params));
}
$em = $this->get('doctrine')->getEntityManager();
- if ($user->isUsingBundle($bundle)) {
+ if ($owner->isUsingBundle($bundle)) {
$bundle->updateScore(-5);
- $bundle->removeRecommender($user);
+ $bundle->removeRecommender($owner);
} else {
$bundle->updateScore(5);
- $bundle->addRecommender($user);
+ $bundle->addRecommender($owner);
}
$em->persist($bundle);
@@ -300,7 +301,7 @@ public function settingsAction(Request $request, $id)
}
// Save only if sender is owner of bundle
- if ((null !== $user = $this->get('security.context')->getToken()->getUser()) && $bundle->isOwnerOrContributor($user)) {
+ if ((null !== $owner = $this->get('security.context')->getToken()->getUser()) && $bundle->isOwnerOrContributor($owner)) {
$state = $request->request->get('state', Bundle::STATE_UNKNOWN);
$bundle->setState($state);
@@ -312,6 +313,6 @@ public function settingsAction(Request $request, $id)
$request->getSession()->setFlash('notice', sprintf('Bundle status was successful changed to: %s', $state));
}
- return $this->redirect($this->generateUrl('bundle_show', array('username' => $bundle->getUserName(), 'name' => $bundle->getName())));
+ return $this->redirect($this->generateUrl('bundle_show', array('ownerName' => $bundle->getOwnerName(), 'name' => $bundle->getName())));
}
}
View
44 ...ndlesBundle/Controller/UserController.php → ...Bundle/Controller/DeveloperController.php
@@ -3,15 +3,15 @@
namespace Knp\Bundle\KnpBundlesBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Templating\EngineInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
-use Zend\Paginator\Paginator;
use Knp\Menu\MenuItem;
-class UserController extends BaseController
+class DeveloperController extends BaseController
{
protected $sortFields = array(
'name' => 'name',
@@ -19,13 +19,13 @@ class UserController extends BaseController
);
protected $sortLegends = array(
- 'name' => 'users.sort.name',
- 'best' => 'users.sort.best',
+ 'name' => 'developers.sort.name',
+ 'best' => 'developers.sort.best',
);
public function userbarAction()
{
- $response = $this->render('KnpBundlesBundle:User:userbar.html.twig');
+ $response = $this->render('KnpBundlesBundle:Developer:userbar.html.twig');
// this is private cache (don't cache with shared proxy)
$response->setPrivate();
@@ -35,17 +35,17 @@ public function userbarAction()
public function showAction(Request $request, $name)
{
- if (!$user = $this->getUserRepository()->findOneByNameWithRepos($name)) {
- throw new NotFoundHttpException(sprintf('The user "%s" does not exist', $name));
+ if (!$developer = $this->getRepository('Developer')->findOneByNameWithRepos($name)) {
+ throw new NotFoundHttpException(sprintf('The developer "%s" does not exist', $name));
}
$format = $this->recognizeRequestFormat($request);
- $this->highlightMenu('users');
+ $this->highlightMenu('developers');
- return $this->render('KnpBundlesBundle:User:show.'.$format.'.twig', array(
- 'user' => $user,
- 'callback' => $request->query->get('callback')
+ return $this->render('KnpBundlesBundle:Developer:show.'.$format.'.twig', array(
+ 'developer' => $developer,
+ 'callback' => $request->query->get('callback')
));
}
@@ -59,13 +59,13 @@ public function listAction(Request $request, $sort = 'name')
$sortField = $this->sortFields[$sort];
- $this->highlightMenu('users');
+ $this->highlightMenu('developers');
- $query = $this->getUserRepository()->queryAllWithBundlesSortedBy($sortField);
- $users = $this->getPaginator($query, $request->query->get('page', 1), 18);
+ $query = $this->getRepository('Developer')->queryAllWithBundlesSortedBy($sortField);
+ $developers = $this->getPaginator($query, $request->query->get('page', 1), 18);
- return $this->render('KnpBundlesBundle:User:list.'.$format.'.twig', array(
- 'users' => $users,
+ return $this->render('KnpBundlesBundle:Developer:list.'.$format.'.twig', array(
+ 'developers' => $developers,
'sort' => $sort,
'sortLegends' => $this->sortLegends,
'callback' => $request->query->get('callback')
@@ -74,14 +74,18 @@ public function listAction(Request $request, $sort = 'name')
public function bundlesAction(Request $request, $name)
{
- if (!$user = $this->getUserRepository()->findOneByName($name)) {
- throw new NotFoundHttpException(sprintf('The user "%s" does not exist', $name));
+ $format = $this->recognizeRequestFormat($request);
+
+ if ($format == 'html') {
+ return $this->redirect($this->generateUrl('developer_show', array('name' => $name)));
}
- $format = $this->recognizeRequestFormat($request);
+ if (!$developer = $this->getRepository('Developer')->findOneByName($name)) {
+ throw new NotFoundHttpException(sprintf('The developer "%s" does not exist', $name));
+ }
return $this->render('KnpBundlesBundle:Bundle:list.'.$format.'.twig', array(
- 'bundles' => $user->getBundles(),
+ 'bundles' => $developer->getBundles(),
'callback' => $request->query->get('callback')
));
}
View
108 src/Knp/Bundle/KnpBundlesBundle/Controller/OrganizationController.php
@@ -0,0 +1,108 @@
+<?php
+
+namespace Knp\Bundle\KnpBundlesBundle\Controller;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Exception\HttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+
+class OrganizationController extends BaseController
+{
+ protected $sortFields = array(
+ 'name' => 'name',
+ 'bundles' => 'bundles',
+ 'developers' => 'developers'
+ );
+
+ protected $sortLegends = array(
+ 'name' => 'organizations.sort.name',
+ 'bundles' => 'organizations.sort.bundles',
+ 'developers' => 'organizations.sort.developers',
+ );
+
+ public function showAction(Request $request, $name)
+ {
+ if (!$organization = $this->getRepository('Organization')->findOneByNameWithRepos($name)) {
+ throw new NotFoundHttpException(sprintf('The organization "%s" does not exist', $name));
+ }
+
+ $format = $this->recognizeRequestFormat($request);
+
+ $this->highlightMenu('organizations');
+
+ return $this->render('KnpBundlesBundle:Organization:show.'.$format.'.twig', array(
+ 'organization' => $organization,
+ 'callback' => $request->query->get('callback')
+ ));
+ }
+
+ public function listAction(Request $request, $sort = 'name')
+ {
+ if (!array_key_exists($sort, $this->sortFields)) {
+ throw new HttpException(sprintf('%s is not a valid sorting field', $sort), 406);
+ }
+
+ $format = $this->recognizeRequestFormat($request);
+
+ $sortField = $this->sortFields[$sort];
+
+ $this->highlightMenu('organizations');
+
+ $query = $this->getRepository('Organization')->queryAllWithBundlesSortedBy($sortField);
+ $paginator = $this->getPaginator($query, $request->query->get('page', 1));
+
+ $organizations = $paginator->getCurrentPageResults();
+ /**
+ * @see http://stackoverflow.com/a/8527531
+ */
+ if (is_array($organizations[0])) {
+ foreach ($organizations as $i => $org) {
+ $organizations[$i] = $org[0];
+ }
+ }
+
+ return $this->render('KnpBundlesBundle:Organization:list.'.$format.'.twig', array(
+ 'organizations' => $organizations,
+ 'paginator' => $paginator,
+ 'callback' => $request->query->get('callback'),
+ 'sortLegends' => $this->sortLegends,
+ 'sort' => $sort
+ ));
+ }
+
+ public function bundlesAction(Request $request, $name)
+ {
+ $format = $this->recognizeRequestFormat($request);
+
+ if ($format == 'html') {
+ return $this->redirect($this->generateUrl('organization_show', array('name' => $name)));
+ }
+
+ if (!$organization = $this->getRepository('Organization')->findOneByName($name)) {
+ throw new NotFoundHttpException(sprintf('The organization "%s" does not exist', $name));
+ }
+
+ return $this->render('KnpBundlesBundle:Bundle:list.'.$format.'.twig', array(
+ 'bundles' => $organization->getBundles(),
+ 'callback' => $request->query->get('callback')
+ ));
+ }
+
+ public function membersAction(Request $request, $name)
+ {
+ $format = $this->recognizeRequestFormat($request);
+
+ if ($format == 'html') {
+ return $this->redirect($this->generateUrl('organization_show', array('name' => $name)));
+ }
+
+ if (!$organization = $this->getRepository('Organization')->findOneByName($name)) {
+ throw new NotFoundHttpException(sprintf('The organization "%s" does not exist', $name));
+ }
+
+ return $this->render('KnpBundlesBundle:Developer:list.'.$format.'.twig', array(
+ 'bundles' => $organization->getMembers(),
+ 'callback' => $request->query->get('callback')
+ ));
+ }
+}
View
223 src/Knp/Bundle/KnpBundlesBundle/DataFixtures/ORM/Data.php
@@ -8,7 +8,7 @@
class Data implements FixtureInterface
{
- protected $names = array(
+ protected $devNames = array(
'John' => 'John Doe',
'Brian' => 'Brian Lester',
'Jack' => 'Jack Gill',
@@ -26,6 +26,13 @@ class Data implements FixtureInterface
'Dexter' => 'Dexter Schwartz'
);
+ protected $orgNames = array(
+ 'KnpLabs' => 'Happy Awesome Developers',
+ 'FriendsOfSymfony' => 'FriendsOfSymfony',
+ 'sonata-project' => 'Sonata Project',
+ 'nelmio' => 'Nelmio'
+ );
+
private $keywords = array(
'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit'
);
@@ -128,118 +135,80 @@ class XX
EOD;
+ private $states = array(
+ Entity\Bundle::STATE_UNKNOWN,
+ Entity\Bundle::STATE_NOT_YET_READY,
+ Entity\Bundle::STATE_READY,
+ Entity\Bundle::STATE_DEPRECATED
+ );
+
+ private $canonicalConfigDump = <<<EOT
+vendor_bundle_name:
+ app_id: ~ # Required
+ secret: ~ # Required
+ file: ~
+ cookie: false
+ domain: ~
+ alias: ~
+ logging: %kernel.debug%
+ culture: en_US
+ class:
+ api: Vendor\\FixtureBundle\\APIKey
+ type: Vendor\\FixtureBundle\\Type
+ permissions: []
+
+EOT;
+
public function load(ObjectManager $manager)
{
- $users = array();
- $trilean = array(true, false, null);
+ $developers = array();
+ $organizations = array();
$i = 0;
- foreach ($this->names as $name => $fullName) {
+ foreach ($this->devNames as $name => $fullName) {
$i++;
- $user = new Entity\User();
- $user->fromArray(array(
+ $developer = new Entity\Developer();
+ $developer->fromArray(array(
'name' => $name,
'email' => strtolower(str_replace(' ', '.', $fullName)).'@foomail.bar',
'fullName' => $fullName,
'company' => ($i%2) ? 'Company '.$i : null,
'location' => ($i%2) ? 'Location '.$i : null,
- 'blog' => ($i%2) ? 'blog'.$i.'.com' : null,
+ 'url' => ($i%2) ? 'blog'.$i.'.com' : null,
'score' => 0,
));
- $manager->persist($user);
+ $manager->persist($developer);
- $users[] = $user;
+ $developers[] = $developer;
}
- $states = array(
- Entity\Bundle::STATE_UNKNOWN,
- Entity\Bundle::STATE_NOT_YET_READY,
- Entity\Bundle::STATE_READY,
- Entity\Bundle::STATE_DEPRECATED
- );
+ foreach ($this->orgNames as $name => $fullName) {
+ $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
+ ));
- $canonicalConfigDump = <<<EOT
-vendor_bundle_name:
- app_id: ~ # Required
- secret: ~ # Required
- file: ~
- cookie: false
- domain: ~
- alias: ~
- logging: %kernel.debug%
- culture: en_US
- class:
- api: Vendor\\FixtureBundle\\APIKey
- type: Vendor\\FixtureBundle\\Type
- permissions: []
+ $manager->persist($organization);
-EOT;
+ $organizations[] = $organization;
+ }
- foreach ($users as $i => $user) {
+ foreach ($developers as $i => $developer) {
$contributors = array();
- $contributors[] = isset($users[$i + 1]) ? $users[$i + 1] : $users[0];
- $contributors[] = isset($users[$i - 1]) ? $users[$i - 1] : $users[count($users) - 1];
+ $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\User */
+ /* @var $contributor Entity\Developer */
$contributor = array_pop($contributors);
- $bundle = new Entity\Bundle();
- $bundle->fromArray(array(
- 'name' => ucfirst($user->getName()).'FooBundle',
- 'username' => $user->getName(),
- 'user' => $user,
- 'description' => $this->descriptions[mt_rand(0, 4)],
- 'homepage' => ($i%2) ? 'Bundle'.$i.'.com' : null,
- 'readme' => str_replace('__BUNDLE__', "the bundle number: {$i}", $this->readme),
- 'tags' => ($i%2) ? array('1.0', '1.1') : array(),
- 'usesTravisCi' => ($i%2) ? false : true,
- 'composerName' => ($i%2) ? null : 'knplabs/knp-menu-bundle',
- 'state' => $states[mt_rand(0, 3)],
- 'travisCiBuildStatus' => ($i%2 == 0) ? $trilean[$i%3] : null,
- 'nbFollowers' => $i*10,
- 'nbForks' => $i,
- 'lastCommitAt' => \DateTime::createFromFormat('Y-m-d', sprintf('2012-07-%d', $i)),
- 'lastCommits' => array(
- array(
- 'commit' => array(
- 'author' => array(
- 'date' => '2010-05-16T09:58:32-09:00',
- 'name' => $contributor->getFullName(),
- 'email' => $contributor->getEmail()
- ),
- 'committer' => array(
- 'date' => '2010-05-16T09:58:32-09:00',
- 'name' => $contributor->getFullName(),
- 'login' => $contributor->getName()
- ),
- 'url' => 'http://github.com',
- 'message' => 'Fix something on this Bundle',
- ),
- ),
- array(
- 'commit' => array(
- 'author' => array(
- 'date' => '2010-05-16T09:58:32-07:00',
- 'name' => $user->getFullName(),
- 'email' => $user->getEmail()
- ),
- 'committer' => array(
- 'date' => '2010-05-16T09:58:32-07:00',
- 'name' => $user->getFullName(),
- 'email' => $user->getEmail()
- ),
- 'url' => 'http://github.com',
- 'message' => 'Commit something on this bundle',
- ),
- ),
- ),
- 'isFork' => false,
- 'contributors' => array($contributor),
- 'canonicalConfig' => ($i%2 == 0) ? $canonicalConfigDump : null,
- 'nbRecommenders' => rand(0, 90),
- ));
+ $bundle = $this->makeBundle($developer, $i, $contributor);
if ($i%5 == 0) {
$bundle->setLastTweetedAt(new \DateTime());
@@ -252,7 +221,7 @@ class:
}
$bundle->setScore(mt_rand(10, 666));
- $bundle->addRecommender(isset($users[$i + 2]) ? $users[$i + 2] : ($users[0] != $user ? $users[0] : $users[1]));
+ $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]);
@@ -291,6 +260,80 @@ class:
}
}
+ foreach ($organizations as $key => $organization) {
+ for ($i = 1; $i < rand(2, 7); $i++) {
+ $manager->persist($this->makeBundle($organization, $i));
+ }
+ }
+
$manager->flush();
}
+
+ protected function makeBundle($owner, $i, $contributor = null)
+ {
+ $trilean = array(true, false, null);
+
+ $bundle = new Entity\Bundle();
+ $bundle->fromArray(array(
+ 'name' => ucfirst($owner->getName()).$i.'FooBundle',
+ 'ownerName' => $owner->getName(),
+ 'owner' => $owner,
+ 'description' => $this->descriptions[mt_rand(0, 4)],
+ 'homepage' => ($i%2) ? 'Bundle'.$i.'.com' : null,
+ 'readme' => str_replace('__BUNDLE__', "the bundle number: {$i}", $this->readme),
+ 'tags' => ($i%2) ? array('1.0', '1.1') : array(),
+ 'usesTravisCi' => ($i%2) ? false : true,
+ 'composerName' => ($i%2) ? null : 'knplabs/knp-menu-bundle',
+ 'symfonyVersions' => array(
+ 'dev-master' => '2.1.*',
+ '1.2.0' => '2.0.*',
+ '1.1.0' => '2.*',
+ ),
+ 'state' => $this->states[mt_rand(0, 3)],
+ 'travisCiBuildStatus' => ($i%2 == 0) ? $trilean[$i%3] : null,
+ 'nbFollowers' => $i*10,
+ 'nbForks' => $i,
+ 'lastCommitAt' => \DateTime::createFromFormat('Y-m-d', sprintf('2012-07-%d', $i)),
+ 'lastCommits' => array(
+ array(
+ 'commit' => array(
+ 'author' => array(
+ 'date' => '2010-05-16T09:58:32-09:00',
+ 'name' => $owner->getFullName(),
+ 'email' => $owner->getEmail()
+ ),
+ 'committer' => array(
+ 'date' => '2010-05-16T09:58:32-09:00',
+ 'name' => $owner->getFullName(),
+ 'login' => $owner->getName()
+ ),
+ 'url' => 'http://github.com',
+ 'message' => 'Fix something on this Bundle',
+ ),
+ ),
+ array(
+ 'commit' => array(
+ 'author' => array(
+ 'date' => '2010-05-16T09:58:32-07:00',
+ 'name' => $owner->getFullName(),
+ 'email' => $owner->getEmail()
+ ),
+ 'committer' => array(
+ 'date' => '2010-05-16T09:58:32-07:00',
+ 'name' => $owner->getFullName(),
+ 'email' => $owner->getEmail()
+ ),
+ 'url' => 'http://github.com',
+ 'message' => 'Commit something on this bundle',
+ ),
+ ),
+ ),
+ 'isFork' => false,
+ 'contributors' => $contributor ? array($contributor) : array(),
+ 'canonicalConfig' => ($i%2 == 0) ? $this->canonicalConfigDump : null,
+ 'nbRecommenders' => rand(0, 90),
+ ));
+
+ return $bundle;
+ }
}
View
94 src/Knp/Bundle/KnpBundlesBundle/Entity/Bundle.php
@@ -19,7 +19,7 @@
* indexes={
* @ORM\Index(name="trend1", columns={"trend1"})
* },
- * uniqueConstraints={@ORM\UniqueConstraint(name="full_name_unique",columns={"username", "name"})}
+ * uniqueConstraints={@ORM\UniqueConstraint(name="full_name_unique",columns={"ownerName", "name"})}
* )
* @ORM\HasLifecycleCallbacks
*/
@@ -49,31 +49,31 @@ class Bundle
protected $name;
/**
- * The name of the user who owns this bundle
- * This value is redundant with the name of the referenced User, for performance reasons
+ * The name of the owner who owns this bundle
+ * This value is redundant with the name of the referenced Owner, for performance reasons
*
* @Assert\NotBlank()
* @Assert\Length(min = 2)
*
* @ORM\Column(type="string", length=127)
*/
- protected $username;
+ protected $ownerName;
/**
- * User who owns the bundle
+ * Owner of the bundle
*
- * @ORM\ManyToOne(targetEntity="User", inversedBy="bundles")
- * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
+ * @ORM\ManyToOne(targetEntity="Owner", inversedBy="bundles")
+ * @ORM\JoinColumn(name="owner_id", referencedColumnName="id", nullable=false)
*/
- protected $user;
+ protected $owner;
/**
- * Recommenders recommending the bundle
+ * Developers recommending the bundle
*
- * @ORM\ManyToMany(targetEntity="User", inversedBy="recommendedBundles")
+ * @ORM\ManyToMany(targetEntity="Developer", inversedBy="recommendedBundles")
* @ORM\JoinTable(name="bundles_usage",
* joinColumns={@ORM\JoinColumn(name="bundle_id", referencedColumnName="id")},
- * inverseJoinColumns={@ORM\JoinColumn(name="knpbundles_user_id", referencedColumnName="id")}
+ * inverseJoinColumns={@ORM\JoinColumn(name="knpbundles_owner_id", referencedColumnName="id")}
* )
*/
protected $recommenders;
@@ -186,12 +186,12 @@ class Bundle
protected $state = self::STATE_UNKNOWN;
/**
- * Recommenders who contributed to the Repo
+ * Developers who contributed to the Repo
*
- * @ORM\ManyToMany(targetEntity="User", inversedBy="contributionBundles")
+ * @ORM\ManyToMany(targetEntity="Developer", inversedBy="contributionBundles")
* @ORM\JoinTable(name="contribution",
* joinColumns={@ORM\JoinColumn(name="bundle_id", referencedColumnName="id", onDelete="CASCADE")},
- * inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")}
+ * inverseJoinColumns={@ORM\JoinColumn(name="developer_id", referencedColumnName="id", onDelete="CASCADE")}
* )
*
* @var Collection
@@ -293,11 +293,11 @@ class Bundle
public function __construct($fullName = null)
{
if ($fullName) {
- list($this->username, $this->name) = explode('/', $fullName);
+ list($this->ownerName, $this->name) = explode('/', $fullName);
}
- $this->createdAt = new \DateTime('NOW');
- $this->updatedAt = new \DateTime('NOW');
+ $this->createdAt = new \DateTime();
+ $this->updatedAt = new \DateTime();
$this->lastCommitAt = new \DateTime('2010-01-01');
$this->lastCommits = serialize(array());
@@ -491,7 +491,7 @@ public function setLastCommits(array $lastCommits)
{
foreach($lastCommits as $index => $commit) {
$lastCommits[$index]['bundle_name'] = $this->getName();
- $lastCommits[$index]['bundle_username'] = $this->getUsername();
+ $lastCommits[$index]['bundle_ownerName'] = $this->getOwnerName();
}
$this->lastCommits = serialize($lastCommits);
@@ -695,7 +695,7 @@ public function setNbFollowers($nbFollowers)
*/
public function getGitHubUrl()
{
- return sprintf('http://github.com/%s/%s', $this->username, $this->name);
+ return sprintf('http://github.com/%s/%s', $this->ownerName, $this->name);
}
/**
@@ -705,7 +705,7 @@ public function getGitHubUrl()
*/
public function getTravisUrl()
{
- return $this->usesTravisCi ? sprintf('http://travis-ci.org/%s/%s', $this->username, $this->name) : false;
+ return $this->usesTravisCi ? sprintf('http://travis-ci.org/%s/%s', $this->ownerName, $this->name) : false;
}
/**
@@ -725,17 +725,17 @@ public function getPackagistUrl()
*/
public function getGitUrl()
{
- return sprintf('git://github.com/%s/%s.git', $this->username, $this->name);
+ return sprintf('git://github.com/%s/%s.git', $this->ownerName, $this->name);
}
/**
- * Get full name, including username
+ * Get full name, including ownerName
*
* @return string
*/
public function getFullName()
{
- return $this->username.'/'.$this->name;
+ return $this->ownerName.'/'.$this->name;
}
/**
@@ -769,39 +769,39 @@ public function getId()
}
/**
- * Get username
+ * Get ownername
*
* @return string
*/
- public function getUsername()
+ public function getOwnerName()
{
- return $this->username;
+ return $this->ownerName;
}
/**
- * Set username
+ * Set ownername
*
* @param string
*/
- public function setUsername($username)
+ public function setOwnerName($ownername)
{
- $this->username = $username;
+ $this->ownerName = $ownername;
}
/**
- * @return User
+ * @return Owner
*/
- public function getUser()
+ public function getOwner()
{
- return $this->user;
+ return $this->owner;
}
/**
- * @param null|User $user
+ * @param null|Owner $owner
*/
- public function setUser(User $user = null)
+ public function setOwner(Owner $owner = null)
{
- $this->user = $user;
+ $this->owner = $owner;
}
/**
@@ -1007,7 +1007,7 @@ public function toSmallArray()
return array(
'type' => $this->getClass(),
'name' => $this->getName(),
- 'username' => $this->getUsername(),
+ 'ownerName' => $this->getOwnerName(),
'description' => $this->getDescription(),
'homepage' => $this->getHomepage(),
'score' => $this->getScore(),
@@ -1030,7 +1030,7 @@ public function fromArray(array $data)
public function __toString()
{
- return $this->username.'/'.$this->name;
+ return $this->ownerName.'/'.$this->name;
}
public function getClass()
@@ -1066,34 +1066,34 @@ public function getNbRecommenders()
return count($this->recommenders);
}
- public function addRecommender(User $user)
+ public function addRecommender(Owner $owner)
{
- $user->addRecommendedBundle($this);
+ $owner->addRecommendedBundle($this);
- $this->recommenders[] = $user;
+ $this->recommenders[] = $owner;
$this->nbRecommenders++;
}
- public function removeRecommender(User $user)
+ public function removeRecommender(Owner $owner)
{
- $user->getUsedBundles()->removeElement($this);
+ $owner->getUsedBundles()->removeElement($this);
- $this->recommenders->removeElement($user);
+ $this->recommenders->removeElement($owner);
$this->nbRecommenders--;
}
/**
- * @param User $user
+ * @param Owner $owner
*
* @return boolean
*/
- public function isOwnerOrContributor(User $user)
+ public function isOwnerOrContributor(Owner $owner)
{
- if ($this->user->isEqualTo($user)) {
+ if ($this->owner->isEqualTo($owner)) {
return true;
}
- return $this->contributors->contains($user);
+ return $this->contributors->contains($owner);
}
/**
View
290 src/Knp/Bundle/KnpBundlesBundle/Entity/Developer.php
@@ -0,0 +1,290 @@
+<?php
+
+namespace Knp\Bundle\KnpBundlesBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Doctrine\Common\Collections\ArrayCollection;
+use Symfony\Component\Validator\Constraints as Assert;
+use Symfony\Component\Security\Core\User\UserInterface;
+
+/**
+ * An user living on GitHub
+ *
+ * @ORM\Entity(repositoryClass="Knp\Bundle\KnpBundlesBundle\Repository\DeveloperRepository")
+ */
+class Developer extends Owner implements UserInterface
+{
+ /**
+ * The user company name
+ *
+ * @ORM\Column(type="string", length=255, nullable=true)
+ */
+ private $company;
+
+ /**
+ * Organizations where developer part of
+ *
+ * @var ArrayCollection
+ * @ORM\ManyToMany(targetEntity="Organization", mappedBy="members")
+ */
+ private $organizations;
+
+ /**
+ * Bundles this User recommended to
+ *
+ * @var ArrayCollection
+ * @ORM\ManyToMany(targetEntity="Bundle", mappedBy="recommenders")
+ */
+ private $recommendedBundles;
+
+ /**
+ * Bundles this User contributed to
+ *
+ * @var ArrayCollection
+ * @ORM\ManyToMany(targetEntity="Bundle", mappedBy="contributors")
+ */
+ private $contributionBundles;
+
+ /**
+ * local cache, not persisted
+ */
+ private $lastCommitsCache;
+
+ public function __construct()
+ {
+ $this->organizations = new ArrayCollection();
+ $this->recommendedBundles = new ArrayCollection();
+ $this->contributionBundles = new ArrayCollection();
+
+ parent::__construct();
+ }
+
+
+ /**
+ * @param $company
+ */
+ public function setCompany($company)
+ {
+ $this->company = $company;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getCompany()
+ {
+ return $this->company;
+ }
+
+ /**
+ * Add organizations
+ *
+ * @param Organization $organizations
+ */
+ public function addOrganization(Organization $organizations)
+ {
+ $this->organizations[] = $organizations;
+ }
+
+ /**
+ * Remove organizations
+ *
+ * @param Organization $organizations
+ */
+ public function removeOrganization(Organization $organizations)
+ {
+ $this->organizations->removeElement($organizations);
+ }
+
+ /**
+ * Get organizations
+ *
+ * @return ArrayCollection
+ */
+ public function getOrganizations()
+ {
+ return $this->organizations;
+ }
+
+ /**
+ * Add recommendedBundles
+ *
+ * @param Bundle $recommendedBundles
+ */
+ public function addRecommendedBundle(Bundle $recommendedBundles)
+ {
+ $this->recommendedBundles[] = $recommendedBundles;
+ }
+
+ /**
+ * Remove recommendedBundles
+ *
+ * @param Bundle $recommendedBundles
+ */
+ public function removeRecommendedBundle(Bundle $recommendedBundles)
+ {
+ $this->recommendedBundles->removeElement($recommendedBundles);
+ }
+
+ /**
+ * Get recommendedBundles
+ *
+ * @return ArrayCollection
+ */
+ public function getRecommendedBundles()
+ {
+ return $this->recommendedBundles;
+ }
+
+ /**
+ * Add contributionBundles
+ *
+ * @param Bundle $contributionBundles
+ */
+ public function addContributionBundle(Bundle $contributionBundles)
+ {
+ $this->contributionBundles[] = $contributionBundles;
+ }
+
+ /**
+ * Remove contributionBundles
+ *
+ * @param Bundle $contributionBundles
+ */
+ public function removeContributionBundle(Bundle $contributionBundles)
+ {
+ $this->contributionBundles->removeElement($contributionBundles);
+ }
+
+ /**
+ * Get contributionBundles
+ *
+ * @return ArrayCollection
+ */
+ public function getContributionBundles()
+ {
+ return $this->contributionBundles;
+ }
+
+ /**
+ * @param $lastCommitsCache
+ */
+ public function setLastCommitsCache($lastCommitsCache)
+ {
+ $this->lastCommitsCache = $lastCommitsCache;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getLastCommitsCache()
+ {
+ return $this->lastCommitsCache;
+ }
+
+ /**
+ * Get the date of the last commit
+ *
+ * @return \DateTime
+ */
+ public function getLastCommitAt()
+ {
+ $lastCommits = $this->getLastCommits(1);
+ if (empty($lastCommits)) {
+ return null;
+ }
+ $lastCommit = $lastCommits[0];
+ $date = new \DateTime($lastCommit['committed_date']);
+
+ return $date;
+ }
+
+ /**
+ * Get the more recent commits by this user
+ *
+ * @param integer $nb
+ * @return array
+ */
+ public function getLastCommits($nb = 10)
+ {
+ if (null === $this->lastCommitsCache) {
+ $commits = array();
+ foreach ($this->getAllBundles() as $bundle) {
+ foreach ($bundle->getLastCommits() as $commit) {
+ if (isset($commit['author']['login']) && $commit['author']['login'] === $this->name) {
+ $commits[] = $commit;
+ }
+ }
+ }
+ usort($commits, function($a, $b) {
+ return strtotime($a['committed_date']) < strtotime($b['committed_date']);
+ });
+ $this->lastCommitsCache = $commits;
+ }
+ $commits = array_slice($this->lastCommitsCache, 0, $nb);
+
+ return $commits;
+ }
+
+ public function toSmallArray()
+ {
+ return array(
+ 'name' => $this->getName(),
+ 'email' => $this->getEmail(),
+ 'gravatarHash' => $this->getAvatarUrl(),
+ 'fullName' => $this->getFullName(),
+ 'company' => $this->getCompany(),
+ 'location' => $this->getLocation(),
+ 'blog' => $this->getUrl(),
+ 'bundles' => $this->getBundleNames(),
+ 'lastCommitAt' => $this->getLastCommitAt() ? $this->getLastCommitAt()->getTimestamp() : null,
+ 'score' => $this->getScore(),
+ );
+ }
+
+ public function toBigArray()
+ {
+ return $this->toSmallArray() + array(
+ 'lastCommits' => $this->getLastCommits()
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function getAllBundles()
+ {
+ return array_merge($this->bundles->toArray(), $this->contributionBundles->toArray());
+ }
+
+ /* ---------- Security User ---------- */
+ public function getUsername()
+ {
+ return $this->name;
+ }
+
+ public function getRoles()
+ {
+ return array('ROLE_USER');
+ }
+
+ public function getPassword()
+ {
+ return '';
+ }
+
+ public function getSalt()
+ {
+ return '';
+ }
+
+ public function eraseCredentials()
+ {
+ }
+
+ public function isEqualTo(Developer $developer)
+ {
+ return $developer->getName() === $this->getName();
+ }
+ /* !--------- Security User ---------! */
+}
View
105 src/Knp/Bundle/KnpBundlesBundle/Entity/Organization.php
@@ -0,0 +1,105 @@
+<?php
+
+namespace Knp\Bundle\KnpBundlesBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Doctrine\Common\Collections\ArrayCollection;
+
+/**
+ * An organization living on GitHub
+ *
+ * @ORM\Entity(repositoryClass="Knp\Bundle\KnpBundlesBundle\Repository\OrganizationRepository")
+ */
+class Organization extends Owner
+{
+ /**
+ * Members of this organization
+ *
+ * @ORM\ManyToMany(targetEntity="Developer", inversedBy="organizations", cascade={"persist"})
+ */
+ private $members;
+
+ public function __construct()
+ {
+ $this->members = new ArrayCollection();
+
+ parent::__construct();
+ }
+
+ /**
+ * Add members
+ *
+ * @param Developer $member
+ */
+ public function addMember(Developer $member)
+ {
+ $this->members[] = $member;
+ }
+
+ /**
+ * Remove members
+ *
+ * @param Developer $member
+ */
+ public function removeMember(Developer $member)
+ {
+ $this->members->removeElement($member);
+ }
+
+ /**
+ * Get members
+ *
+ * @return ArrayCollection
+ */
+ public function getMembers()
+ {
+ return $this->members;
+ }
+
+ /**
+ * Set members
+ * @param ArrayCollection|array $members
+ */
+ public function setMembers($members)
+ {
+ if ($members instanceof ArrayCollection) {
+ $this->members = $members;
+ } elseif (is_array($members)) {
+ foreach ($members as $member) {
+ if (!$this->members->contains($member)) {
+ $this->addMember($member);
+ }
+ }
+ }
+ }
+
+ /**
+ * Get the names of this organization members
+ *
+ * @return array
+ */
+ public function getMemberNames()
+ {
+ $names = array();
+ foreach ($this->members as $member) {
+ $names[] = $member->getName();
+ }
+
+ return $names;
+ }
+
+ public function toArray()
+ {
+ return array(
+ 'name' => $this->getName(),
+ 'email' => $this->getEmail(),
+ 'avatarUrl' => $this->getAvatarUrl(),
+ 'fullName' => $this->getFullName(),
+ 'location' => $this->getLocation(),
+ 'blog' => $this->getUrl(),
+ 'bundles' => $this->getBundleNames(),
+ 'members' => $this->getMemberNames(),
+ 'score' => $this->getScore(),
+ );
+ }
+}
View
355 src/Knp/Bundle/KnpBundlesBundle/Entity/Owner.php
@@ -0,0 +1,355 @@
+<?php
+
+namespace Knp\Bundle\KnpBundlesBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Doctrine\Common\Collections\ArrayCollection;
+use Symfony\Component\Validator\Constraints as Assert;
+
+/**
+ * @ORM\Entity(repositoryClass="Knp\Bundle\KnpBundlesBundle\Repository\OrganizationRepository")
+ * @ORM\Table(
+ * name="owner",
+ * uniqueConstraints={@ORM\UniqueConstraint(name="name_unique",columns={"name"})}
+ * )