Skip to content

Commit ed68f01

Browse files
authored
Merge pull request #542 from topcoder-platform/issues-523-1
Issues-523: Fixed 'Unknown column u.UserID in 'where clause'
2 parents 242e57b + 9c105b4 commit ed68f01

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

config/vanilla/bootstrap.early.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,17 @@
156156
// FIX: https://github.com/topcoder-platform/forums/issues/479
157157
if(!Gdn::structure()->table('User')->columnExists('CountWatchedCategories')) {
158158
Gdn::structure()->table('User')
159-
->column('CountWatchedCategories', 'int', null)
159+
->column('CountWatchedCategories', 'int', true)
160160
->set(false, false);
161161

162-
// Set count of WatchedCategories for users
163-
Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = (
164-
select count(c.CategoryID) from GDN_Category c, (select distinct CAST(SUBSTRING_INDEX(um.Name, ".", -1) as UNSIGNED) as CategoryID from GDN_UserMeta um
165-
where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID)', 'update');
162+
// Set count of Watched Categories for users
163+
Gdn::sql()->query('update GDN_User u, (select wc.UserID, count(wc.CategoryID) count from GDN_Category c
164+
join (select distinct um.UserID, SUBSTRING_INDEX(um.Name, ".", -1) as CategoryID from GDN_UserMeta um where um.Name LIKE "Preferences.%" and Value = 1) wc
165+
where wc.CategoryID = c.CategoryID group by wc.UserID) uc
166+
set u.CountWatchedCategories = uc.count
167+
where u.UserID = uc.UserID', 'update');
166168

169+
Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = 0 where u.CountWatchedCategories is null', 'update');
167170
}
168171

169-
// FIX: https://github.com/topcoder-platform/forums/issues/479
170-
// Re-calculate count of WatchedCategories if WatchedCategories is null
171-
// Gdn::sql()->query('update GDN_User u set u.CountWatchedCategories = (
172-
// select count(c.CategoryID) from GDN_Category c, (select distinct CAST(SUBSTRING_INDEX(um.Name, ".", -1) as UNSIGNED) as CategoryID from GDN_UserMeta um
173-
// where um.Name LIKE "Preferences.%" AND UserID = u.UserID and Value = 1) ws where ws.CategoryID = c.CategoryID) where CountWatchedCategories is null', 'update');
174172
}

0 commit comments

Comments
 (0)