You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/05/18 19:11:12 UTC
[2/3] allura git commit: [#1731] ticket:767 Add script to re-create
'fake' deleted parents
[#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/41a9ec99
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/41a9ec99
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/41a9ec99
Branch: refs/heads/ib/1731
Commit: 41a9ec99ca43cb809859cbc4e88cd22f3033a905
Parents: b3aaa54
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon May 18 16:10:09 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon May 18 16:33:10 2015 +0000
----------------------------------------------------------------------
.../allura/scripts/create_deleted_comments.py | 74 ++++++++++++++++++++
1 file changed, 74 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/41a9ec99/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()