allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/7] allura git commit: [#1731] ticket:767 Add script to re-create 'fake' deleted parents
Date Wed, 27 May 2015 19:41:57 GMT
Repository: allura
Updated Branches:
  refs/heads/master 1accce536 -> e07794389


[#1731] ticket:767 Add script to re-create 'fake' deleted parents


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/da4094d4
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/da4094d4
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/da4094d4

Branch: refs/heads/master
Commit: da4094d4d456903d5052f7722485d19b32e0234d
Parents: 89b65ff
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon May 18 16:10:09 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Mon May 25 13:31:52 2015 +0000

----------------------------------------------------------------------
 .../allura/scripts/create_deleted_comments.py   | 74 ++++++++++++++++++++
 1 file changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/da4094d4/Allura/allura/scripts/create_deleted_comments.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/create_deleted_comments.py b/Allura/allura/scripts/create_deleted_comments.py
new file mode 100644
index 0000000..b0e7260
--- /dev/null
+++ b/Allura/allura/scripts/create_deleted_comments.py
@@ -0,0 +1,74 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+import argparse
+import logging
+
+from ming.odm import session
+from pylons import tmpl_context as c
+
+from allura.scripts import ScriptTask
+from allura.model import Post
+from allura.lib.utils import chunked_find
+from forgediscussion.model import ForumPost
+
+
+log = logging.getLogger(__name__)
+
+
+class CreateDeletedComments(ScriptTask):
+
+    @classmethod
+    def execute(cls, options):
+        models = [Post, ForumPost]
+        # Find all posts that have parent_id, but does not have actual parent
+        # and create fake parent for them
+        for model in models:
+            for chunk in chunked_find(model, {'parent_id': {'$ne': None}}):
+                for post in chunk:
+                    if not post.parent:
+                        log.info('Creating deleted parent for %s %s',
+                                 model.__mongometa__.name, post._id)
+                        c.project = post.app_config.project
+                        slug = post.slug.rsplit('/', 1)[0]
+                        full_slug = post.full_slug.rsplit('/', 1)[0]
+                        author = c.project.admins()[0]
+                        deleted_post = model(
+                            _id=post.parent_id,
+                            deleted=True,
+                            text="Automatically created in place of deleted post",
+                            app_id=post.app_id,
+                            app_config_id=post.app_config_id,
+                            discussion_id=post.discussion_id,
+                            thread_id=post.thread_id,
+                            author_id=author._id,
+                            slug=slug,
+                            full_slug=full_slug,
+                        )
+                        session(deleted_post).flush(deleted_post)
+
+    @classmethod
+    def parser(cls):
+        parser = argparse.ArgumentParser(
+            description='Create comments marked as deleted in place of '
+                        'actually deleted parent comments (ticket:#1731)'
+        )
+        return parser
+
+
+if __name__ == '__main__':
+    CreateDeletedComments.main()


Mime
View raw message