Commit 2e380c71 by Martyn James

Merge pull request #7435 from edx/mjames/SOL-499

Update course_publish event actions - Logged SOL-611 for follow up work 
parents 13b43a96 838060f3
...@@ -119,6 +119,7 @@ class BulkOpsRecord(object): ...@@ -119,6 +119,7 @@ class BulkOpsRecord(object):
""" """
def __init__(self): def __init__(self):
self._active_count = 0 self._active_count = 0
self.has_publish_item = False
@property @property
def active(self): def active(self):
...@@ -281,6 +282,15 @@ class BulkOperationsMixin(object): ...@@ -281,6 +282,15 @@ class BulkOperationsMixin(object):
""" """
return self._get_bulk_ops_record(course_key, ignore_case).active return self._get_bulk_ops_record(course_key, ignore_case).active
def send_bulk_published_signal(self, bulk_ops_record, course_id):
"""
Sends out the signal that items have been published from within this course.
"""
signal_handler = getattr(self, 'signal_handler', None)
if signal_handler and bulk_ops_record.has_publish_item:
signal_handler.send("course_published", course_key=course_id)
bulk_ops_record.has_publish_item = False
class EditInfo(object): class EditInfo(object):
""" """
...@@ -1299,6 +1309,23 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite): ...@@ -1299,6 +1309,23 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite):
parent.children.append(item.location) parent.children.append(item.location)
self.update_item(parent, user_id) self.update_item(parent, user_id)
def _flag_publish_event(self, course_key):
"""
Wrapper around calls to fire the course_published signal
Unless we're nested in an active bulk operation, this simply fires the signal
otherwise a publish will be signalled at the end of the bulk operation
Arguments:
course_key - course_key to which the signal applies
"""
signal_handler = getattr(self, 'signal_handler', None)
if signal_handler:
bulk_record = self._get_bulk_ops_record(course_key) if isinstance(self, BulkOperationsMixin) else None
if bulk_record and bulk_record.active:
bulk_record.has_publish_item = True
else:
signal_handler.send("course_published", course_key=course_key)
def only_xmodules(identifier, entry_points): def only_xmodules(identifier, entry_points):
"""Only use entry_points that are supplied by the xmodule package""" """Only use entry_points that are supplied by the xmodule package"""
......
...@@ -474,8 +474,8 @@ class MongoBulkOpsMixin(BulkOperationsMixin): ...@@ -474,8 +474,8 @@ class MongoBulkOpsMixin(BulkOperationsMixin):
if bulk_ops_record.dirty: if bulk_ops_record.dirty:
self.refresh_cached_metadata_inheritance_tree(course_id) self.refresh_cached_metadata_inheritance_tree(course_id)
if emit_signals and self.signal_handler: if emit_signals:
self.signal_handler.send("course_published", course_key=course_id) self.send_bulk_published_signal(bulk_ops_record, course_id)
bulk_ops_record.dirty = False # brand spanking clean now bulk_ops_record.dirty = False # brand spanking clean now
...@@ -1328,7 +1328,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -1328,7 +1328,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
else: else:
parent.children.insert(kwargs.get('position'), xblock.location) parent.children.insert(kwargs.get('position'), xblock.location)
self.update_item(parent, user_id) self.update_item(parent, user_id, child_update=True)
return xblock return xblock
......
...@@ -439,7 +439,15 @@ class DraftModuleStore(MongoModuleStore): ...@@ -439,7 +439,15 @@ class DraftModuleStore(MongoModuleStore):
# convert the subtree using the original item as the root # convert the subtree using the original item as the root
self._breadth_first(convert_item, [location]) self._breadth_first(convert_item, [location])
def update_item(self, xblock, user_id, allow_not_found=False, force=False, isPublish=False, **kwargs): def update_item(
self,
xblock,
user_id,
allow_not_found=False,
force=False,
isPublish=False,
child_update=False,
**kwargs):
""" """
See superclass doc. See superclass doc.
In addition to the superclass's behavior, this method converts the unit to draft if it's not In addition to the superclass's behavior, this method converts the unit to draft if it's not
...@@ -451,9 +459,8 @@ class DraftModuleStore(MongoModuleStore): ...@@ -451,9 +459,8 @@ class DraftModuleStore(MongoModuleStore):
if draft_loc.revision == MongoRevisionKey.published: if draft_loc.revision == MongoRevisionKey.published:
item = super(DraftModuleStore, self).update_item(xblock, user_id, allow_not_found) item = super(DraftModuleStore, self).update_item(xblock, user_id, allow_not_found)
course_key = xblock.location.course_key course_key = xblock.location.course_key
bulk_record = self._get_bulk_ops_record(course_key) if isPublish or (item.category in DIRECT_ONLY_CATEGORIES and not child_update):
if self.signal_handler and not bulk_record.active: self._flag_publish_event(course_key)
self.signal_handler.send("course_published", course_key=course_key)
return item return item
if not super(DraftModuleStore, self).has_item(draft_loc): if not super(DraftModuleStore, self).has_item(draft_loc):
...@@ -532,7 +539,8 @@ class DraftModuleStore(MongoModuleStore): ...@@ -532,7 +539,8 @@ class DraftModuleStore(MongoModuleStore):
parent_block = super(DraftModuleStore, self).get_item(parent_location) parent_block = super(DraftModuleStore, self).get_item(parent_location)
parent_block.children.remove(location) parent_block.children.remove(location)
parent_block.location = parent_location # ensure the location is with the correct revision parent_block.location = parent_location # ensure the location is with the correct revision
self.update_item(parent_block, user_id) self.update_item(parent_block, user_id, child_update=True)
self._flag_publish_event(location.course_key)
if is_item_direct_only or revision == ModuleStoreEnum.RevisionOption.all: if is_item_direct_only or revision == ModuleStoreEnum.RevisionOption.all:
as_functions = [as_draft, as_published] as_functions = [as_draft, as_published]
...@@ -728,8 +736,7 @@ class DraftModuleStore(MongoModuleStore): ...@@ -728,8 +736,7 @@ class DraftModuleStore(MongoModuleStore):
bulk_record.dirty = True bulk_record.dirty = True
self.collection.remove({'_id': {'$in': to_be_deleted}}) self.collection.remove({'_id': {'$in': to_be_deleted}})
if self.signal_handler and not bulk_record.active: self._flag_publish_event(course_key)
self.signal_handler.send("course_published", course_key=course_key)
# Now it's been published, add the object to the courseware search index so that it appears in search results # Now it's been published, add the object to the courseware search index so that it appears in search results
CoursewareSearchIndexer.do_publish_index(self, location) CoursewareSearchIndexer.do_publish_index(self, location)
...@@ -747,9 +754,7 @@ class DraftModuleStore(MongoModuleStore): ...@@ -747,9 +754,7 @@ class DraftModuleStore(MongoModuleStore):
self._convert_to_draft(location, user_id, delete_published=True) self._convert_to_draft(location, user_id, delete_published=True)
course_key = location.course_key course_key = location.course_key
bulk_record = self._get_bulk_ops_record(course_key) self._flag_publish_event(course_key)
if self.signal_handler and not bulk_record.active:
self.signal_handler.send("course_published", course_key=course_key)
def revert_to_published(self, location, user_id=None): def revert_to_published(self, location, user_id=None):
""" """
......
...@@ -268,9 +268,7 @@ class SplitBulkWriteMixin(BulkOperationsMixin): ...@@ -268,9 +268,7 @@ class SplitBulkWriteMixin(BulkOperationsMixin):
self.db_connection.update_course_index(bulk_write_record.index, from_index=bulk_write_record.initial_index) self.db_connection.update_course_index(bulk_write_record.index, from_index=bulk_write_record.initial_index)
if dirty and emit_signals: if dirty and emit_signals:
signal_handler = getattr(self, 'signal_handler', None) self.send_bulk_published_signal(bulk_write_record, course_key)
if signal_handler:
signal_handler.send("course_published", course_key=course_key)
def get_course_index(self, course_key, ignore_case=False): def get_course_index(self, course_key, ignore_case=False):
""" """
......
...@@ -201,6 +201,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli ...@@ -201,6 +201,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
] ]
) )
self._flag_publish_event(location.course_key)
for branch in branches_to_delete: for branch in branches_to_delete:
branched_location = location.for_branch(branch) branched_location = location.for_branch(branch)
parent_loc = self.get_parent_location(branched_location) parent_loc = self.get_parent_location(branched_location)
...@@ -356,6 +357,8 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli ...@@ -356,6 +357,8 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
blacklist=blacklist blacklist=blacklist
) )
self._flag_publish_event(location.course_key)
# Now it's been published, add the object to the courseware search index so that it appears in search results # Now it's been published, add the object to the courseware search index so that it appears in search results
CoursewareSearchIndexer.do_publish_index(self, location) CoursewareSearchIndexer.do_publish_index(self, location)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment