Add Rebuild Entries job

This commit is contained in:
2026-07-02 18:06:32 +02:00
parent afd0f434db
commit 86f97c3103
12 changed files with 200 additions and 12 deletions

56
Job/EntriesCount.php Normal file
View 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');
}
}