Changeset 491


Ignore:
Timestamp:
08/08/2010 03:42:53 AM (18 months ago)
Author:
ofer
Message:

Add the option in the transposh interface to remove automated translations that are older then 2 weeks (or all of them)

Location:
trunk/WordPress/plugin/transposh
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/js/transposhcontrol.js

    r387 r491  
    121121    }); 
    122122 
     123    jQuery.ajaxSetup({ 
     124        cache: false 
     125    }); 
     126 
    123127    // backup button 
    124128    backupclick = function () { 
    125         jQuery("#transposh-backup").click(function(){ 
     129        jQuery("#transposh-backup").unbind('click').click(function(){ 
    126130            return false 
    127             }).text("Backup In Progress"); 
    128         jQuery.get(t_jp.post_url + "?backup=" + Math.random(),function(data) { 
     131        }).text("Backup In Progress"); 
     132        jQuery.get(t_jp.post_url + "?backup",function(data) { 
    129133            var color = 'red'; 
    130134            if (data[0] == '2') color = 'green'; 
    131135            jQuery('#backup_result').html(data).css('color',color); 
    132             jQuery("#transposh-backup").click(backupclick).text("Do Backup Now"); 
     136            jQuery("#transposh-backup").unbind('click').click(backupclick).text("Do Backup Now"); 
    133137        }); 
    134138        return false; 
    135139    }; 
    136140    jQuery("#transposh-backup").click(backupclick); 
     141 
     142    // cleanup button 
     143    cleanautoclick = function (days,button) { 
     144        if (!confirm("Are you sure you want to do this?")) return false; 
     145        if (days == 0 && !confirm("Are you REALLY sure you want to do this?")) return false; 
     146        //var button = jQuery(this); 
     147        console.log(button); 
     148        var prevtext = button.text(); 
     149        button.unbind('click').click(function(){ 
     150            return false 
     151        }).text("Cleanup in progress"); 
     152        jQuery.get(t_jp.post_url + "?nonce="+button.attr('nonce')+"&days="+days+"&cleanup",function(data) { 
     153            button.unbind('click').click(function() { 
     154                cleanautoclick(days,button); 
     155                return false; 
     156            }).text(prevtext); 
     157        }); 
     158        return false; 
     159    }; 
     160    jQuery("#transposh-clean-auto").click(function() { 
     161        cleanautoclick(0,jQuery(this)); 
     162        return false; 
     163    }); 
     164    jQuery("#transposh-clean-auto14").click(function() { 
     165        cleanautoclick(14,jQuery(this)); 
     166        return false; 
     167    }); 
    137168 
    138169    // translate all button 
     
    181212        }); 
    182213        jQuery("#transposh-translate").text("Stop translate") 
    183         jQuery("#transposh-translate").click(stop_translate); 
     214        jQuery("#transposh-translate").unbind('click').click(stop_translate); 
    184215        return false; 
    185216    } 
     
    189220        stop_translate_var = true; 
    190221        jQuery("#transposh-translate").text("Translate All Now") 
    191         jQuery("#transposh-translate").click(do_translate_all); 
     222        jQuery("#transposh-translate").unbind('click').click(do_translate_all); 
    192223        return false; 
    193224    } 
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r488 r491  
    202202        add_meta_box('transposh-contentbox-autotranslation', 'Automatic translation settings', array(&$this, 'on_contentbox_auto_translation_content'), $this->pagehook, 'normal', 'core'); 
    203203        add_meta_box('transposh-contentbox-general', 'Generic settings', array(&$this, 'on_contentbox_generic_content'), $this->pagehook, 'normal', 'core'); 
     204        add_meta_box('transposh-contentbox-database', 'Database maintenance', array(&$this, 'on_contentbox_database_content'), $this->pagehook, 'normal', 'core'); 
    204205    } 
    205206 
     
    535536    } 
    536537 
     538    function on_contentbox_database_content($data) { 
     539        /* 
     540         * Insert two buttons allowing removal of automated translations from database 
     541         */ 
     542        echo '<div style="margin:10px 0"><a id="transposh-clean-auto" href="#" nonce="'.  wp_create_nonce('transposh-clean').'" class="button">Clean all automated translations</a></div>'; 
     543        echo '<div style="margin:10px 0"><a id="transposh-clean-auto14" href="#" nonce="'.  wp_create_nonce('transposh-clean').'" class="button">Clean automated translations older than 14 days</a></div>'; 
     544    } 
     545 
    537546    function on_contentbox_community_content($data) { 
    538547        echo '<h4>Backup service for human translation</h4>'; 
  • trunk/WordPress/plugin/transposh/wp/transposh_ajax.php

    r488 r491  
    101101    $my_transposh_plugin->run_backup(); 
    102102} 
     103// Start cleanup on demand 
     104elseif (isset($_GET['cleanup'])) { 
     105    // just make sure the admin started this... recently enough 
     106    check_ajax_referer('transposh-clean','nonce'); 
     107    $my_transposh_plugin->database->cleanup($_GET['days']); 
     108} 
     109 
    103110?> 
  • trunk/WordPress/plugin/transposh/wp/transposh_db.php

    r488 r491  
    488488    } 
    489489 
     490    /** 
     491     * Provides some stats about our database 
     492     */ 
    490493    function db_stats() { 
    491494        echo "<h4>Database stats</h4>"; 
     
    558561    } 
    559562 
     563    /** 
     564     * This function removes translations and translation logs from the database, only 
     565     * when the last translation is automated 
     566     * @param int $days 
     567     */ 
     568    function cleanup($days = 0) { 
     569        $days = intval($days); // some security 
     570        $cleanup = 'DELETE ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . ' ,' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG . 
     571                ' FROM ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . 
     572                ' INNER JOIN '. $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG. 
     573                ' ON '.$GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE .'.original = '.$GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG .'.original'. 
     574                ' AND '.$GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE .'.lang = '.$GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG .'.lang'. 
     575                ' WHERE '. $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE.'.source > 0'. 
     576                " AND timestamp < SUBDATE(NOW(),$days)"; 
     577        apc_clear_cache('user'); // clean up cache so that results will actually show 
     578        $result = $GLOBALS['wpdb']->query($cleanup); 
     579        exit; 
     580    } 
     581 
    560582} 
    561583?> 
Note: See TracChangeset for help on using the changeset viewer.