From 6830354677dbe6434bfc89b537b45bdb09ac1273 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 10:24:53 +0530 Subject: [PATCH 01/20] Increase version --- addon.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon.json b/addon.json index 3b55c4f..c50a778 100644 --- a/addon.json +++ b/addon.json @@ -2,8 +2,8 @@ "legacy_addon_id": "", "title": "Change Content Owner or Date", "description": "This add-on allows allows you to change the owner of content or the timestamp content.", - "version_id": 2001370, - "version_string": "2.0.13", + "version_id": 2001470, + "version_string": "2.0.14", "dev": "TickTackk", "dev_url": "https://xenforo.com/community/members/90375/", "faq_url": "", From c7dc44d40d3fe306e339d08527a23d98220f463d Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 10:28:00 +0530 Subject: [PATCH 02/20] closes #75 --- CHANGELOG.md | 4 ++++ InlineMod/AbstractOwnerChangerAction.php | 22 +++++++++++----------- Service/Content/AbstractOwnerChanger.php | 20 +++++++++----------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce6df5a..6185549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========================== +## 2.0.14 (`2001470`) + +- **Fix:** Time interval does not apply correctly (#75) + ## 2.0.13 (`2001370`) - **Change:** Drop PHP Calendar extension requirement (#79) diff --git a/InlineMod/AbstractOwnerChangerAction.php b/InlineMod/AbstractOwnerChangerAction.php index 4766f39..b1c057c 100644 --- a/InlineMod/AbstractOwnerChangerAction.php +++ b/InlineMod/AbstractOwnerChangerAction.php @@ -258,12 +258,22 @@ protected function getOwnerChangerSvc(AbstractCollection $contents) : AbstractOw */ protected function applyToEntity(Entity $entity, array $options) : void { + if ($this->contentNewDateCounter === null) + { + $this->contentNewDateCounter = 1; + } + else + { + $this->contentNewDateCounter++; + } + $entities = new ArrayCollection([ $entity->getEntityId() => $entity ]); $ownerChangerSvc = $this->getOwnerChangerSvc($entities); - $newOwner = $this->newOwner; + $ownerChangerSvc->setContentNewDateCounter($this->contentNewDateCounter); + $newOwner = $this->newOwner; if ($newOwner && $entity->canChangeOwner($newOwner)) { $ownerChangerSvc->setNewOwner($newOwner); @@ -293,17 +303,7 @@ protected function applyToEntity(Entity $entity, array $options) : void } $ownerChangerSvc->setPerformValidations(false); - $ownerChangerSvc->setContentNewDateCounter($this->contentNewDateCounter); $ownerChangerSvc->save(); - - if ($this->contentNewDateCounter === null) - { - $this->contentNewDateCounter = 0; - } - else - { - $this->contentNewDateCounter++; - } } /** diff --git a/Service/Content/AbstractOwnerChanger.php b/Service/Content/AbstractOwnerChanger.php index cfccc6b..b5ed7de 100644 --- a/Service/Content/AbstractOwnerChanger.php +++ b/Service/Content/AbstractOwnerChanger.php @@ -382,23 +382,21 @@ public function getNewTimestamp(Entity $content) :? int { if ($this->contentNewDateCounter === null) // first content { - $this->contentNewDateCounter = 0; + $this->contentNewDateCounter = 1; } - else + + foreach ($timeIntervals AS $unit => $value) { - foreach ($timeIntervals AS $unit => $value) + if (!$value) { - if (!$value) - { - continue; - } - - $counter = $value + $this->contentNewDateCounter; - $dateTime->modify("+{$counter} {$unit}"); + continue; } - $this->contentNewDateCounter++; + $counter = $value * $this->contentNewDateCounter; + $dateTime->modify("+{$counter} {$unit}"); } + + $this->contentNewDateCounter++; } $this->contentNewDateMapping[$uniqueKey] = $dateTime->getTimestamp(); From ddbc58f2b244e94cc758885ad49731c11f98ad11 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 10:33:45 +0530 Subject: [PATCH 03/20] Remove redundant phpstorm inspection suppressions --- ChangeOwner/AbstractHandler.php | 2 -- ControllerPlugin/Content.php | 2 +- Entity/ContentTrait.php | 3 ++- Service/Content/EditorTrait.php | 2 -- _output/entity_hint.php | 1 - 5 files changed, 3 insertions(+), 7 deletions(-) diff --git a/ChangeOwner/AbstractHandler.php b/ChangeOwner/AbstractHandler.php index 1850293..0d1db70 100644 --- a/ChangeOwner/AbstractHandler.php +++ b/ChangeOwner/AbstractHandler.php @@ -81,7 +81,6 @@ public function getOldOwner(Entity $content): UserEntity $oldContentOwner = null; try { - /** @noinspection PhpUndefinedFieldInspection */ $oldContentOwner = $content->User; } catch (\InvalidArgumentException $e) @@ -229,7 +228,6 @@ public function canNewOwnerViewContent(Entity $content, UserEntity $newOwner, &$ return \XF::asVisitor($newOwner, function () use($content, $error) { - /** @noinspection PhpUndefinedMethodInspection */ return $content->canView($error); }); } diff --git a/ControllerPlugin/Content.php b/ControllerPlugin/Content.php index 107dfec..0ced7c5 100644 --- a/ControllerPlugin/Content.php +++ b/ControllerPlugin/Content.php @@ -116,7 +116,7 @@ public function extendEditorService(Entity $content, EditorSvcInterface $editor) * @throws ExceptionReply * @throws \Exception */ - protected function setNewOwnerDateTimeAndInterval(AbstractService $service, /** @noinspection PhpUnusedParameterInspection */ContentEntityInterface $content) : void + protected function setNewOwnerDateTimeAndInterval(AbstractService $service, ContentEntityInterface $content) : void { $handler = $content->getChangeOwnerHandler(true); $newOwnerUsername = $this->filter('username', 'str'); diff --git a/Entity/ContentTrait.php b/Entity/ContentTrait.php index 08fbd69..245119f 100644 --- a/Entity/ContentTrait.php +++ b/Entity/ContentTrait.php @@ -15,9 +15,10 @@ trait ContentTrait * @param bool $throw * * @return AbstractHandler + * * @throws \Exception */ - public function getChangeOwnerHandler(bool $throw = false) : AbstractHandler + public function getChangeOwnerHandler(bool $throw = false) :? AbstractHandler { $contentType = $this->getEntityContentType(); $handlerClass = \XF::app()->getContentTypeFieldValue($contentType, 'change_owner_handler_class'); diff --git a/Service/Content/EditorTrait.php b/Service/Content/EditorTrait.php index 3ad47b3..7eae6d1 100644 --- a/Service/Content/EditorTrait.php +++ b/Service/Content/EditorTrait.php @@ -96,7 +96,6 @@ protected function assertOwnerChangerHasBeenSetup() : void */ protected function _validate() { - /** @noinspection PhpUndefinedClassInspection */ $errors = parent::_validate(); if ($this->ownerChanger) @@ -119,7 +118,6 @@ protected function _save() $db = $this->db(); $db->beginTransaction(); - /** @noinspection PhpUndefinedClassInspection */ $content = parent::_save(); if ($this->ownerChanger) diff --git a/_output/entity_hint.php b/_output/entity_hint.php index 38c2062..135fea5 100644 --- a/_output/entity_hint.php +++ b/_output/entity_hint.php @@ -5,7 +5,6 @@ namespace XF\Entity { - /** @noinspection PhpUndefinedClassInspection */ /** @noinspection PhpMissingDocCommentInspection */ class LikedContent extends \XF\Mvc\Entity\Entity {} } \ No newline at end of file From ea8689d1e465c4f2d79ba59922c585c8c126045c Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 10:40:14 +0530 Subject: [PATCH 04/20] Use consistent parameter names --- Entity/ContentInterface.php | 2 +- InlineMod/AbstractOwnerChangerAction.php | 26 ++++++++++++------------ XF/Entity/Post.php | 8 ++++---- XF/Entity/ProfilePost.php | 6 +++--- XF/Entity/ProfilePostComment.php | 6 +++--- XF/Entity/Thread.php | 8 ++++---- XFA/CSVGrapher/Entity/Graph.php | 6 +++--- XFMG/Entity/Album.php | 6 +++--- XFMG/Entity/Comment.php | 6 +++--- XFMG/Entity/MediaItem.php | 6 +++--- 10 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Entity/ContentInterface.php b/Entity/ContentInterface.php index cdf988c..5f1963d 100644 --- a/Entity/ContentInterface.php +++ b/Entity/ContentInterface.php @@ -33,5 +33,5 @@ public function canChangeDate(int $newDate = null, &$error = null) : bool; * * @return AbstractHandler */ - public function getChangeOwnerHandler(bool $throw = false) : AbstractHandler; + public function getChangeOwnerHandler(bool $throw = false) :? AbstractHandler; } \ No newline at end of file diff --git a/InlineMod/AbstractOwnerChangerAction.php b/InlineMod/AbstractOwnerChangerAction.php index b1c057c..566466f 100644 --- a/InlineMod/AbstractOwnerChangerAction.php +++ b/InlineMod/AbstractOwnerChangerAction.php @@ -82,17 +82,17 @@ protected function getContentTypePlural() : string abstract protected function getFormViewClass() : string; /** - * @param AbstractCollection|ContentEntityInterface[] $contents + * @param AbstractCollection|ContentEntityInterface[] $entities * @param Controller $controller * * @return ReplyView */ - public function renderForm(AbstractCollection $contents, Controller $controller) : ReplyView + public function renderForm(AbstractCollection $entities, Controller $controller) : ReplyView { $canChangeOwner = false; $canChangeDate = false; - foreach ($contents AS $content) + foreach ($entities AS $content) { if ($content->canChangeOwner()) { @@ -118,21 +118,21 @@ public function renderForm(AbstractCollection $contents, Controller $controller) 'canChangeOwner' => $canChangeOwner, 'canChangeDate' => $canChangeDate, - 'contents' => $contents, - 'total' => \count($contents) + 'contents' => $entities, + 'total' => \count($entities) ]; return $controller->view($this->getFormViewClass(), 'inline_mod_content_change_owner', $viewParams); } /** - * @param AbstractCollection $contents + * @param AbstractCollection $entities * @param array $options * @param $error * * @return bool */ - protected function canApplyInternal(AbstractCollection $contents, array $options, &$error) : bool + protected function canApplyInternal(AbstractCollection $entities, array $options, &$error) : bool { $newOwnerUsername = $options['username']; if ($newOwnerUsername) @@ -145,19 +145,19 @@ protected function canApplyInternal(AbstractCollection $contents, array $options $this->newOwner = $user; } - return parent::canApplyInternal($contents, $options, $error); + return parent::canApplyInternal($entities, $options, $error); } /** - * @param Entity|ContentEntityInterface $content + * @param Entity|ContentEntityInterface $entity * @param array $options * @param null $error * * @return bool */ - protected function canApplyToEntity(Entity $content, array $options, &$error = null) : bool + protected function canApplyToEntity(Entity $entity, array $options, &$error = null) : bool { - return $content->canChangeOwner(null, $error) || $content->canChangeDate(null, $error); + return $entity->canChangeOwner(null, $error) || $entity->canChangeDate(null, $error); } /** @@ -175,12 +175,12 @@ public function getBaseOptions() : array } /** - * @param AbstractCollection $contents + * @param AbstractCollection $entities * @param Request $request * * @return array */ - public function getFormOptions(AbstractCollection $contents, Request $request) : array + public function getFormOptions(AbstractCollection $entities, Request $request) : array { $options = [ 'username' => $request->filter('username', 'str'), diff --git a/XF/Entity/Post.php b/XF/Entity/Post.php index 25e3f6a..aabad14 100644 --- a/XF/Entity/Post.php +++ b/XF/Entity/Post.php @@ -19,12 +19,12 @@ class Post extends XFCP_Post implements ContentInterface use ContentTrait; /** - * @param UserEntity|null $newUser + * @param UserEntity|null $newOwner * @param null $error * * @return bool */ - public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool + public function canChangeOwner(UserEntity $newOwner = null, &$error = null): bool { $thread = $this->Thread; if (!$thread) @@ -37,12 +37,12 @@ public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool return false; } - if ($newUser && $this->getExistingValue('user_id') === $newUser->user_id) + if ($newOwner && $this->getExistingValue('user_id') === $newOwner->user_id) { return false; } - return $thread->canChangePostOwner($newUser, $error); + return $thread->canChangePostOwner($newOwner, $error); } /** diff --git a/XF/Entity/ProfilePost.php b/XF/Entity/ProfilePost.php index 72d5372..1228d8e 100644 --- a/XF/Entity/ProfilePost.php +++ b/XF/Entity/ProfilePost.php @@ -16,12 +16,12 @@ class ProfilePost extends XFCP_ProfilePost implements ContentInterface use ContentTrait; /** - * @param UserEntity|null $newUser + * @param UserEntity|null $newOwner * @param null $error * * @return bool */ - public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool + public function canChangeOwner(UserEntity $newOwner = null, &$error = null): bool { $visitor = \XF::visitor(); @@ -30,7 +30,7 @@ public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool return false; } - if ($newUser && $this->getExistingValue('user_id') === $newUser->user_id) + if ($newOwner && $this->getExistingValue('user_id') === $newOwner->user_id) { return false; } diff --git a/XF/Entity/ProfilePostComment.php b/XF/Entity/ProfilePostComment.php index 03ac121..98cf2e3 100644 --- a/XF/Entity/ProfilePostComment.php +++ b/XF/Entity/ProfilePostComment.php @@ -16,12 +16,12 @@ class ProfilePostComment extends XFCP_ProfilePostComment implements ContentInter use ContentTrait; /** - * @param UserEntity|null $newUser + * @param UserEntity|null $newOwner * @param null $error * * @return bool */ - public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool + public function canChangeOwner(UserEntity $newOwner = null, &$error = null): bool { $visitor = \XF::visitor(); @@ -30,7 +30,7 @@ public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool return false; } - if ($newUser && $this->getExistingValue('user_id') === $newUser->user_id) + if ($newOwner && $this->getExistingValue('user_id') === $newOwner->user_id) { return false; } diff --git a/XF/Entity/Thread.php b/XF/Entity/Thread.php index f888805..2724c91 100644 --- a/XF/Entity/Thread.php +++ b/XF/Entity/Thread.php @@ -19,12 +19,12 @@ class Thread extends XFCP_Thread implements ContentInterface use ContentTrait; /** - * @param UserEntity|null $newUser + * @param UserEntity|null $newOwner * @param null $error * * @return bool */ - public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool + public function canChangeOwner(UserEntity $newOwner = null, &$error = null): bool { $forum = $this->Forum; if (!$forum) @@ -32,12 +32,12 @@ public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool return false; } - if ($newUser && $this->getExistingValue('user_id') === $newUser->user_id) + if ($newOwner && $this->getExistingValue('user_id') === $newOwner->user_id) { return false; } - return $forum->canChangePostOwner($newUser, $error); + return $forum->canChangePostOwner($newOwner, $error); } /** diff --git a/XFA/CSVGrapher/Entity/Graph.php b/XFA/CSVGrapher/Entity/Graph.php index 6ada136..04665ab 100644 --- a/XFA/CSVGrapher/Entity/Graph.php +++ b/XFA/CSVGrapher/Entity/Graph.php @@ -16,12 +16,12 @@ class Graph extends XFCP_Graph implements ContentInterface use ContentTrait; /** - * @param UserEntity|null $newUser + * @param UserEntity|null $newOwner * @param null $error * * @return bool */ - public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool + public function canChangeOwner(UserEntity $newOwner = null, &$error = null): bool { $visitor = \XF::visitor(); if (!$visitor->user_id || !$this->user_id) @@ -29,7 +29,7 @@ public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool return false; } - if ($newUser && $this->getExistingValue('user_id') === $newUser->user_id) + if ($newOwner && $this->getExistingValue('user_id') === $newOwner->user_id) { return false; } diff --git a/XFMG/Entity/Album.php b/XFMG/Entity/Album.php index 2d473d5..7438728 100644 --- a/XFMG/Entity/Album.php +++ b/XFMG/Entity/Album.php @@ -16,12 +16,12 @@ class Album extends XFCP_Album implements ContentInterface use ContentTrait; /** - * @param UserEntity|null $newUser + * @param UserEntity|null $newOwner * @param null $error * * @return bool */ - public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool + public function canChangeOwner(UserEntity $newOwner = null, &$error = null): bool { $visitor = \XF::visitor(); if (!$visitor->user_id) @@ -29,7 +29,7 @@ public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool return false; } - if ($newUser && $this->getExistingValue('user_id') === $newUser->user_id) + if ($newOwner && $this->getExistingValue('user_id') === $newOwner->user_id) { return false; } diff --git a/XFMG/Entity/Comment.php b/XFMG/Entity/Comment.php index 4f83317..c5b3823 100644 --- a/XFMG/Entity/Comment.php +++ b/XFMG/Entity/Comment.php @@ -16,12 +16,12 @@ class Comment extends XFCP_Comment implements ContentInterface use ContentTrait; /** - * @param UserEntity|null $newUser + * @param UserEntity|null $newOwner * @param null $error * * @return bool */ - public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool + public function canChangeOwner(UserEntity $newOwner = null, &$error = null): bool { $visitor = \XF::visitor(); if (!$visitor->user_id) @@ -35,7 +35,7 @@ public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool return false; } - if ($newUser && $this->getExistingValue('user_id') === $newUser->user_id) + if ($newOwner && $this->getExistingValue('user_id') === $newOwner->user_id) { return false; } diff --git a/XFMG/Entity/MediaItem.php b/XFMG/Entity/MediaItem.php index edc97b8..b8fdf07 100644 --- a/XFMG/Entity/MediaItem.php +++ b/XFMG/Entity/MediaItem.php @@ -16,12 +16,12 @@ class MediaItem extends XFCP_MediaItem implements ContentInterface use ContentTrait; /** - * @param UserEntity|null $newUser + * @param UserEntity|null $newOwner * @param null $error * * @return bool */ - public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool + public function canChangeOwner(UserEntity $newOwner = null, &$error = null): bool { $visitor = \XF::visitor(); if (!$visitor->user_id) @@ -29,7 +29,7 @@ public function canChangeOwner(UserEntity $newUser = null, &$error = null): bool return false; } - if ($newUser && $this->getExistingValue('user_id') === $newUser->user_id) + if ($newOwner && $this->getExistingValue('user_id') === $newOwner->user_id) { return false; } From ceca85f6de99beebcb155a166028d8071496c3bf Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 10:51:03 +0530 Subject: [PATCH 05/20] Even more code clean up --- ChangeOwner/AbstractHandler.php | 1 - ControllerPlugin/Content.php | 7 +------ Entity/ContentTrait.php | 2 ++ InlineMod/AbstractOwnerChangerAction.php | 2 ++ Job/Upgrade/RebuildAttachmentOwner.php | 7 ++++--- Job/Upgrade/RebuildModeratorLogAction.php | 1 - Pub/Controller/ContentTrait.php | 2 ++ Service/Content/AbstractOwnerChanger.php | 9 +++++---- Service/Content/EditorTrait.php | 5 ++--- XF/ChangeOwner/Post.php | 2 ++ XF/ChangeOwner/ProfilePost.php | 2 ++ XF/ChangeOwner/ProfilePostComment.php | 2 ++ XFA/CSVGrapher/ChangeOwner/Graph.php | 2 ++ XFA/CSVGrapher/Entity/Graph.php | 2 ++ XFA/CSVGrapher/Pub/Controller/Graph.php | 2 ++ XFA/CSVGrapher/Service/Graph/Editor.php | 2 ++ XFA/CSVGrapher/Service/Graph/OwnerChanger.php | 2 ++ XFMG/ChangeOwner/Comment.php | 2 ++ 18 files changed, 36 insertions(+), 18 deletions(-) diff --git a/ChangeOwner/AbstractHandler.php b/ChangeOwner/AbstractHandler.php index 0d1db70..0510907 100644 --- a/ChangeOwner/AbstractHandler.php +++ b/ChangeOwner/AbstractHandler.php @@ -78,7 +78,6 @@ public function getChangeOwnerLink(Entity $content) : string */ public function getOldOwner(Entity $content): UserEntity { - $oldContentOwner = null; try { $oldContentOwner = $content->User; diff --git a/ControllerPlugin/Content.php b/ControllerPlugin/Content.php index 0ced7c5..9c7e66a 100644 --- a/ControllerPlugin/Content.php +++ b/ControllerPlugin/Content.php @@ -124,11 +124,6 @@ protected function setNewOwnerDateTimeAndInterval(AbstractService $service, Cont if ($newOwnerUsername) { $newOwner = $this->assertViewableUser($newOwnerUsername); - if (!$newOwner) - { - throw $this->exception($this->error(\XF::phrase('please_enter_valid_name'))); - } - if (!$handler->canChangeOwner($content, $newOwner, $error)) { throw $this->exception($this->noPermission($error)); @@ -215,7 +210,7 @@ protected function assertViewableUser(string $username, array $extraWith = []) : $extraWith[] = 'Option'; $extraWith[] = 'Privacy'; $extraWith[] = 'Profile'; - array_unique($extraWith); + $extraWith = array_unique($extraWith); /** @var UserEntity $user */ $user = $this->em->findOne('XF:User', ['username' => $username], $extraWith); diff --git a/Entity/ContentTrait.php b/Entity/ContentTrait.php index 245119f..189faed 100644 --- a/Entity/ContentTrait.php +++ b/Entity/ContentTrait.php @@ -1,5 +1,7 @@ app()->findByContentType($contentType, $id); if (!$content) { @@ -95,7 +96,7 @@ protected function rebuildById($id) : void // current owner $oldUser = $changeOwnerHandler->getOldOwner($content); - if (!$oldUser) + if (!$oldUser->exists()) { return; } diff --git a/Job/Upgrade/RebuildModeratorLogAction.php b/Job/Upgrade/RebuildModeratorLogAction.php index 905e11c..36366bf 100644 --- a/Job/Upgrade/RebuildModeratorLogAction.php +++ b/Job/Upgrade/RebuildModeratorLogAction.php @@ -5,7 +5,6 @@ use XF\Entity\ModeratorLog as ModeratorLogEntity; use XF\Job\AbstractRebuildJob; use XF\App as BaseApp; -use XF\Mvc\Entity\Finder; use XF\Phrase; /** diff --git a/Pub/Controller/ContentTrait.php b/Pub/Controller/ContentTrait.php index a9e8d82..a85c3db 100644 --- a/Pub/Controller/ContentTrait.php +++ b/Pub/Controller/ContentTrait.php @@ -1,5 +1,7 @@ 59) + if ($newTime['minute'] < 0 || $newTime['minute'] > 59) { throw new \InvalidArgumentException('Invalid minute provided.'); } @@ -652,7 +654,7 @@ protected function _validate() : array { $handler = $this->getHandler(); - foreach ($this->contents AS $id => $content) + foreach ($this->contents AS $content) { if (!$handler->canNewOwnerViewContent($content, $newOwner, $error)) { @@ -743,7 +745,7 @@ protected function _save() : void $logger = $this->app->logger(); $logModerator = $this->getLogModerator(); - foreach ($this->contents AS $id => $content) + foreach ($this->contents AS $content) { $this->additionalEntitySave($content); @@ -795,7 +797,6 @@ protected function _save() : void /** * @param Entity|ContentEntityInterface $content * - * @throws \XF\Db\Exception * @throws \XF\PrintableException * @throws \Exception */ diff --git a/Service/Content/EditorTrait.php b/Service/Content/EditorTrait.php index 7eae6d1..83627dd 100644 --- a/Service/Content/EditorTrait.php +++ b/Service/Content/EditorTrait.php @@ -1,9 +1,10 @@ db(); $db->beginTransaction(); diff --git a/XF/ChangeOwner/Post.php b/XF/ChangeOwner/Post.php index 9b88752..74ce21f 100644 --- a/XF/ChangeOwner/Post.php +++ b/XF/ChangeOwner/Post.php @@ -43,6 +43,8 @@ public function getContentRoute(Entity $content): string * @param Entity|ExtendedPostEntity $content * * @return string|\XF\Phrase + * + * @noinspection PhpReturnDocTypeMismatchInspection */ public function getContentTitle(Entity $content) { diff --git a/XF/ChangeOwner/ProfilePost.php b/XF/ChangeOwner/ProfilePost.php index ee79d15..bcb9165 100644 --- a/XF/ChangeOwner/ProfilePost.php +++ b/XF/ChangeOwner/ProfilePost.php @@ -44,6 +44,8 @@ public function getOldTimestamp(Entity $content): int * @param Entity|ExtendedProfilePostEntity $content * * @return string|\XF\Phrase + * + * @noinspection PhpReturnDocTypeMismatchInspection */ public function getContentTitle(Entity $content) { diff --git a/XF/ChangeOwner/ProfilePostComment.php b/XF/ChangeOwner/ProfilePostComment.php index e00c6fd..2d6687c 100644 --- a/XF/ChangeOwner/ProfilePostComment.php +++ b/XF/ChangeOwner/ProfilePostComment.php @@ -50,6 +50,8 @@ public function getOldTimestamp(Entity $content): int * @param Entity|ExtendedProfilePostCommentEntity $content * * @return string|void|\XF\Phrase + * + * @noinspection PhpReturnDocTypeMismatchInspection */ public function getContentTitle(Entity $content) { diff --git a/XFA/CSVGrapher/ChangeOwner/Graph.php b/XFA/CSVGrapher/ChangeOwner/Graph.php index 9372d7a..e4bbd27 100644 --- a/XFA/CSVGrapher/ChangeOwner/Graph.php +++ b/XFA/CSVGrapher/ChangeOwner/Graph.php @@ -1,5 +1,7 @@ Date: Tue, 8 Feb 2022 11:43:13 +0530 Subject: [PATCH 06/20] closes #84 --- CHANGELOG.md | 1 + XF/Service/Post/OwnerChanger.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6185549..425a014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG ## 2.0.14 (`2001470`) - **Fix:** Time interval does not apply correctly (#75) +- **Fix:** Changing post date does not rebuild first/last post info (#84) ## 2.0.13 (`2001370`) diff --git a/XF/Service/Post/OwnerChanger.php b/XF/Service/Post/OwnerChanger.php index 9db590e..216087a 100644 --- a/XF/Service/Post/OwnerChanger.php +++ b/XF/Service/Post/OwnerChanger.php @@ -149,6 +149,8 @@ protected function additionalEntitySave(Entity $content): void } /** + * @version 2.0.14 + * * @param Entity|ExtendedPostEntity $content * * @throws \Exception @@ -162,6 +164,13 @@ protected function postContentSave(Entity $content): void $threadRepo = $this->getThreadRepo(); $threadRepo->rebuildThreadPostPositions($content->thread_id); } + + $thread = $content->Thread; + if ($thread) + { + $thread->rebuildCounters(); + $thread->saveIfChanged(); + } } /** From cf71c77b83877ba62187e9d55bd19f4d9ca39273 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 11:45:48 +0530 Subject: [PATCH 07/20] closes #85 --- CHANGELOG.md | 3 ++- XF/Service/ProfilePostComment/OwnerChanger.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 425a014..a7929f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ CHANGELOG ## 2.0.14 (`2001470`) - **Fix:** Time interval does not apply correctly (#75) -- **Fix:** Changing post date does not rebuild first/last post info (#84) +- **Fix:** Changing post date does not rebuild counters on thread (#84) +- **Fix:** Changing profile post comment does not rebuild counters on profile post (#85) ## 2.0.13 (`2001370`) diff --git a/XF/Service/ProfilePostComment/OwnerChanger.php b/XF/Service/ProfilePostComment/OwnerChanger.php index e329abe..6b0fab6 100644 --- a/XF/Service/ProfilePostComment/OwnerChanger.php +++ b/XF/Service/ProfilePostComment/OwnerChanger.php @@ -65,6 +65,22 @@ protected function changeContentDate(Entity $content, int $newDate): Entity return $content; } + /** + * @since 2.0.14 + * + * @param Entity|ExtendedProfilePostCommentEntity $content + * + * @return void + */ + protected function postContentSave(Entity $content): void + { + $profilePost = $content->ProfilePost; + if ($profilePost) + { + $profilePost->rebuildCounters(); + } + } + /** * @param Entity|ExtendedProfilePostCommentEntity $content */ From ad4b8260bfb012e334dde33ecbac30f18f121a87 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 11:49:02 +0530 Subject: [PATCH 08/20] closes #86 --- CHANGELOG.md | 1 + XF/Service/Post/OwnerChanger.php | 2 ++ XF/Service/ProfilePostComment/OwnerChanger.php | 3 +++ XF/Service/Thread/OwnerChanger.php | 15 +++++++++++++++ 4 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7929f3..31318bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG - **Fix:** Time interval does not apply correctly (#75) - **Fix:** Changing post date does not rebuild counters on thread (#84) - **Fix:** Changing profile post comment does not rebuild counters on profile post (#85) +- **Fix:** Changing thread date does not rebuild counters on thread (#86) ## 2.0.13 (`2001370`) diff --git a/XF/Service/Post/OwnerChanger.php b/XF/Service/Post/OwnerChanger.php index 216087a..9d33292 100644 --- a/XF/Service/Post/OwnerChanger.php +++ b/XF/Service/Post/OwnerChanger.php @@ -12,6 +12,8 @@ use XF\Repository\Thread as ThreadRepo; /** + * @version 2.0.14 + * * Class OwnerChanger * * @package TickTackk\ChangeContentOwner\XF\Service\Post diff --git a/XF/Service/ProfilePostComment/OwnerChanger.php b/XF/Service/ProfilePostComment/OwnerChanger.php index 6b0fab6..19fbb5c 100644 --- a/XF/Service/ProfilePostComment/OwnerChanger.php +++ b/XF/Service/ProfilePostComment/OwnerChanger.php @@ -8,6 +8,8 @@ use XF\Mvc\Entity\Entity; /** + * @version 2.0.14 + * * Class OwnerChanger * * @package TickTackk\ChangeContentOwner\XF\Service\ProfilePostComment @@ -78,6 +80,7 @@ protected function postContentSave(Entity $content): void if ($profilePost) { $profilePost->rebuildCounters(); + $profilePost->saveIfChanged(); } } diff --git a/XF/Service/Thread/OwnerChanger.php b/XF/Service/Thread/OwnerChanger.php index 42cf266..156b7b3 100644 --- a/XF/Service/Thread/OwnerChanger.php +++ b/XF/Service/Thread/OwnerChanger.php @@ -11,6 +11,8 @@ use XF\Entity\ThreadUserPost as ThreadUserPostEntity; /** + * @version 2.0.14 + * * Class OwnerChanger * * @package TickTackk\ChangeContentOwner\XF\Service\Thread @@ -146,6 +148,19 @@ protected function changeContentDate(Entity $content, int $newDate): Entity return $content; } + /** + * @since 2.0.14 + * + * @param Entity|ExtendedThreadEntity $content + * + * @return void + */ + protected function postContentSave(Entity $content): void + { + $content->rebuildCounters(); + $content->saveIfChanged(); + } + /** * @param Entity|ExtendedThreadEntity $content * From 880908729fcf5e1afdeb0b41b9648ffc5a4b47e3 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 12:00:07 +0530 Subject: [PATCH 09/20] closes #87 --- CHANGELOG.md | 1 + XFMG/Service/Comment/OwnerChanger.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31318bb..5d81fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ CHANGELOG - **Fix:** Changing post date does not rebuild counters on thread (#84) - **Fix:** Changing profile post comment does not rebuild counters on profile post (#85) - **Fix:** Changing thread date does not rebuild counters on thread (#86) +- **Fix:** Changing media/album comment does not rebuild counters on media/album (#87) ## 2.0.13 (`2001370`) diff --git a/XFMG/Service/Comment/OwnerChanger.php b/XFMG/Service/Comment/OwnerChanger.php index 6c05627..9fc37a4 100644 --- a/XFMG/Service/Comment/OwnerChanger.php +++ b/XFMG/Service/Comment/OwnerChanger.php @@ -6,8 +6,12 @@ use TickTackk\ChangeContentOwner\XFMG\Entity\Comment as ExtendedCommentEntity; use XF\Entity\User as UserEntity; use XF\Mvc\Entity\Entity; +use XFMG\Entity\Album as AlbumEntity; +use XFMG\Entity\MediaItem as MediaItemEntity; /** + * @version 2.0.14 + * * Class OwnerChanger * * @package TickTackk\ChangeContentOwner\XFMG\Service\Comment @@ -75,6 +79,23 @@ protected function changeContentDate(Entity $content, int $newDate): Entity return $content; } + /** + * @since 2.0.14 + * + * @param Entity|ExtendedCommentEntity $content + * + * @return void + */ + protected function postContentSave(Entity $content): void + { + $container = $content->Content; + if ($container instanceof MediaItemEntity || $container instanceof AlbumEntity) + { + $container->rebuildCounters(); + $container->saveIfChanged(); + } + } + /** * @param Entity|ExtendedCommentEntity $content * @throws \XF\PrintableException From d0df9b8bceeea1100e21d5e0bb8bed0246dc3a86 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 12:21:34 +0530 Subject: [PATCH 10/20] Rebuild last comment info instead all counters #87 --- CHANGELOG.md | 2 +- XFMG/Service/Comment/OwnerChanger.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d81fcb..d868f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ CHANGELOG - **Fix:** Changing post date does not rebuild counters on thread (#84) - **Fix:** Changing profile post comment does not rebuild counters on profile post (#85) - **Fix:** Changing thread date does not rebuild counters on thread (#86) -- **Fix:** Changing media/album comment does not rebuild counters on media/album (#87) +- **Fix:** Changing media/album comment does not rebuild last comment info on media/album (#87) ## 2.0.13 (`2001370`) diff --git a/XFMG/Service/Comment/OwnerChanger.php b/XFMG/Service/Comment/OwnerChanger.php index 9fc37a4..dc9e4b1 100644 --- a/XFMG/Service/Comment/OwnerChanger.php +++ b/XFMG/Service/Comment/OwnerChanger.php @@ -91,7 +91,7 @@ protected function postContentSave(Entity $content): void $container = $content->Content; if ($container instanceof MediaItemEntity || $container instanceof AlbumEntity) { - $container->rebuildCounters(); + $container->rebuildLastCommentInfo(); $container->saveIfChanged(); } } From 6421d80313e51011f41c24991a57cd8332aa0324 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 12:24:30 +0530 Subject: [PATCH 11/20] Rebuild last post info on thread and forum instead of just rebuilding all counters #84 --- CHANGELOG.md | 2 +- XF/Service/Post/OwnerChanger.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d868f50..e42c531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG ## 2.0.14 (`2001470`) - **Fix:** Time interval does not apply correctly (#75) -- **Fix:** Changing post date does not rebuild counters on thread (#84) +- **Fix:** Changing post date does not rebuild last post info on thread/forum (#84) - **Fix:** Changing profile post comment does not rebuild counters on profile post (#85) - **Fix:** Changing thread date does not rebuild counters on thread (#86) - **Fix:** Changing media/album comment does not rebuild last comment info on media/album (#87) diff --git a/XF/Service/Post/OwnerChanger.php b/XF/Service/Post/OwnerChanger.php index 9d33292..fb6cfbf 100644 --- a/XF/Service/Post/OwnerChanger.php +++ b/XF/Service/Post/OwnerChanger.php @@ -170,8 +170,15 @@ protected function postContentSave(Entity $content): void $thread = $content->Thread; if ($thread) { - $thread->rebuildCounters(); + $thread->rebuildLastPostInfo(); $thread->saveIfChanged(); + + $forum = $thread->Forum; + if ($forum) + { + $forum->rebuildLastPost(); + $forum->saveIfChanged(); + } } } From 8c70e615410aaed11128db14e6b99a0777c4ca87 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 12:26:36 +0530 Subject: [PATCH 12/20] Rebuild last post info on forum instead of rebuilding all counters when changing thread date #86 --- CHANGELOG.md | 2 +- XF/Service/Thread/OwnerChanger.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e42c531..995c4f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ CHANGELOG - **Fix:** Time interval does not apply correctly (#75) - **Fix:** Changing post date does not rebuild last post info on thread/forum (#84) - **Fix:** Changing profile post comment does not rebuild counters on profile post (#85) -- **Fix:** Changing thread date does not rebuild counters on thread (#86) +- **Fix:** Changing thread date does not rebuild last post info on forum (#86) - **Fix:** Changing media/album comment does not rebuild last comment info on media/album (#87) ## 2.0.13 (`2001370`) diff --git a/XF/Service/Thread/OwnerChanger.php b/XF/Service/Thread/OwnerChanger.php index 156b7b3..1d75a75 100644 --- a/XF/Service/Thread/OwnerChanger.php +++ b/XF/Service/Thread/OwnerChanger.php @@ -157,8 +157,12 @@ protected function changeContentDate(Entity $content, int $newDate): Entity */ protected function postContentSave(Entity $content): void { - $content->rebuildCounters(); - $content->saveIfChanged(); + $forum = $content->Forum; + if ($forum) + { + $forum->rebuildLastPost(); + $forum->saveIfChanged(); + } } /** From 7fb150dac17c82849665bfeb89c670f44be86155 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Tue, 8 Feb 2022 12:28:37 +0530 Subject: [PATCH 13/20] closes #85 --- CHANGELOG.md | 2 +- XF/Service/ProfilePostComment/OwnerChanger.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 995c4f4..a69f390 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ CHANGELOG - **Fix:** Time interval does not apply correctly (#75) - **Fix:** Changing post date does not rebuild last post info on thread/forum (#84) -- **Fix:** Changing profile post comment does not rebuild counters on profile post (#85) +- **Fix:** Changing profile post comment date does not rebuild first comment, last comment infos and latest comment ids on profile post (#85) - **Fix:** Changing thread date does not rebuild last post info on forum (#86) - **Fix:** Changing media/album comment does not rebuild last comment info on media/album (#87) diff --git a/XF/Service/ProfilePostComment/OwnerChanger.php b/XF/Service/ProfilePostComment/OwnerChanger.php index 19fbb5c..ac7cb91 100644 --- a/XF/Service/ProfilePostComment/OwnerChanger.php +++ b/XF/Service/ProfilePostComment/OwnerChanger.php @@ -79,7 +79,9 @@ protected function postContentSave(Entity $content): void $profilePost = $content->ProfilePost; if ($profilePost) { - $profilePost->rebuildCounters(); + $profilePost->rebuildFirstCommentInfo(); + $profilePost->rebuildLastCommentInfo(); + $profilePost->rebuildLatestCommentIds(); $profilePost->saveIfChanged(); } } From 32607dca52b58c8b1426b6708481378fd1bc63f3 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Thu, 10 Feb 2022 09:01:51 +0530 Subject: [PATCH 14/20] Update LICENSE.md --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index e306318..d183806 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018-2021 TickTackk +Copyright (c) 2018-2022 TickTackk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 4dacd585ce1eb2e6b82f9227c68abfd54546fa69 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Thu, 10 Feb 2022 09:03:20 +0530 Subject: [PATCH 15/20] Fix typo in add-on description --- addon.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.json b/addon.json index c50a778..5c9622c 100644 --- a/addon.json +++ b/addon.json @@ -1,7 +1,7 @@ { "legacy_addon_id": "", "title": "Change Content Owner or Date", - "description": "This add-on allows allows you to change the owner of content or the timestamp content.", + "description": "This add-on allows you to change the owner of content or the timestamp content.", "version_id": 2001470, "version_string": "2.0.14", "dev": "TickTackk", From 195884649dff098a82c92a44b2d3c3c70e471847 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Thu, 10 Feb 2022 09:04:22 +0530 Subject: [PATCH 16/20] Rebuild readme files --- README.md | 8 ++++---- _dev/resource_description.html | 2 +- _dev/resource_description.txt | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 838188f..ef3d5c0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Change Content Owner or Date for XenForo 2.0.10+ Description ----------- -This add-on allows allows you to change the owner of content or the timestamp content. +This add-on allows you to change the owner of content or the timestamp content. Requirements ------------ @@ -16,9 +16,9 @@ Options #### Change content owner -| Name | Description | -| --------------------- | ----------- | -| Default time interval | | +| Name | Description | +|---|---| +| Default time interval | | Permissions ----------- diff --git a/_dev/resource_description.html b/_dev/resource_description.html index d0ed9bd..f283842 100644 --- a/_dev/resource_description.html +++ b/_dev/resource_description.html @@ -1,2 +1,2 @@ -

