Add Rebuild Entries job
This commit is contained in:
56
Job/EntriesCount.php
Normal file
56
Job/EntriesCount.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user