Changeset 660 for trunk


Ignore:
Timestamp:
08/13/2011 02:20:09 AM (9 months ago)
Author:
ofer
Message:

Added remove duplication from translation to maint, and a killer bug when memcached is installed but the db was down

Location:
trunk/WordPress/plugin/transposh/wp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r657 r660  
    232232        } 
    233233 
    234         if (!(class_exists('Memcache') && @$this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT)) && !function_exists('apc_fetch') && !function_exists('xcache_get') && !function_exists('eaccelerator_get')) { 
     234        if (!(class_exists('Memcache') /*!!&& $this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT)*/) && !function_exists('apc_fetch') && !function_exists('xcache_get') && !function_exists('eaccelerator_get')) { 
    235235            $this->add_warning('tp_cache_warning', __('We were not able to find a supported in-memory caching engine, installing one can improve performance.', TRANSPOSH_TEXT_DOMAIN) . ' <a href="http://transposh.org/faq#performance">' . __('Check Transposh FAQs', TRANSPOSH_TEXT_DOMAIN) . '</a>'); 
    236236        } 
  • trunk/WordPress/plugin/transposh/wp/transposh_db.php

    r657 r660  
    5454 
    5555        if (class_exists('Memcache')) { 
    56             logger('I am using memcached!', 3); 
     56            logger('I am using pecl-Memcache!', 3); 
    5757            $this->memcache_working = true; 
    5858            $this->memcache = new Memcache; 
    5959            @$this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT) or $this->memcache_working = false; 
    60             logger($this->memcache_working); 
    61         } 
     60        } 
     61        // I have space in keys issues... 
     62        /* elseif (class_exists('Memcached')) { 
     63          logger('I am using pecl-Memcached!', 3); 
     64          $this->memcache_working = true; 
     65          $this->memcache = new Memcached(); 
     66          //if (!count($this->memcache->getServerList())) { 
     67          $this->memcache->addServer(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT); 
     68          // } 
     69          //@$this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT) or $this->memcache_working = false; 
     70          } */ 
     71        logger($this->memcache_working); 
    6272    } 
    6373 
     
    7484        if ($this->memcache_working) { 
    7585            $cached = $this->memcache->get($key); 
    76             logger('memcached', 5); 
     86            logger('memcached ' . $key . ' ' . $cached, 5); 
    7787        } elseif (function_exists('apc_fetch')) { 
    7888            $cached = apc_fetch($key, $rc); 
     
    790800            $this->cache_delete($row->original, $row->lang); 
    791801        } 
     802 
     803        // clean duplication in the translation table (don't know how it ever happened...) 
     804        $dedup = 'SELECT * , count( * )' . 
     805                ' FROM ' . $this->translation_table . 
     806                ' GROUP BY `original` , `lang`' . 
     807                ' HAVING count( * ) >1'; 
     808        $rows = $GLOBALS['wpdb']->get_results($dedup); 
     809        logger($dedup, 3); 
     810        foreach ($rows as $row) { 
     811            $row->original = $GLOBALS['wpdb']->escape($row->original); 
     812            $row->lang = $GLOBALS['wpdb']->escape($row->lang); 
     813            list($source, $tranlation) = $this->fetch_translation($row->original, $row->lang); 
     814            if ($source != NULL) { 
     815                $delvalues = "(original ='{$row->original}' AND lang='{$row->lang}'"; 
     816                $update = "DELETE FROM " . $this->translation_table . " WHERE $delvalues"; 
     817                logger($update, 3); 
     818                $result = $GLOBALS['wpdb']->query($update); 
     819            } 
     820            $row->translated = $GLOBALS['wpdb']->escape($translation); 
     821            $row->source = $GLOBALS['wpdb']->escape($source); 
     822            $values = "('{$row->original}','{$row->lang}','{$row->translated}','$row->source')"; 
     823            $update = "INSERT INTO " . $this->translation_table . " (original, lang, translated, source) VALUES $values"; 
     824            logger($update, 3); 
     825            $result = $GLOBALS['wpdb']->query($update); 
     826            $this->cache_delete($row->original, $row->lang); 
     827        } 
     828 
    792829        // check for discrepencies (last translation in log does not equal current translation) 
    793830        // TODO 
Note: See TracChangeset for help on using the changeset viewer.