Files
XenForoRomhackPlazaAddon/Job/EntriesCount.php

56 lines
1.2 KiB
PHP
Raw Normal View History

2026-07-02 18:06:32 +02:00
<?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');
}
}