update_option(OPTION_NAME_SCHEDULE, 'true');
     wpo_cron_deactivate();
     /* if (!wp_next_scheduled('wpo_cron_event2')) {
     				wp_schedule_event(time(), 'wpo_weekly', 'wpo_cron_event2');
     				add_filter('cron_schedules', 'wpo_cron_update_sched');
     				
     			}	 */
     if (isset($_POST["schedule_type"])) {
         $schedule_type = $_POST['schedule_type'];
         update_option(OPTION_NAME_SCHEDULE_TYPE, $schedule_type);
     } else {
         update_option(OPTION_NAME_SCHEDULE_TYPE, 'wpo_weekly');
     }
     wpo_cron_activate();
     add_action('wpo_cron_event2', 'wpo_cron_action');
     wpo_debugLog('We are at setting page form submission and reached wpo_cron_activate()');
 } else {
     update_option(OPTION_NAME_SCHEDULE, 'false');
     update_option(OPTION_NAME_SCHEDULE_TYPE, 'wpo_weekly');
     wpo_cron_deactivate();
 }
 if (isset($_POST["enable-retention"])) {
     $retention_period = $_POST['retention-period'];
     update_option(OPTION_NAME_RETENTION_ENABLED, 'true');
     update_option(OPTION_NAME_RETENTION_PERIOD, $retention_period);
 } else {
     update_option(OPTION_NAME_RETENTION_ENABLED, 'false');
 }
 if (isset($_POST["enable-admin-bar"])) {
     update_option(OPTION_NAME_ENABLE_ADMIN_MENU, 'true');
 } else {
function optimizeTablesQuick($Optimize)
{
    global $wpdb;
    $total_gain = 0;
    $row_usage = 0;
    $data_usage = 0;
    $index_usage = 0;
    $overhead_usage = 0;
    $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
    foreach ($tablesstatus as $tablestatus) {
        $row_usage += $tablestatus->Rows;
        $data_usage += $tablestatus->Data_length;
        $index_usage += $tablestatus->Index_length;
        if ($tablestatus->Engine != 'InnoDB') {
            $overhead_usage += $tablestatus->Data_free;
            $total_gain += $tablestatus->Data_free;
        }
    }
    if ($Optimize == "yes") {
        //if ($tablestatus->Engine != 'InnoDB'){
        $tables = $wpdb->get_col("SHOW TABLES");
        foreach ($tables as $table_name) {
            $local_query = 'OPTIMIZE TABLE `' . $table_name . '`';
            wpo_debugLog('optimizing .... ' . $table_name);
            $result_query = $wpdb->query($local_query);
        }
        //end for
        wpo_updateTotalCleaned(strval($total_gain));
        // #TODO for testing only
        // $thistime = current_time( "timestamp", 0 );
        // $thedate = gmdate(get_option('date_format') . ' ' . get_option('time_format'), $thistime );
        // list($part3, $part4) = wpo_getCurrentDBSize();
        // wpo_sendEmail($thedate, strval($part4)); //TODO TEMPORARY - send email to admin
        // wpo_debugLog('Invoked+ Updating options with value +'.$part4);
        wpo_debugLog('Total Gain .... ' . strval($total_gain));
    }
    //end if
    //
    // clear up total gain values
    $total_gain = 0;
}
Example #3
0
function wpo_getCurrentDBSize()
{
    global $wpdb;
    $total_gain = 0;
    $total_size = 0;
    $no = 0;
    $row_usage = 0;
    $data_usage = 0;
    $index_usage = 0;
    $overhead_usage = 0;
    $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
    wpo_debugLog('Checking DB size .... ');
    foreach ($tablesstatus as $tablestatus) {
        $row_usage += $tablestatus->Rows;
        $data_usage += $tablestatus->Data_length;
        $index_usage += $tablestatus->Index_length;
        if ($tablestatus->Engine != 'InnoDB') {
            $overhead_usage += $tablestatus->Data_free;
            $total_gain += $tablestatus->Data_free;
        }
    }
    $total_size = $data_usage + $index_usage;
    wpo_debugLog('Total Size .... ' . $total_size);
    wpo_debugLog('Total Gain .... ' . $total_gain);
    return array(wpo_format_size($total_size), wpo_format_size($total_gain));
    //$wpdb->flush();
}
Example #4
0
function wpo_cron_deactivate()
{
    //wp_clear_scheduled_hook('wpo_cron_event');
    wpo_debugLog('running wpo_cron_deactivate()');
    wp_clear_scheduled_hook('wpo_cron_event2');
}
Example #5
0
function optimizeTablesQuick($Optimize)
{
    global $wpdb;
    $total_gain = 0;
    $row_usage = 0;
    $data_usage = 0;
    $index_usage = 0;
    $overhead_usage = 0;
    $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
    foreach ($tablesstatus as $tablestatus) {
        $row_usage += $tablestatus->Rows;
        $data_usage += $tablestatus->Data_length;
        $index_usage += $tablestatus->Index_length;
        if ($tablestatus->Engine != 'InnoDB') {
            $overhead_usage += $tablestatus->Data_free;
            $total_gain += $tablestatus->Data_free;
        }
    }
    if ($Optimize == "yes") {
        //if ($tablestatus->Engine != 'InnoDB'){
        $tables = $wpdb->get_col("SHOW TABLES");
        foreach ($tables as $table_name) {
            $local_query = 'OPTIMIZE TABLE `' . $table_name . '`';
            wpo_debugLog('optimizing .... ' . $table_name);
            $result_query = $wpdb->query($local_query);
        }
        //end for
        wpo_updateTotalCleaned(strval($total_gain));
        wpo_debugLog('Total Gain .... ' . strval($total_gain));
    }
    //end if
    //
    // clear up total gain values
    $total_gain = 0;
}
function wpo_cron_action()
{
    global $wpdb;
    list($retention_enabled, $retention_period) = wpo_getRetainInfo();
    wpo_debugLog('Starting wpo_cron_action()');
    if (get_option(OPTION_NAME_SCHEDULE) == 'true') {
        $this_options = get_option('wp-optimize-auto');
        // revisions
        if ($this_options['revisions'] == 'true') {
            $clean = "DELETE FROM {$wpdb->posts} WHERE post_type = 'revision'";
            if ($retention_enabled == 'true') {
                $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $revisions = $wpdb->query($clean);
        }
        // auto drafts
        if ($this_options['drafts'] == 'true') {
            $clean = "DELETE FROM {$wpdb->posts} WHERE post_status = 'auto-draft'";
            if ($retention_enabled == 'true') {
                $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $autodraft = $wpdb->query($clean);
            // trash posts
            // TODO:  query trashed posts and cleanup metadata
            $clean = "DELETE FROM {$wpdb->posts} WHERE post_status = 'trash'";
            if ($retention_enabled == 'true') {
                $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $posttrash = $wpdb->query($clean);
        }
        // spam comments
        if ($this_options['spams'] == 'true') {
            $clean = "DELETE FROM {$wpdb->comments} WHERE comment_approved = 'spam'";
            if ($retention_enabled == 'true') {
                $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $comments = $wpdb->query($clean);
            // trashed comments
            // TODO:  query trashed comments and cleanup metadata
            $clean = "DELETE FROM {$wpdb->comments} WHERE comment_approved = 'trash'";
            if ($retention_enabled == 'true') {
                $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $commentstrash = $wpdb->query($clean);
            // TODO:  still need to test now cleaning up comments meta tables
            //                $clean = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM $wpdb->comments )";
            //                $clean .= ';';
            //                $commentstrash1 = $wpdb->query( $clean );
            // TODO:  still need to test now cleaning up comments meta tables - removing akismet related settings
            //                $clean = "DELETE FROM $wpdb->commentmeta WHERE meta_key LIKE '%akismet%'";
            //                $clean .= ';';
            //                $commentstrash2 = $wpdb->query( $clean );
        }
        // transient options
        if ($this_options['transient'] == 'true') {
            $clean = "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_%' OR option_name LIKE '_site_transient_%'";
            $clean .= ';';
            $transient_options = $wpdb->query($clean);
        }
        // postmeta
        // TODO:  refactor this with proper query
        if ($this_options['postmeta'] == 'true') {
            $clean = "DELETE pm FROM  {$wpdb->postmeta}  pm LEFT JOIN  {$wpdb->posts}  wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
            $clean .= ';';
            //$postmeta = $wpdb->query( $clean );
        }
        // unused tags
        if ($this_options['tags'] == 'true') {
            //$clean = "DELETE t,tt FROM  $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON t.term_id=tt.term_id WHERE tt.taxonomy='post_tag' AND tt.count=0";
            //$clean .= ';';
            //$tags = $wpdb->query( $clean );
        }
        //db optimize part - optimize
        // disble optimization if innoDB
        if (WPO_TABLE_TYPE != 'innodb') {
            if ($this_options['optimize'] == 'true') {
                $db_tables = $wpdb->get_results('SHOW TABLES', ARRAY_A);
                foreach ($db_tables as $table) {
                    $t = array_values($table);
                    $wpdb->query("OPTIMIZE TABLE " . $t[0]);
                    wpo_debugLog('optimizing .... ' . $t[0]);
                }
                //$dateformat = __('l jS \of F Y h:i:s A');
                $dateformat = 'l jS \\of F Y h:i:s A';
                $thisdate = date($dateformat);
                list($part1, $part2) = wpo_getCurrentDBSize();
                update_option(OPTION_NAME_LAST_OPT, $thisdate);
                wpo_updateTotalCleaned(strval($part2));
                wpo_debugLog('Updating options with value +' . $part2);
            }
            // endif $this_options['optimize']
        }
        //end if if (WPO_TABLE_TYPE != 'innodb'){
    }
    // end if ( get_option(OPTION_NAME_SCHEDULE) == 'true')
}
function wpo_cron_action()
{
    global $wpdb;
    list($retention_enabled, $retention_period) = wpo_getRetainInfo();
    wpo_debugLog('Starting wpo_cron_action()');
    if (get_option(OPTION_NAME_SCHEDULE) == 'true') {
        $this_options = get_option('wp-optimize-auto');
        // revisions
        if ($this_options['revisions'] == 'true') {
            $clean = "DELETE FROM {$wpdb->posts} WHERE post_type = 'revision'";
            if ($retention_enabled == 'true') {
                $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $revisions = $wpdb->query($clean);
        }
        // auto drafts
        if ($this_options['drafts'] == 'true') {
            $clean = "DELETE FROM {$wpdb->posts} WHERE post_status = 'auto-draft'";
            if ($retention_enabled == 'true') {
                $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $autodraft = $wpdb->query($clean);
            // trash posts
            $clean = "DELETE FROM {$wpdb->posts} WHERE post_status = 'trash'";
            if ($retention_enabled == 'true') {
                $clean .= ' and post_modified < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $posttrash = $wpdb->query($clean);
        }
        // spam comments
        if ($this_options['spams'] == 'true') {
            $clean = "DELETE FROM {$wpdb->comments} WHERE comment_approved = 'spam'";
            if ($retention_enabled == 'true') {
                $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $comments = $wpdb->query($clean);
            // trashed comments
            $clean = "DELETE FROM {$wpdb->comments} WHERE comment_approved = 'post-trashed'";
            if ($retention_enabled == 'true') {
                $clean .= ' and comment_date < NOW() - INTERVAL ' . $retention_period . ' WEEK';
            }
            $clean .= ';';
            $commentstrash = $wpdb->query($clean);
        }
        // transient options
        if ($this_options['transient'] == 'true') {
            $clean = "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_%' OR option_name LIKE '_site_transient_%'";
            $clean .= ';';
            $transient_options = $wpdb->query($clean);
        }
        // postmeta
        if ($this_options['postmeta'] == 'true') {
            $clean = "DELETE pm FROM  {$wpdb->postmeta}  pm LEFT JOIN  {$wpdb->posts}  wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
            $clean .= ';';
            $postmeta = $wpdb->query($clean);
        }
        // unused tags
        if ($this_options['tags'] == 'true') {
            $clean = "DELETE t,tt FROM  {$wpdb->terms} t INNER JOIN {$wpdb->term_taxonomy} tt ON t.term_id=tt.term_id WHERE tt.taxonomy='post_tag' AND tt.count=0";
            $clean .= ';';
            $tags = $wpdb->query($clean);
        }
        //db optimize part - optimize
        if ($this_options['optimize'] == 'true') {
            $db_tables = $wpdb->get_results('SHOW TABLES', ARRAY_A);
            foreach ($db_tables as $table) {
                $t = array_values($table);
                $wpdb->query("OPTIMIZE TABLE " . $t[0]);
                wpo_debugLog('optimizing .... ' . $t[0]);
            }
            //$dateformat = __('l jS \of F Y h:i:s A');
            $dateformat = 'l jS \\of F Y h:i:s A';
            $thisdate = date($dateformat);
            list($part1, $part2) = wpo_getCurrentDBSize();
            update_option(OPTION_NAME_LAST_OPT, $thisdate);
            wpo_updateTotalCleaned($part2);
            wpo_debugLog('Updating options with value +' . $part2);
        }
        // endif $this_options['optimize']
    }
}