Change Content Owner or Date for XenForo 2.0.10+

Description

This add-on allows allows you to change the owner of content or the timestamp content.

Requirements

  • PHP 7.1.0+

Options

Change content owner

NameDescription
Default time interval

Permissions

XFMG: Album moderator permissions

  • Can change album owner
  • Can change album date

Profile post moderator permissions

  • Can change profile post owner
  • Can change profile post date
  • Can change profile post comment owner
  • Can change profile post comment date

XFMG: Media moderator permissions

  • Can change media owner
  • Can change media date

XFMG: Comment moderator permissions

  • Can change comment owner
  • Can change comment date

Forum moderator permissions

  • Can change thread owner
  • Can change thread date
  • Can change post owner
  • Can change post date

License

+

Change Content Owner or Date for XenForo 2.0.10+

Description

This add-on allows you to change the owner of content or the timestamp content.

Requirements

  • PHP 7.1.0+

Options

Change content owner

NameDescription
Default time interval

Permissions

XFMG: Album moderator permissions

  • Can change album owner
  • Can change album date

Profile post moderator permissions

  • Can change profile post owner
  • Can change profile post date
  • Can change profile post comment owner
  • Can change profile post comment date

XFMG: Media moderator permissions

  • Can change media owner
  • Can change media date

XFMG: Comment moderator permissions

  • Can change comment owner
  • Can change comment date

