{"action":"created","comment":{"url":"https://api.github.com/repos/superdesk/superdesk-server/pulls/comments/24397093","id":24397093,"diff_hunk":"@@ -265,6 +266,48 @@ def restore_version(self, id, doc):\n         doc.update(old)\n         return res\n \n+    def duplicate_content(self, original_doc):\n+        if original_doc.get('type', '') == 'composite':\n+            for groups in original_doc.get('groups'):\n+                if groups.get('id') != 'root':\n+                    associations = groups.get('refs', [])\n+                    for assoc in associations:\n+                        if assoc.get('residRef'):\n+                            item, item_id, endpoint = \\\n+                                superdesk.get_resource_service('packages').get_associated_item(assoc)\n+                            assoc['residRef'] = assoc['guid'] = self.duplicate_content(item)\n+\n+        return self.duplicate_item(original_doc)\n+\n+    def duplicate_item(self, original_doc):\n+        new_doc = original_doc.copy()\n+        del new_doc['_id']\n+        del new_doc['guid']\n+        generate_unique_id_and_name(new_doc)\n+        item_model = get_model(ItemModel)\n+        on_duplicate_item(new_doc)\n+        item_model.create([new_doc])\n+        self.duplicate_versions(original_doc['guid'], new_doc)\n+        if new_doc.get('state') != 'submitted':\n+            get_resource_service('tasks').patch(new_doc['_id'], {'state': 'submitted'})\n+        return new_doc['guid']\n+\n+    def duplicate_versions(self, old_id, new_doc):\n+        lookup = {'guid': old_id}\n+        old_versions = get_resource_service('archive_versions').get(req=None, lookup=lookup)\n+\n+        new_versions = []\n+        for old_version in old_versions:\n+            old_version['_id_document'] = new_doc['_id']\n+            del old_version['_id']\n+            old_version['guid'] = new_doc['guid']\n+            old_version['unique_name'] = new_doc['unique_name']\n+            old_version['unique_id'] = new_doc['unique_id']\n+            old_version['versioncreated'] = utcnow()\n+            new_versions.append(old_version)","path":"apps/archive/archive.py","position":72,"original_position":72,"commit_id":"09d131691eac2112810570f166b062d6707bf007","original_commit_id":"09d131691eac2112810570f166b062d6707bf007","user":{"login":"petrjasek","id":179249,"avatar_url":"https://avatars.githubusercontent.com/u/179249?v=3","gravatar_id":"","url":"https://api.github.com/users/petrjasek","html_url":"https://github.com/petrjasek","followers_url":"https://api.github.com/users/petrjasek/followers","following_url":"https://api.github.com/users/petrjasek/following{/other_user}","gists_url":"https://api.github.com/users/petrjasek/gists{/gist_id}","starred_url":"https://api.github.com/users/petrjasek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petrjasek/subscriptions","organizations_url":"https://api.github.com/users/petrjasek/orgs","repos_url":"https://api.github.com/users/petrjasek/repos","events_url":"https://api.github.com/users/petrjasek/events{/privacy}","received_events_url":"https://api.github.com/users/petrjasek/received_events","type":"User","site_admin":false},"body":"`old_versions` reference old document, not the new copy of it","created_at":"2015-02-10T08:58:19Z","updated_at":"2015-02-10T08:58:19Z","html_url":"https://github.com/superdesk/superdesk-server/pull/527#discussion_r24397093","pull_request_url":"https://api.github.com/repos/superdesk/superdesk-server/pulls/527","_links":{"self":{"href":"https://api.github.com/repos/superdesk/superdesk-server/pulls/comments/24397093"},"html":{"href":"https://github.com/superdesk/superdesk-server/pull/527#discussion_r24397093"},"pull_request":{"href":"https://api.github.com/repos/superdesk/superdesk-server/pulls/527"}}},"pull_request":{"url":"https://api.github.com/repos/superdesk/superdesk-server/pulls/527","id":28981447,"html_url":"https://github.com/superdesk/superdesk-server/pull/527","diff_url":"https://github.com/superdesk/superdesk-server/pull/527.diff","patch_url":"https://github.com/superdesk/superdesk-server/pull/527.patch","issue_url":"https://api.github.com/repos/superdesk/superdesk-server/issues/527","number":527,"state":"open","locked":false,"title":"Duplication of content and ingest items","user":{"login":"marwoodandrew","id":8639069,"avatar_url":"https://avatars.githubusercontent.com/u/8639069?v=3","gravatar_id":"","url":"https://api.github.com/users/marwoodandrew","html_url":"https://github.com/marwoodandrew","followers_url":"https://api.github.com/users/marwoodandrew/followers","following_url":"https://api.github.com/users/marwoodandrew/following{/other_user}","gists_url":"https://api.github.com/users/marwoodandrew/gists{/gist_id}","starred_url":"https://api.github.com/users/marwoodandrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marwoodandrew/subscriptions","organizations_url":"https://api.github.com/users/marwoodandrew/orgs","repos_url":"https://api.github.com/users/marwoodandrew/repos","events_url":"https://api.github.com/users/marwoodandrew/events{/privacy}","received_events_url":"https://api.github.com/users/marwoodandrew/received_events","type":"User","site_admin":false},"body":"[SD-1290] As a User, I want the ability to fetch previously fetched content.\r\n[SD-815] As a user, I want to duplicate content items\r\n\r\nMajor changes\r\n\r\n* Fetch action allowed from both ingest and archive.\r\n* Fetch is allowed more than once from ingest.\r\n* New guids are created with each ingest.\r\n* Original guids are saved in new field ingest_id\r\n* New field family_id allows related items to be identified.\r\n* All versions are duplicated along with content items (deep copy)","created_at":"2015-02-10T05:08:16Z","updated_at":"2015-02-10T08:58:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a33c68f4c492f0023348a66c839bbf8175036a1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/superdesk/superdesk-server/pulls/527/commits","review_comments_url":"https://api.github.com/repos/superdesk/superdesk-server/pulls/527/comments","review_comment_url":"https://api.github.com/repos/superdesk/superdesk-server/pulls/comments/{number}","comments_url":"https://api.github.com/repos/superdesk/superdesk-server/issues/527/comments","statuses_url":"https://api.github.com/repos/superdesk/superdesk-server/statuses/09d131691eac2112810570f166b062d6707bf007","head":{"label":"marwoodandrew:Duplication","ref":"Duplication","sha":"09d131691eac2112810570f166b062d6707bf007","user":{"login":"marwoodandrew","id":8639069,"avatar_url":"https://avatars.githubusercontent.com/u/8639069?v=3","gravatar_id":"","url":"https://api.github.com/users/marwoodandrew","html_url":"https://github.com/marwoodandrew","followers_url":"https://api.github.com/users/marwoodandrew/followers","following_url":"https://api.github.com/users/marwoodandrew/following{/other_user}","gists_url":"https://api.github.com/users/marwoodandrew/gists{/gist_id}","starred_url":"https://api.github.com/users/marwoodandrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marwoodandrew/subscriptions","organizations_url":"https://api.github.com/users/marwoodandrew/orgs","repos_url":"https://api.github.com/users/marwoodandrew/repos","events_url":"https://api.github.com/users/marwoodandrew/events{/privacy}","received_events_url":"https://api.github.com/users/marwoodandrew/received_events","type":"User","site_admin":false},"repo":{"id":23611604,"name":"superdesk-server","full_name":"marwoodandrew/superdesk-server","owner":{"login":"marwoodandrew","id":8639069,"avatar_url":"https://avatars.githubusercontent.com/u/8639069?v=3","gravatar_id":"","url":"https://api.github.com/users/marwoodandrew","html_url":"https://github.com/marwoodandrew","followers_url":"https://api.github.com/users/marwoodandrew/followers","following_url":"https://api.github.com/users/marwoodandrew/following{/other_user}","gists_url":"https://api.github.com/users/marwoodandrew/gists{/gist_id}","starred_url":"https://api.github.com/users/marwoodandrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marwoodandrew/subscriptions","organizations_url":"https://api.github.com/users/marwoodandrew/orgs","repos_url":"https://api.github.com/users/marwoodandrew/repos","events_url":"https://api.github.com/users/marwoodandrew/events{/privacy}","received_events_url":"https://api.github.com/users/marwoodandrew/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/marwoodandrew/superdesk-server","description":"Superdesk API server for ui devs","fork":true,"url":"https://api.github.com/repos/marwoodandrew/superdesk-server","forks_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/forks","keys_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/teams","hooks_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/hooks","issue_events_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/issues/events{/number}","events_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/events","assignees_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/assignees{/user}","branches_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/branches{/branch}","tags_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/tags","blobs_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/statuses/{sha}","languages_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/languages","stargazers_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/stargazers","contributors_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/contributors","subscribers_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/subscribers","subscription_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/subscription","commits_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/contents/{+path}","compare_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/merges","archive_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/downloads","issues_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/issues{/number}","pulls_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/pulls{/number}","milestones_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/milestones{/number}","notifications_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/labels{/name}","releases_url":"https://api.github.com/repos/marwoodandrew/superdesk-server/releases{/id}","created_at":"2014-09-03T07:56:08Z","updated_at":"2015-02-02T00:26:45Z","pushed_at":"2015-02-10T05:05:22Z","git_url":"git://github.com/marwoodandrew/superdesk-server.git","ssh_url":"git@github.com:marwoodandrew/superdesk-server.git","clone_url":"https://github.com/marwoodandrew/superdesk-server.git","svn_url":"https://github.com/marwoodandrew/superdesk-server","homepage":"","size":44845,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"superdesk:master","ref":"master","sha":"7889a5171fe278e5b601d03aa3756958d2bda8f8","user":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars.githubusercontent.com/u/5527298?v=3","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"repo":{"id":10975025,"name":"superdesk-server","full_name":"superdesk/superdesk-server","owner":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars.githubusercontent.com/u/5527298?v=3","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/superdesk/superdesk-server","description":"Superdesk API server for ui devs","fork":false,"url":"https://api.github.com/repos/superdesk/superdesk-server","forks_url":"https://api.github.com/repos/superdesk/superdesk-server/forks","keys_url":"https://api.github.com/repos/superdesk/superdesk-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/superdesk/superdesk-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/superdesk/superdesk-server/teams","hooks_url":"https://api.github.com/repos/superdesk/superdesk-server/hooks","issue_events_url":"https://api.github.com/repos/superdesk/superdesk-server/issues/events{/number}","events_url":"https://api.github.com/repos/superdesk/superdesk-server/events","assignees_url":"https://api.github.com/repos/superdesk/superdesk-server/assignees{/user}","branches_url":"https://api.github.com/repos/superdesk/superdesk-server/branches{/branch}","tags_url":"https://api.github.com/repos/superdesk/superdesk-server/tags","blobs_url":"https://api.github.com/repos/superdesk/superdesk-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/superdesk/superdesk-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/superdesk/superdesk-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/superdesk/superdesk-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/superdesk/superdesk-server/statuses/{sha}","languages_url":"https://api.github.com/repos/superdesk/superdesk-server/languages","stargazers_url":"https://api.github.com/repos/superdesk/superdesk-server/stargazers","contributors_url":"https://api.github.com/repos/superdesk/superdesk-server/contributors","subscribers_url":"https://api.github.com/repos/superdesk/superdesk-server/subscribers","subscription_url":"https://api.github.com/repos/superdesk/superdesk-server/subscription","commits_url":"https://api.github.com/repos/superdesk/superdesk-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/superdesk/superdesk-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/superdesk/superdesk-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/superdesk/superdesk-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/superdesk/superdesk-server/contents/{+path}","compare_url":"https://api.github.com/repos/superdesk/superdesk-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/superdesk/superdesk-server/merges","archive_url":"https://api.github.com/repos/superdesk/superdesk-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/superdesk/superdesk-server/downloads","issues_url":"https://api.github.com/repos/superdesk/superdesk-server/issues{/number}","pulls_url":"https://api.github.com/repos/superdesk/superdesk-server/pulls{/number}","milestones_url":"https://api.github.com/repos/superdesk/superdesk-server/milestones{/number}","notifications_url":"https://api.github.com/repos/superdesk/superdesk-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/superdesk/superdesk-server/labels{/name}","releases_url":"https://api.github.com/repos/superdesk/superdesk-server/releases{/id}","created_at":"2013-06-26T18:02:40Z","updated_at":"2015-02-09T15:26:42Z","pushed_at":"2015-02-09T15:26:42Z","git_url":"git://github.com/superdesk/superdesk-server.git","ssh_url":"git@github.com:superdesk/superdesk-server.git","clone_url":"https://github.com/superdesk/superdesk-server.git","svn_url":"https://github.com/superdesk/superdesk-server","homepage":"","size":48509,"stargazers_count":17,"watchers_count":17,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":5,"forks":24,"open_issues":5,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/superdesk/superdesk-server/pulls/527"},"html":{"href":"https://github.com/superdesk/superdesk-server/pull/527"},"issue":{"href":"https://api.github.com/repos/superdesk/superdesk-server/issues/527"},"comments":{"href":"https://api.github.com/repos/superdesk/superdesk-server/issues/527/comments"},"review_comments":{"href":"https://api.github.com/repos/superdesk/superdesk-server/pulls/527/comments"},"review_comment":{"href":"https://api.github.com/repos/superdesk/superdesk-server/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/superdesk/superdesk-server/pulls/527/commits"},"statuses":{"href":"https://api.github.com/repos/superdesk/superdesk-server/statuses/09d131691eac2112810570f166b062d6707bf007"}}}}