/** * Shutdown function for detecting if the PHP script reaches the maximum execution time limit * while importing a feed. * * @since 4.6.6 */ function wprss_detect_exec_timeout() { // Get last error if ($error = error_get_last()) { // Check if it is an E_ERROR and if it is a max exec time limit error if ($error['type'] === E_ERROR && stripos($error['message'], 'maximum execution') === 0) { // If the importing process was running if (array_key_exists('wprss_importing_feed', $GLOBALS) && $GLOBALS['wprss_importing_feed'] !== NULL) { // Get the ID of the feed that was importing $feed_ID = $GLOBALS['wprss_importing_feed']; // Perform clean up wprss_flag_feed_as_idle($feed_ID); $msg = sprintf(__('The PHP script timed out while importing an item from this feed, after %d seconds.', WPRSS_TEXT_DOMAIN), wprss_get_item_import_time_limit()); update_post_meta($feed_ID, 'wprss_error_last_import', $msg); // Log the error wprss_log('The PHP script timed out while importing feed #' . $feed_ID, NULL, WPRSS_LOG_LEVEL_ERROR); } } } }
/** * Delete old feed items from the database to avoid bloat. * As of 3.8, it uses the new feed age system. * * @since 3.8 */ function wprss_truncate_posts() { // Get general settings $general_settings = get_option('wprss_settings_general'); // Get all feed sources $feed_sources = wprss_get_all_feed_sources(); // Check if there are feed sources if ($feed_sources->have_posts()) { // FOR EACH FEED SOURCE while ($feed_sources->have_posts()) { $feed_sources->the_post(); // Get the max age setting for this feed source $max_age = wprss_get_max_age_for_feed_source(get_the_ID()); // If the data is empty, do not delete if ($max_age === FALSE) { continue; } // Get all feed items for this source $feed_items = wprss_get_feed_items_for_source(get_the_ID()); // If there are feed items if ($feed_items->have_posts()) { // Extend the timeout time limit for the deletion of the feed items $time_limit = wprss_get_item_import_time_limit(); wprss_log("Extended execution time limit by {$time_limit}s for imported items truncation.", null, WPRSS_LOG_LEVEL_INFO); set_time_limit($time_limit); // For each feed item while ($feed_items->have_posts()) { $feed_items->the_post(); // If the post is older than the maximum age if (wprss_is_feed_item_older_than(get_the_ID(), $max_age) === TRUE) { // Delete the post wp_delete_post(get_the_ID(), true); } } // Reset feed items query data wp_reset_postdata(); } } // Reset feed sources query data wp_reset_postdata(); } // If the filter to use the fixed limit is enabled, call the old truncation function if (apply_filters('wprss_use_fixed_feed_limit', FALSE) === TRUE && isset($general_settings['limit_feed_items_db'])) { wprss_old_truncate_posts(); } }