Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,16 +12,27 @@
|
||||
namespace IPS\forums\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use DateTimeZone;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use IPS\Task\Exception;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* solvedStatsAggregation Task
|
||||
*/
|
||||
class _solvedStatsAggregation extends \IPS\Task
|
||||
class solvedStatsAggregation extends Task
|
||||
{
|
||||
/**
|
||||
* Aggregate yesterday's (server time 0:00:00 to 23:59:59) solve stats per forum. Depending when the task runs, it is possible for it to run multiple
|
||||
@@ -37,31 +48,31 @@ class _solvedStatsAggregation extends \IPS\Task
|
||||
* time: timestamp of the start of the day (so 0:00:00)
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : mixed
|
||||
{
|
||||
$timezone = new \DateTimeZone( \IPS\Settings::i()->reputation_timezone );
|
||||
$end = \IPS\DateTime::create()->setTimezone( $timezone )->sub( new \DateInterval( 'P1D' ) )->setTime( 23, 59 );
|
||||
$timezone = new DateTimeZone( Settings::i()->reputation_timezone );
|
||||
$end = DateTime::create()->setTimezone( $timezone )->sub( new DateInterval( 'P1D' ) )->setTime( 23, 59 );
|
||||
|
||||
/* Now to iterate over all forums that have solved enabled and crunch the statistics */
|
||||
foreach( \IPS\Db::i()->select( '*', 'forums_forums', [ '(' . \IPS\Db::i()->bitwiseWhere( \IPS\forums\Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers' ) . ') OR ( ' . \IPS\Db::i()->bitwiseWhere( \IPS\forums\Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers_moderator' ) . ' )' ] ) as $forum )
|
||||
foreach( Db::i()->select( '*', 'forums_forums', [ '( ' . Db::i()->bitwiseWhere( Forum::$bitOptions['forums_bitoptions'], 'bw_solved_set_by_moderator' ) . ' )' ] ) as $forum )
|
||||
{
|
||||
$start = \IPS\DateTime::ts( \IPS\forums\Forum::constructFromData( $forum )->getFirstSolvedTime() )->setTimezone( $timezone );
|
||||
$start = DateTime::ts( Forum::constructFromData( $forum )->getFirstSolvedTime() )->setTimezone( $timezone );
|
||||
|
||||
$where = [
|
||||
[ \IPS\Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ],
|
||||
[ \IPS\Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ],
|
||||
[ Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ],
|
||||
[ Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ],
|
||||
[ 'forum_id=?', $forum['id'] ],
|
||||
[ 'start_date > ? AND start_date < ?', $start->getTimestamp(), $end->getTimestamp() ]
|
||||
];
|
||||
|
||||
$total = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', $where )->first();
|
||||
$solved = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $where, [ [ 'core_solved_index.id IS NOT NULL' ] ] ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$avg = \IPS\Db::i()->select( 'AVG(CAST(core_solved_index.solved_date AS SIGNED)-forums_topics.start_date)', 'forums_topics', array_merge( $where, [ [ 'core_solved_index.id IS NOT NULL' ] ] ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$total = Db::i()->select( 'COUNT(*)', 'forums_topics', $where )->first();
|
||||
$solved = Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $where, [ [ 'core_solved_index.id IS NOT NULL AND type=?', 'solved' ] ] ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$avg = Db::i()->select( 'AVG(CAST(core_solved_index.solved_date AS SIGNED)-forums_topics.start_date)', 'forums_topics', array_merge( $where, [ [ 'core_solved_index.id IS NOT NULL AND type=?', 'solved' ] ] ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
|
||||
\IPS\Db::i()->delete( 'core_statistics', [ 'type=? and time=? and value_1=?', 'solved', $end->getTimestamp(), $forum['id'] ] );
|
||||
\IPS\Db::i()->insert( 'core_statistics', [
|
||||
Db::i()->delete( 'core_statistics', [ 'type=? and time=? and value_1=?', 'solved', $end->getTimestamp(), $forum['id'] ] );
|
||||
Db::i()->insert( 'core_statistics', [
|
||||
'type' => 'solved',
|
||||
'value_1' => $forum['id'],
|
||||
'value_2' => $total,
|
||||
|
||||
Reference in new issue
Block a user