function update() { global $CFG; global $CURMAN; $old = new cluster($this->id); $parent_obj = new cluster($this->parent); $this->depth = empty($parent_obj->depth) ? 1 : $parent_obj->depth + 1; $result = parent::update(); if ($this->parent != $old->parent) { $cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin'); $cluster_context_instance = get_context_instance($cluster_context_level, $this->id); // find all subclusters and adjust their depth $delta_depth = $this->depth - $old->depth; $sql = "UPDATE {$CURMAN->db->prefix_table(CLSTTABLE)}\n SET depth = depth + {$delta_depth}\n WHERE id IN (SELECT instanceid\n FROM {$CURMAN->db->prefix_table('context')}\n WHERE contextlevel = {$cluster_context_level}\n AND path LIKE '{$cluster_context_instance->path}/%')"; execute_sql($sql, false); // Blank out the depth and path for associated records and child records in context table $sql = "UPDATE {$CFG->prefix}context\n SET depth=0, path=NULL\n WHERE id={$cluster_context_instance->id} OR path LIKE '{$cluster_context_instance->path}/%'"; execute_sql($sql, false); // Rebuild any blanked out records in context table build_context_path(); } $plugins = cluster::get_plugins(); foreach ($plugins as $plugin) { require_once CURMAN_DIRLOCATION . '/cluster/' . $plugin . '/lib.php'; call_user_func('cluster_' . $plugin . '_update', $this); } $result = $result && field_data::set_for_context_from_datarecord('cluster', $this); events_trigger('crlm_cluster_updated', $this); return $result; }