function ausers_get_option($option) { // allows user reports to be run either at site level and/or at blog level global $ausersadminurl, $amr_nicenames; if (amr_is_network_admin()) { $result = get_site_option('network_' . $option); } else { $result = get_option($option); } if (empty($result)) { // it's new, get defaults //if ($option == 'amr-users-no-lists' ) return ameta_default_main(); // old - leave for upgrade check if ($option == 'amr-users-main') { // and it's empty //------------------------- //if (WP_DEBUG) echo '<br />Renaming stored option "amr-users-no-lists" to "amr-users-main" '; $amain = get_site_option('amr-users-no-lists'); // might return default ok, if not will have done upgrade check if (empty($amain)) { $amain = ausers_get_option('amr-users-no-lists'); if (empty($amain)) { $amain = ameta_default_main(); } } $amain['version'] = AUSERS_VERSION; ausers_update_option('amr-users-main', $amain); ausers_delete_option('amr-users-no-lists'); return $amain; //------------------------- } if ($option == 'amr-users') { return ameta_default_list_options(); } if ($option == 'amr-users-nicenames-excluded') { return array('attachment_count' => true, 'activation_key' => true, 'dismissed_wp_pointers' => true, 'default_password_nag' => true, 'nav_menu_item_count' => true, 'revision_count' => true, 'comment_count' => true, 'show_admin_bar_front' => true, 'show_welcome_panel' => true, 'user_activation_key' => true, 'user_status' => true, 'yim' => true, 'aim' => true, 'jabber' => true, 'reply_count' => true, 'topic_count' => true, 'forum_count' => true, 'use_ssl' => true); } if ($option == 'amr-users-original-keys') { return array(); } if ($option == 'amr-users-custom-headings') { return array(); } if ($option == 'amr-users-prefixes-in-use') { return array(); } if ($option == 'amr-users-nicenames') { $amr_nicenames = ameta_defaultnicenames(); } } return $result; }
function cache_status() { /* show the cache status and offer to rebuild */ global $wpdb; global $amain; $problem = false; $now = time(); $dt = new DateTime('now', $this->tz); $nowtxt = date_format($dt, 'D, j M Y G:i e'); if (is_admin()) { if (!($amain = ausers_get_option('amr-users-main'))) { $amain = ameta_default_main(); } $wpdb->show_errors(); $sql = 'SELECT DISTINCT reportid AS "rid", COUNT(reportid) AS "lines" FROM ' . $this->table_name . ' GROUP BY reportid'; $results = $wpdb->get_results($sql, ARRAY_A); /* Now e have a summary of what isin the cache table - rid, lines */ if (is_wp_error($results)) { echo '<h2>' . $results->get_error_message() . '</h2>'; return false; } else { if (!empty($results)) { //var_dump($results); var_dump($amain); foreach ($results as $i => $rpt) { $r = intval(substr($rpt['rid'], 5)); /* *** skip the 'users' and take the rest */ $summary[$r]['rid'] = $rpt['rid']; $summary[$r]['lines'] = $rpt['lines'] - 2; /* as first two liens are headers anyway*/ $summary[$r]['name'] = $amain['names'][intval($r)]; } } else { echo adb_cache::get_error('nocacheany'); // attempt a realtime run NO!!! Don't do this - for large databases that are failing anyway will be no good. //foreach ($amain['names'] as $i => $name) { // amr_build_user_data_maybe_cache($i); //} } $status = ausers_get_option('amr-users-cache-status'); /* Now pickup the record of starts etc reportid, start and reportid end*/ if (!empty($status)) { foreach ($status as $rd => $se) { $r = intval(substr($rd, 5)); /* *** skip the 'users' and take the rest */ if (empty($se['end'])) { $now = time(); $diff = $now - $se['start']; if ($diff > 60 * 5) { $problem = true; $summary[$r]['end'] = __('Taking too long, may have been aborted... delete cache status, try again, check server logs and/or memory limit', 'amr-users'); delete_transient('amr_users_cache_' . $r); // so another can run } else { $summary[$r]['end'] = sprintf(__('Started %s', 'amr-users'), human_time_diff($now, $se['start'])); } $summary[$r]['time_since'] = __('?', 'amr-users'); $summary[$r]['time_taken'] = __('?', 'amr-users'); $summary[$r]['peakmem'] = __('?', 'amr-users'); $summary[$r]['rid'] = $rd; $r = intval(substr($rd, 5)); /* *** skip the 'users' and take the rest */ $summary[$r]['name'] = $amain['names'][intval($r)]; } else { if (empty($se['end'])) { $summary[$r]['end'] = 'In progress'; } else { $datetime = new datetime(date('Y-m-d H:i:s', $se['end'])); if (empty($tzobj)) { $tzobj = amr_getset_timezone(); } $datetime->setTimezone($tzobj); $summary[$r]['end'] = $datetime->format('D, j M G:i'); } //$summary[$r]['end'] = empty($se['end']) ? 'In progress' : date_i18n('D, j M H:i:s',$se['end']); /* this is in unix timestamp not "our time" , so just say how long ago */ $summary[$r]['start'] = date_i18n('D, j M Y H:i:s', $se['start']); /* this is in unix timestamp not "our time" , so just say how long ago */ $dt = new DateTime('now', $this->tz); $nowtxt = date_format($dt, 'D, j M Y G:i e'); $summary[$r]['time_since'] = human_time_diff($se['end'], time()); /* the time that the last cache ended */ $summary[$r]['time_taken'] = $se['end'] - $se['start']; /* the time that the last cache ended */ $summary[$r]['peakmem'] = $se['peakmem']; $summary[$r]['headings'] = $se['headings']; } } } else { if (!empty($summary)) { foreach ($summary as $rd => $rpt) { $summary[$rd]['time_since'] = $summary[$rd]['time_taken'] = $summary[$rd]['end'] = $summary[$rd]['peakmem'] = ''; } } } if (!empty($summary)) { echo PHP_EOL . '<div class="wrap" style="padding-top: 20px;">' . '<h3>' . $nowtxt . '</h3>' . PHP_EOL . '<table class="widefat" style="width:auto; ">' . '<thead><tr><th>' . __('Report Id', 'amr-users') . '</th><th>' . __('Name', 'amr-users') . '</th><th>' . __('Lines', 'amr-users') . '</th><th style="text-align: right;">' . __('Ended?', 'amr-users') . '</th><th style="text-align: right;">' . __('How long ago?', 'amr-users') . '</th><th style="text-align: right;">' . __('Seconds taken', 'amr-users') . '</th><th style="text-align: right;">' . __('Peak Memory', 'amr-users') . '</th><th style="text-align: right;">' . __('Details', 'amr-users') . '</th></tr></thead>'; foreach ($summary as $rd => $rpt) { if (!isset($rpt['headings'])) { $rpt['headings'] = ' '; } if (!isset($rpt['lines'])) { $rpt['lines'] = ' '; } if (isset($rpt['rid'])) { echo '<tr>' . '<td>' . $rpt['rid'] . '</td>' . '<td>' . au_view_link($rpt['name'], $rd, '') . '</td>' . '<td align="right">' . $rpt['lines'] . '</td>' . '<td align="right">' . $rpt['end'] . '</td>' . '<td align="right">' . $rpt['time_since'] . '</td>' . '<td align="right">' . $rpt['time_taken'] . '</td>' . '<td align="right">' . $rpt['peakmem'] . '</td>' . '<td align="right">' . $rpt['headings'] . '</td>' . '</tr>'; } } echo PHP_EOL . '</table>' . PHP_EOL . '</div><!-- end wrap -->' . PHP_EOL; } } } else { echo '<h3>not admin?</h3>'; } if ($problem) { $fun = '<a target="_blank" title="' . __('Link to audio file of the astronauts of Apollo 13 reporting a problem.', 'amr-users') . '" href="http://upload.wikimedia.org/wikipedia/commons/1/12/Apollo13-wehaveaproblem_edit_1.ogg" >' . __('Houston, we have a problem', 'amr-users') . '</a>'; $text = __('The background job\'s may be having problems.', 'amr-users'); $text .= '<br />' . __('Delete all the cache records and try again', 'amr-users'); $text .= '<br />' . __('Check the server logs and your php wordpress memory limit.', 'amr-users'); $text .= '<br />' . __('The TPC memory usage plugin may be useful to assess whether the problem is memory.', 'amr-users'); $text = $fun . '<br/>' . $text; amr_users_message($text); } }