diff --git a/app/Config/version.php b/app/Config/version.php index 1826ac93a..cec29ae88 100644 --- a/app/Config/version.php +++ b/app/Config/version.php @@ -1,4 +1,4 @@ */ - $categories = $this->Category->getCategoriesSelectForAccession(0); + $categories = $this->CurrentUser->Categories->getAllowed('list'); unset($categories[$id]); $this->set('targetCategory', $categories); diff --git a/app/Controller/EntriesController.php b/app/Controller/EntriesController.php index efd71af37..2db382364 100644 --- a/app/Controller/EntriesController.php +++ b/app/Controller/EntriesController.php @@ -819,35 +819,37 @@ protected function _setNotifications($newEntry) { } } -/** - * Gets the thread ids of all threads which should be visisble on the an - * entries/index/# page. - * - * @param CurrentUserComponent $User - * @return array - */ + /** + * Gets thread ids for paginated entries/index. + * + * @param CurrentUserComponent $User + * @param array $order sort order + * @return array thread ids + */ protected function _getInitialThreads(CurrentUserComponent $User, $order) { Stopwatch::start('Entries->_getInitialThreads() Paginate'); $categories = $this->_setupCategoryChooser($User); - $this->paginate = array( - /* Whenever you change the conditions here check if you have to adjust - * the db index. Running this query without appropriate db index is a huge - * performance bottleneck! - */ - 'conditions' => array( - 'pid' => 0, - 'Entry.category' => $categories - ), + //! Check DB performance after changing conditions/sorting! + $this->paginate = [ + 'conditions' => [ + 'pid' => 0, + 'Entry.category' => $categories + ], 'contain' => false, 'fields' => 'id, pid, tid, time, last_answer, fixed', 'limit' => Configure::read('Saito.Settings.topics_per_page'), 'order' => $order, 'getInitialThreads' => 1, - ); + ]; - $initialThreads = $this->paginate(); + // disallows overwriting pagination params from request + unset( + $this->request->params['named']['direction'], + $this->request->params['named']['sort'] + ); + $initialThreads = $this->paginate(null, null, array_keys($order)); $initialThreadsNew = []; foreach ($initialThreads as $k => $v) { diff --git a/app/Controller/SearchesController.php b/app/Controller/SearchesController.php index 164cd498b..bb50407c6 100644 --- a/app/Controller/SearchesController.php +++ b/app/Controller/SearchesController.php @@ -156,7 +156,12 @@ public function advanced() { ->Categories->getAllowed(); } $this->Paginator->settings = $settings; - $this->set('results', $this->Paginator->paginate()); + unset( + $this->request->query['direction'], + $this->request->query['sort'] + ); + $this->set('results', + $this->Paginator->paginate(null, null, ['Entry.time'])); } if (!isset($query['category'])) { diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php index ad274ff98..5cb17aed9 100644 --- a/app/Controller/UsersController.php +++ b/app/Controller/UsersController.php @@ -177,17 +177,25 @@ public function admin_index() { } public function index() { + $menuItems = [ + 'username' => [__('username_marking'), []], + 'user_type' => [__('user_type'), []], + 'UserOnline.logged_in' => [__('userlist_online'), ['direction' => 'desc']], + 'registered' => [__('registered'), ['direction' => 'desc']] + ]; + $showBlocked = Configure::read('Saito.Settings.block_user_ui'); + if ($showBlocked) { + $menuItems['user_lock'] = [__('user.set.lock.t'), ['direction' => 'desc']]; + } + $this->paginate = [ 'contain' => 'UserOnline', 'limit' => 400, - 'order' => [ - 'UserOnline.logged_in' => 'asc', - 'User.username' => 'asc' - ] + 'order' => ['UserOnline.logged_in' => 'desc', 'User.username' => 'asc'] ]; + $users = $this->paginate('User', null, array_keys($menuItems)); - $data = $this->paginate('User'); - $this->set('users', $data); + $this->set(compact('menuItems', 'users')); } public function ignore($blockedId) { diff --git a/app/Lib/Cache/CacheSupport.php b/app/Lib/Cache/CacheSupport.php index 0c9533359..879326d4d 100644 --- a/app/Lib/Cache/CacheSupport.php +++ b/app/Lib/Cache/CacheSupport.php @@ -20,7 +20,7 @@ public function __construct() { foreach ($this->_buildInCaches as $_name) { $this->add(new $_name); } - CakeEventManager::instance()->instance($this); + CakeEventManager::instance()->attach($this); } public function implementedEvents() { @@ -57,7 +57,9 @@ public function clear($cache = null, $id = null) { $_Cache->clear(); } } else { - $this->_Caches[$cache]->clear($id); + if (isset($this->_Caches[$cache])) { + $this->_Caches[$cache]->clear($id); + } } } @@ -83,6 +85,9 @@ public function getId(); abstract class CacheSupportCachelet implements CacheSupportCacheletInterface { public function getId() { + if (!empty($this->_title)) { + return $this->_title; + } return str_replace('CacheSupportCachelet', '', get_class($this)); } @@ -90,8 +95,6 @@ public function getId() { class SaitoCacheSupportCachelet extends CacheSupportCachelet { - protected $_title = 'Saito'; - public function clear($id = null) { Cache::clear(false, 'default'); Cache::clear(false, 'short'); @@ -101,8 +104,6 @@ public function clear($id = null) { class ApcCacheSupportCachelet extends CacheSupportCachelet { - protected $_title = 'Apc'; - public function clear($id = null) { if (function_exists('apc_store')) { apc_clear_cache(); @@ -115,8 +116,6 @@ public function clear($id = null) { class OpCacheSupportCachelet extends CacheSupportCachelet { - protected $_title = 'OpCache'; - public function clear($id = null) { if (function_exists('opcache_reset')) { opcache_reset(); diff --git a/app/Lib/Model/AppSettingModel.php b/app/Lib/Model/AppSettingModel.php index 0605de334..123501a3f 100644 --- a/app/Lib/Model/AppSettingModel.php +++ b/app/Lib/Model/AppSettingModel.php @@ -2,14 +2,18 @@ class AppSettingModel extends AppModel { + /** + * afterSave callback + * + * @param bool $created + * @param array $options + * - 'clearCache' set to 'false' to prevent cache clearing + */ public function afterSave($created, $options = []) { parent::afterSave($created, $options); - if (isset($options['clearCache'])) { - if ($options['clearCache'] === false) { - return; - } + if (!isset($options['clearCache']) || $options['clearCache'] !== false) { + $this->clearCache(); } - $this->clearCache(); } public function afterDelete() { diff --git a/app/Locale/deu/LC_MESSAGES/default.po b/app/Locale/deu/LC_MESSAGES/default.po index b58bfc992..33ec4a0e1 100644 --- a/app/Locale/deu/LC_MESSAGES/default.po +++ b/app/Locale/deu/LC_MESSAGES/default.po @@ -1244,7 +1244,7 @@ msgstr "Der Zugriff auf diese Funktion ist eingeschränkt!" #: Controller/Component/EmailNotificationComponent.php:48 #, php-format msgid "New reply to \"%s\"" -msgstr "Neu Antwort zu \"%s\"" +msgstr "Neue Antwort zu \"%s\"" #: Controller/Component/EmailNotificationComponent.php:82 msgid "Successfull registration" diff --git a/app/Model/Category.php b/app/Model/Category.php index e17eefad2..6e7bea2d6 100755 --- a/app/Model/Category.php +++ b/app/Model/Category.php @@ -100,9 +100,7 @@ public function updateThreadCounter() { public function afterSave($created, $options = array()) { // don't empty cache if it's only a thread count update - if (isset($this->data[$this->alias]['thread_count']) || - !isset($this->data[$this->alias]['category']) - ) { + if (!$created && !isset($this->data[$this->alias]['category'])) { $options['clearCache'] = false; } parent::afterSave($created, $options); diff --git a/app/Test/Case/Controller/EntriesControllerTest.php b/app/Test/Case/Controller/EntriesControllerTest.php index 6c10397f0..b856840d4 100755 --- a/app/Test/Case/Controller/EntriesControllerTest.php +++ b/app/Test/Case/Controller/EntriesControllerTest.php @@ -10,7 +10,7 @@ class EntriesMockController extends EntriesController { public $uses = array('Entry'); // @codingStandardsIgnoreEnd - public function getInitialThreads($User, $order = 'Entry.last_answer DESC') { + public function getInitialThreads($User, $order = ['Entry.last_answer' => 'DESC']) { $this->_getInitialThreads($User, $order); } diff --git a/app/View/Helper/EntryHHelper.php b/app/View/Helper/EntryHHelper.php index 43c5e6511..1a3cdc01a 100755 --- a/app/View/Helper/EntryHHelper.php +++ b/app/View/Helper/EntryHHelper.php @@ -188,14 +188,18 @@ public function categorySelect($entry, $categories) { * Everything you do in here is in worst case done a few hundred times on * the frontpage. Think about (and benchmark) performance before you change it. */ - public function threadCached(array $entrySub, ForumsUserInterface $CurrentUser, $level = 0, array $currentEntry = [], $lastAnswer = null) { + public function threadCached(array $entrySub, ForumsUserInterface $CurrentUser, $level = 0, array $currentEntry = [], $lastAnswer = null, $options = []) { + $options = $options + ['ignore' => null]; $id = (int)$entrySub['Entry']['id']; $out = ''; if ($lastAnswer === null) { $lastAnswer = $entrySub['Entry']['last_answer']; } - if (!$CurrentUser->ignores($entrySub['Entry']['user_id'])) { + if ($options['ignore'] === null) { + $options['ignore'] = $CurrentUser->ignores($entrySub['Entry']['user_id']); + } + if (!$options['ignore']) { $useLineCache = $level > 0; if ($useLineCache) { $_threadLineCached = $this->_LineCache->get($id); @@ -251,8 +255,9 @@ class='link_show_thread {$id} et threadLine-content'> if (isset($entrySub['_children'])) { $subLevel = $level + 1; $sub = ''; + unset($options['ignore']); foreach ($entrySub['_children'] as $child) { - $sub .= $this->threadCached($child, $CurrentUser, $subLevel, $currentEntry, $lastAnswer); + $sub .= $this->threadCached($child, $CurrentUser, $subLevel, $currentEntry, $lastAnswer, $options); } $out .= '