Forum moderator permissions

  • Can change thread owner
  • Can change thread date
  • Can change post owner
  • Can change post date

License

This project is licensed under the MIT License - see the LICENSE.md file for details. \ No newline at end of file diff --git a/_dev/resource_description.txt b/_dev/resource_description.txt index 1a1c89f..c74f621 100644 --- a/_dev/resource_description.txt +++ b/_dev/resource_description.txt @@ -1,6 +1,6 @@ [HEADING=1]Change Content Owner or Date for XenForo 2.0.10+[/HEADING] [HEADING=1]Description[/HEADING] -This add-on allows allows you to change the owner of content or the timestamp content. +This add-on allows you to change the owner of content or the timestamp content. [HEADING=1]Requirements[/HEADING] [LIST] [*]PHP 7.1.0+ From 9e5f49f19bd3a83a579de547be7c699e810f24fb Mon Sep 17 00:00:00 2001 From: TickTackk Date: Thu, 10 Feb 2022 12:41:37 +0530 Subject: [PATCH 17/20] Drop _no_upload directory --- _no_upload/LICENSE.md | 21 --------------------- _no_upload/README.md | 38 -------------------------------------- 2 files changed, 59 deletions(-) delete mode 100644 _no_upload/LICENSE.md delete mode 100644 _no_upload/README.md diff --git a/_no_upload/LICENSE.md b/_no_upload/LICENSE.md deleted file mode 100644 index d58333b..0000000 --- a/_no_upload/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018-2019 TickTackk - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/_no_upload/README.md b/_no_upload/README.md deleted file mode 100644 index f79686e..0000000 --- a/_no_upload/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# ChangeContentOwnerForXF2 -This add-on allows changing content owner and date for supported content types. - -## Options -##### Default new date time interval: -> Default value for time interval used when changing date of multiple contents. - -## Permissions -###### XenForo: -*Forum moderator permissions*: -- Can change thread owner -- Can change thread date -- Can change post owner -- Can change post date - -*Profile post moderator permissions:* -- Can change profile post owner -- Can change profile post date -- Can change profile post comment owner -- Can change profile post comment date - ------------- - -###### XenForo Media Gallery: -*XFMG: Media moderator permissions*: -- Can change media owner -- Can change media date - -*XFMG: Album moderator permissions*: -- Can change album owner -- Can change album date - -*XFMG: Comment moderator permissions* -- Can change comment owner -- Can change comment date - -## License -This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details \ No newline at end of file From a80e539cd26490038eeb0c0e7995d8158055cc59 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Thu, 10 Feb 2022 14:50:50 +0530 Subject: [PATCH 18/20] Add upgrade steps to rebuild last content dates --- Setup.php | 432 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 432 insertions(+) diff --git a/Setup.php b/Setup.php index 02dc637..6dfb92e 100644 --- a/Setup.php +++ b/Setup.php @@ -279,6 +279,438 @@ public function upgrade2001170Step1() : void } } + /** + * @since 2.0.14 + * + * @param array $stepParams + * + * @return array|bool + */ + public function upgrade2001470Step1(array $stepParams) + { + $position = !empty($stepParams[0]) ? $stepParams[0] : 0; + $perPage = 1000; + + $db = $this->db(); + $db->beginTransaction(); + + if (!isset($stepData['max'])) + { + $stepData['max'] = $db->fetchOne("SELECT MAX(thread_id) FROM xf_thread"); + } + + $threadIds = $db->fetchAllColumn($db->limit( + " + SELECT DISTINCT post.thread_id + FROM xf_post AS post + INNER JOIN xf_thread AS thread + ON (post.thread_id = thread.thread_id) + WHERE post.message_state = 'visible' + AND thread.last_post_date < post.post_date + AND thread.thread_id > ? + ORDER BY post.thread_id ASC + ", $perPage + ), $position); + if (!$threadIds) + { + $db->commit(); + return true; + } + + $startTime = microtime(true); + $maxRunTime = $this->app()->config('jobMaxRunTime'); + + foreach ($threadIds AS $threadId) + { + $position = $threadId; + + $lastPost = $db->fetchRow(" + SELECT post_id, post_date, user_id, username + FROM xf_post USE INDEX (thread_id_post_date) + WHERE thread_id = ? + AND message_state = 'visible' + ORDER BY post_date DESC + LIMIT 1 + ", $threadId); + if (!$lastPost) // This can be first post as well :) + { + continue; + } + + $db->update('xf_thread', [ + 'last_post_id' => (int) $lastPost['post_id'], + 'last_post_date' => (int) $lastPost['post_date'], + 'last_post_user_id' => (int) $lastPost['user_id'], + 'last_post_username' => $lastPost['username'] ?: '-' + ], 'thread_id = ?', $threadId); + + if ($maxRunTime && microtime(true) - $startTime > $maxRunTime) + { + break; + } + } + + $db->commit(); + + return [ + $position, + "{$position} / {$stepData['max']}", + $stepData + ]; + } + + /** + * @since 2.0.14 + * + * @param array $stepParams + * + * @return array|bool + */ + public function upgrade2001470Step2(array $stepParams) + { + $position = !empty($stepParams[0]) ? $stepParams[0] : 0; + $perPage = 1000; + + $db = $this->db(); + $db->beginTransaction(); + + if (!isset($stepData['max'])) + { + $stepData['max'] = $db->fetchOne("SELECT MAX(node_id) FROM xf_forum"); + } + + $nodeIds = $db->fetchAllColumn($db->limit( + " + SELECT DISTINCT thread.node_id + FROM xf_thread AS thread + INNER JOIN xf_post AS post + ON (post.thread_id = thread.thread_id) + WHERE thread.discussion_state = 'visible' + AND post.message_state = 'visible' + AND post.post_date > thread.last_post_date + AND thread.last_post_id <> post.post_id + AND thread.node_id > ? + ORDER BY thread.node_id + ", $perPage + ), $position); + if (!$nodeIds) + { + $db->commit(); + return true; + } + + $startTime = microtime(true); + $maxRunTime = $this->app()->config('jobMaxRunTime'); + + foreach ($nodeIds AS $nodeId) + { + $position = $nodeId; + + $lastThread = $db->fetchRow(" + SELECT * + FROM xf_thread + WHERE node_id = ? + AND discussion_state = 'visible' + AND discussion_type <> 'redirect' + ORDER BY last_post_date DESC + LIMIT 1 + ", $nodeId); + if (!$lastThread) + { + $lastThread = [ + 'post_id' => 0, + 'post_date' => 0, + 'user_id' => 0, + 'username' => '', // this should be empty string or '-' ? + 'thread_id' => 0, + 'title' => '', + 'prefix_id' => 0 + ]; + } + + $db->update('xf_forum', [ + 'last_post_id' => (int) $lastThread['post_id'], + 'last_post_date' => (int) $lastThread['post_date'], + 'last_post_user_id' => (int) $lastThread['user_id'], + 'last_post_username' => $lastThread['username'] ?: '-', + 'last_thread_id' => (int) $lastThread['thread_id'], + 'last_thread_title' => (string) $lastThread['title'], + 'last_thread_prefix_id' => (int) $lastThread['prefix_id'] + ], 'node_id = ?', $nodeId); + + if ($maxRunTime && microtime(true) - $startTime > $maxRunTime) + { + break; + } + } + + $db->commit(); + + return [ + $position, + "{$position} / {$stepData['max']}", + $stepData + ]; + } + + /** + * @since 2.0.14 + * + * @param array $stepParams + * + * @return array|bool + */ + public function upgrade2001470Step3(array $stepParams) + { + $position = !empty($stepParams[0]) ? $stepParams[0] : 0; + $perPage = 1000; + + $db = $this->db(); + $db->beginTransaction(); + + if (!isset($stepData['max'])) + { + $stepData['max'] = $db->fetchOne("SELECT MAX(node_id) FROM xf_forum"); + } + + $profilePostIds = $db->fetchAllColumn($db->limit( + " + SELECT DISTINCT comment.profile_post_id + FROM xf_profile_post_comment AS comment + INNER JOIN xf_profile_post AS profile_post + ON (comment.profile_post_id = profile_post.profile_post_id) + WHERE comment.message_state = 'visible' + AND ((profile_post.first_comment_date < comment.comment_date) OR (profile_post.last_comment_date > comment.comment_date)) + AND comment.profile_post_id > ? + ORDER BY comment.profile_post_id ASC + ", $perPage + ), $position); + if (!$profilePostIds) + { + $db->commit(); + return true; + } + + $startTime = microtime(true); + $maxRunTime = $this->app()->config('jobMaxRunTime'); + + foreach ($profilePostIds AS $profilePostId) + { + $position = $profilePostId; + + $firstComment = $db->fetchRow(" + SELECT profile_post_comment_id, comment_date, user_id, username + FROM xf_profile_post_comment + WHERE profile_post_id = ? + AND message_state = 'visible' + ORDER BY comment_date + LIMIT 1 + ", $profilePostId); + if ($firstComment) + { + $lastComment = $db->fetchRow(" + SELECT profile_post_comment_id, comment_date, user_id, username + FROM xf_profile_post_comment + WHERE profile_post_id = ? + AND message_state = 'visible' + ORDER BY comment_date DESC + LIMIT 1 + ", $profilePostId); // this can be the first comment as well ;) + } + else + { + $firstComment = [ + 'profile_post_comment_id' => 0, + 'comment_date' => 0, + 'user_id' => 0, + 'username' => '' + ]; + $lastComment = $firstComment; + } + + $latestCommentIds = []; + if ($firstComment['profile_post_comment_id']) + { + $comments = $db->fetchAllKeyed($db->limit( + " + SELECT profile_post_id, profile_post_comment_id, message_state, user_id + FROM xf_profile_post_comment + WHERE profile_post_id = ? + ORDER BY comment_date DESC + ", 20 + ), 'profile_post_comment_id', $profilePostId); + + $visCount = 0; + $latestComments = []; + + foreach ($comments AS $commentId => $comment) + { + if ($comment['message_state'] === 'visible') + { + $visCount++; + } + + $latestComments[$commentId] = [$comment['message_state'], $comment['user_id']]; + + if ($visCount === 3) + { + break; + } + } + + $latestCommentIds = array_reverse($latestComments, true); + } + + $db->update('xf_profile_post', [ + 'first_comment_date' => (int) $firstComment['profile_post_comment_id'], + 'last_comment_date' => (int) $lastComment['profile_post_comment_id'], + 'latest_comment_ids' => json_encode($latestCommentIds) + ], 'profile_post_id = ?', $profilePostId); + + if ($maxRunTime && microtime(true) - $startTime > $maxRunTime) + { + break; + } + } + + $db->commit(); + + return [ + $position, + "{$position} / {$stepData['max']}", + $stepData + ]; + } + + /** + * @since 2.0.14 + * + * @param array $stepParams + * + * @return array|bool + */ + public function upgrade2001470Step4(array $stepParams) + { + return $this->rebuildXFMGContentLastComment( + $stepParams, + 'xf_mg_media_item', + 'media_id', + 'xfmg_media' + ); + } + + /** + * @since 2.0.14 + * + * @param array $stepParams + * + * @return array|bool + */ + public function upgrade2001470Step5(array $stepParams) + { + return $this->rebuildXFMGContentLastComment( + $stepParams, + 'xf_mg_album', + 'album_id', + 'xfmg_album' + ); + } + + /** + * @since 2.0.14 + * + * @param array $stepParams + * @param string $tableName + * @param string $primaryKey + * @param string $contentType + * @param int $perPage + * + * @return array|bool + */ + protected function rebuildXFMGContentLastComment( + array $stepParams, + string $tableName, + string $primaryKey, + string $contentType, + int $perPage = 1000 + ) + { + $position = !empty($stepParams[0]) ? $stepParams[0] : 0; + + $db = $this->db(); + $db->beginTransaction(); + + if (!isset($stepData['max'])) + { + $stepData['max'] = $db->fetchOne("SELECT MAX({$primaryKey}) FROM {$tableName}"); + } + + $quotedContentType = $db->quote($contentType); + + $contentIds = $db->fetchAllColumn($db->limit( + " + SELECT DISTINCT comment.content_id + FROM xf_mg_comment AS comment + INNER JOIN {$tableName} AS content + ON (content.{$primaryKey} = comment.content_id AND comment.content_type = {$quotedContentType}) + WHERE comment.content_type = {$quotedContentType} + AND comment.content_id > ? + AND comment.comment_state = 'visible' + AND content.last_comment_date < comment.comment_date + ORDER BY comment.content_id ASC + ", $perPage + ), $position); + if (!$contentIds) + { + $db->commit(); + return true; + } + + $startTime = microtime(true); + $maxRunTime = $this->app()->config('jobMaxRunTime'); + + foreach ($contentIds AS $contentId) + { + $position = $contentId; + $lastComment = $db->fetchRow(" + SELECT comment_id AS last_comment_id, + comment_date AS last_comment_date, + user_id AS last_comment_user_id, + username AS last_comment_username + FROM xf_mg_comment + WHERE content_id = ? + AND content_type = ? + AND comment_state = 'visible' + ORDER BY comment_date DESC + LIMIT 1 + ", [$contentId, $contentType]); + if (!$lastComment) + { + $lastComment = [ + 'comment_id' => 0, + 'comment_date' => 0, + 'user_id' => 0, + 'username' => '' + ]; + } + + $db->update($tableName, $lastComment, "{$primaryKey} = ?", $contentId); + + if ($maxRunTime && microtime(true) - $startTime > $maxRunTime) + { + break; + } + } + + $db->commit(); + + return [ + $position, + "{$position} / {$stepData['max']}", + $stepData + ]; + } + /** * @param array $errors * @param array $warnings From 5552898891db2f58f6fdf8834ab167ed7009c5b1 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Sat, 12 Feb 2022 19:32:10 +0530 Subject: [PATCH 19/20] Use partial output if json_encode() fails for latest_comment_ids --- Setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup.php b/Setup.php index 6dfb92e..371163e 100644 --- a/Setup.php +++ b/Setup.php @@ -564,7 +564,7 @@ public function upgrade2001470Step3(array $stepParams) $db->update('xf_profile_post', [ 'first_comment_date' => (int) $firstComment['profile_post_comment_id'], 'last_comment_date' => (int) $lastComment['profile_post_comment_id'], - 'latest_comment_ids' => json_encode($latestCommentIds) + 'latest_comment_ids' => json_encode($latestCommentIds, JSON_PARTIAL_OUTPUT_ON_ERROR) ], 'profile_post_id = ?', $profilePostId); if ($maxRunTime && microtime(true) - $startTime > $maxRunTime) From e54e014a25bbd29846551d97499a875b3d4147a5 Mon Sep 17 00:00:00 2001 From: TickTackk Date: Sun, 13 Feb 2022 11:52:22 +0530 Subject: [PATCH 20/20] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69f390..fe03edf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ CHANGELOG - **Fix:** Changing thread date does not rebuild last post info on forum (#86) - **Fix:** Changing media/album comment does not rebuild last comment info on media/album (#87) +On upgrade: Will attempt to rebuild last post info for both thread and forum, first and last profile post comment date with the latest comment ids for profile posts and last comment date for media items and albums. + ## 2.0.13 (`2001370`) - **Change:** Drop PHP Calendar extension requirement (#79)