{"action":"created","comment":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/39605881","id":39605881,"diff_hunk":"@@ -0,0 +1,81 @@\n+<?php\n+\n+namespace Pim\\Bundle\\CatalogBundle\\EventSubscriber;\n+\n+use Akeneo\\Bundle\\StorageUtilsBundle\\Event\\BaseEvents;\n+use Akeneo\\Component\\StorageUtils\\Event\\RemoveEvent;\n+use Doctrine\\Common\\Persistence\\ObjectManager;\n+use Pim\\Bundle\\CatalogBundle\\Builder\\ProductTemplateBuilderInterface;\n+use Pim\\Bundle\\CatalogBundle\\Model\\AttributeInterface;\n+use Pim\\Bundle\\CatalogBundle\\Repository\\ProductTemplateRepositoryInterface;\n+use Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\n+\n+/**\n+ * Cascade the removal of the attributes in the product templates.\n+ *\n+ * @author    Clement Gautier <clement.gautier@akeneo.com>\n+ * @copyright 2015 Akeneo SAS (http://www.akeneo.com)\n+ * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)\n+ * @todo      We should configure cascading properly in doctrine to avoid such event subscriber\n+ */\n+class CascadeProductTemplateOnAttributeRemoveSubscriber implements EventSubscriberInterface\n+{\n+    /** @var ObjectManager */\n+    protected $objectManager;\n+\n+    /** @var ProductTemplateBuilderInterface */\n+    protected $productTplBuilder;\n+\n+    /** @var ProductTemplateRepositoryInterface */\n+    protected $productTplRepository;\n+\n+    /**\n+     * @param ObjectManager                      $objectManager\n+     * @param ProductTemplateBuilderInterface    $productTplBuilder\n+     * @param ProductTemplateRepositoryInterface $productTplRepository\n+     */\n+    public function __construct(\n+        ObjectManager $objectManager,\n+        ProductTemplateBuilderInterface $productTplBuilder,\n+        ProductTemplateRepositoryInterface $productTplRepository\n+    ) {\n+        $this->objectManager        = $objectManager;\n+        $this->productTplBuilder    = $productTplBuilder;\n+        $this->productTplRepository = $productTplRepository;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public static function getSubscribedEvents()\n+    {\n+        return [BaseEvents::PRE_REMOVE => 'preRemove'];\n+    }\n+\n+    /**\n+     * @param RemoveEvent $event\n+     */\n+    public function preRemove(RemoveEvent $event)\n+    {\n+        $subject = $event->getSubject();\n+\n+        if (!$subject instanceof AttributeInterface) {\n+            return;\n+        }\n+\n+        $productTemplates = $this->productTplRepository->findAll();\n+\n+        foreach ($productTemplates as $productTemplate) {\n+            if (!$productTemplate->hasValueForAttribute($subject)) {\n+                continue;","path":"src/Pim/Bundle/CatalogBundle/EventSubscriber/CascadeProductTemplateOnAttributeRemoveSubscriber.php","position":70,"original_position":70,"commit_id":"f086d132cf9b8b3b0c572c2af97270a496713910","original_commit_id":"00aeb569c9cc1ee88366714345883f248351a1c6","user":{"login":"grena","id":301169,"avatar_url":"https://avatars.githubusercontent.com/u/301169?v=3","gravatar_id":"","url":"https://api.github.com/users/grena","html_url":"https://github.com/grena","followers_url":"https://api.github.com/users/grena/followers","following_url":"https://api.github.com/users/grena/following{/other_user}","gists_url":"https://api.github.com/users/grena/gists{/gist_id}","starred_url":"https://api.github.com/users/grena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grena/subscriptions","organizations_url":"https://api.github.com/users/grena/orgs","repos_url":"https://api.github.com/users/grena/repos","events_url":"https://api.github.com/users/grena/events{/privacy}","received_events_url":"https://api.github.com/users/grena/received_events","type":"User","site_admin":false},"body":"Yep, I was commenting the line about `continue;`","created_at":"2015-09-16T08:42:10Z","updated_at":"2015-09-16T08:42:10Z","html_url":"https://github.com/akeneo/pim-community-dev/pull/3289#discussion_r39605881","pull_request_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3289","_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/39605881"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/3289#discussion_r39605881"},"pull_request":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3289"}}},"pull_request":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3289","id":45029420,"html_url":"https://github.com/akeneo/pim-community-dev/pull/3289","diff_url":"https://github.com/akeneo/pim-community-dev/pull/3289.diff","patch_url":"https://github.com/akeneo/pim-community-dev/pull/3289.patch","issue_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3289","number":3289,"state":"open","locked":false,"title":"[TR] Remove specific events","user":{"login":"ClementGautier","id":660091,"avatar_url":"https://avatars.githubusercontent.com/u/660091?v=3","gravatar_id":"","url":"https://api.github.com/users/ClementGautier","html_url":"https://github.com/ClementGautier","followers_url":"https://api.github.com/users/ClementGautier/followers","following_url":"https://api.github.com/users/ClementGautier/following{/other_user}","gists_url":"https://api.github.com/users/ClementGautier/gists{/gist_id}","starred_url":"https://api.github.com/users/ClementGautier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClementGautier/subscriptions","organizations_url":"https://api.github.com/users/ClementGautier/orgs","repos_url":"https://api.github.com/users/ClementGautier/repos","events_url":"https://api.github.com/users/ClementGautier/events{/privacy}","received_events_url":"https://api.github.com/users/ClementGautier/received_events","type":"User","site_admin":false},"body":"| Q                  | A\r\n| ------------------ | ---\r\n| Migration script?  | N/A\r\n| Behats             | ✓\r\n| Specs & Static     | ✓\r\n| Changelog updated  | Y\r\n","created_at":"2015-09-15T09:55:28Z","updated_at":"2015-09-16T08:42:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1bc01a68b7c58aade4cf5a6a0a81e1216ea269e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3289/commits","review_comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3289/comments","review_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3289/comments","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/f086d132cf9b8b3b0c572c2af97270a496713910","head":{"label":"akeneo:cleanup-events","ref":"cleanup-events","sha":"f086d132cf9b8b3b0c572c2af97270a496713910","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"Akeneo PIM development repository","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","created_at":"2012-08-10T09:27:26Z","updated_at":"2015-09-15T10:42:44Z","pushed_at":"2015-09-16T08:40:07Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://akeneo.com","size":165562,"stargazers_count":246,"watchers_count":246,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":123,"mirror_url":null,"open_issues_count":60,"forks":123,"open_issues":60,"watchers":246,"default_branch":"master"}},"base":{"label":"akeneo:master","ref":"master","sha":"72de8202420a9fdde58b23184feecc01ae43fcfb","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"Akeneo PIM development repository","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","created_at":"2012-08-10T09:27:26Z","updated_at":"2015-09-15T10:42:44Z","pushed_at":"2015-09-16T08:40:07Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://akeneo.com","size":165562,"stargazers_count":246,"watchers_count":246,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":123,"mirror_url":null,"open_issues_count":60,"forks":123,"open_issues":60,"watchers":246,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3289"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/3289"},"issue":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3289"},"comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/3289/comments"},"review_comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3289/comments"},"review_comment":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/3289/commits"},"statuses":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/f086d132cf9b8b3b0c572c2af97270a496713910"}}}}