@@ -830,19 +830,21 @@ public function checkPermission($userID,$groupID,$categoryID = null, $permission
830
830
* @return bool|Gdn_DataSet|object|string
831
831
*/
832
832
public function join ($ GroupID , $ UserID , $ watched = true , $ followed = true ){
833
- $ results = [] ;
833
+ GroupsPlugin:: logMessage ( ' !!!-----------------join:enter-----------------!!! ' , [ ' GroupID ' => $ GroupID , ' userID ' => $ UserID , ' watched ' => $ watched , ' followed ' => $ followed ], __FILE__ , __LINE__ ) ;
834
834
$ Fields = ['Role ' => GroupModel::ROLE_MEMBER , 'GroupID ' => $ GroupID ,'UserID ' => $ UserID , 'DateInserted ' => Gdn_Format::toDateTime ()];
835
835
if ( $ this ->SQL ->getWhere ('UserGroup ' , ['GroupID ' => $ GroupID ,'UserID ' => $ UserID ])->numRows () == 0 ) {
836
836
$ this ->SQL ->insert ('UserGroup ' , $ Fields );
837
+ GroupsPlugin::logMessage ('join:user was added in UserGroup ' , ['userID ' =>$ UserID , 'watched ' => $ watched , 'followed ' =>$ followed ],__FILE__ , __LINE__ );
837
838
if ($ followed === true ) {
838
- $ results [ ' Followed ' ] = $ this ->followGroup ($ GroupID , $ UserID );
839
+ $ this ->followGroup ($ GroupID , $ UserID );
839
840
}
840
841
if ($ watched === true ) {
841
- $ results [ ' Watched ' ] = $ this ->watchGroup ($ GroupID , $ UserID );
842
+ $ this ->watchGroup ($ GroupID , $ UserID );
842
843
}
843
844
$ this ->notifyJoinGroup ($ GroupID , $ UserID );
844
845
}
845
- return $ results ;
846
+ GroupsPlugin::logMessage ('join:exit ' , [],__FILE__ , __LINE__ );
847
+
846
848
}
847
849
848
850
/**
@@ -1248,110 +1250,128 @@ public function hasWatchedGroup($group) {
1248
1250
1249
1251
/**
1250
1252
* Follow all group's categories
1251
- *
1253
+ * @param $group
1254
+ * @param $userID
1252
1255
*/
1253
1256
public function followGroup ($ group , $ userID ) {
1254
- $ result = [];
1257
+ //TODO: Remove extra logging after testing
1258
+ GroupsPlugin::logMessage ('-----------------followGroup:enter------------ ' , ['userID ' =>$ userID , 'group ' =>$ group ],__FILE__ , __LINE__ );
1255
1259
if (is_numeric ($ group ) && $ group > 0 ) {
1256
1260
$ group = $ this ->getByGroupID ($ group );
1257
1261
}
1258
-
1259
1262
if ($ group ->ChallengeID ) {
1260
- // Remove existing UserCategory cache
1261
- // Before calculating the user-specific information on a category.
1262
- CategoryModel::clearUserCache ($ userID );
1263
- Gdn::cache ()->remove ("Follow_ {$ userID }" );
1264
- $ categoryModel = CategoryModel::instance ();
1265
- $ groupCategory = $ categoryModel ->getByCode ($ group ->ChallengeID );
1266
- $ parentCategoryID = val ('CategoryID ' , $ groupCategory );
1267
- $ isFollowed = $ categoryModel ->follow ($ userID , $ parentCategoryID , true );
1268
- $ result [strval ($ parentCategoryID )] = $ isFollowed ;
1269
- $ childrenCategories = CategoryModel::getChildren ($ parentCategoryID );
1270
- $ categoryIDs = array_column ($ childrenCategories , 'CategoryID ' );
1263
+ $ categories = Gdn::sql ()->getWhere ('Category ' , ['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1264
+ $ categoryIDs = array_column ($ categories , 'CategoryID ' );
1265
+ GroupsPlugin::logMessage ('follow:allCatIDs ' , ['userID ' =>$ userID , 'catIds ' =>$ categoryIDs ], __FILE__ , __LINE__ ) ;
1266
+
1271
1267
foreach ($ categoryIDs as $ categoryID ) {
1272
- $ isFollowed = $ categoryModel ->follow ($ userID , $ categoryID , true );
1273
- $ result [strval ($ categoryID )] = $ isFollowed ;
1268
+ try {
1269
+ Gdn::sql ()->insert (
1270
+ 'UserCategory ' ,
1271
+ ['Followed ' => 1 , 'UserID ' => $ userID , 'CategoryID ' => $ categoryID ]
1272
+ );
1273
+ } catch (Exception $ e ) {
1274
+ Gdn::sql ()->update ('UserCategory ' ,
1275
+ ['Followed ' => 1 ],
1276
+ ['UserID ' => $ userID , 'CategoryID ' => $ categoryID ]
1277
+ )->put ();
1278
+ }
1274
1279
}
1275
-
1276
1280
CategoryModel::clearUserCache ($ userID );
1281
+ Gdn::cache ()->remove ("Follow_ {$ userID }" );
1277
1282
}
1278
- return $ result ;
1279
1283
}
1280
1284
1281
1285
/**
1282
1286
* Unfollow all group's categories
1283
- *
1287
+ * @param $group
1288
+ * @param $userID
1284
1289
*/
1285
1290
public function unfollowGroup ($ group , $ userID ) {
1291
+ GroupsPlugin::logMessage ('-----------------unfollow:enter----------------- ' , ['userID ' =>$ userID , 'group ' =>$ group ], __FILE__ , __LINE__ ) ;
1286
1292
if (is_numeric ($ group ) && $ group > 0 ) {
1287
1293
$ group = $ this ->getByGroupID ($ group );
1288
1294
}
1289
1295
1290
1296
if ($ group ->ChallengeID ) {
1291
- $ categoryModel = new CategoryModel ();
1292
- $ groupCategory = $ categoryModel ->getByCode ($ group ->ChallengeID );
1293
- $ categories = CategoryModel::getSubtree ($ groupCategory ->CategoryID , true );
1297
+ $ categories = Gdn::sql ()->getWhere ('Category ' , ['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1294
1298
$ categoryIDs = array_column ($ categories , 'CategoryID ' );
1299
+ GroupsPlugin::logMessage ('unfollow:allCatIDs ' , ['userID ' =>$ userID , 'catIds ' =>$ categoryIDs ], __FILE__ , __LINE__ ) ;
1295
1300
1296
1301
foreach ($ categoryIDs as $ categoryID ) {
1297
- $ categoryModel ->follow ($ userID , $ categoryID , false );
1302
+ Gdn::sql ()->update ('UserCategory ' , [ 'Followed ' => 0 ],
1303
+ ['UserID ' => $ userID ,'CategoryID ' => $ categoryID ])->put ();
1298
1304
}
1299
1305
1306
+ Gdn::cache ()->remove ("Follow_ {$ userID }" );
1300
1307
CategoryModel::clearUserCache ($ userID );
1301
1308
}
1302
1309
}
1303
1310
1304
1311
/**
1305
1312
* Watch all group's categories
1306
1313
* @param $group
1314
+ * @param $userID
1307
1315
*/
1308
1316
public function watchGroup ($ group , $ userID ) {
1309
- $ results = [];
1317
+ //TODO: Remove extra logging after testing
1318
+ GroupsPlugin::logMessage ('-----------------watch:enter----------------- ' , ['userID ' =>$ userID , 'group ' =>$ group ], __FILE__ , __LINE__ ) ;
1319
+
1310
1320
if (is_numeric ($ group ) && $ group > 0 ) {
1311
1321
$ group = $ this ->getByGroupID ($ group );
1312
1322
}
1313
1323
1314
1324
if ($ group ->ChallengeID ) {
1315
- // Remove existing UserCategory cache
1316
- // Before calculating the user-specific information on a category.
1317
- CategoryModel::clearUserCache ($ userID );
1318
- Gdn::cache ()->remove ("UserMeta_ {$ userID }" );
1319
-
1320
- $ categoryModel = CategoryModel::instance ();
1321
- $ groupCategory = $ categoryModel ->getByCode ($ group ->ChallengeID );
1322
- $ parentCategoryID = val ('CategoryID ' , $ groupCategory );
1323
- $ childrenCategories = CategoryModel::getChildren ($ parentCategoryID );
1324
- $ categoryIDs = array_column ($ childrenCategories , 'CategoryID ' );
1325
- array_push ($ categoryIDs , $ parentCategoryID );
1326
- $ categoryModel ->setCategoryMetaData ($ categoryIDs , $ userID , 1 );
1327
- $ userMetaModel = new UserMetaModel ();
1328
- $ results = $ userMetaModel ->getUserMeta ($ userID );
1325
+ $ categories = Gdn::sql ()->getWhere ('Category ' , ['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1326
+ $ categoryIDs = array_column ($ categories , 'CategoryID ' );
1327
+ GroupsPlugin::logMessage ('watch:allCatIDs ' , ['userID ' =>$ userID , 'catIds ' =>$ categoryIDs ], __FILE__ , __LINE__ ) ;
1328
+ // Don't use setCategoryMetaData due to cache
1329
+ $ metaKeys = ['Preferences.Email.NewComment. ' ,
1330
+ 'Preferences.Email.NewDiscussion. ' ,
1331
+ 'Preferences.Popup.NewComment. ' ,
1332
+ 'Preferences.Popup.NewDiscussion. ' ];
1333
+ foreach ($ categoryIDs as $ categoryID ) {
1334
+ foreach ($ metaKeys as $ metaKey ) {
1335
+ Gdn::sql ()->insert ('UserMeta ' , [
1336
+ 'UserID ' => $ userID ,
1337
+ 'Name ' => $ metaKey . $ categoryID ,
1338
+ 'Value ' => 1
1339
+ ]);
1340
+ }
1341
+ }
1329
1342
CategoryModel::clearUserCache ($ userID );
1343
+ $ result = Gdn::cache ()->remove ("UserMeta_ {$ userID }" );
1344
+ GroupsPlugin::logMessage ('watch:UserMetaCacheRemoved ' , ['userID ' =>$ userID , 'cacheRemoved ' =>$ result ], __FILE__ , __LINE__ ) ;
1330
1345
}
1331
-
1332
- return $ results ;
1333
1346
}
1334
1347
1335
1348
/**
1336
1349
* Unwatch all group's categories
1337
1350
* @param $group
1338
1351
*/
1339
1352
public function unwatchGroup ($ group , $ userID ) {
1353
+ GroupsPlugin::logMessage ('-----------------unwatch:enter----------------- ' , ['userID ' =>$ userID , 'group ' =>$ group ], __FILE__ , __LINE__ ) ;
1354
+
1340
1355
if (is_numeric ($ group ) && $ group > 0 ) {
1341
1356
$ group = $ this ->getByGroupID ($ group );
1342
1357
}
1343
-
1344
1358
if ($ group ->ChallengeID ) {
1345
- CategoryModel::clearUserCache ($ userID );
1359
+ $ categories = Gdn::sql ()->getWhere ('Category ' , ['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1360
+ $ categoryIDs = array_column ($ categories , 'CategoryID ' );
1361
+ // Don't use setCategoryMetaData due to cache
1362
+ $ metaKeys = ['Preferences.Email.NewComment. ' ,
1363
+ 'Preferences.Email.NewDiscussion. ' ,
1364
+ 'Preferences.Popup.NewComment. ' ,
1365
+ 'Preferences.Popup.NewDiscussion. ' ];
1366
+ foreach ($ categoryIDs as $ categoryID ) {
1367
+ foreach ($ metaKeys as $ metaKey ) {
1368
+ Gdn::sql ()->delete ('UserMeta ' , [
1369
+ 'UserID ' => $ userID ,
1370
+ 'Name ' => $ metaKey . $ categoryID
1371
+ ]);
1372
+ }
1373
+ }
1346
1374
Gdn::cache ()->remove ("UserMeta_ {$ userID }" );
1347
- $ categoryModel = new CategoryModel ();
1348
- $ groupCategory = $ categoryModel ->getByCode ($ group ->ChallengeID );
1349
- $ parentCategoryID = val ('CategoryID ' , $ groupCategory );
1350
- $ childrenCategories = CategoryModel::getChildren ($ parentCategoryID );
1351
- $ categoryIDs = array_column ($ childrenCategories , 'CategoryID ' );
1352
- array_push ($ categoryIDs , $ parentCategoryID );
1353
- $ categoryModel ->setCategoryMetaData ($ categoryIDs , $ userID , null );
1354
-
1355
1375
CategoryModel::clearUserCache ($ userID );
1356
1376
}
1357
1377
}
0 commit comments