56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace RomhackPlaza\Master\Job;
|
||
|
|
|
||
|
|
use RomhackPlaza\Master\Helper\Laravel;
|
||
|
|
use XF\Entity\User;
|
||
|
|
use XF\Job\AbstractRebuildJob;
|
||
|
|
use XF\Phrase;
|
||
|
|
|
||
|
|
class EntriesCount extends AbstractRebuildJob {
|
||
|
|
|
||
|
|
protected function getNextIds($start, $batch): array
|
||
|
|
{
|
||
|
|
$db = $this->app->db();
|
||
|
|
|
||
|
|
return $db->fetchAllColumn(
|
||
|
|
$db->limit(
|
||
|
|
'SELECT user_id
|
||
|
|
FROM xf_user
|
||
|
|
WHERE user_id > ?
|
||
|
|
ORDER BY user_id',
|
||
|
|
$batch
|
||
|
|
),
|
||
|
|
$start
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
private function countPublishedEntriesByUserId($userId): int
|
||
|
|
{
|
||
|
|
$db = Laravel::db();
|
||
|
|
|
||
|
|
if( $userId instanceof User )
|
||
|
|
$userId = $userId->user_id;
|
||
|
|
|
||
|
|
return $db->fetchOne(
|
||
|
|
"SELECT COUNT(*) FROM entries WHERE state = 'published' AND user_id = ?", $userId
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function rebuildById($id): void
|
||
|
|
{
|
||
|
|
$count = $this->countPublishedEntriesByUserId($id);
|
||
|
|
|
||
|
|
$this->app->db()->update(
|
||
|
|
'xf_user',
|
||
|
|
['rhpz_entry_count' => $count],
|
||
|
|
'user_id = ?',
|
||
|
|
$id
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function getStatusType(): Phrase
|
||
|
|
{
|
||
|
|
return \XF::phrase('entries');
|
||
|
|
}
|
||
|
|
}
|