Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* @brief bulkmail Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 21 Jun 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* bulkmail Task
*/
class _bulkmail extends \IPS\Task
{
/**
* Execute
*
* @return mixed Message to log or NULL
*/
public function execute()
{
try
{
\IPS\core\BulkMail\Bulkmailer::constructFromData( \IPS\DB::i()->select( '*', 'core_bulk_mail', 'mail_active=1', 'mail_start ASC', 1 )->first() )->send();
}
catch ( \UnderflowException $e )
{
\IPS\core\BulkMail\Bulkmailer::updateTask( 0 );
\IPS\Log::i( \LOG_CRIT )->write( get_class( $e ) . "\n" . $e->getCode() . ": " . $e->getMessage() . "\n" . $e->getTraceAsString() );
}
}
}
+172
View File
@@ -0,0 +1,172 @@
<?php
/**
* @brief Daily Cleanup Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 27 Aug 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Daily Cleanup Task
*/
class _cleanup extends \IPS\Task
{
/**
* Execute
*
* @return mixed Message to log or NULL
* @throws \RuntimeException
*/
public function execute()
{
/* Delete old password reset requests */
\IPS\Db::i()->delete( 'core_validating', array( 'lost_pass=1 AND entry_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() ) );
/* Delete old validating members */
if ( \IPS\Settings::i()->validate_day_prune )
{
$select = \IPS\Db::i()->select( 'core_validating.member_id, core_members.member_posts', 'core_validating', array( 'core_validating.new_reg=1 AND core_validating.coppa_user<>1 AND core_validating.entry_date<? AND core_validating.lost_pass<>1 AND core_validating.user_verified=0 AND core_members.member_posts < 1', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->validate_day_prune . 'D' ) )->getTimestamp() ) )->join( 'core_members', 'core_members.member_id=core_validating.member_id' );
foreach ( $select as $row )
{
try
{
\IPS\Member::load( $row['member_id'] )->delete();
}
catch ( \OutOfRangeException $e )
{
\IPS\Db::i()->delete( 'core_validating', array( 'member_id=?', $row['member_id'] ) );
}
}
}
/* Delete edit history past prune date */
if( \IPS\Settings::i()->edit_log_prune > 0 )
{
\IPS\Db::i()->delete( 'core_edit_history', array( 'time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->edit_log_prune . 'D' ) )->getTimestamp() ) );
}
/* Delete task logs older than the prune-since date */
if( \IPS\Settings::i()->prune_log_tasks )
{
\IPS\Db::i()->delete( 'core_tasks_log', array( 'time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_tasks . 'D' ) )->getTimestamp() ) );
}
/* Delete email error logs older than the prune-since date */
if( \IPS\Settings::i()->prune_log_email_error )
{
\IPS\Db::i()->delete( 'core_mail_error_logs', array( 'mlog_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_email_error . 'D' ) )->getTimestamp() ) );
}
/* ...and admin logs */
if( \IPS\Settings::i()->prune_log_admin )
{
\IPS\Db::i()->delete( 'core_admin_logs', array( 'ctime < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_admin . 'D' ) )->getTimestamp() ) );
}
/* ...and error logs */
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() ) );
}
/* ...and system logs */
if( \IPS\Settings::i()->prune_log_system )
{
\IPS\Log::pruneLogs( \IPS\Settings::i()->prune_log_system );
}
/* ...and spam service logs */
if( \IPS\Settings::i()->prune_log_spam )
{
\IPS\Db::i()->delete( 'core_spam_service_log', array( 'log_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_spam . 'D' ) )->getTimestamp() ) );
}
/* ...and admin login logs */
if( \IPS\Settings::i()->prune_log_adminlogin )
{
\IPS\Db::i()->delete( 'core_admin_login_logs', array( 'admin_time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_adminlogin . '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 )
{
$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() ) );
foreach( $memberIds as $member )
{
\IPS\Member::load( $member )->recountNotifications();
}
}
/* Delete moved links */
if ( \IPS\Settings::i()->topic_redirect_prune )
{
foreach ( \IPS\Content::routedClasses( FALSE, FALSE, TRUE ) as $class )
{
if ( isset( $class::$databaseColumnMap['moved_on'] ) )
{
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', $class::$databaseTable, array( $class::$databasePrefix . $class::$databaseColumnMap['moved_on'] . '>0 AND ' . $class::$databasePrefix . $class::$databaseColumnMap['moved_on'] . '<?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->topic_redirect_prune . 'D' ) )->getTimestamp() ), $class::$databasePrefix . $class::$databaseColumnId, 100 ), $class ) as $item )
{
$item->delete();
}
}
}
}
/* Remove warnings points */
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members_warn_logs', array( 'wl_expire_date>0 AND wl_expire_date<?', time() ), 'wl_date ASC', 25 ), 'IPS\core\Warnings\Warning' ) as $warning )
{
$member = \IPS\Member::load( $warning->member );
$member->warn_level -= $warning->points;
$member->save();
$warning->expire_date = 0;
$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( 'joined<? AND last_visit=0', \IPS\DateTime::create()->sub( new \DateInterval( 'PT1H' ) )->getTimestamp() ) ) ), 'IPS\Member' ) as $incompleteMember )
{
$incompleteMember->delete();
}
/* Prune search index */
if ( \IPS\Settings::i()->search_index_timeframe )
{
try
{
\IPS\Content\Search\Index::i()->prune( \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->search_index_timeframe . 'D' ) ) );
}
catch ( \UnexpectedValueException $e ) { }
}
/* Remove widget trash (configs stored older than a day) */
\IPS\Db::i()->delete( 'core_widget_trash', array( 'date < ?', time() - 86400 ) );
/* Reset expired "moderate content till.." timestamps */
\IPS\Db::i()->update( 'core_members', array( 'mod_posts' => 0 ), array( 'mod_posts != -1 and mod_posts <?', time() ) );
return NULL;
}
}
+58
View File
@@ -0,0 +1,58 @@
<?php
/**
* @brief clearcache Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 29 May 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* clearcache Task
*/
class _clearcache extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
/* Note: We previously disabled the task if the caching method was disabled however this lead to people re-enabling through a constants edit which would not re-enabled the task */
\IPS\Db::i()->delete( 'core_cache', array( 'cache_expire<?', time() ) );
return NULL;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+66
View File
@@ -0,0 +1,66 @@
<?php
/**
* @brief clearsessions Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 29 May 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* clearsessions Task
*/
class _clearsessions extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
$timeout = 1440;
if( function_exists('ini_get') )
{
$phpTimeout = @ini_get('session.gc_maxlifetime');
$timeout = $phpTimeout ?: $timeout;
}
\IPS\Session\Front::i()->gc( $timeout );
\IPS\Session\Admin::i()->gc( $timeout );
return NULL;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+91
View File
@@ -0,0 +1,91 @@
<?php
/**
* @brief Reattempt queued IPS Connect requests
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 3 Dec 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Reattempt queued IPS Connect requests
*/
class _connect extends \IPS\Task
{
/**
* Execute
*
* @return mixed Message to log or NULL
* @throws \RuntimeException
*/
public function execute()
{
/* Get the next request */
try
{
$request = \IPS\Db::i()->select( 'q.*, s.*', array( 'core_ipsconnect_queue', 'q' ), array(), 'q.id asc', array( 0, 1 ) )
->join( array( 'core_ipsconnect_slaves', 's' ), "s.slave_id=q.slave_id" )
->first();
/* Try to process request again */
try
{
parse_str( $request['request_url'], $variables );
$response = \IPS\Http\Url::external( $request['slave_url'] )
->setQueryString( $variables )
->request()
->get();
if( $response->httpResponseCode !== NULL AND $response->httpResponseCode > 200 )
{
/* Update fail count */
\IPS\Db::i()->update( 'core_ipsconnect_queue', 'fail_count=fail_count+1', array( 'id=?', $request['id'] ) );
return NULL;
}
$response = $response->decodeJson();
/* If this is a registered slave but the slave is telling us Connect is disabled, remove it */
if( isset( $response['status'] ) AND $response['status'] == 'DISABLED' )
{
\IPS\Db::i()->delete( 'core_ipsconnect_slaves', array( 'slave_id=?', $request['slave_id'] ) );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Db::i()->select( 'COUNT(*)', 'core_ipsconnect_slaves' )->first() ), array( 'conf_key=?', 'connect_slaves' ) );
unset( \IPS\Data\Store::i()->settings );
}
/* If we are here, request succeeded - remove from queue */
\IPS\Db::i()->delete( 'core_ipsconnect_queue', array( 'id=?', $request['id'] ) );
return NULL;
}
catch( \RuntimeException $e )
{
/* Update fail count */
\IPS\Db::i()->update( 'core_ipsconnect_queue', 'fail_count=fail_count+1', array( 'id=?', $request['id'] ) );
return NULL;
}
}
catch( \UnderflowException $e )
{
/* There are none left - disable task */
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), "`key`='ipsconnect'" );
return NULL;
}
return NULL;
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
/**
* @brief digest Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 08 May 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* digest Task
*/
class _digest extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
/* Doing daily or weekly this run? */
$frequencies = array( 'daily', 'weekly' );
$frequency = $frequencies[ array_rand( $frequencies ) ];
/* Grab some members to send digests to. */
$members = \IPS\DB::i()->select( 'follow_member_id', 'core_follow', array( 'follow_notify_do=1 AND follow_visible=1 AND follow_notify_freq = ? AND follow_notify_sent < ?', $frequency, ( $frequency == 'daily' ) ? time() - 86400 : time() - 604800 ), 'follow_member_id ASC', array( 0, 50 ), 'follow_member_id' );
if( !count( $members ) )
{
/* Nothing to send */
return NULL;
}
/* Fetch the member's follows so we can build their digest */
$follows = \IPS\DB::i()->select( '*', 'core_follow', array( 'follow_notify_do=1 AND follow_notify_freq=? AND follow_visible=1 AND follow_notify_sent < ? AND ' . \IPS\Db::i()->in( 'follow_member_id', iterator_to_array( $members ) ), $frequency, time() - 86400 ), 'follow_member_id ASC, follow_app ASC, follow_area ASC' );
$groupedFollows = array();
foreach( $follows as $follow )
{
$groupedFollows[ $follow['follow_member_id'] ][ $follow['follow_app'] ][ $follow['follow_area'] ][] = $follow;
}
foreach( $groupedFollows as $id => $data )
{
$member = \IPS\Member::load( $id );
if( !$member->email )
{
continue;
}
/* Build it */
$digest = new \IPS\core\Digest\Digest;
$digest->member = $member;
$digest->frequency = $frequency;
$digest->build( $data );
/* Send it */
$digest->send();
}
return NULL;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
View File
Whitespace-only changes.
+117
View File
@@ -0,0 +1,117 @@
<?php
/**
* @brief POP3 Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 16 Apr 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* POP3 Task
*/
class _pop extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
/* If we haven't set up POP3, disable ourselves */
if ( !\IPS\Settings::i()->pop3_server )
{
$this->enabled = FALSE;
$this->save();
return;
}
/* Or do it */
require_once \IPS\ROOT_PATH . '/system/3rd_party/pop3/pop3.class.inc';
$pop3 = new \POP3;
try
{
/* Connect */
if ( !$pop3->connect( ( \IPS\Settings::i()->pop3_tls ? 'ssl://' : '' ) . \IPS\Settings::i()->pop3_server, \IPS\Settings::i()->pop3_port ) )
{
throw new \IPS\Task\Exception( $this, \IPS\Member::loggedIn()->language()->addToStack( 'pop3_cant_connect' ) );
}
/* Login */
if ( !$pop3->login( \IPS\Settings::i()->pop3_user, \IPS\Settings::i()->pop3_password ) )
{
throw new \IPS\Task\Exception( $this, \IPS\Member::loggedIn()->language()->addToStack( 'pop3_cant_login ' ) );
}
/* Got any? */
$status = @$pop3->get_office_status();
if ( $status['count_mails'] )
{
foreach ( range( 1, $status['count_mails'] ) as $i )
{
if( $pop3->_putline( "RETR $i" ) )
{
if ( mb_substr( @$pop3->_getnextstring(), 0, 3 ) == "+OK" )
{
$message = '';
while ( TRUE )
{
$line = @$pop3->_getnextstring();
if ( preg_match( "/^\.\r\n/", $line ) )
{
break;
}
$message .= $line;
}
\IPS\Email\Incoming::i( $message )->route();
$pop3->delete_mail( $i );
}
}
}
}
/* Close Connection */
$pop3->close();
}
catch ( \Exception $exception )
{
\IPS\Log::i( \LOG_CRIT )->write( get_class( $exception ) . "\n" . $exception->getCode() . ": " . $exception->getMessage() . "\n" . $exception->getTraceAsString() );
throw new \IPS\Task\Exception( $this, $exception->getMessage() );
}
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
/**
* @brief Profile-sync Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 21 Jun 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Profile-sync Task
*/
class _profilesync extends \IPS\Task
{
/**
* Execute
*
* @return void
*/
public function execute()
{
$services = \IPS\core\ProfileSync\ProfileSyncAbstract::services();
if ( !empty( $services ) )
{
foreach ( \IPS\Db::i()->select( '*', 'core_members', 'profilesync IS NOT NULL', 'profilesync_lastsync ASC', 25 ) as $row )
{
foreach ( $services as $class )
{
$obj = new $class( \IPS\Member::constructFromData( $row ) );
$obj->sync();
}
}
}
}
}
+75
View File
@@ -0,0 +1,75 @@
<?php
/**
* @brief publish Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 07 Oct 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* publish Task
*/
class _publish extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
$types = array();
foreach ( \IPS\Content::routedClasses( FALSE, FALSE, TRUE ) as $class )
{
if( is_subclass_of( $class, 'IPS\Content\FuturePublishing' ) )
{
$types[] = $class;
}
}
if( count( $types ) )
{
foreach( $types as $class )
{
foreach( \IPS\Db::i()->select( '*', $class::$databaseTable, array( $class::$databasePrefix . $class::$databaseColumnMap['is_future_entry'] . '=1 and ' . $class::$databasePrefix . $class::$databaseColumnMap['date'] . ' <= ' . time() ) ) as $row )
{
$obj = $class::constructFromData( $row );
$obj->publish();
}
}
}
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+171
View File
@@ -0,0 +1,171 @@
<?php
/**
* @brief Queue Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 04 Dec 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Queue Task
*/
class _queue extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
/* Work out the maximum execution time */
$timeLeft = 45;
if ( $phpMaxExecutionTime = ini_get('max_execution_time') and $phpMaxExecutionTime <= $timeLeft )
{
$timeLeft = $phpMaxExecutionTime - 2;
}
/* Factor in wait_timeout if possible */
try
{
$mysqlTimeout = \IPS\Db::i()->query( "SHOW SESSION VARIABLES LIKE 'wait_timeout'" )->fetch_assoc();
$mysqlTimeout = $mysqlTimeout['Value'];
if( $mysqlTimeout <= $timeLeft )
{
$timeLeft = $mysqlTimeout - 2;
}
}
catch( \IPS\Db\Exception $e ){}
$timeTheLastRunTook = 0;
/* Work out the memory limit */
$memoryLeft = 0;
$memoryUnlimited = FALSE;
if ( function_exists( 'memory_get_usage' ) )
{
$memory_limit = ini_get('memory_limit');
if ( $memory_limit == -1 )
{
$memoryUnlimited = TRUE;
}
else
{
if ( preg_match('/^(\d+)(.)$/', $memory_limit, $matches ) )
{
if ( $matches[2] == 'M' )
{
$memory_limit = $matches[1] * 1024 * 1024;
}
elseif ( $matches[2] == 'K' )
{
$memory_limit = $matches[1] * 1024;
}
}
$memoryLeft = $memory_limit - memory_get_usage( TRUE );
}
}
$memoryTheLastRunTook = 0;
/* Run until we run out of time */
do
{
/* Try and get a queue item */
try
{
/* Get it */
$queueData = \IPS\Db::i()->select( '*', 'core_queue', NULL, 'priority ASC, RAND()', 1 )->first();
/* Start a timer */
$timer = microtime( TRUE );
$memoryTimer = function_exists( 'memory_get_usage' ) ? memory_get_usage( TRUE ) : 0;
/* Got one, try to run it */
try
{
$extensions = \IPS\Application::load( $queueData['app'] )->extensions( 'core', 'Queue', FALSE );
if ( !isset( $extensions[ $queueData['key'] ] ) )
{
throw new \OutOfRangeException;
}
$class = new $extensions[ $queueData['key'] ];
$data = json_decode( $queueData['data'], TRUE );
$newOffset = $class->run( $data, $queueData['offset'] );
if ( is_null( $newOffset ) )
{
\IPS\Db::i()->delete( 'core_queue', array( 'id=?', $queueData['id'] ) );
}
else
{
\IPS\Db::i()->update( 'core_queue', array( 'offset' => $newOffset ), array( 'id=?', $queueData['id'] ) );
$newData = json_encode( $data );
/* Did it change?? */
if ( $newData !== $data )
{
\IPS\Db::i()->update( 'core_queue', array( 'data' => $newData ), array( 'id=?', $queueData['id'] ) );
}
}
}
/* An error in running - delete it */
catch ( \OutOfRangeException $e )
{
\IPS\Db::i()->delete( 'core_queue', array( 'id=?', $queueData['id'] ) );
}
/* Decrease the time left */
$timeTheLastRunTook = round( ( microtime( TRUE ) - $timer ), 2 );
$timeLeft -= $timeTheLastRunTook;
$memoryTheLastRunTook = function_exists( 'memory_get_usage' ) ? ( memory_get_usage( TRUE ) - $memoryTimer ) : 0;
if ( !$memoryUnlimited )
{
$memoryLeft = $memory_limit - memory_get_usage( TRUE );;
}
}
/* If there's no queue items left, disable this task and return */
catch ( \UnderflowException $e )
{
$this->enabled = FALSE;
$this->save();
return;
}
}
while ( $timeLeft > $timeTheLastRunTook and ( $memoryUnlimited or $memoryLeft > $memoryTheLastRunTook ) );
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
@@ -0,0 +1,52 @@
<?php
/**
* @brief Task to generate sitemaps
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 30 Aug 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Task to generate sitemaps
*/
class _sitemapgenerator extends \IPS\Task
{
/**
* Execute
*
* @return void
*/
public function execute()
{
try
{
$generator = new \IPS\Sitemap;
$generator->buildNextSitemap();
}
catch( \Exception $e )
{
return $e->getMessage();
}
if( count( $generator->log ) )
{
return $generator->log;
}
else
{
return null;
}
}
}
+140
View File
@@ -0,0 +1,140 @@
<?php
/**
* @brief updatecheck Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 14 Aug 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* updatecheck Task
*/
class _updatecheck extends \IPS\Task
{
/**
* Execute
*
* @return mixed Message to log or NULL
*/
public function execute()
{
$fails = array();
/* Do IPS apps */
$versions = array();
foreach ( \IPS\Db::i()->select( '*', 'core_applications', \IPS\Db::i()->in( 'app_directory', \IPS\Application::$ipsApps ) ) as $app )
{
if ( $app['app_enabled'] )
{
$versions[] = $app['app_long_version'];
}
}
$version = min( $versions );
$url = \IPS\Http\Url::ips('updateCheck');
if ( \IPS\USE_DEVELOPMENT_BUILDS )
{
$url = $url->setQueryString( 'development', 1 );
}
try
{
$response = $url->setQueryString( 'version', $version )->request()->get()->decodeJson();
$coreApp = \IPS\Application::load('core');
$coreApp->update_version = json_encode( $response );
$coreApp->update_last_check = time();
$coreApp->save();
}
catch ( \Exception $e ) { }
/* Do everything else */
foreach ( \IPS\Db::i()->union(
array(
\IPS\Db::i()->select( "'core_applications' AS `table`, app_directory AS `id`, app_update_check AS `url`, app_update_last_check AS `last`, app_long_version AS `current`", 'core_applications', "( app_update_check<>'' AND app_update_check IS NOT NULL )" ),
\IPS\Db::i()->select( "'core_plugins' AS `table`, plugin_id AS id, plugin_update_check as url, plugin_update_check_last AS last, plugin_version_long AS `current`", 'core_plugins', "plugin_update_check<>'' AND plugin_update_check IS NOT NULL" ),
\IPS\Db::i()->select( "'core_themes' AS `table`, set_id AS `id`, set_update_check AS `url`, set_update_last_check AS `last`, set_long_version AS `current`", 'core_themes', "set_update_check<>'' AND set_update_check IS NOT NULL" )
),
'last ASC',
3
) as $row )
{
switch ( $row['table'] )
{
case 'core_applications':
$dataColumn = 'app_update_version';
$timeColumn = 'app_update_last_check';
$idColumn = 'app_directory';
/* Account for legacy applications */
try
{
$key = "__app_{$row['id']}";
$source = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( $key );
}
catch( \UnexpectedValueException $e )
{
continue 2;
}
catch( \UnderflowException $e )
{
continue 2;
}
break;
case 'core_plugins':
$dataColumn = 'plugin_update_check_data';
$timeColumn = 'plugin_update_check_last';
$idColumn = 'plugin_id';
$source = \IPS\Plugin::load( $row['id'] )->name;
break;
case 'core_themes':
$dataColumn = 'set_update_data';
$timeColumn = 'set_update_last_check';
$idColumn = 'set_id';
$key = "core_theme_set_title_{$row['id']}";
$source = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( $key );
break;
}
try
{
$url = \IPS\Http\Url::external( $row['url'] )->setQueryString( 'version', $row['current'] );
$response = $url->request()->get()->decodeJson();
\IPS\Db::i()->update( $row['table'], array(
$dataColumn => json_encode( array(
'version' => $response['version'],
'longversion' => $response['longversion'],
'released' => $response['released'],
'updateurl' => $response['updateurl'],
'releasenotes' => isset( $response['releasenotes'] ) ? $response['releasenotes'] : NULL
) ),
$timeColumn => time()
), array( "{$idColumn}=?", $row['id'] ) );
}
/* \RuntimeException catches BAD_JSON and \IPS\Http\Request\Exception both */
catch ( \RuntimeException $e )
{
$fails[] = $source . ": " . $e->getMessage();
}
}
if ( !empty( $fails ) )
{
return $fails;
}
return NULL;
}
}