Skip to content

Commit f063f0b

Browse files
committed
Merge branch 'develop'
2 parents b4d610b + bf1c7bc commit f063f0b

File tree

14 files changed

+4753
-110
lines changed

14 files changed

+4753
-110
lines changed

config/vanilla/bootstrap.before.php

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,7 @@ function updateRolePermissions($roleType, $roles) {
417417
*/
418418
function sortsDropDown($baseUrl, array $filters = [], $extraClasses = '', $default = null, $defaultUrl = null, $label = 'Sort') {
419419
$links = [];
420-
$active = paramPreference(
421-
'sort',
422-
'CategorySort',
423-
null,
424-
null,
425-
false
426-
);
420+
$active = Gdn::session()->getPreference('CategorySort', null);
427421
// Translate filters into links.
428422
foreach ($filters as $filter) {
429423
// Make sure we have the bare minimum: a label and a URL parameter.
@@ -486,8 +480,7 @@ function categorySorts($extraClasses = '') {
486480
return;
487481
}
488482

489-
$baseUrl = Gdn::request()->getFullPath();
490-
483+
$baseUrl = preg_replace('/\?.*/', '', Gdn::request()->getFullPath());
491484
$transientKey = Gdn::session()->transientKey();
492485
$filters = [
493486
[
@@ -505,11 +498,7 @@ function categorySorts($extraClasses = '') {
505498
]
506499
];
507500

508-
$defaultParams = ['TransientKey' => $transientKey];
509-
if (Gdn::request()->get('sort')) {
510-
$defaultParams['sort'] = Gdn::request()->get('sort');
511-
}
512-
501+
$defaultParams = [];
513502
if (!empty($defaultParams)) {
514503
$defaultUrl = $baseUrl.'?'.http_build_query($defaultParams);
515504
} else {
@@ -539,9 +528,8 @@ function discussionSorts($extraClasses = '') {
539528
return;
540529
}
541530

542-
$baseUrl = Gdn::request()->getFullPath();
531+
$baseUrl = preg_replace('/\?.*/', '', Gdn::request()->getFullPath());
543532
$transientKey = Gdn::session()->transientKey();
544-
545533
$filters = [
546534
[
547535
'name' => t('New'),
@@ -558,11 +546,7 @@ function discussionSorts($extraClasses = '') {
558546
];
559547

560548

561-
$defaultParams = ['save' => 1, 'TransientKey' => $transientKey];
562-
if (Gdn::request()->get('sort')) {
563-
$defaultParams['sort'] = '';
564-
}
565-
549+
$defaultParams = [];
566550
if (!empty($defaultParams)) {
567551
$defaultUrl = $baseUrl.'?'.http_build_query($defaultParams);
568552
} else {
@@ -595,7 +579,7 @@ function discussionFilters($extraClasses = '') {
595579
return;
596580
}
597581

598-
$baseUrl = Gdn::request()->getFullPath();
582+
$baseUrl = preg_replace('/\?.*/', '', Gdn::request()->getFullPath());
599583
$transientKey = Gdn::session()->transientKey();
600584
$filters = [
601585
[
@@ -612,11 +596,7 @@ function discussionFilters($extraClasses = '') {
612596
]
613597
];
614598

615-
$defaultParams = ['save' => 1, 'TransientKey' => $transientKey];
616-
if (Gdn::request()->get('followed')) {
617-
$defaultParams['followed'] = '';
618-
}
619-
599+
$defaultParams = [];
620600
if (!empty($defaultParams)) {
621601
$defaultUrl = $baseUrl.'?'.http_build_query($defaultParams);
622602
} else {
@@ -650,7 +630,7 @@ function categoryFilters($extraClasses = '') {
650630
return;
651631
}
652632

653-
$baseUrl = Gdn::request()->getFullPath();
633+
$baseUrl = preg_replace('/\?.*/', '', Gdn::request()->getFullPath());
654634
$transientKey = Gdn::session()->transientKey();
655635
$filters = [
656636
[
@@ -668,11 +648,7 @@ function categoryFilters($extraClasses = '') {
668648
]
669649
];
670650

671-
$defaultParams = ['save' => 1, 'TransientKey' => $transientKey];
672-
if (Gdn::request()->get('followed')) {
673-
$defaultParams['followed'] = '';
674-
}
675-
651+
$defaultParams = [];
676652
if (!empty($defaultParams)) {
677653
$defaultUrl = $baseUrl.'?'.http_build_query($defaultParams);
678654
} else {
@@ -714,13 +690,7 @@ function filtersDropDown($baseUrl, array $filters = [], $extraClasses = '', $def
714690

715691
if (c('Vanilla.EnableCategoryFollowing')) {
716692
$links = [];
717-
$active = paramPreference(
718-
'followed',
719-
'FollowedCategories',
720-
'Vanilla.SaveFollowingPreference',
721-
null,
722-
false
723-
);
693+
$active = Gdn::session()->getPreference('FollowedCategories', null);
724694

725695
// Translate filters into links.
726696
foreach ($filters as $filter) {

config/vanilla/bootstrap.early.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,81 @@
6060
// Delete the records with UserID=0 (Guests) from UserRole table
6161
// FIX: https://github.com/topcoder-platform/forums/issues/108
6262
Gdn::sql()->delete('UserRole',['UserID' => 0]);
63+
64+
// FIX: https://github.com/topcoder-platform/forums/issues/227
65+
// Sorting discussions by last date.
66+
// The last date can be any of InsertedDate(discussion), UpdatedDate(discussion), InsertedDate(comment) or UpdatedDate(comment).
67+
// The new columns will be added to keep the last date and who made changes.
68+
// By default Vanilla uses only DateInserted in calculated columns.
69+
// Moreover, the calculated columns (LastCommentID, LastDiscussionID and others) are used in calculations/aggregations.
70+
// Don't modified default Vanilla calculated columns.
71+
if(!Gdn::structure()->table('Discussion')->columnExists('LastDiscussionCommentsDate')) {
72+
Gdn::structure()->table('Discussion')
73+
->column('LastDiscussionCommentsDate', 'datetime', true, ['index', 'index.CategoryPages'])
74+
->column('LastDiscussionCommentsUserID', 'int', true)
75+
->set(false, false);
76+
// Step 1. Calculate the last date for discussions.
77+
$query = "UPDATE GDN_Discussion p
78+
SET p.LastDiscussionCommentsDate = (SELECT greatest(COALESCE(MAX(c.DateInserted), 0), COALESCE(MAX(c.DateUpdated), 0), COALESCE(p.DateUpdated, 0), COALESCE(p.DateInserted,0))
79+
FROM GDN_Comment c WHERE p.DiscussionID = c.DiscussionID)";
80+
Gdn::sql()->query($query);
81+
82+
// Step 2. Update discussions with comments.
83+
$query = "UPDATE GDN_Discussion p
84+
SET p.LastDiscussionCommentsUserID = (
85+
SELECT CASE
86+
WHEN COALESCE(p.DateUpdated,p.DateInserted) > COALESCE(c.DateUpdated,c.DateInserted) THEN
87+
COALESCE(p.UpdateUserID, p.InsertUserID)
88+
ELSE COALESCE(c.UpdateUserID,c.InsertUserID) END AS LastUserID FROM GDN_Comment c
89+
WHERE c.DiscussionID = p.DiscussionID ORDER BY c.DateUpdated DESC,c.DateInserted DESC LIMIT 1)";
90+
Gdn::sql()->query($query);
91+
92+
// Step 3. Update discussions without comments.
93+
$query ="UPDATE GDN_Discussion p
94+
SET p.LastDiscussionCommentsUserID = COALESCE(p.UpdateUserID,p.InsertUserID)
95+
WHERE p.LastDiscussionCommentsUserID IS NULL";
96+
Gdn::sql()->query($query);
97+
}
98+
99+
// Sorting categories by the last date
100+
// https://github.com/topcoder-platform/forums/issues/227
101+
if(!Gdn::structure()->table('Category')->columnExists('LastDiscussionCommentsUserID')) {
102+
Gdn::structure()->table('Category')
103+
->column('LastDiscussionCommentsUserID', 'int', true)
104+
->column('LastDiscussionCommentsDiscussionID', 'int', true)
105+
->column('LastDiscussionCommentsDate', 'datetime', true)
106+
->set(false, false);
107+
108+
// Step1. Update categories with type 'discussions':
109+
$query = "UPDATE GDN_Category c
110+
SET c.LastDiscussionCommentsDate = (SELECT MAX(d.LastDiscussionCommentsDate)FROM GDN_Discussion d WHERE d.CategoryID = c.CategoryID),
111+
c.LastDiscussionCommentsUserID = (SELECT d.LastDiscussionCommentsUserID FROM GDN_Discussion d
112+
WHERE d.CategoryID = c.CategoryID ORDER BY d.LastDiscussionCommentsDate DESC limit 1),
113+
c.LastDiscussionCommentsDiscussionID = (SELECT d.DiscussionID FROM GDN_Discussion d
114+
WHERE d.CategoryID = c.CategoryID ORDER BY d.LastDiscussionCommentsDate DESC limit 1)";
115+
Gdn::sql()->query($query);
116+
117+
118+
// Step2. Update all ancestor categories.
119+
// The MAX category depth is 4 for challenges
120+
$ancestorQuery = "UPDATE GDN_Category pc, (
121+
SELECT c1.ParentCategoryID AS ParentCategoryID, c1.LastDiscussionCommentsDate, c1.LastDiscussionCommentsUserID, c1.LastDiscussionCommentsDiscussionID
122+
FROM GDN_Category c1 inner join (SELECT c.ParentCategoryID, MAX(c.LastDiscussionCommentsDate) AS LastDiscussionCommentsDate FROM GDN_Category c
123+
GROUP BY c.ParentCategoryID) c2 on c1.ParentCategoryID = c2.ParentCategoryID AND c1.LastDiscussionCommentsDate = c2.LastDiscussionCommentsDate) c3
124+
SET pc.LastDiscussionCommentsDiscussionID = c3.LastDiscussionCommentsDiscussionID, pc.LastDiscussionCommentsUserID = c3.LastDiscussionCommentsUserID,
125+
pc.LastDiscussionCommentsDate = c3.LastDiscussionCommentsDate
126+
WHERE pc.CategoryID = c3.ParentCategoryID AND pc.Depth = %d";
127+
128+
for ($i = 3; $i > -1; $i--) {
129+
Gdn::sql()->query(sprintf($ancestorQuery, $i));
130+
}
131+
132+
//Step 3. Update categories without discussions.
133+
$emptyAncestorQuery = "UPDATE GDN_Category p
134+
SET p.LastDiscussionCommentsDate = COALESCE(p.DateUpdated, p.DateInserted)
135+
WHERE p.LastDiscussionCommentsDate IS NULL && p.LastDiscussionCommentsUserID IS NULL &&
136+
p.LastDiscussionCommentsDiscussionID IS NULL";
137+
Gdn::sql()->query($emptyAncestorQuery);
138+
}
139+
63140
}

config/vanilla/bootstrap.late.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,30 @@
2929
// Check all roles in the env and update all role permissions in RoleModel
3030
// updateRolePermissions(RoleModel::TYPE_TOPCODER, RoleModel::TOPCODER_ROLES);
3131
// updateTopcoderRolePermissions(RoleModel::TYPE_TOPCODER,RoleModel::TOPCODER_PROJECT_ROLES);
32+
33+
// FIX: https://github.com/topcoder-platform/forums/issues/218
34+
// Create a parent category for Groups if it doesn't exist
35+
// Make sure that the UrlCode is unique among categories.
36+
$GroupCategoryExists = Gdn::sql()->select('CategoryID')
37+
->from('Category')
38+
->where('UrlCode', 'groups')
39+
->get()->numRows();
40+
if($GroupCategoryExists == 0) {
41+
$data = [
42+
'Name' => 'Groups',
43+
'UrlCode' => 'groups',
44+
'DisplayAs' => 'categories',
45+
'ParentCategoryID' => -1,
46+
'AllowDiscussions'=> 0,
47+
];
48+
$date = Gdn_Format::toDateTime();
49+
$CategoryModel = CategoryModel::instance();
50+
Gdn::sql()->insert('Category', ['ParentCategoryID' => -1, 'TreeLeft' => 2, 'TreeRight' => 3, 'Depth' => 1, 'InsertUserID' => 1,
51+
'UpdateUserID' => 1, 'DateInserted' => $date, 'DateUpdated' => $date,
52+
'Name' => 'Groups', 'UrlCode' => 'groups', 'Description' => '', 'PermissionCategoryID' => -1, 'DisplayAs' => 'Categories',
53+
'LastDiscussionCommentsDate' => $date]);
54+
$CategoryModel->rebuildTree();
55+
$CategoryModel->recalculateTree();
56+
unset($CategoryModel);
57+
}
3258
}

config/vanilla/config.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
$Configuration['EnabledPlugins']['GettingStarted'] = 'GettingStarted';
2525
$Configuration['EnabledPlugins']['stubcontent'] = false;
2626
$Configuration['EnabledPlugins']['Topcoder'] = true;
27-
$Configuration['EnabledPlugins']['rich-editor'] = false;
28-
$Configuration['EnabledPlugins']['editor'] = true;
27+
$Configuration['EnabledPlugins']['rich-editor'] = true;
28+
$Configuration['EnabledPlugins']['editor'] = false;
2929
$Configuration['EnabledPlugins']['emojiextender'] = true;
3030
$Configuration['EnabledPlugins']['GooglePrettify'] = true;
3131
$Configuration['EnabledPlugins']['Quotes'] = true;
@@ -56,14 +56,14 @@
5656
$Configuration['Garden']['Email']['SmtpPort'] = getenv('MAIL_SMTP_PORT');
5757
$Configuration['Garden']['Email']['SmtpSecurity'] = getenv('MAIL_SMTP_SECURITY');
5858
$Configuration['Garden']['UpdateToken'] = '105e786dc643fd20143d3c137b593af168560c13';
59-
$Configuration['Garden']['InputFormatter'] = 'Rich';
59+
$Configuration['Garden']['InputFormatter'] = 'Markdown';
6060
$Configuration['Garden']['Version'] = 'Undefined';
6161
$Configuration['Garden']['CanProcessImages'] = true;
6262
$Configuration['Garden']['Theme'] = 'topcoder-theme';
6363
$Configuration['Garden']['MobileTheme'] = 'topcoder-theme';
6464
$Configuration['Garden']['Profile']['EditPhotos'] = false;
6565
$Configuration['Garden']['SystemUserID'] = '1';
66-
$Configuration['Garden']['MobileInputFormatter'] = 'Rich';
66+
$Configuration['Garden']['MobileInputFormatter'] = 'Markdown';
6767
$Configuration['Garden']['AllowFileUploads'] = true;
6868
$Configuration['Garden']['EditContentTimeout'] = -1;
6969
$Configuration['Garden']['Profile']['EditPhotos'] = false;
@@ -168,3 +168,17 @@
168168
// 'Email.ConversationMessage' = 'Notify me of private messages.'
169169
// 'Popup.ConversationMessage' = 'Notify me of private messages.'
170170
$Configuration['Garden']['Profile']['ShowActivities']=false;
171+
172+
// Flood Control
173+
$Configuration['Vanilla']['Comment']['SpamCount'] = '5';
174+
$Configuration['Vanilla']['Comment']['SpamTime'] = '60';
175+
$Configuration['Vanilla']['Comment']['SpamLock'] = '120';
176+
$Configuration['Vanilla']['Discussion']['SpamCount'] = '3';
177+
$Configuration['Vanilla']['Discussion']['SpamTime'] = '60';
178+
$Configuration['Vanilla']['Discussion']['SpamLock'] = '120';
179+
$Configuration['Vanilla']['Activity']['SpamCount'] = '5';
180+
$Configuration['Vanilla']['Activity']['SpamTime'] = '60';
181+
$Configuration['Vanilla']['Activity']['SpamLock'] = '120';
182+
$Configuration['Vanilla']['ActivityComment']['SpamCount'] = '5';
183+
$Configuration['Vanilla']['ActivityComment']['SpamTime'] = '60';
184+
$Configuration['Vanilla']['ActivityComment']['SpamLock'] = '120';

0 commit comments

Comments
 (0)