kopia lustrzana https://github.com/nextcloud/social
details result
Signed-off-by: Maxence Lange <maxence@artificial-owl.com> fix Signed-off-by: Maxence Lange <maxence@artificial-owl.com> fix Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/691/head
rodzic
dbd85cff3b
commit
dab2b22415
|
@ -31,13 +31,13 @@ declare(strict_types=1);
|
||||||
namespace OCA\Social\Command;
|
namespace OCA\Social\Command;
|
||||||
|
|
||||||
|
|
||||||
|
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||||
use Exception;
|
use Exception;
|
||||||
use OC\Core\Command\Base;
|
use OC\Core\Command\Base;
|
||||||
use OCA\Social\Service\CheckService;
|
use OCA\Social\Service\CheckService;
|
||||||
use OCA\Social\Service\MiscService;
|
use OCA\Social\Service\MiscService;
|
||||||
use OCA\Social\Service\PushService;
|
use OCA\Social\Service\PushService;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\Push\Exceptions\PushInstallException;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -46,6 +46,9 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
class CheckInstall extends Base {
|
class CheckInstall extends Base {
|
||||||
|
|
||||||
|
|
||||||
|
use TArrayTools;
|
||||||
|
|
||||||
|
|
||||||
/** @var IUserManager */
|
/** @var IUserManager */
|
||||||
private $userManager;
|
private $userManager;
|
||||||
|
|
||||||
|
@ -86,7 +89,8 @@ class CheckInstall extends Base {
|
||||||
parent::configure();
|
parent::configure();
|
||||||
$this->setName('social:check:install')
|
$this->setName('social:check:install')
|
||||||
->addOption(
|
->addOption(
|
||||||
'push', '', InputOption::VALUE_REQUIRED, 'a local account used to test integration to Nextcloud Push',
|
'push', '', InputOption::VALUE_REQUIRED,
|
||||||
|
'a local account used to test integration to Nextcloud Push',
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
->setDescription('Check the integrity of the installation');
|
->setDescription('Check the integrity of the installation');
|
||||||
|
@ -100,9 +104,14 @@ class CheckInstall extends Base {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||||
$this->checkService->checkInstallationStatus();
|
$result = $this->checkService->checkInstallationStatus();
|
||||||
|
|
||||||
$this->checkPushApp($input, $output);
|
if ($this->checkPushApp($input, $output)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->writeln('- ' . $this->getInt('invalidFollowers', $result, 0) . ' invalid followers removed');
|
||||||
|
$output->writeln('- ' . $this->getInt('invalidNotes', $result, 0) . ' invalid notes removed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,11 +119,15 @@ class CheckInstall extends Base {
|
||||||
* @param InputInterface $input
|
* @param InputInterface $input
|
||||||
* @param OutputInterface $output
|
* @param OutputInterface $output
|
||||||
*
|
*
|
||||||
|
* @return bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function checkPushApp(InputInterface $input, OutputInterface $output) {
|
private function checkPushApp(InputInterface $input, OutputInterface $output): bool {
|
||||||
$userId = $input->getOption('push');
|
$userId = $input->getOption('push');
|
||||||
if ($userId !== '') {
|
if ($userId === '') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$user = $this->userManager->get($userId);
|
$user = $this->userManager->get($userId);
|
||||||
if ($user === null) {
|
if ($user === null) {
|
||||||
throw new Exception('unknown user');
|
throw new Exception('unknown user');
|
||||||
|
@ -123,7 +136,8 @@ class CheckInstall extends Base {
|
||||||
$wrapper = $this->pushService->testOnAccount($userId);
|
$wrapper = $this->pushService->testOnAccount($userId);
|
||||||
|
|
||||||
$output->writeln(json_encode($wrapper, JSON_PRETTY_PRINT));
|
$output->writeln(json_encode($wrapper, JSON_PRETTY_PRINT));
|
||||||
}
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ class NavigationController extends Controller {
|
||||||
try {
|
try {
|
||||||
$data['serverData']['cloudAddress'] = $this->configService->getCloudUrl();
|
$data['serverData']['cloudAddress'] = $this->configService->getCloudUrl();
|
||||||
} catch (SocialAppConfigException $e) {
|
} catch (SocialAppConfigException $e) {
|
||||||
$this->checkService->checkInstallationStatus();
|
$this->checkService->checkInstallationStatus(true);
|
||||||
$cloudAddress = $this->setupCloudAddress();
|
$cloudAddress = $this->setupCloudAddress();
|
||||||
if ($cloudAddress !== '') {
|
if ($cloudAddress !== '') {
|
||||||
$data['serverData']['cloudAddress'] = $cloudAddress;
|
$data['serverData']['cloudAddress'] = $cloudAddress;
|
||||||
|
|
|
@ -305,17 +305,17 @@ class FollowsRequest extends FollowsRequestBuilder {
|
||||||
$qb->execute();
|
$qb->execute();
|
||||||
|
|
||||||
$qb = $this->getFollowsDeleteSql();
|
$qb = $this->getFollowsDeleteSql();
|
||||||
$this->limitToFollowId($qb, $actorId);
|
$this->limitToObjectId($qb, $actorId);
|
||||||
|
|
||||||
$qb->execute();
|
$qb->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $followId
|
* @param string $id
|
||||||
*/
|
*/
|
||||||
public function deleteFollowById(string $followId) {
|
public function deleteById(string $id) {
|
||||||
$qb = $this->getFollowsDeleteSql();
|
$qb = $this->getFollowsDeleteSql();
|
||||||
$this->limitToIdString($qb, $followId);
|
$this->limitToIdString($qb, $id);
|
||||||
|
|
||||||
$qb->execute();
|
$qb->execute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,11 +196,17 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
* @return Stream[]
|
* @return Stream[]
|
||||||
*/
|
*/
|
||||||
public function getAll(): array {
|
public function getAll(string $type = ''): array {
|
||||||
$qb = $this->getStreamSelectSql();
|
$qb = $this->getStreamSelectSql();
|
||||||
|
|
||||||
|
if ($type !== '') {
|
||||||
|
$this->limitToType($qb, $type);
|
||||||
|
}
|
||||||
|
|
||||||
$streams = [];
|
$streams = [];
|
||||||
$cursor = $qb->execute();
|
$cursor = $qb->execute();
|
||||||
while ($data = $cursor->fetch()) {
|
while ($data = $cursor->fetch()) {
|
||||||
|
@ -212,7 +218,6 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
$cursor->closeCursor();
|
$cursor->closeCursor();
|
||||||
|
|
||||||
return $streams;
|
return $streams;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -539,8 +544,7 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true
|
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true): array {
|
||||||
): array {
|
|
||||||
$qb = $this->getStreamSelectSql();
|
$qb = $this->getStreamSelectSql();
|
||||||
$this->limitPaginate($qb, $since, $limit);
|
$this->limitPaginate($qb, $since, $limit);
|
||||||
|
|
||||||
|
@ -636,10 +640,10 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param string $type
|
* @param string $type
|
||||||
*/
|
*/
|
||||||
public function deleteStreamById(string $id, string $type = '') {
|
public function deleteById(string $id, string $type = '') {
|
||||||
$qb = $this->getStreamDeleteSql();
|
$qb = $this->getStreamDeleteSql();
|
||||||
|
|
||||||
$this->limitToIdString($qb, $id);
|
$this->limitToIdString($qb, $id);
|
||||||
|
|
||||||
if ($type !== '') {
|
if ($type !== '') {
|
||||||
$this->limitToType($qb, $type);
|
$this->limitToType($qb, $type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,13 +63,12 @@ class DeleteInterface implements IActivityPubInterface {
|
||||||
*/
|
*/
|
||||||
public function processIncomingRequest(ACore $item) {
|
public function processIncomingRequest(ACore $item) {
|
||||||
$item->checkOrigin($item->getId());
|
$item->checkOrigin($item->getId());
|
||||||
|
$item->checkOrigin($item->getObjectId());
|
||||||
|
|
||||||
if (!$item->hasObject()) {
|
if (!$item->hasObject()) {
|
||||||
$types = ['Note', 'Person'];
|
$types = ['Note', 'Person'];
|
||||||
foreach ($types as $type) {
|
foreach ($types as $type) {
|
||||||
try {
|
try {
|
||||||
$item->checkOrigin($item->getObjectId());
|
|
||||||
|
|
||||||
$interface = AP::$activityPub->getInterfaceFromType($type);
|
$interface = AP::$activityPub->getInterfaceFromType($type);
|
||||||
$object = $interface->getItemById($item->getObjectId());
|
$object = $interface->getItemById($item->getObjectId());
|
||||||
$interface->delete($object);
|
$interface->delete($object);
|
||||||
|
|
|
@ -157,7 +157,7 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
|
||||||
*/
|
*/
|
||||||
public function delete(ACore $item) {
|
public function delete(ACore $item) {
|
||||||
/** @var Stream $item */
|
/** @var Stream $item */
|
||||||
$this->streamRequest->deleteStreamById($item->getId(), SocialAppNotification::TYPE);
|
$this->streamRequest->deleteById($item->getId(), SocialAppNotification::TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,7 @@ class AnnounceInterface implements IActivityPubInterface {
|
||||||
$knownItem->removeCc($actor->getFollowers());
|
$knownItem->removeCc($actor->getFollowers());
|
||||||
|
|
||||||
if (empty($knownItem->getCcArray())) {
|
if (empty($knownItem->getCcArray())) {
|
||||||
$this->streamRequest->deleteStreamById($knownItem->getId(), Announce::TYPE);
|
$this->streamRequest->deleteById($knownItem->getId(), Announce::TYPE);
|
||||||
} else {
|
} else {
|
||||||
$this->streamRequest->update($knownItem);
|
$this->streamRequest->update($knownItem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ class NoteInterface implements IActivityPubInterface {
|
||||||
*/
|
*/
|
||||||
public function delete(ACore $item) {
|
public function delete(ACore $item) {
|
||||||
/** @var Note $item */
|
/** @var Note $item */
|
||||||
$this->streamRequest->deleteStreamById($item->getId(), Note::TYPE);
|
$this->streamRequest->deleteById($item->getId(), Note::TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ class CheckInstallation implements IRepairStep {
|
||||||
* @param IOutput $output
|
* @param IOutput $output
|
||||||
*/
|
*/
|
||||||
public function run(IOutput $output) {
|
public function run(IOutput $output) {
|
||||||
$this->checkService->checkInstallationStatus();
|
$this->checkService->checkInstallationStatus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -318,7 +318,7 @@ class ACore extends Item implements JsonSerializable {
|
||||||
$origin = $this->getRoot()
|
$origin = $this->getRoot()
|
||||||
->getOrigin();
|
->getOrigin();
|
||||||
|
|
||||||
if ($origin === $host && $host !== '') {
|
if ($id !== '' && $origin === $host && $host !== '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ use OCA\Social\Db\FollowsRequest;
|
||||||
use OCA\Social\Db\StreamRequest;
|
use OCA\Social\Db\StreamRequest;
|
||||||
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
||||||
use OCA\Social\Model\ActivityPub\Object\Follow;
|
use OCA\Social\Model\ActivityPub\Object\Follow;
|
||||||
|
use OCA\Social\Model\ActivityPub\Object\Note;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\Http\Client\IClientService;
|
use OCP\Http\Client\IClientService;
|
||||||
use OCP\ICache;
|
use OCP\ICache;
|
||||||
|
@ -172,14 +173,24 @@ class CheckService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param bool $light
|
||||||
*
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function checkInstallationStatus() {
|
public function checkInstallationStatus(bool $light = false): array {
|
||||||
$this->configService->setCoreValue('public_webfinger', 'social/lib/webfinger.php');
|
$this->configService->setCoreValue('public_webfinger', 'social/lib/webfinger.php');
|
||||||
$this->configService->setCoreValue('public_host-meta', 'social/lib/hostmeta.php');
|
$this->configService->setCoreValue('public_host-meta', 'social/lib/hostmeta.php');
|
||||||
$this->removeInvalidFollows();
|
|
||||||
$this->removeInvalidNotes();
|
if (!$light) {
|
||||||
|
$result = [
|
||||||
|
'invalidFollows' => $this->removeInvalidFollows(),
|
||||||
|
'invalidNotes' => $this->removeInvalidNotes()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$this->checkStatusTableFollows();
|
$this->checkStatusTableFollows();
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,9 +214,9 @@ class CheckService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function removeInvalidFollows() {
|
public function removeInvalidFollows(): int {
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$follows = $this->followRequest->getAll();
|
$follows = $this->followRequest->getAll();
|
||||||
foreach ($follows as $follow) {
|
foreach ($follows as $follow) {
|
||||||
|
@ -213,34 +224,39 @@ class CheckService {
|
||||||
$this->cacheActorsRequest->getFromId($follow->getActorId());
|
$this->cacheActorsRequest->getFromId($follow->getActorId());
|
||||||
$this->cacheActorsRequest->getFromId($follow->getObjectId());
|
$this->cacheActorsRequest->getFromId($follow->getObjectId());
|
||||||
} catch (CacheActorDoesNotExistException $e) {
|
} catch (CacheActorDoesNotExistException $e) {
|
||||||
$this->followRequest->deleteFollowById($follow->getId());
|
$this->followRequest->deleteById($follow->getId());
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->miscService->log('removeInvalidFollows removed ' . $count . ' entries', 1);
|
$this->miscService->log('removeInvalidFollows removed ' . $count . ' entries', 1);
|
||||||
|
|
||||||
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function removeInvalidNotes() {
|
public function removeInvalidNotes(): int {
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$streams = $this->streamRequest->getAll();
|
$streams = $this->streamRequest->getAll(Note::TYPE);
|
||||||
foreach ($streams as $stream) {
|
foreach ($streams as $stream) {
|
||||||
try {
|
try {
|
||||||
// Check if it's enough for Note, Announce, ...
|
// Check if it's enough for Note, Announce, ...
|
||||||
$this->cacheActorsRequest->getFromId($stream->getAttributedTo());
|
$this->cacheActorsRequest->getFromId($stream->getAttributedTo());
|
||||||
} catch (CacheActorDoesNotExistException $e) {
|
} catch (CacheActorDoesNotExistException $e) {
|
||||||
$this->streamRequest->deleteStreamById($stream->getId());
|
$this->streamRequest->deleteById($stream->getId(), Note::TYPE);
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->miscService->log('removeInvalidNotes removed ' . $count . ' entries', 1);
|
$this->miscService->log('removeInvalidNotes removed ' . $count . ' entries', 1);
|
||||||
|
|
||||||
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $base
|
* @param string $base
|
||||||
*
|
*
|
||||||
|
|
|
@ -363,7 +363,7 @@ class StreamService {
|
||||||
|
|
||||||
$item->setActorId($item->getAttributedTo());
|
$item->setActorId($item->getAttributedTo());
|
||||||
$this->activityService->deleteActivity($item);
|
$this->activityService->deleteActivity($item);
|
||||||
$this->streamRequest->deleteStreamById($item->getId(), $type);
|
$this->streamRequest->deleteById($item->getId(), $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue