Commit efb321c3 authored by Aaron Wells's avatar Aaron Wells
Browse files

Adding ArtefactType::postcommit_hook function

Bug 1401210. In order for watchlists to properly handle blog
blocks, we need to give the Blog artefact a chance to update
the view_artefacts table before the "saveartefact" event gets
fired at the bottom of ArtefactType::commit().

So I'm adding a postcommit_hook() method which gets called in
the middle of commit(), and shifting ArtefactType's commit()
method into there.

Change-Id: I23986597fd411fa8f93da7cdbfa8d0b577de66fc
parent d5672034
......@@ -535,18 +535,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
* The post content may now link to different artefacts. See {@link
* PluginBlocktypeBlogPost::get_artefacts for more information}
*/
public function commit() {
if (empty($this->dirty)) {
return;
}
db_begin();
$new = empty($this->id);
parent::commit();
$this->dirty = true;
protected function postcommit_hook($new) {
$data = (object)array(
'blogpost' => $this->get('id'),
'published' => ($this->get('published') ? 1 : 0)
......@@ -559,17 +548,21 @@ class ArtefactTypeBlogPost extends ArtefactType {
update_record('artefact_blog_blogpost', $data, 'blogpost');
}
// We want to get all blockinstances that contain this blog post. That is currently:
// We want to get all blockinstances that may contain this blog post. That is currently:
// 1) All blogpost blocktypes with this post in it
// 2) All blog blocktypes with this posts's blog in it
//
// With these, we tell them to rebuild what artefacts they have in them,
// since the post content could have changed and now have links to
// different artefacts in it
// 3) All recentposts blocktypes with this post's blog in it
// 4) All taggedposts blocktypes with this post's tags
$blockinstanceids = (array)get_column_sql('SELECT block
FROM {view_artefact}
WHERE artefact = ?
OR artefact = ?', array($this->get('id'), $this->get('parent')));
if (!$blockinstanceids) {
$blockinstanceids = array();
}
// Now rebuild the list of which artefacts these blocks contain
// in the view_artefacts table. (This is used for watchlist notifications)
if ($blockinstanceids) {
require_once(get_config('docroot') . 'blocktype/lib.php');
foreach ($blockinstanceids as $id) {
......@@ -577,9 +570,6 @@ class ArtefactTypeBlogPost extends ArtefactType {
$instance->rebuild_artefact_list();
}
}
db_commit();
$this->dirty = false;
}
/**
......
......@@ -600,7 +600,7 @@ abstract class ArtefactType implements IArtefactType {
}
}
artefact_watchlist_notification(array($this->id));
$this->postcommit_hook($is_new);
handle_event('saveartefact', $this);
......@@ -610,6 +610,18 @@ abstract class ArtefactType implements IArtefactType {
db_commit();
}
/**
* A hook method called immediately after the basic data is save in the commit() method,
* but before the DB transaction is closed and before the saveartefact event is triggered.
*
* Child classes may use this to alter data or add data into additional tables so that
* it's present when the saveartefact event is called.
*
* @param boolean $new True if the artefact has just been created
*/
protected function postcommit_hook($new) {
}
/**
* This function provides basic delete functionality. It gets rid of the
* artefact's row in the artefact table, and the tables that reference the
......
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