{"action":"created","comment":{"url":"https://api.github.com/repos/CanalTP/MttBundle/pulls/comments/42256387","id":42256387,"diff_hunk":"@@ -120,20 +123,56 @@ protected function getUniqueId($layout)\n         return $layout->getId();\n     }\n \n-    protected function saveInDb($label, $twigPath, $previewPath, $orientation)\n+    protected function saveInDb($path, $label, $previewPath, $orientation, $templates)\n     {\n         // Do not change the name if we update the layout\n         if (null === $this->layout->getLabel()) {\n             $this->layout->setLabel($label);\n         }\n-        $this->layout->setPath($twigPath);\n         $this->layout->setPreviewPath($previewPath);\n         $this->layout->setOrientation($orientation);\n         $this->layout->setNotesModes(array(0 => 1));\n         $this->layout->setCssVersion(1);\n         $this->layout->setUpdated(new \\DateTime());\n \n-        $this->om->flush($this->layout);\n+        // Deleting unused templates\n+        foreach ($this->layout->getTemplates() as $template)\n+        {\n+            if (!array_key_exists($template->getType(), $templates))\n+            {\n+                $this->layout->removeTemplate($template);\n+                $this->om->remove($template);\n+            }\n+        }\n+\n+        // Adding/updating templates\n+        foreach ($templates as $templateType => $templateConfig)\n+        {\n+            if (!in_array($templateType, $this->layout->getTemplatesTypes()))\n+            {\n+                $template = new Template();\n+\n+                $template->setType($templateType);\n+                $template->setPath($path.$templateConfig['file']);\n+\n+                $this->om->persist($template);\n+                $this->layout->addTemplate($template);\n+            }\n+            else\n+            {\n+                $template = $this->layout->getTemplate($templateType);\n+\n+                if ($template->getPath() != $path.$templateConfig['file'])\n+                {\n+                    $template->setPath($path.$templateConfig['file']);","path":"Services/LayoutModelManager.php","position":81,"original_position":81,"commit_id":"00a088f373672b55199e7013e0ca58bed319b965","original_commit_id":"00a088f373672b55199e7013e0ca58bed319b965","user":{"login":"Netmisa","id":1167753,"avatar_url":"https://avatars.githubusercontent.com/u/1167753?v=3","gravatar_id":"","url":"https://api.github.com/users/Netmisa","html_url":"https://github.com/Netmisa","followers_url":"https://api.github.com/users/Netmisa/followers","following_url":"https://api.github.com/users/Netmisa/following{/other_user}","gists_url":"https://api.github.com/users/Netmisa/gists{/gist_id}","starred_url":"https://api.github.com/users/Netmisa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Netmisa/subscriptions","organizations_url":"https://api.github.com/users/Netmisa/orgs","repos_url":"https://api.github.com/users/Netmisa/repos","events_url":"https://api.github.com/users/Netmisa/events{/privacy}","received_events_url":"https://api.github.com/users/Netmisa/received_events","type":"User","site_admin":false},"body":"See with @dvdn\r\nWhen we upload a model we have a dependence with the layout id in the field path. \r\nExample: we have \"uploads/3/stop.html.twig\" & \"uploads/3/line.html.twig\"\r\nWe think it will be better to remove $path from it.\r\nWhat do you think ?","created_at":"2015-10-16T15:38:33Z","updated_at":"2015-10-16T15:38:33Z","html_url":"https://github.com/CanalTP/MttBundle/pull/74#discussion_r42256387","pull_request_url":"https://api.github.com/repos/CanalTP/MttBundle/pulls/74","_links":{"self":{"href":"https://api.github.com/repos/CanalTP/MttBundle/pulls/comments/42256387"},"html":{"href":"https://github.com/CanalTP/MttBundle/pull/74#discussion_r42256387"},"pull_request":{"href":"https://api.github.com/repos/CanalTP/MttBundle/pulls/74"}}},"pull_request":{"url":"https://api.github.com/repos/CanalTP/MttBundle/pulls/74","id":47642394,"html_url":"https://github.com/CanalTP/MttBundle/pull/74","diff_url":"https://github.com/CanalTP/MttBundle/pull/74.diff","patch_url":"https://github.com/CanalTP/MttBundle/pull/74.patch","issue_url":"https://api.github.com/repos/CanalTP/MttBundle/issues/74","number":74,"state":"open","locked":false,"title":"Upload line model and assignements","user":{"login":"vpassama","id":2248947,"avatar_url":"https://avatars.githubusercontent.com/u/2248947?v=3","gravatar_id":"","url":"https://api.github.com/users/vpassama","html_url":"https://github.com/vpassama","followers_url":"https://api.github.com/users/vpassama/followers","following_url":"https://api.github.com/users/vpassama/following{/other_user}","gists_url":"https://api.github.com/users/vpassama/gists{/gist_id}","starred_url":"https://api.github.com/users/vpassama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vpassama/subscriptions","organizations_url":"https://api.github.com/users/vpassama/orgs","repos_url":"https://api.github.com/users/vpassama/repos","events_url":"https://api.github.com/users/vpassama/events{/privacy}","received_events_url":"https://api.github.com/users/vpassama/received_events","type":"User","site_admin":false},"body":"This PR is about CanalTP/MttBundle#58 and brings these modifications : \r\n\r\nTemplate\r\n------------\r\n\r\n* Adding Template entity (linked to Layout through association table layout_template)\r\n* Modifying template structure and configuration (see: https://github.com/Tisseo/MttTemplate)\r\n\r\nLineTimetable\r\n------------------\r\n\r\n* Adding LineTimetable entity (linked to LineConfig)\r\n* Adding a view in order to link a LineTimetable object to LineConfig/LayoutConfig/Layout using a 'Choose layout' button\r\n* Adding rights to MttBundle : \r\n    * BUSINESS_MANAGE_STOP_TIMETABLE (display Timetable menu and views)\r\n    * BUSINESS_MANAGE_LINE_TIMETABLE (display LineTimetable menu and views)\r\n* The menu button related to Timetable entity now contains two submenus\r\n\r\nOther changes\r\n-------------------\r\n\r\n* Applying dos2unix on left_menu.js file\r\n* Renaming some variables like current_route, current_season into externalRouteId, season/currentSeason\r\n* Navigation route is changed and contains now an optional array named options : \r\n    * This array contains externalRouteId / externalLineId used to determine left_menu behavior\r\n    * If options is empty, left_menu displays routes\r\n* Calendar::view doesn't have to overload navigation block declared in container_and_menu view\r\n* Removing some parameters when StopPointController renders StopPoint::list view\r\n* Adding a method addFlashMessage in AbstractController (for coding confort only)\r\n* LineController redirects to LineTimetable or Timetable views looking at externalRouteId value","created_at":"2015-10-14T10:35:21Z","updated_at":"2015-10-16T15:38:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"20734a347f18333c9d413d41db86de0059d94f29","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CanalTP/MttBundle/pulls/74/commits","review_comments_url":"https://api.github.com/repos/CanalTP/MttBundle/pulls/74/comments","review_comment_url":"https://api.github.com/repos/CanalTP/MttBundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CanalTP/MttBundle/issues/74/comments","statuses_url":"https://api.github.com/repos/CanalTP/MttBundle/statuses/00a088f373672b55199e7013e0ca58bed319b965","head":{"label":"Tisseo:upload-line-model-and-assignements","ref":"upload-line-model-and-assignements","sha":"00a088f373672b55199e7013e0ca58bed319b965","user":{"login":"Tisseo","id":5136514,"avatar_url":"https://avatars.githubusercontent.com/u/5136514?v=3","gravatar_id":"","url":"https://api.github.com/users/Tisseo","html_url":"https://github.com/Tisseo","followers_url":"https://api.github.com/users/Tisseo/followers","following_url":"https://api.github.com/users/Tisseo/following{/other_user}","gists_url":"https://api.github.com/users/Tisseo/gists{/gist_id}","starred_url":"https://api.github.com/users/Tisseo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tisseo/subscriptions","organizations_url":"https://api.github.com/users/Tisseo/orgs","repos_url":"https://api.github.com/users/Tisseo/repos","events_url":"https://api.github.com/users/Tisseo/events{/privacy}","received_events_url":"https://api.github.com/users/Tisseo/received_events","type":"Organization","site_admin":false},"repo":{"id":43498702,"name":"MttBundle","full_name":"Tisseo/MttBundle","owner":{"login":"Tisseo","id":5136514,"avatar_url":"https://avatars.githubusercontent.com/u/5136514?v=3","gravatar_id":"","url":"https://api.github.com/users/Tisseo","html_url":"https://github.com/Tisseo","followers_url":"https://api.github.com/users/Tisseo/followers","following_url":"https://api.github.com/users/Tisseo/following{/other_user}","gists_url":"https://api.github.com/users/Tisseo/gists{/gist_id}","starred_url":"https://api.github.com/users/Tisseo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tisseo/subscriptions","organizations_url":"https://api.github.com/users/Tisseo/orgs","repos_url":"https://api.github.com/users/Tisseo/repos","events_url":"https://api.github.com/users/Tisseo/events{/privacy}","received_events_url":"https://api.github.com/users/Tisseo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Tisseo/MttBundle","description":"","fork":true,"url":"https://api.github.com/repos/Tisseo/MttBundle","forks_url":"https://api.github.com/repos/Tisseo/MttBundle/forks","keys_url":"https://api.github.com/repos/Tisseo/MttBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tisseo/MttBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tisseo/MttBundle/teams","hooks_url":"https://api.github.com/repos/Tisseo/MttBundle/hooks","issue_events_url":"https://api.github.com/repos/Tisseo/MttBundle/issues/events{/number}","events_url":"https://api.github.com/repos/Tisseo/MttBundle/events","assignees_url":"https://api.github.com/repos/Tisseo/MttBundle/assignees{/user}","branches_url":"https://api.github.com/repos/Tisseo/MttBundle/branches{/branch}","tags_url":"https://api.github.com/repos/Tisseo/MttBundle/tags","blobs_url":"https://api.github.com/repos/Tisseo/MttBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tisseo/MttBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tisseo/MttBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tisseo/MttBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tisseo/MttBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/Tisseo/MttBundle/languages","stargazers_url":"https://api.github.com/repos/Tisseo/MttBundle/stargazers","contributors_url":"https://api.github.com/repos/Tisseo/MttBundle/contributors","subscribers_url":"https://api.github.com/repos/Tisseo/MttBundle/subscribers","subscription_url":"https://api.github.com/repos/Tisseo/MttBundle/subscription","commits_url":"https://api.github.com/repos/Tisseo/MttBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tisseo/MttBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tisseo/MttBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tisseo/MttBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tisseo/MttBundle/contents/{+path}","compare_url":"https://api.github.com/repos/Tisseo/MttBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tisseo/MttBundle/merges","archive_url":"https://api.github.com/repos/Tisseo/MttBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tisseo/MttBundle/downloads","issues_url":"https://api.github.com/repos/Tisseo/MttBundle/issues{/number}","pulls_url":"https://api.github.com/repos/Tisseo/MttBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/Tisseo/MttBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/Tisseo/MttBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tisseo/MttBundle/labels{/name}","releases_url":"https://api.github.com/repos/Tisseo/MttBundle/releases{/id}","created_at":"2015-10-01T13:44:04Z","updated_at":"2015-10-01T13:46:02Z","pushed_at":"2015-10-16T13:43:56Z","git_url":"git://github.com/Tisseo/MttBundle.git","ssh_url":"git@github.com:Tisseo/MttBundle.git","clone_url":"https://github.com/Tisseo/MttBundle.git","svn_url":"https://github.com/Tisseo/MttBundle","homepage":null,"size":2912,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"CanalTP:feature-58-upload-line-models-and-assignation","ref":"feature-58-upload-line-models-and-assignation","sha":"28eee1218701af9ce1beabd13fb6badce66e82ec","user":{"login":"CanalTP","id":2743985,"avatar_url":"https://avatars.githubusercontent.com/u/2743985?v=3","gravatar_id":"","url":"https://api.github.com/users/CanalTP","html_url":"https://github.com/CanalTP","followers_url":"https://api.github.com/users/CanalTP/followers","following_url":"https://api.github.com/users/CanalTP/following{/other_user}","gists_url":"https://api.github.com/users/CanalTP/gists{/gist_id}","starred_url":"https://api.github.com/users/CanalTP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CanalTP/subscriptions","organizations_url":"https://api.github.com/users/CanalTP/orgs","repos_url":"https://api.github.com/users/CanalTP/repos","events_url":"https://api.github.com/users/CanalTP/events{/privacy}","received_events_url":"https://api.github.com/users/CanalTP/received_events","type":"Organization","site_admin":false},"repo":{"id":26320350,"name":"MttBundle","full_name":"CanalTP/MttBundle","owner":{"login":"CanalTP","id":2743985,"avatar_url":"https://avatars.githubusercontent.com/u/2743985?v=3","gravatar_id":"","url":"https://api.github.com/users/CanalTP","html_url":"https://github.com/CanalTP","followers_url":"https://api.github.com/users/CanalTP/followers","following_url":"https://api.github.com/users/CanalTP/following{/other_user}","gists_url":"https://api.github.com/users/CanalTP/gists{/gist_id}","starred_url":"https://api.github.com/users/CanalTP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CanalTP/subscriptions","organizations_url":"https://api.github.com/users/CanalTP/orgs","repos_url":"https://api.github.com/users/CanalTP/repos","events_url":"https://api.github.com/users/CanalTP/events{/privacy}","received_events_url":"https://api.github.com/users/CanalTP/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CanalTP/MttBundle","description":"","fork":false,"url":"https://api.github.com/repos/CanalTP/MttBundle","forks_url":"https://api.github.com/repos/CanalTP/MttBundle/forks","keys_url":"https://api.github.com/repos/CanalTP/MttBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CanalTP/MttBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CanalTP/MttBundle/teams","hooks_url":"https://api.github.com/repos/CanalTP/MttBundle/hooks","issue_events_url":"https://api.github.com/repos/CanalTP/MttBundle/issues/events{/number}","events_url":"https://api.github.com/repos/CanalTP/MttBundle/events","assignees_url":"https://api.github.com/repos/CanalTP/MttBundle/assignees{/user}","branches_url":"https://api.github.com/repos/CanalTP/MttBundle/branches{/branch}","tags_url":"https://api.github.com/repos/CanalTP/MttBundle/tags","blobs_url":"https://api.github.com/repos/CanalTP/MttBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CanalTP/MttBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CanalTP/MttBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/CanalTP/MttBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CanalTP/MttBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/CanalTP/MttBundle/languages","stargazers_url":"https://api.github.com/repos/CanalTP/MttBundle/stargazers","contributors_url":"https://api.github.com/repos/CanalTP/MttBundle/contributors","subscribers_url":"https://api.github.com/repos/CanalTP/MttBundle/subscribers","subscription_url":"https://api.github.com/repos/CanalTP/MttBundle/subscription","commits_url":"https://api.github.com/repos/CanalTP/MttBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/CanalTP/MttBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/CanalTP/MttBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/CanalTP/MttBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/CanalTP/MttBundle/contents/{+path}","compare_url":"https://api.github.com/repos/CanalTP/MttBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CanalTP/MttBundle/merges","archive_url":"https://api.github.com/repos/CanalTP/MttBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CanalTP/MttBundle/downloads","issues_url":"https://api.github.com/repos/CanalTP/MttBundle/issues{/number}","pulls_url":"https://api.github.com/repos/CanalTP/MttBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/CanalTP/MttBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/CanalTP/MttBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CanalTP/MttBundle/labels{/name}","releases_url":"https://api.github.com/repos/CanalTP/MttBundle/releases{/id}","created_at":"2014-11-07T13:16:05Z","updated_at":"2015-10-01T14:04:35Z","pushed_at":"2015-10-16T13:31:11Z","git_url":"git://github.com/CanalTP/MttBundle.git","ssh_url":"git@github.com:CanalTP/MttBundle.git","clone_url":"https://github.com/CanalTP/MttBundle.git","svn_url":"https://github.com/CanalTP/MttBundle","homepage":null,"size":3962,"stargazers_count":2,"watchers_count":2,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":16,"forks":6,"open_issues":16,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CanalTP/MttBundle/pulls/74"},"html":{"href":"https://github.com/CanalTP/MttBundle/pull/74"},"issue":{"href":"https://api.github.com/repos/CanalTP/MttBundle/issues/74"},"comments":{"href":"https://api.github.com/repos/CanalTP/MttBundle/issues/74/comments"},"review_comments":{"href":"https://api.github.com/repos/CanalTP/MttBundle/pulls/74/comments"},"review_comment":{"href":"https://api.github.com/repos/CanalTP/MttBundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CanalTP/MttBundle/pulls/74/commits"},"statuses":{"href":"https://api.github.com/repos/CanalTP/MttBundle/statuses/00a088f373672b55199e7013e0ca58bed319b965"}}}}