Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -32,20 +32,17 @@ class _cleanup extends \IPS\Task
|
||||
{
|
||||
/* Delete old password / security answer reset requests */
|
||||
\IPS\Db::i()->delete( 'core_validating', array( '( lost_pass=1 OR forgot_security=1 ) AND email_sent < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() ) );
|
||||
|
||||
/* Delete cancelled registration members */
|
||||
foreach( \IPS\Db::i()->select( 'member_id', 'core_validating', array( 'do_not_delete=0 and reg_cancelled > 0 and reg_cancelled < ?', time() - 86400 ) ) as $id )
|
||||
|
||||
/* If we are currently pruning any large tables via a bg task, find out so we don't try to prune them normally here as well. The bg task should finish first. */
|
||||
$currentlyPruning = array();
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_queue', array( '`key`=?', 'PruneLargeTable' ) ) as $pruneTask )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Member::load( $id )->delete();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_validating', array( 'member_id=?', $id ) );
|
||||
}
|
||||
$data = json_decode( $pruneTask['data'], true );
|
||||
|
||||
$currentlyPruning[] = $data['table'];
|
||||
}
|
||||
|
||||
|
||||
/* Delete old validating members */
|
||||
if ( \IPS\Settings::i()->validate_day_prune )
|
||||
{
|
||||
@@ -53,11 +50,13 @@ class _cleanup extends \IPS\Task
|
||||
|
||||
foreach ( $select as $row )
|
||||
{
|
||||
try
|
||||
$member = \IPS\Member::load( $row['member_id'] );
|
||||
|
||||
if( $member->member_id )
|
||||
{
|
||||
\IPS\Member::load( $row['member_id'] )->delete();
|
||||
$member->delete();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_validating', array( 'member_id=?', $row['member_id'] ) );
|
||||
}
|
||||
@@ -104,6 +103,12 @@ class _cleanup extends \IPS\Task
|
||||
if( \IPS\Settings::i()->prune_log_error )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_error_logs', array( 'log_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_error . 'D' ) )->getTimestamp() ) );
|
||||
|
||||
/* If we don't have any logs left, remove any notifications */
|
||||
if( \IPS\Db::i()->select( 'count(log_id)', 'core_error_logs' )->first() === 0 )
|
||||
{
|
||||
\IPS\core\AdminNotification::remove( 'core', 'Error' );
|
||||
}
|
||||
}
|
||||
|
||||
/* ...and spam service logs */
|
||||
@@ -128,9 +133,19 @@ class _cleanup extends \IPS\Task
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_statistics', array( 'type=? AND time < ?', 'keyword', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->stats_keywords_prune . 'D' ) )->getTimestamp() ) );
|
||||
}
|
||||
|
||||
if( \IPS\Settings::i()->stats_search_prune )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_statistics', array( 'type=? AND time < ?', 'search', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->stats_search_prune . 'D' ) )->getTimestamp() ) );
|
||||
}
|
||||
|
||||
if( \IPS\Settings::i()->prune_log_emailstats > 0 )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_statistics', array( "type IN('emails_sent','email_views','email_clicks') AND time < ?", \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_emailstats . 'D' ) )->getTimestamp() ) );
|
||||
}
|
||||
|
||||
/* ...and geoip cache */
|
||||
\IPS\Db::i()->delete( 'core_geoip_cache', array( 'date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'PT12H' ) )->getTimestamp() ) );
|
||||
\IPS\Db::i()->delete( 'core_geoip_cache', array( 'date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P7D' ) )->getTimestamp() ) );
|
||||
|
||||
/* ...and API logs */
|
||||
if( \IPS\Settings::i()->api_log_prune )
|
||||
@@ -139,32 +154,66 @@ class _cleanup extends \IPS\Task
|
||||
}
|
||||
|
||||
/* ...and member history */
|
||||
if( \IPS\Settings::i()->prune_member_history )
|
||||
if( \IPS\Settings::i()->prune_member_history AND !\in_array( 'core_member_history', $currentlyPruning ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_member_history', array( 'log_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_member_history . 'D' ) )->getTimestamp(), 0 ) );
|
||||
\IPS\Db::i()->delete( 'core_member_history', array( 'log_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_member_history . 'D' ) )->getTimestamp() ) );
|
||||
}
|
||||
|
||||
/* ...and promote response logs */
|
||||
\IPS\Db::i()->delete( 'core_social_promote_content', array( 'response_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P6M' ) )->getTimestamp() ) );
|
||||
|
||||
/* ...and webhook logs */
|
||||
if( \IPS\Settings::i()->webhook_logs_success )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_api_webhook_fires', array( "status='successful' AND time < ?", \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->webhook_logs_success . 'D' ) )->getTimestamp() ) );
|
||||
}
|
||||
if( \IPS\Settings::i()->webhook_logs_fail )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_api_webhook_fires', array( "status='failed' AND time < ?", \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->webhook_logs_fail . 'D' ) )->getTimestamp() ) );
|
||||
}
|
||||
|
||||
/* Delete old notifications */
|
||||
if ( \IPS\Settings::i()->prune_notifications )
|
||||
{
|
||||
$memberIds = array();
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'member', 'core_notifications', array( 'sent_time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_notifications . 'M' ) )->getTimestamp() ) ) as $member )
|
||||
foreach( \IPS\Db::i()->select( '`member`', 'core_notifications', array( 'sent_time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_notifications . 'D' ) )->getTimestamp() ) ) as $member )
|
||||
{
|
||||
$memberIds[ $member ] = $member;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'core_notifications', array( 'sent_time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_notifications . 'M' ) )->getTimestamp() ) );
|
||||
\IPS\Db::i()->delete( 'core_notifications', array( 'sent_time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_notifications . 'D' ) )->getTimestamp() ) );
|
||||
|
||||
foreach( $memberIds as $member )
|
||||
{
|
||||
\IPS\Member::load( $member )->recountNotifications();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Delete old follows */
|
||||
if ( \IPS\Settings::i()->prune_follows AND !\in_array( 'core_follow', $currentlyPruning ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_follow', array( 'follow_member_id IN(?)', \IPS\Db::i()->select( 'member_id', 'core_members', array( 'last_activity < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_follows . 'D' ) )->getTimestamp() ) ) ) );
|
||||
}
|
||||
|
||||
/* Delete old item markers */
|
||||
if ( \IPS\Settings::i()->prune_item_markers AND !\in_array( 'core_item_markers', $currentlyPruning ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_item_markers', array( 'item_member_id IN(?)', \IPS\Db::i()->select( 'member_id', 'core_members', array( 'last_activity < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_item_markers . 'D' ) )->getTimestamp() ) ) ) );
|
||||
}
|
||||
|
||||
/* Delete old seen IP addresses */
|
||||
if ( \IPS\Settings::i()->prune_known_ips AND !\in_array( 'core_members_known_ip_addresses', $currentlyPruning ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_members_known_ip_addresses', array( 'last_seen < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_known_ips . 'D' ) )->getTimestamp() ) );
|
||||
}
|
||||
|
||||
/* Delete old seen devices */
|
||||
if ( \IPS\Settings::i()->prune_known_devices AND !\in_array( 'core_members_known_devices', $currentlyPruning ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_members_known_devices', array( 'last_seen < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_known_devices . 'D' ) )->getTimestamp() ) );
|
||||
}
|
||||
|
||||
/* Delete moved links */
|
||||
if ( \IPS\Settings::i()->topic_redirect_prune )
|
||||
{
|
||||
@@ -191,12 +240,6 @@ class _cleanup extends \IPS\Task
|
||||
$warning->save();
|
||||
}
|
||||
|
||||
/* Delete any incompleted accounts (for example, someone has clicked "Sign in with Twitter" and never provided a username or email */
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members', array( array( '(name=? OR email=?)', '', '' ), array( '! (members_bitoptions2 & 16384 ) AND joined<? AND last_visit=0', \IPS\DateTime::create()->sub( new \DateInterval( 'PT1H' ) )->getTimestamp() ) ) ), 'IPS\Member' ) as $incompleteMember )
|
||||
{
|
||||
$incompleteMember->delete();
|
||||
}
|
||||
|
||||
/* Remove widgets */
|
||||
if ( \IPS\Application::appIsEnabled('cms') )
|
||||
{
|
||||
@@ -224,6 +267,26 @@ class _cleanup extends \IPS\Task
|
||||
\IPS\Db::i()->delete( 'core_oauth_server_authorization_codes', array( 'expires<?', time() ) );
|
||||
\IPS\Db::i()->delete( 'core_oauth_server_access_tokens', array( 'refresh_token_expires<?', time() ) );
|
||||
\IPS\Db::i()->delete( 'core_oauth_authorize_prompts', array( 'timestamp<?', ( time() - 300 ) ) );
|
||||
|
||||
/* Delete any unfinished "Post before register" posts */
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_post_before_registering', array( "`member` IS NULL AND followup IS NOT NULL AND followup<" . ( time() - ( 86400 * 6 ) ) ), 'followup ASC' ) as $row )
|
||||
{
|
||||
$class = $row['class'];
|
||||
try
|
||||
{
|
||||
$class::load( $row['id'] )->delete();
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
|
||||
\IPS\Db::i()->delete( 'core_post_before_registering', array( 'class=? AND id=?', $row['class'], $row['id'] ) );
|
||||
}
|
||||
|
||||
/* Delete old core follow caches */
|
||||
\IPS\Db::i()->delete( 'core_follow_count_cache', array( 'added < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P30D' ) )->getTimestamp() ) );
|
||||
|
||||
|
||||
/* Truncate the output caches table */
|
||||
\IPS\Output\Cache::i()->deleteExpired( TRUE );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user