public function save() { $db = JFactory::getDBO(); // Perform custom validation of config data before we write it. $this->check(); // Get current configuration $params = $this->getProperties(); unset($params['id']); $db->setQuery("REPLACE INTO #__kunena_configuration SET id=1, params={$db->quote(json_encode($params))}"); $db->query(); KunenaError::checkDatabaseError(); // Clear cache. KunenaCacheHelper::clear(); }
/** * @see KunenaDatabaseObject::saveInternal() */ protected function saveInternal() { // Reorder categories $table = $this->getTable(); $table->bind($this->getProperties()); $table->exists($this->_exists); // Update alias $success = $this->addAlias($this->get('alias')); if ($success) { $this->_alias = $this->alias; } // TODO: remove this hack... if (!isset($this->_noreorder)) { $table->reorder(); $this->ordering = $table->ordering; unset($this->_noreorder); } // Clear cache $access = KunenaAccess::getInstance(); $access->clearCache(); KunenaCacheHelper::clear(); return true; }
/** * @param string|array $categories * * @return boolean|integer */ public static function recount($categories = '') { $db = JFactory::getDBO(); if (is_array($categories)) { $categories = implode(',', $categories); } $categories = !empty($categories) ? "AND t.category_id IN ({$categories})" : ''; // Update category post count and last post info on categories which have published topics $query = "UPDATE #__kunena_categories AS c\n\t\t\tINNER JOIN (\n\t\t\t\t\tSELECT t.category_id AS id, COUNT( * ) AS numTopics, SUM( t.posts ) AS numPosts, t2.id as last_topic_id\n\t\t\t\t\tFROM #__kunena_topics AS t INNER JOIN (SELECT t.id, t.category_id, t.last_post_time\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM #__kunena_topics AS t,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(SELECT category_id , max(last_post_time) as last_post_time\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `#__kunena_topics`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE hold =0\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND moved_id =0\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tGROUP BY category_id) AS temp\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE temp.last_post_time = t.last_post_time\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$categories}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND t.category_id=temp.category_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) AS t2 ON t2.category_id=t.category_id\n\t\t\t\t\tWHERE t.hold =0\n\t\t\t\t\tAND t.moved_id =0\n\t\t\t\t\t{$categories}\n\t\t\t\t\tGROUP BY t.category_id\n\t\t\t) AS r ON r.id=c.id\n\t\t\tINNER JOIN #__kunena_topics AS tt ON tt.id=r.last_topic_id\n\t\t\tSET c.numTopics = r.numTopics,\n\t\t\t\tc.numPosts = r.numPosts,\n\t\t\t\tc.last_topic_id=r.last_topic_id,\n\t\t\t\tc.last_post_id = tt.last_post_id,\n\t\t\t\tc.last_post_time = tt.last_post_time"; $db->setQuery($query); $db->execute(); if (KunenaError::checkDatabaseError()) { return false; } $rows = $db->getAffectedRows(); // Update categories which have no published topics $query = "UPDATE #__kunena_categories AS c\n\t\t\tLEFT JOIN #__kunena_topics AS tt ON c.id=tt.category_id AND tt.hold=0\n\t\t\tSET c.numTopics=0,\n\t\t\t\tc.numPosts=0,\n\t\t\t\tc.last_topic_id=0,\n\t\t\t\tc.last_post_id=0,\n\t\t\t\tc.last_post_time=0\n\t\t\tWHERE tt.id IS NULL"; $db->setQuery($query); $db->execute(); if (KunenaError::checkDatabaseError()) { return false; } $rows += $db->getAffectedRows(); if ($rows) { // If something changed, clean our cache KunenaCacheHelper::clearCategories(); } return $rows; }
/** * */ function uninstall() { $cid = $this->app->input->get('cid', array(), 'method', 'array'); $id = array_shift($cid); $template = $id; if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } // Initialize variables $otemplate = KunenaTemplateHelper::parseXmlFile($id); if (!$otemplate) { $this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_NOT_SPECIFIED'), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } if (in_array($id, $this->locked)) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CTRL_TEMPLATES_ERROR_UNINSTALL_SYSTEM_TEMPLATE', $otemplate->name), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } if (KunenaTemplateHelper::isDefault($template)) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CTRL_TEMPLATES_ERROR_UNINSTALL_DEFAULT_TEMPLATE', $otemplate->name), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $tpl = KPATH_SITE . '/template/' . $template; // Delete the template directory if (is_dir($tpl)) { $retval = KunenaFolder::delete($tpl); // Clear all cache, just in case. KunenaCacheHelper::clearAll(); $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_UNINSTALL_SUCCESS', $id)); } else { $this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE') . ' ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_UNINSTALL') . ': ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_DIR_NOT_EXIST')); $retval = false; } $this->setRedirect(KunenaRoute::_($this->baseurl, false)); }