Commit d6b12ca0 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon

Bug 1655456: fix shared collection not displaying

Collection shared to a group was not displaying
in group page and shared with me page
after first page of collection was deleted.
Fixed by resetting the order when deleting a view.

behatnotneeded

Change-Id: I096114ecf50b7a3af6d1393b387073676a984006
parent fd99881c
......@@ -653,8 +653,17 @@ class Collection {
*/
public function remove_view($view) {
db_begin();
$position = get_field_sql('
SELECT displayorder FROM {collection_view}
WHERE collection = ?
AND view = ?',
array($this->get('id'),$view)
);
delete_records('collection_view','view',$view,'collection',$this->get('id'));
$this->update_display_order($position);
// Secret url records belong to the collection, so remove them from the view.
// @todo: add user message to whatever calls this.
delete_records_select('view_access', 'view = ? AND token IS NOT NULL', array($view));
......@@ -662,6 +671,24 @@ class Collection {
db_commit();
}
/**
* Updates the position number of the views in a collection
*
* @param integer $start position from where to start updating
*/
public function update_display_order($start = 0) {
$start = intval($start);
$ids = get_column_sql('
SELECT view FROM {collection_view}
WHERE collection = ?
ORDER BY displayorder', array($this->get('id')));
foreach ($ids as $k => $v) {
if ($start <= $k) {
set_field('collection_view', 'displayorder', $k, 'view', $v, 'collection',$this->get('id'));
}
}
}
/**
* Sets the displayorder for a view
*
......
......@@ -4353,5 +4353,31 @@ function xmldb_core_upgrade($oldversion=0) {
bump_cache_version();
}
if ($oldversion < 2015092936) {
log_debug('Update view positions in collections');
$sql = 'SELECT collection, COUNT(*) - 1 AS count, MAX(displayorder) AS maxposition
FROM {collection_view}
GROUP BY collection
HAVING COUNT(*) - 1 != MAX(displayorder)';
$collections = get_records_sql_array($sql);
if ($collections) {
require_once(get_config('libroot') . 'collection.php');
$count = 0;
$limit = 1000;
$total = count($collections);
foreach ($collections as $collectiondata) {
$collection = new Collection($collectiondata->collection);
$collection->update_display_order();
$count++;
if (($count % $limit) == 0 || $count == $total) {
log_debug("$count/$total");
set_time_limit(30);
}
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2015092935;
$config->version = 2015092936;
$config->series = '15.10';
$config->release = '15.10.8testing';
$config->minupgradefrom = 2012080604;
......
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