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):
"""
def __init__(self):
self._active_count = 0
self.has_publish_item = False
@property
def active(self):
......@@ -281,6 +282,15 @@ class BulkOperationsMixin(object):
"""
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):
"""
......@@ -1299,6 +1309,23 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite):
parent.children.append(item.location)
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):
"""Only use entry_points that are supplied by the xmodule package"""
......
......@@ -474,8 +474,8 @@ class MongoBulkOpsMixin(BulkOperationsMixin):
if bulk_ops_record.dirty:
self.refresh_cached_metadata_inheritance_tree(course_id)
if emit_signals and self.signal_handler:
self.signal_handler.send("course_published", course_key=course_id)
if emit_signals:
self.send_bulk_published_signal(bulk_ops_record, course_id)
bulk_ops_record.dirty = False # brand spanking clean now
......@@ -1328,7 +1328,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
else:
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
......
......@@ -439,7 +439,15 @@ class DraftModuleStore(MongoModuleStore):
# convert the subtree using the original item as the root
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.
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):
if draft_loc.revision == MongoRevisionKey.published:
item = super(DraftModuleStore, self).update_item(xblock, user_id, allow_not_found)
course_key = xblock.location.course_key
bulk_record = self._get_bulk_ops_record(course_key)
if self.signal_handler and not bulk_record.active:
self.signal_handler.send("course_published", course_key=course_key)
if isPublish or (item.category in DIRECT_ONLY_CATEGORIES and not child_update):
self._flag_publish_event(course_key)
return item
if not super(DraftModuleStore, self).has_item(draft_loc):
......@@ -532,7 +539,8 @@ class DraftModuleStore(MongoModuleStore):
parent_block = super(DraftModuleStore, self).get_item(parent_location)
parent_block.children.remove(location)
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:
as_functions = [as_draft, as_published]
......@@ -728,8 +736,7 @@ class DraftModuleStore(MongoModuleStore):
bulk_record.dirty = True
self.collection.remove({'_id': {'$in': to_be_deleted}})
if self.signal_handler and not bulk_record.active:
self.signal_handler.send("course_published", course_key=course_key)
self._flag_publish_event(course_key)
# 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)
......@@ -747,9 +754,7 @@ class DraftModuleStore(MongoModuleStore):
self._convert_to_draft(location, user_id, delete_published=True)
course_key = location.course_key
bulk_record = self._get_bulk_ops_record(course_key)
if self.signal_handler and not bulk_record.active:
self.signal_handler.send("course_published", course_key=course_key)
self._flag_publish_event(course_key)
def revert_to_published(self, location, user_id=None):
"""
......
......@@ -268,9 +268,7 @@ class SplitBulkWriteMixin(BulkOperationsMixin):
self.db_connection.update_course_index(bulk_write_record.index, from_index=bulk_write_record.initial_index)
if dirty and emit_signals:
signal_handler = getattr(self, 'signal_handler', None)
if signal_handler:
signal_handler.send("course_published", course_key=course_key)
self.send_bulk_published_signal(bulk_write_record, course_key)
def get_course_index(self, course_key, ignore_case=False):
"""
......
......@@ -201,6 +201,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
]
)
self._flag_publish_event(location.course_key)
for branch in branches_to_delete:
branched_location = location.for_branch(branch)
parent_loc = self.get_parent_location(branched_location)
......@@ -356,6 +357,8 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
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
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