Skip to content

Commit

Permalink
Merge pull request #90 from ticktackk/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ticktackk authored Feb 13, 2022
2 parents 6025510 + e54e014 commit 25e5a90
Show file tree
Hide file tree
Showing 40 changed files with 630 additions and 156 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
CHANGELOG
==========================

## 2.0.14 (`2001470`)

- **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 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)

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)
Expand Down
3 changes: 0 additions & 3 deletions ChangeOwner/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ public function getChangeOwnerLink(Entity $content) : string
*/
public function getOldOwner(Entity $content): UserEntity
{
$oldContentOwner = null;
try
{
/** @noinspection PhpUndefinedFieldInspection */
$oldContentOwner = $content->User;
}
catch (\InvalidArgumentException $e)
Expand Down Expand Up @@ -229,7 +227,6 @@ public function canNewOwnerViewContent(Entity $content, UserEntity $newOwner, &$

return \XF::asVisitor($newOwner, function () use($content, $error)
{
/** @noinspection PhpUndefinedMethodInspection */
return $content->canView($error);
});
}
Expand Down
9 changes: 2 additions & 7 deletions ControllerPlugin/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,14 @@ 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');

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));
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Entity/ContentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion Entity/ContentTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** @noinspection PhpMultipleClassDeclarationsInspection */

namespace TickTackk\ChangeContentOwner\Entity;

use TickTackk\ChangeContentOwner\ChangeOwner\AbstractHandler;
Expand All @@ -15,9 +17,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');
Expand Down
50 changes: 26 additions & 24 deletions InlineMod/AbstractOwnerChangerAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** @noinspection PhpMultipleClassDeclarationsInspection */

namespace TickTackk\ChangeContentOwner\InlineMod;

use TickTackk\ChangeContentOwner\Entity\ContentInterface as ContentEntityInterface;
Expand Down Expand Up @@ -82,17 +84,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())
{
Expand All @@ -118,21 +120,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)
Expand All @@ -145,19 +147,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);
}

/**
Expand All @@ -175,12 +177,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'),
Expand Down Expand Up @@ -258,12 +260,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);
Expand Down Expand Up @@ -293,17 +305,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++;
}
}

/**
Expand Down
7 changes: 4 additions & 3 deletions Job/Upgrade/RebuildAttachmentOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace TickTackk\ChangeContentOwner\Job\Upgrade;

use TickTackk\ChangeContentOwner\ChangeOwner\AbstractHandler as AbstractChangeOwnerHandler;
use XF\Entity\Attachment as AttachmentEntity;
use TickTackk\ChangeContentOwner\Entity\ContentTrait as ContentEntityTrait;
use XF\Job\AbstractRebuildJob;
use XF\App as BaseApp;
use XF\Mvc\Entity\Entity;
Expand Down Expand Up @@ -65,6 +65,7 @@ protected function getNextIds($start, $batch) : array
* @param int $id
*
* @throws \XF\Db\Exception
* @throws \Exception
*/
protected function rebuildById($id) : void
{
Expand All @@ -74,7 +75,7 @@ protected function rebuildById($id) : void
return;
}

/** @var Entity $content */
/** @var Entity|ContentEntityTrait $content */
$content = $this->app()->findByContentType($contentType, $id);
if (!$content)
{
Expand All @@ -95,7 +96,7 @@ protected function rebuildById($id) : void

// current owner
$oldUser = $changeOwnerHandler->getOldOwner($content);
if (!$oldUser)
if (!$oldUser->exists())
{
return;
}
Expand Down
1 change: 0 additions & 1 deletion Job/Upgrade/RebuildModeratorLogAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions Pub/Controller/ContentTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** @noinspection PhpMultipleClassDeclarationsInspection */

namespace TickTackk\ChangeContentOwner\Pub\Controller;

use TickTackk\ChangeContentOwner\ControllerPlugin\Content as ContentPlugin;
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -16,9 +16,9 @@ Options

#### Change content owner

| Name | Description |
| --------------------- | ----------- |
| Default time interval | |
| Name | Description |
|---|---|
| Default time interval | |

Permissions
-----------
Expand Down
29 changes: 14 additions & 15 deletions Service/Content/AbstractOwnerChanger.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** @noinspection PhpMultipleClassDeclarationsInspection */

namespace TickTackk\ChangeContentOwner\Service\Content;

use TickTackk\ChangeContentOwner\ChangeOwner\AbstractHandler;
Expand Down Expand Up @@ -269,7 +271,7 @@ public function setNewTime(array $newTime) : void
throw new \InvalidArgumentException('Invalid hour provided.');
}

if ($newTime['minute'] < 0 || $newTime['hour'] > 59)
if ($newTime['minute'] < 0 || $newTime['minute'] > 59)
{
throw new \InvalidArgumentException('Invalid minute provided.');
}
Expand Down Expand Up @@ -382,23 +384,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();
Expand Down Expand Up @@ -654,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))
{
Expand Down Expand Up @@ -745,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);

Expand Down Expand Up @@ -797,7 +797,6 @@ protected function _save() : void
/**
* @param Entity|ContentEntityInterface $content
*
* @throws \XF\Db\Exception
* @throws \XF\PrintableException
* @throws \Exception
*/
Expand Down
Loading

0 comments on commit 25e5a90

Please sign in to comment.