Skip to content

Commit f600e17

Browse files
committed
Prevent hidden Wall posts from bumping threads
Closes #3137.
1 parent acb40ee commit f600e17

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Model/Table/WallTable.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ public function afterSave($event, $entity, $options = array())
104104
$this->WallThreads->save($newThreadData);
105105
}
106106

107+
if ($entity->hidden) {
108+
$root = $this->getRootMessageOfReply($entity->id);
109+
$this->recalculateThreadDateIgnoringHiddenPosts($root);
110+
}
111+
}
112+
113+
private function recalculateThreadDateIgnoringHiddenPosts($root)
114+
{
115+
$result = $this->find()
116+
->select(['latest_date' => 'MAX(date)'])
117+
->where([
118+
'lft >=' => $root->lft,
119+
'rght <=' => $root->rght,
120+
'hidden IS' => false,
121+
])
122+
->first();
123+
124+
$thread = $this->WallThreads->get($root->id);
125+
$thread->last_message_date = $result->latest_date;
126+
$this->WallThreads->save($thread);
107127
}
108128

109129

tests/TestCase/Model/Table/WallTableTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,13 @@ public function testSave_correctDateUsingArabicLocale() {
286286

287287
I18n::setLocale($prevLocale);
288288
}
289+
290+
public function testHidingAMessageRecalculatesThreadDateIgnoringHiddenPosts() {
291+
$reply = $this->Wall->get(2);
292+
$reply->hidden = true;
293+
$this->Wall->save($reply);
294+
295+
$threadDate = $this->Wall->WallThreads->get(1)->last_message_date;
296+
$this->assertEquals('2014-04-15 16:37:11', $threadDate);
297+
}
289298
}

0 commit comments

Comments
 (0)