Added code to fire library_updated signal when library is updated
This commit is contained in:
@@ -120,6 +120,7 @@ class BulkOpsRecord(object):
|
||||
def __init__(self):
|
||||
self._active_count = 0
|
||||
self.has_publish_item = False
|
||||
self.has_library_updated_item = False
|
||||
|
||||
@property
|
||||
def active(self):
|
||||
@@ -291,6 +292,15 @@ class BulkOperationsMixin(object):
|
||||
signal_handler.send("course_published", course_key=course_id)
|
||||
bulk_ops_record.has_publish_item = False
|
||||
|
||||
def send_bulk_library_updated_signal(self, bulk_ops_record, library_id):
|
||||
"""
|
||||
Sends out the signal that library have been updated.
|
||||
"""
|
||||
signal_handler = getattr(self, 'signal_handler', None)
|
||||
if signal_handler and bulk_ops_record.has_library_updated_item:
|
||||
signal_handler.send("library_updated", library_key=library_id)
|
||||
bulk_ops_record.has_library_updated_item = False
|
||||
|
||||
|
||||
class EditInfo(object):
|
||||
"""
|
||||
@@ -1326,6 +1336,23 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite):
|
||||
else:
|
||||
signal_handler.send("course_published", course_key=course_key)
|
||||
|
||||
def _flag_library_updated_event(self, library_key):
|
||||
"""
|
||||
Wrapper around calls to fire the library_updated 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:
|
||||
library_updated - library_updated to which the signal applies
|
||||
"""
|
||||
signal_handler = getattr(self, 'signal_handler', None)
|
||||
if signal_handler:
|
||||
bulk_record = self._get_bulk_ops_record(library_key) if isinstance(self, BulkOperationsMixin) else None
|
||||
if bulk_record and bulk_record.active:
|
||||
bulk_record.has_library_updated_item = True
|
||||
else:
|
||||
signal_handler.send("library_updated", library_key=library_key)
|
||||
|
||||
|
||||
def only_xmodules(identifier, entry_points):
|
||||
"""Only use entry_points that are supplied by the xmodule package"""
|
||||
|
||||
@@ -476,6 +476,7 @@ class MongoBulkOpsMixin(BulkOperationsMixin):
|
||||
|
||||
if emit_signals:
|
||||
self.send_bulk_published_signal(bulk_ops_record, course_id)
|
||||
self.send_bulk_library_updated_signal(bulk_ops_record, course_id)
|
||||
|
||||
bulk_ops_record.dirty = False # brand spanking clean now
|
||||
|
||||
|
||||
@@ -269,6 +269,7 @@ class SplitBulkWriteMixin(BulkOperationsMixin):
|
||||
|
||||
if dirty and emit_signals:
|
||||
self.send_bulk_published_signal(bulk_write_record, course_key)
|
||||
self.send_bulk_library_updated_signal(bulk_write_record, course_key)
|
||||
|
||||
def get_course_index(self, course_key, ignore_case=False):
|
||||
"""
|
||||
@@ -1536,6 +1537,9 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
|
||||
block_id=block_key.id,
|
||||
)
|
||||
|
||||
if isinstance(course_key, LibraryLocator):
|
||||
self._flag_library_updated_event(course_key)
|
||||
|
||||
# reconstruct the new_item from the cache
|
||||
return self.get_item(item_loc)
|
||||
|
||||
@@ -1891,6 +1895,9 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
|
||||
else:
|
||||
course_key = CourseLocator(version_guid=new_id)
|
||||
|
||||
if isinstance(course_key, LibraryLocator):
|
||||
self._flag_library_updated_event(course_key)
|
||||
|
||||
# fetch and return the new item--fetching is unnecessary but a good qc step
|
||||
new_locator = course_key.make_usage_key(block_key.type, block_key.id)
|
||||
return self.get_item(new_locator, **kwargs)
|
||||
@@ -2392,6 +2399,9 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
|
||||
else:
|
||||
result = CourseLocator(version_guid=new_id)
|
||||
|
||||
if isinstance(usage_locator.course_key, LibraryLocator):
|
||||
self._flag_library_updated_event(usage_locator.course_key)
|
||||
|
||||
return result
|
||||
|
||||
@contract(block_key=BlockKey, blocks='dict(BlockKey: BlockData)')
|
||||
|
||||
Reference in New Issue
Block a user