Example #1
0
/**
 * Shutdown function: save HIT and update session!
 *
 * This is registered in _main.inc.php with register_shutdown_function()
 * This is called by PHP at the end of the script.
 *
 * NOTE: before PHP 4.1 nothing can be echoed here any more, but the minimum PHP requirement for b2evo is PHP 4.3
 */
function shutdown()
{
    /**
     * @var Hit
     */
    global $Hit;
    /**
     * @var Session
     */
    global $Session;
    global $Settings;
    global $Debuglog;
    global $Timer;
    global $shutdown_count_item_views;
    // Try forking a background process and let the parent return as fast as possbile.
    if (is_callable('pcntl_fork') && function_exists('posix_kill') && defined('STDIN')) {
        if ($pid = pcntl_fork()) {
            return;
        }
        // Parent
        function shutdown_kill()
        {
            posix_kill(posix_getpid(), SIGHUP);
        }
        if (ob_get_level()) {
            // Discard the output buffer and close
            ob_end_clean();
        }
        fclose(STDIN);
        // Close all of the standard
        fclose(STDOUT);
        // file descriptors as we
        fclose(STDERR);
        // are running as a daemon.
        register_shutdown_function('shutdown_kill');
        if (posix_setsid() < 0) {
            return;
        }
        if ($pid = pcntl_fork()) {
            return;
        }
        // Parent
        // Now running as a daemon. This process will even survive
        // an apachectl stop.
    }
    $Timer->resume('shutdown');
    // echo '*** SHUTDOWN FUNC KICKING IN ***';
    // fp> do we need special processing if we are in CLI mode?  probably earlier actually
    // if( ! $is_cli )
    // Note: it might be useful at some point to do special processing if the script has been aborted or has timed out
    // connection_aborted()
    // connection_status()
    if (!empty($shutdown_count_item_views)) {
        // Increment view counts for Items:
        $ItemCache =& get_ItemCache();
        foreach ($shutdown_count_item_views as $item_ID) {
            // asimo> Inserted the $item_ID != 0 check, because another way comes unexpected error on preview page
            if (!empty($item_ID) && ($Item = $ItemCache->get_by_ID($item_ID, false))) {
                $Item->count_view(array('allow_multiple_counts_per_page' => false));
            }
        }
    }
    // Save the current HIT:
    $Hit->log();
    // Update the SESSION:
    $Session->dbsave();
    // Get updates here instead of slowing down normal display of the dashboard
    load_funcs('dashboard/model/_dashboard.funcs.php');
    b2evonet_get_updates();
    // Auto pruning of old HITS, old SESSIONS and potentially MORE analytics data:
    if ($Settings->get('auto_prune_stats_mode') == 'page') {
        // Autopruning is requested
        load_class('sessions/model/_hitlist.class.php', 'Hitlist');
        Hitlist::dbprune();
        // will prune once per day, according to Settings
    }
    // Calling debug_info() here will produce complete data but it will be after </html> hence invalid.
    // Then again, it's for debug only, so it shouldn't matter that much.
    debug_info();
    // Update the SESSION again, at the very end:
    // (e.g. "Debuglogs" may have been removed in debug_info())
    $Session->dbsave();
    $Timer->pause('shutdown');
}
Example #2
0
     break;
 case 'delete_orphan_comment_uploads':
     // delete orphan comment upload, older than 24 hours
     dbm_delete_orphan_comment_uploads();
     break;
 case 'delete_orphan_files':
     // delete orphan File objects with no matching file on disk
 // delete orphan File objects with no matching file on disk
 case 'delete_orphan_file_roots':
     // delete orphan file roots with no matching Blog or User entry in the database
     $template_action = $action;
     break;
 case 'prune_hits_sessions':
     // Prune old hits & sessions
     load_class('sessions/model/_hitlist.class.php', 'Hitlist');
     Hitlist::dbprune();
     // will prune once per day, according to Settings
     break;
 case 'create_sample_comments':
     $blog_ID = param('blog_ID', 'string', 0);
     $num_comments = param('num_comments', 'string', 0);
     $num_posts = param('num_posts', 'string', 0);
     if (!(param_check_number('blog_ID', T_('Blog ID must be a number'), true) && param_check_number('num_comments', T_('Comments per post must be a number'), true) && param_check_number('num_posts', T_('"How many posts" field must be a number'), true))) {
         // param errors
         $action = 'show_create_comments';
         break;
     }
     // check blog_ID
     $BlogCache =& get_BlogCache();
     $selected_Blog = $BlogCache->get_by_ID($blog_ID, false, false);
     if ($selected_Blog == NULL) {
Example #3
0
            param('hit_ID', 'integer', true);
            // Required!
            param('new_hit_type', 'string', true);
            // Required!
            Hitlist::change_type($hit_ID, $new_hit_type);
            $Messages->add(sprintf(T_('Changed hit #%d type to: %s.'), $hit_ID, $new_hit_type), 'success');
            break;
        case 'prune':
            // PRUNE hits for a certain date
            // Check that this action request is not a CSRF hacked request:
            $Session->assert_received_crumb('stats');
            // Check permission:
            $current_User->check_perm('stats', 'edit', true);
            param('date', 'integer', true);
            // Required!
            if ($r = Hitlist::prune($date)) {
                $Messages->add(sprintf(T_('Deleted %d hits for %s.'), $r, date(locale_datefmt(), $date)), 'success');
            } else {
                $Messages->add(sprintf(T_('No hits deleted for %s.'), date(locale_datefmt(), $date)), 'note');
            }
            // Redirect so that a reload doesn't write to the DB twice:
            header_redirect('?ctrl=stats', 303);
            // Will EXIT
            // We have EXITed already at this point!!
            break;
        case 'reset_counters':
            $current_User->check_perm('stats', 'edit', true);
            $sql = 'UPDATE T_track__keyphrase
				SET keyp_count_refered_searches = 0,
					keyp_count_internal_searches = 0';
            $DB->query($sql, ' Reset keyphrases counters');
<?php

/**
 * This file implements the Hit and Session pruning Cron controller
 *
 * @author fplanque: Francois PLANQUE
 *
 * @version $Id: _prune_hits_sessions.job.php 3328 2013-03-26 11:44:11Z yura $
 */
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
global $Settings;
if ($Settings->get('auto_prune_stats_mode') != 'cron') {
    // Autopruning is NOT requested
    $result_message = T_('Auto pruning is not set to run as a scheduled task');
    return 2;
}
load_class('sessions/model/_hitlist.class.php', 'Hitlist');
$result_message = Hitlist::dbprune();
// will prune once per day, according to Settings
if (empty($result_message)) {
    return 1;
    /* ok */
}
return 100;
Example #5
0
 /**
  * Log a hit on a blog page / rss feed.
  *
  * This function should be called at the end of the page, otherwise if the page
  * is displaying previous hits, it may display the current one too.
  *
  * The hit will not be logged in special occasions, see {@link $ignore} and {@link is_good_hit()}.
  *
  * It will call {@link Hitlist::dbprune()} to do the automatic pruning of old hits in case
  * of auto_prune_stats_mode == "page".
  *
  * @return boolean true if the hit gets logged; false if not
  */
 function log()
 {
     global $Settings, $Plugins, $Debuglog, $is_admin_page;
     if ($this->logged) {
         // Already logged
         return false;
     }
     // Remember we have already attempted to log:
     $this->logged = true;
     // Auto pruning:
     // We need to do this now because even if we don't log anything, we stil need to prune old sessions.
     if ($Settings->get('auto_prune_stats_mode') == 'page') {
         // Autopruning is requested
         load_class('sessions/model/_hitlist.class.php');
         Hitlist::dbprune();
         // will prune once per day, according to Settings
     }
     // Real logging:
     if ($is_admin_page && !$Settings->get('log_admin_hits')) {
         // We don't want to log admin hits:
         return false;
     }
     if (!$is_admin_page && !$Settings->get('log_public_hits')) {
         // We don't want to log public hits:
         return false;
     }
     if ($this->ignore || !$this->is_good_hit()) {
         // We don't want to log this hit!
         $hit_info = 'referer_type: ' . var_export($this->referer_type, true) . ', agent_type: ' . var_export($this->agent_type, true) . ', is' . ($this->ignore ? '' : ' NOT') . ' ignored' . ', is' . ($this->is_good_hit() ? '' : ' NOT') . ' a good hit';
         $Debuglog->add('log(): Hit NOT logged, (' . $hit_info . ')', 'hit');
         return false;
     }
     if (!$Plugins->trigger_event_first_true('AppendHitLog', array('Hit' => &$this)) && $this->is_good_hit()) {
         // Record it here:
         $this->record_the_hit();
     }
     return true;
 }
if (!defined('EVO_MAIN_INIT')) {
    die('Please, do not access this page directly.');
}
global $Settings, $DB;
// Print all unknown errors on screen and save error message
ob_start();
$DB->save_error_state();
$DB->show_errors = true;
$DB->halt_on_error = false;
if ($Settings->get('auto_prune_stats_mode') != 'cron') {
    // Autopruning is NOT requested
    $result_message = T_('Auto pruning is not set to run as a scheduled task');
    return 2;
}
load_class('sessions/model/_hitlist.class.php', 'Hitlist');
$result = Hitlist::dbprune();
// will prune once per day, according to Settings
// Restore DB error states
$DB->restore_error_state();
// Get the unknown errors from screen
$unknown_errors = ob_get_clean();
if (!empty($unknown_errors)) {
    // Some errors were created, probably DB errors
    if (!is_array($result)) {
        // Set result to array format
        $result = array();
    }
    // This result must have an error status
    $result['result'] = 'error';
    // Append the unknown error from screen to already generated message
    $result['message'] = (isset($result['message']) ? $result['message'] : '') . "\n" . $unknown_errors;