Commit b156f2e2 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1774103: Looking to combine all the *_tag tables



So that we only have one 'tag' table that holds all the tag information

behatnotneeded

Change-Id: Ieb83e61da45edddfa8703816c11f3658c5394c47
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent ffa51659
...@@ -270,7 +270,7 @@ $elements['externalauthjs'] = array( ...@@ -270,7 +270,7 @@ $elements['externalauthjs'] = array(
'value' => $js, 'value' => $js,
); );
$tags = get_column_sql('SELECT tag FROM {usr_tag} WHERE usr = ? AND NOT tag ' . db_ilike() . " 'lastinstitution:%'", array($user->id)); $tags = get_column_sql('SELECT tag FROM {tag} WHERE resourcetype = ? AND resourceid = ? AND NOT tag ' . db_ilike() . " 'lastinstitution:%'", array('usr', $user->id));
$elements['tags'] = array( $elements['tags'] = array(
'defaultvalue' => $tags, 'defaultvalue' => $tags,
...@@ -603,18 +603,23 @@ function edituser_site_submit(Pieform $form, $values) { ...@@ -603,18 +603,23 @@ function edituser_site_submit(Pieform $form, $values) {
// Update user's primary email address // Update user's primary email address
set_user_primary_email($user->id, $values['email']); set_user_primary_email($user->id, $values['email']);
delete_records('usr_tag', 'usr', $user->id); delete_records('tag', 'resourcetype', 'usr', 'resourceid', $user->id);
if (is_array($values['tags'])) { if (is_array($values['tags'])) {
$values['tags'] = check_case_sensitive($values['tags'], 'usr_tag'); $values['tags'] = check_case_sensitive($values['tags'], 'tag');
foreach(array_unique($values['tags']) as $tag) { foreach(array_unique($values['tags']) as $tag) {
if (empty($tag)) { if (empty($tag)) {
continue; continue;
} }
insert_record( insert_record(
'usr_tag', 'tag',
(object) array( (object) array(
'usr' => $user->id, 'resourcetype' => 'usr',
'resourceid' => $user->id,
'ownertype' => 'user',
'ownerid' => $user->id,
'tag' => strtolower($tag), 'tag' => strtolower($tag),
'ctime' => db_format_timestamp(time()),
'editedby' => $USER->get('id'),
) )
); );
} }
......
...@@ -348,13 +348,13 @@ function search_folders_and_files($username, $search='') { ...@@ -348,13 +348,13 @@ function search_folders_and_files($username, $search='') {
$filetypesql = "('" . join("','", $filetypes) . "')"; $filetypesql = "('" . join("','", $filetypes) . "')";
$ownersql = artefact_owner_sql($user->id); $ownersql = artefact_owner_sql($user->id);
$typecast = is_postgres() ? '::varchar' : '';
//retrieve folders and files of a specific Mahara folder // Retrieve folders and files of a specific Mahara folder
$sql = "SELECT $sql = "SELECT
* *
FROM FROM
{artefact} a {artefact} a
LEFT JOIN {artefact_tag} at ON (at.artefact = a.id) LEFT JOIN {tag} at ON (at.resourcetype = 'artefact' AND at.resourceid = a.id" . $typecast . ")
WHERE WHERE
$ownersql $ownersql
AND AND
......
...@@ -107,31 +107,32 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype { ...@@ -107,31 +107,32 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
} }
$tagsout = array_filter($tagsout); $tagsout = array_filter($tagsout);
$sqlvalues = array($view); $sqlvalues = array($view);
$typecast = is_postgres() ? '::varchar' : '';
$sql = $sql =
'SELECT a.title, p.title AS parenttitle, a.id, a.parent, a.owner, a.description, a.allowcomments, at.tag, a.ctime, a.mtime "SELECT a.title, p.title AS parenttitle, a.id, a.parent, a.owner, a.description, a.allowcomments, at.tag, a.ctime, a.mtime
FROM {artefact} a FROM {artefact} a
JOIN {artefact} p ON a.parent = p.id JOIN {artefact} p ON a.parent = p.id
JOIN {artefact_blog_blogpost} ab ON (ab.blogpost = a.id AND ab.published = 1) JOIN {artefact_blog_blogpost} ab ON (ab.blogpost = a.id AND ab.published = 1)
JOIN {artefact_tag} at ON (at.artefact = a.id) JOIN {tag} at ON (at.resourcetype = 'artefact' AND at.resourceid = a.id" . $typecast . ")
WHERE a.artefacttype = \'blogpost\' WHERE a.artefacttype = 'blogpost'
AND a.owner = (SELECT "owner" from {view} WHERE id = ?)'; AND a.owner = (SELECT \"owner\" from {view} WHERE id = ?)";
if (!empty($tagsin)) { if (!empty($tagsin)) {
foreach ($tagsin as $tagin) { foreach ($tagsin as $tagin) {
$sql .= ' AND EXISTS ( $sql .= " AND EXISTS (
SELECT * FROM {artefact_tag} AS at SELECT * FROM {tag} AS at
WHERE a.id = at.artefact WHERE at.resourcetype = 'artefact' AND at.resourceid = a.id" . $typecast . "
AND at.tag = ? AND at.tag = ?
)'; )";
} }
$sqlvalues = array_merge($sqlvalues, $tagsin); $sqlvalues = array_merge($sqlvalues, $tagsin);
} }
if (!empty($tagsout)) { if (!empty($tagsout)) {
foreach ($tagsout as $tagout) { foreach ($tagsout as $tagout) {
$sql .= ' AND NOT EXISTS ( $sql .= " AND NOT EXISTS (
SELECT * FROM {artefact_tag} AS at SELECT * FROM {tag} AS at
WHERE a.id = at.artefact WHERE at.resourcetype = 'artefact' AND at.resourceid = a.id" . $typecast . "
AND at.tag = ? AND at.tag = ?
)'; )";
} }
$sqlvalues = array_merge($sqlvalues, $tagsout); $sqlvalues = array_merge($sqlvalues, $tagsout);
} }
...@@ -234,7 +235,7 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype { ...@@ -234,7 +235,7 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
$result->comments = $comments; $result->comments = $comments;
// get all tags for this post // get all tags for this post
$taglist = get_records_array('artefact_tag', 'artefact', $result->id, "tag DESC"); $taglist = get_records_sql_array("SELECT tag FROM {tag} WHERE resourcetype = 'artefact' AND resourceid = ? ORDER BY tag DESC", array($result->id));
foreach ($taglist as $t) { foreach ($taglist as $t) {
$result->taglist[] = $t->tag; $result->taglist[] = $t->tag;
} }
...@@ -318,12 +319,11 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype { ...@@ -318,12 +319,11 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
private static function get_chooseable_tags() { private static function get_chooseable_tags() {
global $USER; global $USER;
$typecast = is_postgres() ? '::varchar' : '';
return get_records_sql_array(" return get_records_sql_array("
SELECT at.tag SELECT at.tag
FROM FROM {tag} at
{artefact_tag} at JOIN {artefact} a ON (at.resourcetype ='artefact' AND at.resourceid = a.id" . $typecast . ")
JOIN {artefact} a
ON a.id = at.artefact
WHERE WHERE
a.owner = ? a.owner = ?
AND a.artefacttype = 'blogpost' AND a.artefacttype = 'blogpost'
......
...@@ -28,9 +28,12 @@ if ($page < 1) { ...@@ -28,9 +28,12 @@ if ($page < 1) {
} }
$tagsperpage = 5; $tagsperpage = 5;
$values = array($USER->id); $values = array($USER->id);
$sql = "SELECT at.tag FROM {artefact_tag} at $typecast = is_postgres() ? '::varchar' : '';
JOIN {artefact} a ON a.id = at.artefact $sql = "SELECT at.tag FROM {tag} at
JOIN {artefact} a ON (at.resourcetype = 'artefact' AND at.resourceid = a.id" . $typecast . ")
WHERE a.owner = ? WHERE a.owner = ?
AND at.resourcetype = 'artefact'
AND at.resourceid = a.id" . $typecast . "
AND a.artefacttype = 'blogpost'"; AND a.artefacttype = 'blogpost'";
if ($request !== '') { if ($request !== '') {
$sql .= " AND at.tag LIKE '%' || ? || '%'"; $sql .= " AND at.tag LIKE '%' || ? || '%'";
......
...@@ -1056,7 +1056,7 @@ class ArtefactTypeBlogPost extends ArtefactType { ...@@ -1056,7 +1056,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
if ($tags = ArtefactType::tags_from_id_list($postids)) { if ($tags = ArtefactType::tags_from_id_list($postids)) {
foreach($tags as &$at) { foreach($tags as &$at) {
$data[$at->artefact]->tags[] = $at->tag; $data[$at->resourceid]->tags[] = $at->tag;
} }
} }
......
...@@ -693,13 +693,14 @@ abstract class ArtefactTypeFileBase extends ArtefactType { ...@@ -693,13 +693,14 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
} }
} }
} }
$where = 'artefact IN (' . join(',', array_keys($filedata)) . ')'; $tagwhere = "'" . join("','", array_keys($filedata)) . "'";
$tags = get_records_select_array('artefact_tag', $where); $tags = get_records_sql_array("SELECT tag, resourceid FROM {tag} WHERE resourcetype = 'artefact' AND resourceid IN (" . $tagwhere . ")");
if ($tags) { if ($tags) {
foreach ($tags as $t) { foreach ($tags as $t) {
$filedata[$t->artefact]->tags[] = $t->tag; $filedata[$t->resourceid]->tags[] = $t->tag;
} }
} }
$where = 'artefact IN (' . join(',', array_keys($filedata)) . ')';
if ($group) { // Fetch permissions for each artefact if ($group) { // Fetch permissions for each artefact
$perms = get_records_select_array('artefact_access_role', $where); $perms = get_records_select_array('artefact_access_role', $where);
if ($perms) { if ($perms) {
......
...@@ -588,6 +588,8 @@ abstract class ArtefactType implements IArtefactType { ...@@ -588,6 +588,8 @@ abstract class ArtefactType implements IArtefactType {
* this method, and call parent::commit() in your own function. * this method, and call parent::commit() in your own function.
*/ */
public function commit() { public function commit() {
global $USER;
static $last_source, $last_output; static $last_source, $last_output;
$is_new = false; $is_new = false;
...@@ -634,20 +636,36 @@ abstract class ArtefactType implements IArtefactType { ...@@ -634,20 +636,36 @@ abstract class ArtefactType implements IArtefactType {
} }
if (!$is_new) { if (!$is_new) {
$deleted = delete_records('artefact_tag', 'artefact', $this->id); $deleted = delete_records('tag', 'resourcetype', 'artefact', 'resourceid', $this->id);
} }
if (is_array($this->tags)) { if (is_array($this->tags)) {
$this->tags = check_case_sensitive($this->tags, 'artefact_tag'); if ($this->group) {
$ownertype = 'group';
$ownerid = $this->group;
}
else if ($this->institution) {
$ownertype = 'institution';
$ownerid = $this->institution;
}
else {
$ownertype = 'user';
$ownerid = $this->owner;
}
$this->tags = check_case_sensitive($this->tags, 'tag');
foreach (array_unique($this->tags) as $tag) { foreach (array_unique($this->tags) as $tag) {
if (empty($tag)) { if (empty($tag)) {
continue; continue;
} }
insert_record( insert_record('tag',
'artefact_tag',
(object) array( (object) array(
'artefact' => $this->id, 'resourcetype' => 'artefact',
'tag' => $tag, 'resourceid' => $this->get('id'),
'ownertype' => $ownertype,
'ownerid' => $ownerid,
'tag' => $tag,
'ctime' => db_format_timestamp(time()),
'editedby' => $USER->get('id'),
) )
); );
} }
...@@ -831,7 +849,7 @@ abstract class ArtefactType implements IArtefactType { ...@@ -831,7 +849,7 @@ abstract class ArtefactType implements IArtefactType {
BlockInstance::bulk_remove_artefacts($artefactids); BlockInstance::bulk_remove_artefacts($artefactids);
delete_records_select('view_artefact', "artefact IN $idstr"); delete_records_select('view_artefact', "artefact IN $idstr");
delete_records_select('artefact_tag', "artefact IN $idstr"); delete_records_select('tag', "resourcetype = 'artefact' AND resourceid IN ('" . join("','", array_map('intval', $artefactids)) . "')");
delete_records_select('artefact_access_role', "artefact IN $idstr"); delete_records_select('artefact_access_role', "artefact IN $idstr");
delete_records_select('artefact_access_usr', "artefact IN $idstr"); delete_records_select('artefact_access_usr', "artefact IN $idstr");
execute_sql("UPDATE {usr} SET profileicon = NULL WHERE profileicon IN $idstr"); execute_sql("UPDATE {usr} SET profileicon = NULL WHERE profileicon IN $idstr");
...@@ -1215,8 +1233,8 @@ abstract class ArtefactType implements IArtefactType { ...@@ -1215,8 +1233,8 @@ abstract class ArtefactType implements IArtefactType {
if (empty($artefactids)) { if (empty($artefactids)) {
return array(); return array();
} }
$artefactids = join(',', array_map('intval', $artefactids)); $artefactids = join("','", array_map('intval', $artefactids));
$tags = get_records_select_array('artefact_tag', 'artefact IN (' . $artefactids . ')'); $tags = get_records_sql_array("SELECT tag, resourceid FROM {tag} WHERE resourcetype = 'artefact' AND resourceid IN ('" . $artefactids . "')");
if (!$tags) { if (!$tags) {
return array(); return array();
} }
...@@ -1232,10 +1250,10 @@ abstract class ArtefactType implements IArtefactType { ...@@ -1232,10 +1250,10 @@ abstract class ArtefactType implements IArtefactType {
// load tags // load tags
if ($list) { if ($list) {
$tags = get_records_select_array('artefact_tag', 'artefact IN (' . join(',', array_keys($list)) . ')'); $tags = get_records_sql_array("SELECT tag, resourceid FROM {tag} WHERE resourcetype = 'artefact' AND resourceid IN ('" . join("','", array_keys($list)) . "')");
if ($tags) { if ($tags) {
foreach ($tags as $t) { foreach ($tags as $t) {
$list[$t->artefact]->tags[] = $t->tag; $list[$t->resourceid]->tags[] = $t->tag;
} }
foreach ($list as &$attachment) { foreach ($list as &$attachment) {
if (!empty($attachment->tags)) { if (!empty($attachment->tags)) {
...@@ -1338,7 +1356,7 @@ abstract class ArtefactType implements IArtefactType { ...@@ -1338,7 +1356,7 @@ abstract class ArtefactType implements IArtefactType {
if (empty($id)) { if (empty($id)) {
return array(); return array();
} }
$tags = get_column_sql('SELECT tag FROM {artefact_tag} WHERE artefact = ? ORDER BY tag', array($id)); $tags = get_column_sql('SELECT tag FROM {tag} WHERE resourcetype = ? AND resourceid = ? ORDER BY tag', array('artefact', $id));
if (!$tags) { if (!$tags) {
return array(); return array();
} }
......
...@@ -69,16 +69,8 @@ function edit_tag_submit(Pieform $form, $values) { ...@@ -69,16 +69,8 @@ function edit_tag_submit(Pieform $form, $values) {
} }
db_begin(); db_begin();
execute_sql( execute_sql(
"UPDATE {view_tag} SET tag = ? WHERE tag = ? AND \"view\" IN (SELECT id FROM {view} WHERE \"owner\" = ?)", "UPDATE {tag} SET tag = ? WHERE tag = ? AND ownertype = ? AND ownerid = ? AND resourcetype IN ('artefact', 'view', 'collection')",
array($values['tagname'], $tag, $userid) array($values['tagname'], $tag, 'user', $userid)
);
execute_sql(
"UPDATE {collection_tag} SET tag = ? WHERE tag = ? AND \"collection\" IN (SELECT id FROM {collection} WHERE \"owner\" = ?)",
array($values['tagname'], $tag, $userid)
);
execute_sql(
"UPDATE {artefact_tag} SET tag = ? WHERE tag = ? AND artefact IN (SELECT id FROM {artefact} WHERE \"owner\" = ?)",
array($values['tagname'], $tag, $userid)
); );
db_commit(); db_commit();
$SESSION->add_ok_msg(get_string('tagupdatedsuccessfully')); $SESSION->add_ok_msg(get_string('tagupdatedsuccessfully'));
...@@ -92,16 +84,8 @@ function delete_tag_submit(Pieform $form, $values) { ...@@ -92,16 +84,8 @@ function delete_tag_submit(Pieform $form, $values) {
} }
db_begin(); db_begin();
execute_sql( execute_sql(
"DELETE FROM {view_tag} WHERE tag = ? AND view IN (SELECT id FROM {view} WHERE \"owner\" = ?)", "DELETE FROM {tag} WHERE tag = ? AND ownertype = ? AND ownerid = ? AND resourcetype IN ('artefact', 'view', 'collection')",
array($tag, $userid) array($tag, 'user', $userid)
);
execute_sql(
"DELETE FROM {collection_tag} WHERE tag = ? AND collection IN (SELECT id FROM {collection} WHERE \"owner\" = ?)",
array($tag, $userid)
);
execute_sql(
"DELETE FROM {artefact_tag} WHERE tag = ? AND artefact IN (SELECT id FROM {artefact} WHERE \"owner\" = ?)",
array($tag, $userid)
); );
db_commit(); db_commit();
$SESSION->add_ok_msg(get_string('tagdeletedsuccessfully')); $SESSION->add_ok_msg(get_string('tagdeletedsuccessfully'));
......
...@@ -152,7 +152,7 @@ class Collection { ...@@ -152,7 +152,7 @@ class Collection {
} }
delete_records('collection_view','collection',$this->id); delete_records('collection_view','collection',$this->id);
delete_records('collection_tag','collection',$this->id); delete_records('tag', 'resourcetype', 'collection', 'resourceid', $this->id);
delete_records('collection','id',$this->id); delete_records('collection','id',$this->id);
delete_records('existingcopy', 'collection', $this->id); delete_records('existingcopy', 'collection', $this->id);
...@@ -173,6 +173,7 @@ class Collection { ...@@ -173,6 +173,7 @@ class Collection {
* This method updates the contents of the collection table only. * This method updates the contents of the collection table only.
*/ */
public function commit() { public function commit() {
global $USER;
$fordb = new StdClass; $fordb = new StdClass;
foreach (get_object_vars($this) as $k => $v) { foreach (get_object_vars($this) as $k => $v) {
...@@ -196,12 +197,34 @@ class Collection { ...@@ -196,12 +197,34 @@ class Collection {
} }
if (isset($this->tags)) { if (isset($this->tags)) {
delete_records('collection_tag', 'collection', $this->get('id')); if ($this->group) {
$tags = check_case_sensitive($this->get_tags(), 'collection_tag'); $ownertype = 'group';
$ownerid = $this->group;
}
else if ($this->institution) {
$ownertype = 'institution';
$ownerid = $this->institution;
}
else {
$ownertype = 'user';
$ownerid = $this->owner;
}
delete_records('tag', 'resourcetype', 'collection', 'resourceid', $this->get('id'));
$tags = check_case_sensitive($this->get_tags(), 'tag');
foreach ($tags as $tag) { foreach ($tags as $tag) {
//truncate the tag before insert it into the database //truncate the tag before insert it into the database
$tag = substr($tag, 0, 128); $tag = substr($tag, 0, 128);
insert_record('collection_tag', (object)array( 'collection' => $this->get('id'), 'tag' => $tag)); insert_record('tag',
(object)array(
'resourcetype' => 'collection',
'resourceid' => $this->get('id'),
'ownertype' => $ownertype,
'ownerid' => $ownerid,
'tag' => $tag,
'ctime' => db_format_timestamp(time()),
'editedby' => $USER->get('id'),
)
);
} }
} }
...@@ -1332,7 +1355,7 @@ class Collection { ...@@ -1332,7 +1355,7 @@ class Collection {
*/ */
public function get_tags() { public function get_tags() {
if (!isset($this->tags)) { if (!isset($this->tags)) {
$this->tags = get_column('collection_tag', 'tag', 'collection', $this->get('id')); $this->tags = get_column_sql('SELECT tag FROM {tag} WHERE resourcetype = ? AND resourceid = ? ORDER BY tag', array('collection', $this->get('id')));
} }
return $this->tags; return $this->tags;
} }
......
...@@ -5915,6 +5915,11 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -5915,6 +5915,11 @@ function xmldb_core_upgrade($oldversion=0) {
FROM {usr_tag} ut FROM {usr_tag} ut
JOIN {usr} u ON u.id = ut.usr JOIN {usr} u ON u.id = ut.usr
WHERE u.deleted = 0"); WHERE u.deleted = 0");
// Drop old *_tag tables
execute_sql("DROP TABLE {artefact_tag}");
execute_sql("DROP TABLE {usr_tag}");
execute_sql("DROP TABLE {view_tag}");
execute_sql("DROP TABLE {collection_tag}");
} }
} }
......
...@@ -81,16 +81,17 @@ function get_all_tags_for_user($query = null, $limit = null, $offset = null) { ...@@ -81,16 +81,17 @@ function get_all_tags_for_user($query = null, $limit = null, $offset = null) {
if ($USER->is_logged_in()) { if ($USER->is_logged_in()) {
$usertags = ""; $usertags = "";
$userid = $USER->get('id'); $userid = $USER->get('id');
$typecast = is_postgres() ? '::varchar' : '';
if ($USER->get('admin')) { if ($USER->get('admin')) {
$usertags = " $usertags = "
UNION ALL UNION ALL
SELECT tag,COUNT(*) AS count FROM {usr_tag} t INNER JOIN {usr} u ON t.usr=u.id GROUP BY 1"; SELECT tag, COUNT(*) AS count FROM {tag} t INNER JOIN {usr} u ON (t.resourcetype = 'usr' AND t.resourceid = u.id" . $typecast . ") GROUP BY 1";
} }
else if ($admininstitutions = $USER->get('admininstitutions')) { else if ($admininstitutions = $USER->get('admininstitutions')) {
$insql = "'" . join("','", $admininstitutions) . "'"; $insql = "'" . join("','", $admininstitutions) . "'";
$usertags = " $usertags = "
UNION ALL UNION ALL
SELECT tag,COUNT(*) AS count FROM {usr_tag} t INNER JOIN {usr} u ON t.usr=u.id INNER JOIN {usr_institution} ui ON ui.usr=u.id WHERE ui.institution IN ($insql) GROUP BY 1"; SELECT tag, COUNT(*) AS count FROM {tag} t INNER JOIN {usr} u ON (t.resourcetype = 'usr' AND t.resourceid = u.id" . $typecast . ") INNER JOIN {usr_institution} ui ON ui.usr=u.id WHERE ui.institution IN ($insql) GROUP BY 1";
} }
$values = array($userid, $userid, $userid); $values = array($userid, $userid, $userid);
$querystr = ''; $querystr = '';
...@@ -101,11 +102,11 @@ function get_all_tags_for_user($query = null, $limit = null, $offset = null) { ...@@ -101,11 +102,11 @@ function get_all_tags_for_user($query = null, $limit = null, $offset = null) {
$sql = " $sql = "
SELECT tag, SUM(count) AS count SELECT tag, SUM(count) AS count
FROM ( FROM (
SELECT tag,COUNT(*) AS count FROM {artefact_tag} t INNER JOIN {artefact} a ON t.artefact=a.id WHERE a.owner=? GROUP BY 1 SELECT tag,COUNT(*) AS count FROM {tag} t INNER JOIN {artefact} a ON (t.resourcetype = 'artefact' AND t.resourceid = a.id" . $typecast . ") WHERE a.owner=? GROUP BY 1
UNION ALL UNION ALL
SELECT tag,COUNT(*) AS count FROM {view_tag} t INNER JOIN {view} v ON t.view=v.id WHERE v.owner=? GROUP BY 1 SELECT tag,COUNT(*) AS count FROM {tag} t INNER JOIN {view} v ON (t.resourcetype = 'view' AND t.resourceid = v.id" . $typecast . ") WHERE v.owner=? GROUP BY 1
UNION ALL UNION ALL
SELECT tag,COUNT(*) AS count FROM {collection_tag} t INNER JOIN {collection} c ON t.collection=c.id WHERE c.owner=? GROUP BY 1 SELECT tag,COUNT(*) AS count FROM {tag} t INNER JOIN {collection} c ON (t.resourcetype = 'collection' AND t.resourceid = c.id" . $typecast . ") WHERE c.owner=? GROUP BY 1
" . $usertags . " " . $usertags . "
) tags ) tags
" . $querystr . " " . $querystr . "
......
...@@ -343,9 +343,9 @@ class Institution { ...@@ -343,9 +343,9 @@ class Institution {
insert_record('usr_institution', $userinst); insert_record('usr_institution', $userinst);
delete_records('usr_institution_request', 'usr', $userinst->usr, 'institution', $this->name); delete_records('usr_institution_request', 'usr', $userinst->usr, 'institution', $this->name);
execute_sql(" execute_sql("
DELETE FROM {usr_tag} DELETE FROM {tag}
WHERE usr = ? AND tag " . db_ilike() . " 'lastinstitution:%'", WHERE resourcetype = ? AND resourceid = ? AND tag " . db_ilike() . " 'lastinstitution:%'",
array($user->id) array('usr', $user->id)
); );
// Copy institution views and collection to the user's portfolio // Copy institution views and collection to the user's portfolio
$checkviewaccess = empty($user->newuser) && !$USER->get('admin'); $checkviewaccess = empty($user->newuser) && !$USER->get('admin');
...@@ -677,16 +677,21 @@ class Institution { ...@@ -677,16 +677,21 @@ class Institution {
); );
execute_sql(" execute_sql("
DELETE FROM {usr_tag} DELETE FROM {tag}
WHERE usr = ? AND tag " . db_ilike() . " 'lastinstit