コード例 #1
0
ファイル: urls.php プロジェクト: alesconti/FF_2015
 /**
  * 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());
     }
 }
コード例 #2
0
ファイル: sh404sef.class.php プロジェクト: alesconti/FF_2015
function shAddSefUrlToDBAndCache($nonSefUrl, $sefString, $rank, $urlType)
{
    $db = ShlDbHelper::getDb();
    $sefString = JString::ltrim($sefString, '/');
    // V 1.2.4.t just in case you forgot to remove leading slash
    switch ($urlType) {
        case sh404SEF_URLTYPE_AUTO:
            $dateAdd = '0000-00-00';
            break;
        case sh404SEF_URLTYPE_CUSTOM:
            $dateAdd = date("Y-m-d");
            break;
        case sh404SEF_URLTYPE_NONE:
            return null;
            break;
    }
    try {
        $query = '';
        if ($urlType == sh404SEF_URLTYPE_AUTO) {
            $result = ShlDbHelper::quoteQuery('select ??, ?? from ?? where ?? = ? and (?? = ? or ?? = ?)', array('id', 'newurl', '#__sh404sef_urls', 'oldurl', 'newurl', 'newurl'), array($sefString, '', addslashes(urldecode($nonSefUrl))))->shlLoadObject();
            if (!empty($result)) {
                // sef urls was found either as a 404 or as already existing, with also the same non-sef
                if ($result->newurl == $nonSefUrl) {
                    // url already in db, nothing to do
                    ShlSystem_Log::debug('sh404sef', 'url already in db, nothing to do');
                    return true;
                }
                ShlDbHelper::update('#__sh404sef_urls', array('newurl' => addslashes(urldecode($nonSefUrl)), 'rank' => $rank, 'dateadd' => $dateAdd), array('oldurl' => $sefString));
            } else {
                // another option: sef exists, but with another non-sef: that's a duplicate
                // need to check that
                $result = ShlDbHelper::selectObject('#__sh404sef_urls', array('id', 'newurl', 'rank'), $db->quoteName('oldurl') . ' = ? and ' . $db->quoteName('newurl') . ' <> ?', array($sefString, addslashes(urldecode($nonSefUrl))), array('rank' => 'desc'));
                if (!empty($result)) {
                    // we found at least one identical SEF url, with another non-sef. Mark the new one as duplicate of the old one
                    $rank = $result->rank + 1;
                }
                ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $sefString, 'newurl' => $nonSefUrl, 'rank' => $rank, 'dateadd' => $dateAdd));
            }
        }
        // store new sef/non-sef pair in memory cache
        Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $sefString, $urlType);
        // create shURL : get a shURL model, and ask url creation
        $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel');
        $model->createPageId($sefString, $nonSefUrl);
    } catch (Exception $e) {
        ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
    }
}