Commit 359f3540 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic
Browse files

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 dacb2049
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -868,8 +868,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));
@@ -877,6 +886,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
     *
+26 −0
Original line number Diff line number Diff line
@@ -4869,5 +4869,31 @@ function xmldb_core_upgrade($oldversion=0) {
        add_field($table, $field);
    }

    if ($oldversion < 2017012700) {
        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;
}
+1 −1
Original line number Diff line number Diff line
@@ -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 = 2017012600;
$config->version = 2017012700;
$config->series = '17.04';
$config->release = '17.04dev';
$config->minupgradefrom = 2012080604;