From 816b0edfb01f47942dee702d18566869b2b358b8 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 25 Feb 2013 16:00:35 -0500 Subject: [PATCH 1/2] add another command line argument to allow users to only simulate a delete (i.e. show what items would be deleted). This is a handy sanity checker. --- .../management/commands/delete_course.py | 16 ++++++++++++---- .../xmodule/modulestore/store_utilities.py | 14 +++++++++----- rakefile | 5 ++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/delete_course.py b/cms/djangoapps/contentstore/management/commands/delete_course.py index bb38e72d44..ef2505b276 100644 --- a/cms/djangoapps/contentstore/management/commands/delete_course.py +++ b/cms/djangoapps/contentstore/management/commands/delete_course.py @@ -21,18 +21,26 @@ class Command(BaseCommand): '''Delete a MongoDB backed course''' def handle(self, *args, **options): - if len(args) != 1: - raise CommandError("delete_course requires one argument: ") + if len(args) != 1 and len(args) != 2: + raise CommandError("delete_course requires one argument: |commit|") loc_str = args[0] + commit = False + if len(args) == 2: + commit = args[1] == 'commit' + + if commit: + print 'Actually going to delete the course from DB....' + ms = modulestore('direct') cs = contentstore() if query_yes_no("Deleting course {0}. Confirm?".format(loc_str), default="no"): if query_yes_no("Are you sure. This action cannot be undone!", default="no"): loc = CourseDescriptor.id_to_location(loc_str) - if delete_course(ms, cs, loc) == True: + if delete_course(ms, cs, loc, commit) == True: print 'removing User permissions from course....' # in the django layer, we need to remove all the user permissions groups associated with this course - _delete_course_group(loc) + if commit: + _delete_course_group(loc) diff --git a/common/lib/xmodule/xmodule/modulestore/store_utilities.py b/common/lib/xmodule/xmodule/modulestore/store_utilities.py index 192b012bef..f08fdd639a 100644 --- a/common/lib/xmodule/xmodule/modulestore/store_utilities.py +++ b/common/lib/xmodule/xmodule/modulestore/store_utilities.py @@ -92,7 +92,7 @@ def clone_course(modulestore, contentstore, source_location, dest_location, dele return True -def delete_course(modulestore, contentstore, source_location): +def delete_course(modulestore, contentstore, source_location, commit = False): # first check to see if the modulestore is Mongo backed if not isinstance(modulestore, MongoModuleStore): raise Exception("Expected a MongoModuleStore in the runtime. Aborting....") @@ -107,7 +107,8 @@ def delete_course(modulestore, contentstore, source_location): thumb_loc = Location(thumb["_id"]) id = StaticContent.get_id_from_location(thumb_loc) print "Deleting {0}...".format(id) - contentstore.delete(id) + if commit: + contentstore.delete(id) # then delete all of the assets assets = contentstore.get_all_content_for_course(source_location) @@ -115,7 +116,8 @@ def delete_course(modulestore, contentstore, source_location): asset_loc = Location(asset["_id"]) id = StaticContent.get_id_from_location(asset_loc) print "Deleting {0}...".format(id) - contentstore.delete(id) + if commit: + contentstore.delete(id) # then delete all course modules modules = modulestore.get_items([source_location.tag, source_location.org, source_location.course, None, None, None]) @@ -123,10 +125,12 @@ def delete_course(modulestore, contentstore, source_location): for module in modules: if module.category != 'course': # save deleting the course module for last print "Deleting {0}...".format(module.location) - modulestore.delete_item(module.location) + if commit: + modulestore.delete_item(module.location) # finally delete the top-level course module itself print "Deleting {0}...".format(source_location) - modulestore.delete_item(source_location) + if commit: + modulestore.delete_item(source_location) return True diff --git a/rakefile b/rakefile index 5647b5b13a..15692d0d99 100644 --- a/rakefile +++ b/rakefile @@ -415,7 +415,10 @@ end namespace :cms do desc "Delete existing MongoDB based course" task :delete_course do - if ENV['LOC'] + + if ENV['LOC'] and ENV['COMMIT'] + sh(django_admin(:cms, :dev, :delete_course, ENV['LOC'], ENV['COMMIT'])) + elsif ENV['LOC'] sh(django_admin(:cms, :dev, :delete_course, ENV['LOC'])) else raise "You must pass in a LOC parameter" From 20540fbc2d50479622b58e2c9adcce848fc12f24 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Fri, 1 Mar 2013 15:52:27 -0500 Subject: [PATCH 2/2] update usage feedback --- .../contentstore/management/commands/delete_course.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/management/commands/delete_course.py b/cms/djangoapps/contentstore/management/commands/delete_course.py index ef2505b276..e3cac7de02 100644 --- a/cms/djangoapps/contentstore/management/commands/delete_course.py +++ b/cms/djangoapps/contentstore/management/commands/delete_course.py @@ -22,7 +22,7 @@ class Command(BaseCommand): def handle(self, *args, **options): if len(args) != 1 and len(args) != 2: - raise CommandError("delete_course requires one argument: |commit|") + raise CommandError("delete_course requires one or more arguments: |commit|") loc_str = args[0]