/** * Purge urls from database (and cache) * either all automatic, or according to current * sef url list page select options as stored in * in session * @param unknown_type $type */ public function purge($type = 'auto') { // make sure we use latest user state $this->_updateContextData(); // call the appropriate sub-method to get the db query $methodName = '_getPurgeQuery' . ucfirst($type); if (is_callable(array($this, $methodName))) { $deleteQuery = $this->{$methodName}(); } else { $this->setError('Invalid method call _purge' . $type); return; } try { // then run the query $this->_db->setQuery($deleteQuery); $this->_db->shlExecute(); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $this->setError($e->getMessage()); } // delete from cache : we delete the whole cache anyway, except for 404 pages // which are not in the cache if ($type != '404') { Sh404sefHelperCache::purge(); } // reset limit and limitstart variables, to avoid // issue when displaying again results $this->_setState('limitstart', 0); $this->_setState('limit', 0); // reprocess custom urls, checking there is still at least one per group // of identical SEF url with a rank = 0 // as the "main" url for this group was possibly deleted during the purge $query = 'select ?? from (select * from ?? where ?? <> ? order by ?? asc) as tmp_table group by ??'; $nameQuoted = array('id', '#__sh404sef_urls', 'dateadd', 'rank', 'oldurl'); $quoted = array('0000-00-00'); try { // select custom with lowest rank $customs = ShlDbHelper::quoteQuery($query, $nameQuoted, $quoted)->shlLoadColumn(); // make sure there is at least one of those with rank = 0 if (!empty($customs)) { ShlDbHelper::updateIn('#__sh404sef_urls', array('rank' => 0), 'id', $customs); } } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $this->setError('Internal database error # ' . $e->getMessage()); } }
/** * Redirect to a confirmation page showing in * a popup window */ private function _doConfirmPurge($type = 'auto') { // Set the view name and create the view object $viewName = 'confirm'; $document =& JFactory::getDocument(); $viewType = $document->getType(); $viewLayout = JRequest::getCmd('layout', $this->_defaultLayout); $view =& $this->getView($viewName, $viewType, '', array('base_path' => $this->_basePath)); // and who's gonna handle the request $view->assign('actionController', $this->_defaultController); // Get/Create the model if ($model =& $this->getModel($this->_defaultModel, 'Sh404sefModel')) { // store context of the main url view in the model $model->setContext('com_sh404sef.urls.urls.default'); // Push the model into the view (as default) $view->setModel($model, true); } // tell it what to display // we only purge automatic sef urls, count that $numberOfUrls = $model->getUrlsCount($type); // if nothing to do, say so and return to main page if (empty($numberOfUrls)) { // don't forget to delete url cache, just in case Sh404sefHelperCache::purge(); // then do redirect $view->assign('redirectTo', $this->_getDefaultRedirect()); $view->assign('message', JText16::_('COM_SH404SEF_NORECORDS')); } else { // calculate the message and some hidden data to be passed // through the confirmation box switch ($type) { case 'selected': $mainText = JText16::sprintf('COM_SH404SEF_CONFIRM_PURGE_URLS_SELECTED', $numberOfUrls); break; case '404': $mainText = JText16::sprintf('COM_SH404SEF_CONFIRM_PURGE_URLS_404', $numberOfUrls); break; case 'auto': $mainText = JText16::sprintf('COM_SH404SEF_CONFIRM_PURGE_URLS', $numberOfUrls); default: break; } $hiddenText = '<input type="hidden" name="delete_type" value="' . $type . '" />'; // push that into the view $view->assign('mainText', $mainText); $view->assign('hiddenText', $hiddenText); } // Set the layout $view->setLayout($viewLayout); // Display the view $view->display(); }