0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<?php
public function run()
{
$db = Registry::get('Db');
$db->transaction(Db_Database::START);
$success = $db->query()->update()
->table('forum_topics')
->set('PostsCount = PostsCount - 1')
->set('LastPostID = ('
. $db->query()
->select()->fields('ID')
->table('forum_posts')->order('ID', 1) // DESC
->where('TopicID = %d', $this->post->topic->id)
->limit(1)->compile()->getQuery()
. ')')
->set('FirstPostID = ('
. $db->query()
->select()->fields('ID')
->table('forum_posts')->order('ID')
->where('TopicID = %d', $this->post->topic->id)
->limit(1)->compile()->getQuery()
. ')')
->where('ID = %d', $this->post->topic->id)
->compile()->run()->success()
&& $db->query()->update()
->table('forum_cats')
->set('PostsCount = PostsCount - 1')
->set('LastTopicID = ('
. $db->query()
->select()->fields('ID')
->table('forum_topics')->order('LastPostID', 1) // DESC
->where('CatID = %d', $this->post->topic->category->id)
->limit(1)->compile()->getQuery()
. ')')
->where('ID = %d', $this->post->topic->category->id)
->compile()->run()->success()
&& $db->query()->update()
->table('forum_posts')
->set('Deleted = 1')
->where('ID = %d', $this->post->id)
->compile()->run()->success();
$db->transaction($success ? Db_Database::COMMIT : Db_Database::ROLLBACK);
return $success;
}
Вот такая вот жесть бывает. Изменение счетчиков на форуме (денормализация) с использованием альфа-версии кверибилдера. по-моему — устрашающе)
Запостил:
Shock ,
13.10.2009 (Updated 24.03.2018 )
а вообще такое кол-во кода ради апдейта счетчика это пиздец)
хотя, я сомневаюсь, что на, скажем, чистом скл можно сделать меньше кода... )))