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
Maxence Lange 2019-08-22 20:49:27 -01:00
rodzic dbd85cff3b
commit dab2b22415
12 zmienionych plików z 76 dodań i 43 usunięć

Wyświetl plik

@ -31,13 +31,13 @@ declare(strict_types=1);
namespace OCA\Social\Command;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OC\Core\Command\Base;
use OCA\Social\Service\CheckService;
use OCA\Social\Service\MiscService;
use OCA\Social\Service\PushService;
use OCP\IUserManager;
use OCP\Push\Exceptions\PushInstallException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@ -46,6 +46,9 @@ use Symfony\Component\Console\Output\OutputInterface;
class CheckInstall extends Base {
use TArrayTools;
/** @var IUserManager */
private $userManager;
@ -86,7 +89,8 @@ class CheckInstall extends Base {
parent::configure();
$this->setName('social:check:install')
->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');
@ -100,9 +104,14 @@ class CheckInstall extends Base {
* @throws Exception
*/
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,20 +119,25 @@ class CheckInstall extends Base {
* @param InputInterface $input
* @param OutputInterface $output
*
* @return bool
* @throws Exception
*/
private function checkPushApp(InputInterface $input, OutputInterface $output) {
private function checkPushApp(InputInterface $input, OutputInterface $output): bool {
$userId = $input->getOption('push');
if ($userId !== '') {
$user = $this->userManager->get($userId);
if ($user === null) {
throw new Exception('unknown user');
}
$wrapper = $this->pushService->testOnAccount($userId);
$output->writeln(json_encode($wrapper, JSON_PRETTY_PRINT));
if ($userId === '') {
return false;
}
$user = $this->userManager->get($userId);
if ($user === null) {
throw new Exception('unknown user');
}
$wrapper = $this->pushService->testOnAccount($userId);
$output->writeln(json_encode($wrapper, JSON_PRETTY_PRINT));
return true;
}
}

Wyświetl plik

@ -149,7 +149,7 @@ class NavigationController extends Controller {
try {
$data['serverData']['cloudAddress'] = $this->configService->getCloudUrl();
} catch (SocialAppConfigException $e) {
$this->checkService->checkInstallationStatus();
$this->checkService->checkInstallationStatus(true);
$cloudAddress = $this->setupCloudAddress();
if ($cloudAddress !== '') {
$data['serverData']['cloudAddress'] = $cloudAddress;

Wyświetl plik

@ -305,17 +305,17 @@ class FollowsRequest extends FollowsRequestBuilder {
$qb->execute();
$qb = $this->getFollowsDeleteSql();
$this->limitToFollowId($qb, $actorId);
$this->limitToObjectId($qb, $actorId);
$qb->execute();
}
/**
* @param string $followId
* @param string $id
*/
public function deleteFollowById(string $followId) {
public function deleteById(string $id) {
$qb = $this->getFollowsDeleteSql();
$this->limitToIdString($qb, $followId);
$this->limitToIdString($qb, $id);
$qb->execute();
}

Wyświetl plik

@ -196,11 +196,17 @@ class StreamRequest extends StreamRequestBuilder {
/**
* @param string $type
*
* @return Stream[]
*/
public function getAll(): array {
public function getAll(string $type = ''): array {
$qb = $this->getStreamSelectSql();
if ($type !== '') {
$this->limitToType($qb, $type);
}
$streams = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
@ -212,7 +218,6 @@ class StreamRequest extends StreamRequestBuilder {
$cursor->closeCursor();
return $streams;
}
@ -539,8 +544,7 @@ class StreamRequest extends StreamRequestBuilder {
* @return array
* @throws Exception
*/
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true
): array {
public function getTimelineLiked(int $since = 0, int $limit = 5, bool $localOnly = true): array {
$qb = $this->getStreamSelectSql();
$this->limitPaginate($qb, $since, $limit);
@ -636,10 +640,10 @@ class StreamRequest extends StreamRequestBuilder {
* @param string $id
* @param string $type
*/
public function deleteStreamById(string $id, string $type = '') {
public function deleteById(string $id, string $type = '') {
$qb = $this->getStreamDeleteSql();
$this->limitToIdString($qb, $id);
if ($type !== '') {
$this->limitToType($qb, $type);
}

Wyświetl plik

@ -63,13 +63,12 @@ class DeleteInterface implements IActivityPubInterface {
*/
public function processIncomingRequest(ACore $item) {
$item->checkOrigin($item->getId());
$item->checkOrigin($item->getObjectId());
if (!$item->hasObject()) {
$types = ['Note', 'Person'];
foreach ($types as $type) {
try {
$item->checkOrigin($item->getObjectId());
$interface = AP::$activityPub->getInterfaceFromType($type);
$object = $interface->getItemById($item->getObjectId());
$interface->delete($object);

Wyświetl plik

@ -157,7 +157,7 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
*/
public function delete(ACore $item) {
/** @var Stream $item */
$this->streamRequest->deleteStreamById($item->getId(), SocialAppNotification::TYPE);
$this->streamRequest->deleteById($item->getId(), SocialAppNotification::TYPE);
}

Wyświetl plik

@ -277,7 +277,7 @@ class AnnounceInterface implements IActivityPubInterface {
$knownItem->removeCc($actor->getFollowers());
if (empty($knownItem->getCcArray())) {
$this->streamRequest->deleteStreamById($knownItem->getId(), Announce::TYPE);
$this->streamRequest->deleteById($knownItem->getId(), Announce::TYPE);
} else {
$this->streamRequest->update($knownItem);
}

Wyświetl plik

@ -176,7 +176,7 @@ class NoteInterface implements IActivityPubInterface {
*/
public function delete(ACore $item) {
/** @var Note $item */
$this->streamRequest->deleteStreamById($item->getId(), Note::TYPE);
$this->streamRequest->deleteById($item->getId(), Note::TYPE);
}

Wyświetl plik

@ -73,7 +73,7 @@ class CheckInstallation implements IRepairStep {
* @param IOutput $output
*/
public function run(IOutput $output) {
$this->checkService->checkInstallationStatus();
$this->checkService->checkInstallationStatus(true);
}

Wyświetl plik

@ -318,7 +318,7 @@ class ACore extends Item implements JsonSerializable {
$origin = $this->getRoot()
->getOrigin();
if ($origin === $host && $host !== '') {
if ($id !== '' && $origin === $host && $host !== '') {
return;
}

Wyświetl plik

@ -33,6 +33,7 @@ use OCA\Social\Db\FollowsRequest;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCP\AppFramework\Http;
use OCP\Http\Client\IClientService;
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_host-meta', 'social/lib/hostmeta.php');
$this->removeInvalidFollows();
$this->removeInvalidNotes();
if (!$light) {
$result = [
'invalidFollows' => $this->removeInvalidFollows(),
'invalidNotes' => $this->removeInvalidNotes()
];
}
$this->checkStatusTableFollows();
return $result;
}
@ -203,9 +214,9 @@ class CheckService {
/**
*
* @return int
*/
public function removeInvalidFollows() {
public function removeInvalidFollows(): int {
$count = 0;
$follows = $this->followRequest->getAll();
foreach ($follows as $follow) {
@ -213,34 +224,39 @@ class CheckService {
$this->cacheActorsRequest->getFromId($follow->getActorId());
$this->cacheActorsRequest->getFromId($follow->getObjectId());
} catch (CacheActorDoesNotExistException $e) {
$this->followRequest->deleteFollowById($follow->getId());
$this->followRequest->deleteById($follow->getId());
$count++;
}
}
$this->miscService->log('removeInvalidFollows removed ' . $count . ' entries', 1);
return $count;
}
/**
*
* @return int
*/
public function removeInvalidNotes() {
public function removeInvalidNotes(): int {
$count = 0;
$streams = $this->streamRequest->getAll();
$streams = $this->streamRequest->getAll(Note::TYPE);
foreach ($streams as $stream) {
try {
// Check if it's enough for Note, Announce, ...
$this->cacheActorsRequest->getFromId($stream->getAttributedTo());
} catch (CacheActorDoesNotExistException $e) {
$this->streamRequest->deleteStreamById($stream->getId());
$this->streamRequest->deleteById($stream->getId(), Note::TYPE);
$count++;
}
}
$this->miscService->log('removeInvalidNotes removed ' . $count . ' entries', 1);
return $count;
}
/**
* @param string $base
*

Wyświetl plik

@ -363,7 +363,7 @@ class StreamService {
$item->setActorId($item->getAttributedTo());
$this->activityService->deleteActivity($item);
$this->streamRequest->deleteStreamById($item->getId(), $type);
$this->streamRequest->deleteById($item->getId(), $type);
}