$statement = WCF::getDB()->prepare($sql);
$statement->execute();
- $this->count = $statement->fetchSingleColumn();
+ $this->count = $statement->fetchSingleColumn() ?: 0;
}
#[\Override]
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
-class CommentRebuildDataWorker extends AbstractRebuildDataWorker
+final class CommentRebuildDataWorker extends AbstractLinearRebuildDataWorker
{
/**
* @inheritDoc
*/
protected $limit = 500;
- /**
- * @var HtmlInputProcessor
- */
- protected $htmlInputProcessor;
-
/**
* @inheritDoc
*/
- public function countObjects()
- {
- if ($this->count === null) {
- $this->count = 0;
- $sql = "SELECT MAX(commentID) AS commentID
- FROM wcf" . WCF_N . "_comment";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute();
- $row = $statement->fetchArray();
- if ($row !== false) {
- $this->count = $row['commentID'];
- }
- }
- }
+ protected $objectListClassName = CommentList::class;
- /**
- * @inheritDoc
- */
- protected function initObjectList()
- {
- $this->objectList = new CommentList();
- $this->objectList->sqlOrderBy = 'comment.commentID';
- }
+ private HtmlInputProcessor $htmlInputProcessor;
- /**
- * @inheritDoc
- */
+ #[\Override]
public function execute()
{
- $this->objectList->getConditionBuilder()->add(
- 'comment.commentID BETWEEN ? AND ?',
- [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]
- );
-
parent::execute();
- if (!\count($this->objectList)) {
+ if (\count($this->getObjectList()) === 0) {
return;
}
WCF::getDB()->commitTransaction();
}
- /**
- * @return HtmlInputProcessor
- */
- protected function getHtmlInputProcessor()
+ private function getHtmlInputProcessor(): HtmlInputProcessor
{
- if ($this->htmlInputProcessor === null) {
+ if (!isset($this->htmlInputProcessor)) {
$this->htmlInputProcessor = new HtmlInputProcessor();
}
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
-class CommentResponseRebuildDataWorker extends AbstractRebuildDataWorker
+final class CommentResponseRebuildDataWorker extends AbstractLinearRebuildDataWorker
{
/**
* @inheritDoc
*/
protected $limit = 500;
- /**
- * @var HtmlInputProcessor
- */
- protected $htmlInputProcessor;
-
/**
* @inheritDoc
*/
- public function countObjects()
- {
- if ($this->count === null) {
- $this->count = 0;
- $sql = "SELECT MAX(responseID) AS responseID
- FROM wcf" . WCF_N . "_comment_response";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute();
- $row = $statement->fetchArray();
- if ($row !== false) {
- $this->count = $row['responseID'];
- }
- }
- }
+ protected $objectListClassName = CommentResponseList::class;
- /**
- * @inheritDoc
- */
- protected function initObjectList()
- {
- $this->objectList = new CommentResponseList();
- $this->objectList->sqlOrderBy = 'comment_response.responseID';
- }
+ private HtmlInputProcessor $htmlInputProcessor;
- /**
- * @inheritDoc
- */
+ #[\Override]
public function execute()
{
- $this->objectList->getConditionBuilder()->add(
- 'comment_response.responseID BETWEEN ? AND ?',
- [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]
- );
-
parent::execute();
- if (!\count($this->objectList)) {
+ if (\count($this->getObjectList()) === 0) {
return;
}
WCF::getDB()->commitTransaction();
}
- /**
- * @return HtmlInputProcessor
- */
- protected function getHtmlInputProcessor()
+ private function getHtmlInputProcessor(): HtmlInputProcessor
{
- if ($this->htmlInputProcessor === null) {
+ if (!isset($this->htmlInputProcessor)) {
$this->htmlInputProcessor = new HtmlInputProcessor();
}
*
* @method LikeList getObjectList()
*/
-class LikeRebuildDataWorker extends AbstractRebuildDataWorker
+final class LikeRebuildDataWorker extends AbstractLinearRebuildDataWorker
{
/**
* @inheritDoc
*/
protected $limit = 10000;
- /**
- * @inheritDoc
- */
+ #[\Override]
protected function initObjectList()
{
parent::initObjectList();
$this->objectList->sqlOrderBy = 'like_table.objectTypeID, like_table.objectID, like_table.likeID';
}
- /**
- * @inheritDoc
- */
+ #[\Override]
public function execute()
{
parent::execute();
UserActivityPointHandler::getInstance()->reset('com.woltlab.wcf.like.activityPointEvent.receivedLikes');
// reset like object data
- $sql = "UPDATE wcf" . WCF_N . "_like_object
+ $sql = "UPDATE wcf1_like_object
SET likes = 0,
dislikes = 0,
- cumulativeLikes = 0,
+ cumulativeLikes = 0,
cachedReactions = NULL";
- $statement = WCF::getDB()->prepareStatement($sql);
+ $statement = WCF::getDB()->prepare($sql);
$statement->execute();
}
+ if (\count($this->getObjectList()) === 0) {
+ return;
+ }
+
$itemsToUser = [];
$likeObjectData = [];
foreach ($this->objectList as $like) {
}
// No objects are fetched. We can abort the execution.
- if (empty($likeObjectData)) {
+ if ($likeObjectData === []) {
return;
}
$condition->add('objectTypeID = ?', [$objectTypeID]);
$condition->add('objectID IN (?)', [\array_keys($objects)]);
$sql = "SELECT objectTypeID, objectID, objectUserID, likes, dislikes, cumulativeLikes, cachedReactions
- FROM wcf" . WCF_N . "_like_object
+ FROM wcf1_like_object
" . $condition;
- $objectStatement = WCF::getDB()->prepareStatement($sql);
+ $objectStatement = WCF::getDB()->prepare($sql);
$objectStatement->execute($condition->getParameters());
while ($row = $objectStatement->fetchArray()) {
$rows[$objectTypeID][$row['objectID']] = $row;
}
}
- $sql = "INSERT INTO wcf" . WCF_N . "_like_object
+ $sql = "INSERT INTO wcf1_like_object
(objectTypeID, objectID, objectUserID, likes, dislikes, cumulativeLikes, cachedReactions)
VALUES (?, ?, ?, ?, ?, ?, ?)";
- $insertStatement = WCF::getDB()->prepareStatement($sql);
+ $insertStatement = WCF::getDB()->prepare($sql);
- $sql = "UPDATE wcf" . WCF_N . "_like_object
+ $sql = "UPDATE wcf1_like_object
SET objectUserID = ?,
likes = ?,
dislikes = 0,
- cumulativeLikes = ?,
+ cumulativeLikes = ?,
cachedReactions = ?
WHERE objectTypeID = ?
AND objectID = ?";
- $updateStatement = WCF::getDB()->prepareStatement($sql);
+ $updateStatement = WCF::getDB()->prepare($sql);
WCF::getDB()->beginTransaction();
foreach ($likeObjectData as $objectTypeID => $objects) {
use wcf\data\user\UserList;
use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\event\EventHandler;
-use wcf\system\search\SearchIndexManager;
use wcf\system\user\activity\point\UserActivityPointHandler;
use wcf\system\WCF;
*
* @method UserList getObjectList()
*/
-class UserActivityPointItemsRebuildDataWorker extends AbstractRebuildDataWorker
+final class UserActivityPointItemsRebuildDataWorker extends AbstractLinearRebuildDataWorker
{
/**
* @inheritDoc
*/
protected $limit = 50;
- #[\Override]
- public function countObjects()
- {
- if ($this->count === null) {
- $sql = "SELECT MAX(userID) AS userID
- FROM wcf1_user";
- $statement = WCF::getDB()->prepare($sql);
- $statement->execute();
-
- $count = $statement->fetchSingleColumn();
- $this->count = $count ?: 0;
- }
- }
-
- #[\Override]
- protected function initObjectList()
- {
- $this->objectList = new $this->objectListClassName();
- $this->objectList->sqlOrderBy = 'user_table.userID';
- }
-
#[\Override]
public function execute()
{
- $this->objectList->getConditionBuilder()->add(
- 'user_table.userID BETWEEN ? AND ?',
- [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]
- );
-
- $this->objectList->readObjects();
+ parent::execute();
if (\count($this->getObjectList()) === 0) {
return;
}
- // The next two lines are copied from `AbstractRebuildDataWorker::execute()`
- // to prevent event listeners from failing because the object list
- // sometimes no longer contains objects.
- //
- // The return condition above is used to avoid the invocation of the
- // event listeners. Do not call `parent::execute()`!
- SearchIndexManager::getInstance()->beginBulkOperation();
- EventHandler::getInstance()->fireAction($this, 'execute');
-
// update activity points for positive reactions
$reactionObjectType = UserActivityPointHandler::getInstance()
->getObjectTypeByName('com.woltlab.wcf.like.activityPointEvent.receivedLikes');
$conditionBuilder->add('user_activity_point.objectTypeID = ?', [$reactionObjectType->objectTypeID]);
$conditionBuilder->add('user_activity_point.userID IN (?)', [$this->getObjectList()->getObjectIDs()]);
- $sql = "UPDATE wcf" . WCF_N . "_user_activity_point user_activity_point
- LEFT JOIN wcf" . WCF_N . "_user user_table
+ $sql = "UPDATE wcf1_user_activity_point user_activity_point
+ LEFT JOIN wcf1_user user_table
ON user_table.userID = user_activity_point.userID
SET user_activity_point.items = user_table.likesReceived,
user_activity_point.activityPoints = user_activity_point.items * ?
" . $conditionBuilder;
- $statement = WCF::getDB()->prepareStatement($sql);
+ $statement = WCF::getDB()->prepare($sql);
$statement->execute(\array_merge(
[$reactionObjectType->points],
$conditionBuilder->getParameters()
use wcf\data\user\UserProfileList;
use wcf\system\bbcode\BBCodeHandler;
use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\event\EventHandler;
use wcf\system\exception\SystemException;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\image\ImageHandler;
-use wcf\system\search\SearchIndexManager;
use wcf\system\user\storage\UserStorageHandler;
use wcf\system\WCF;
*
* @method UserList getObjectList()
*/
-class UserRebuildDataWorker extends AbstractRebuildDataWorker
+final class UserRebuildDataWorker extends AbstractLinearRebuildDataWorker
{
/**
* @inheritDoc
*/
protected $limit = 50;
- #[\Override]
- public function countObjects()
- {
- if ($this->count === null) {
- $sql = "SELECT MAX(userID) AS userID
- FROM wcf1_user";
- $statement = WCF::getDB()->prepare($sql);
- $statement->execute();
-
- $count = $statement->fetchSingleColumn();
- $this->count = $count ?: 0;
- }
- }
-
#[\Override]
protected function initObjectList()
{
- $this->objectList = new $this->objectListClassName();
+ parent::initObjectList();
+
$this->objectList->sqlSelects = 'user_option_value.userOption' . User::getUserOptionID('aboutMe') . ' AS aboutMe';
$this->objectList->sqlJoins = "
LEFT JOIN wcf" . WCF_N . "_user_option_value user_option_value
ON user_option_value.userID = user_table.userID";
- $this->objectList->sqlOrderBy = 'user_table.userID';
}
#[\Override]
public function execute()
{
- $this->objectList->getConditionBuilder()->add(
- 'user_table.userID BETWEEN ? AND ?',
- [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]
- );
-
- $this->objectList->readObjects();
+ parent::execute();
if (\count($this->getObjectList()) === 0) {
return;
}
- // The next two lines are copied from `AbstractRebuildDataWorker::execute()`
- // to prevent event listeners from failing because the object list
- // sometimes no longer contains objects.
- //
- // The return condition above is used to avoid the invocation of the
- // event listeners. Do not call `parent::execute()`!
- SearchIndexManager::getInstance()->beginBulkOperation();
- EventHandler::getInstance()->fireAction($this, 'execute');
-
$users = $userIDs = [];
foreach ($this->getObjectList() as $user) {
$users[] = new UserEditor($user);
// update article counter
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('user_table.userID IN (?)', [$userIDs]);
- $sql = "UPDATE wcf" . WCF_N . "_user user_table
+ $sql = "UPDATE wcf1_user user_table
SET articles = (
SELECT COUNT(*)
- FROM wcf" . WCF_N . "_article
+ FROM wcf1_article
WHERE userID = user_table.userID
)
" . $conditionBuilder;
- $statement = WCF::getDB()->prepareStatement($sql);
+ $statement = WCF::getDB()->prepare($sql);
$statement->execute($conditionBuilder->getParameters());
// update like counter
if (MODULE_LIKE) {
- $sql = "UPDATE wcf" . WCF_N . "_user user_table
+ $sql = "UPDATE wcf1_user user_table
SET";
$reactionTypeIDs = \array_keys(ReactionTypeCache::getInstance()->getReactionTypes());
$sql .= "
likesReceived = (
SELECT COUNT(*)
- FROM wcf" . WCF_N . "_like
+ FROM wcf1_like
WHERE objectUserID = user_table.userID
AND reactionTypeID IN (" . \implode(',', $reactionTypeIDs) . ")
)";
}
$sql .= " " . $conditionBuilder;
- $statement = WCF::getDB()->prepareStatement($sql);
+ $statement = WCF::getDB()->prepare($sql);
$statement->execute($conditionBuilder->getParameters());
}
// update trophy points
if (MODULE_TROPHY) {
- $sql = "UPDATE wcf" . WCF_N . "_user user_table
+ $sql = "UPDATE wcf1_user user_table
SET trophyPoints = (
SELECT COUNT(*)
- FROM wcf" . WCF_N . "_user_trophy user_trophy
- LEFT JOIN wcf" . WCF_N . "_trophy trophy
+ FROM wcf1_user_trophy user_trophy
+ LEFT JOIN wcf1_trophy trophy
ON user_trophy.trophyID = trophy.trophyID
- LEFT JOIN wcf" . WCF_N . "_category trophy_category
+ LEFT JOIN wcf1_category trophy_category
ON trophy.categoryID = trophy_category.categoryID
WHERE user_trophy.userID = user_table.userID
AND trophy.isDisabled = 0
AND trophy_category.isDisabled = 0
)
" . $conditionBuilder;
- $statement = WCF::getDB()->prepareStatement($sql);
+ $statement = WCF::getDB()->prepare($sql);
$statement->execute($conditionBuilder->getParameters());
}
// update signatures and about me
- $sql = "UPDATE wcf" . WCF_N . "_user_option_value
+ $sql = "UPDATE wcf1_user_option_value
SET userOption" . User::getUserOptionID('aboutMe') . " = ?
WHERE userID = ?";
- $statement = WCF::getDB()->prepareStatement($sql);
+ $statement = WCF::getDB()->prepare($sql);
// retrieve permissions
$userIDs = [];