summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-12-12 11:10:22 -0100
committerGitHub <noreply@github.com>2018-12-12 11:10:22 -0100
commit62c24da769554e792defed457269619cb115a845 (patch)
treec5a52f73bae7f978c79fc1c4515a06d5adecaabc /lib
parent1d5bf5b969235c4469dfe001a9155b7587dd6e9b (diff)
parenta7e644e7acbe813487d9ea3be82f8c3cfc08615d (diff)
Merge branch 'master' into fix-ghost-account
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/NavigationController.php8
-rw-r--r--lib/Controller/QueueController.php22
-rw-r--r--lib/Db/CacheActorsRequest.php13
-rw-r--r--lib/Db/CoreRequestBuilder.php3
-rw-r--r--lib/Db/NotesRequest.php13
-rw-r--r--lib/Migration/Version0001Date20181208185242.php88
-rw-r--r--lib/Service/ActorService.php8
-rw-r--r--lib/Service/ImportService.php2
8 files changed, 128 insertions, 29 deletions
diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php
index 33880792..cbe5a1f1 100644
--- a/lib/Controller/NavigationController.php
+++ b/lib/Controller/NavigationController.php
@@ -148,9 +148,6 @@ class NavigationController extends Controller {
]
];
- $checks = $this->checkService->checkDefault();
- $data['serverData']['checks'] = $checks;
-
try {
$data['serverData']['cloudAddress'] = $this->configService->getCloudAddress();
} catch (SocialAppConfigException $e) {
@@ -171,6 +168,11 @@ class NavigationController extends Controller {
}
}
+ if ($data['serverData']['isAdmin']) {
+ $checks = $this->checkService->checkDefault();
+ $data['serverData']['checks'] = $checks;
+ }
+
/*
* Create social user account if it doesn't exist yet
*/
diff --git a/lib/Controller/QueueController.php b/lib/Controller/QueueController.php
index 3900eec5..4d32b12d 100644
--- a/lib/Controller/QueueController.php
+++ b/lib/Controller/QueueController.php
@@ -93,19 +93,21 @@ class QueueController extends Controller {
* @param string $token
*/
public function asyncWithToken(string $token) {
- $this->async();
-
$requests = $this->queueService->getRequestFromToken($token, RequestQueue::STATUS_STANDBY);
- $this->activityService->manageInit();
- foreach ($requests as $request) {
- $request->setTimeout(ActivityService::TIMEOUT_ASYNC);
- try {
- $this->activityService->manageRequest($request);
- } catch (RequestException $e) {
- } catch (SocialAppConfigException $e) {
+
+ if (!empty($requests)) {
+ $this->async();
+
+ $this->activityService->manageInit();
+ foreach ($requests as $request) {
+ $request->setTimeout(ActivityService::TIMEOUT_ASYNC);
+ try {
+ $this->activityService->manageRequest($request);
+ } catch (RequestException $e) {
+ } catch (SocialAppConfigException $e) {
+ }
}
}
-
// or it will feed the logs.
exit();
}
diff --git a/lib/Db/CacheActorsRequest.php b/lib/Db/CacheActorsRequest.php
index 7a3f0ff2..e69afbc1 100644
--- a/lib/Db/CacheActorsRequest.php
+++ b/lib/Db/CacheActorsRequest.php
@@ -62,10 +62,13 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
* insert cache about an Actor in database.
*
* @param Person $actor
- *
- * @return int
*/
- public function save(Person $actor): int {
+ public function save(Person $actor) {
+ $source = $actor->getSource();
+ if (strlen($source) >= CoreRequestBuilder::SOURCE_LENGTH) {
+ $source = 'too_big';
+ }
+
$qb = $this->getCacheActorsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($actor->getId()))
->setValue('account', $qb->createNamedParameter($actor->getAccount()))
@@ -84,7 +87,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
->setValue('name', $qb->createNamedParameter($actor->getName()))
->setValue('summary', $qb->createNamedParameter($actor->getSummary()))
->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey()))
- ->setValue('source', $qb->createNamedParameter($actor->getSource()))
+ ->setValue('source', $qb->createNamedParameter($source))
->setValue('details', $qb->createNamedParameter(json_encode($actor->getDetails())))
->setValue(
'creation',
@@ -101,8 +104,6 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
$qb->setValue('icon_id', $qb->createNamedParameter($iconId));
$qb->execute();
-
- return $qb->getLastInsertId();
}
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index 7176ed8c..8f594ddd 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -64,6 +64,9 @@ class CoreRequestBuilder {
const TABLE_CACHE_DOCUMENTS = 'social_cache_documents';
+ const SOURCE_LENGTH = 10000;
+
+
/** @var IDBConnection */
protected $dbConnection;
diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php
index 9e687e25..fdd1313b 100644
--- a/lib/Db/NotesRequest.php
+++ b/lib/Db/NotesRequest.php
@@ -61,13 +61,16 @@ class NotesRequest extends NotesRequestBuilder {
* Insert a new Note in the database.
*
* @param Note $note
- *
- * @return int
*/
- public function save(Note $note): int {
+ public function save(Note $note) {
$dTime = new DateTime();
$dTime->setTimestamp($note->getPublishedTime());
+ $source = $note->getSource();
+ if (strlen($source) >= CoreRequestBuilder::SOURCE_LENGTH) {
+ $source = 'too_big';
+ }
+
$qb = $this->getNotesInsertSql();
$qb->setValue('id', $qb->createNamedParameter($note->getId()))
->setValue('type', $qb->createNamedParameter($note->getType()))
@@ -95,7 +98,7 @@ class NotesRequest extends NotesRequestBuilder {
)
->setValue('attributed_to', $qb->createNamedParameter($note->getAttributedTo()))
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
- ->setValue('source', $qb->createNamedParameter($note->getSource()))
+ ->setValue('source', $qb->createNamedParameter($source))
->setValue(
'instances', $qb->createNamedParameter(
json_encode($note->getInstancePaths(), JSON_UNESCAPED_SLASHES)
@@ -108,8 +111,6 @@ class NotesRequest extends NotesRequestBuilder {
);
$qb->execute();
-
- return $qb->getLastInsertId();
}
diff --git a/lib/Migration/Version0001Date20181208185242.php b/lib/Migration/Version0001Date20181208185242.php
new file mode 100644
index 00000000..3194f2ee
--- /dev/null
+++ b/lib/Migration/Version0001Date20181208185242.php
@@ -0,0 +1,88 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Social\Migration;
+
+
+use Closure;
+use OCA\Social\Db\CoreRequestBuilder;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+
+/**
+ * Class Version0001Date20181208185242
+ *
+ * @package OCA\Social\Migration
+ */
+class Version0001Date20181208185242 extends SimpleMigrationStep {
+
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ *
+ * @return ISchemaWrapper
+ * @throws \Doctrine\DBAL\Schema\SchemaException
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options
+ ): ISchemaWrapper {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $table = $schema->getTable(CoreRequestBuilder::TABLE_CACHE_ACTORS);
+ $table->changeColumn(
+ 'source', [
+ 'notnull' => true,
+ 'length' => CoreRequestBuilder::SOURCE_LENGTH,
+ ]
+ );
+
+ $table = $schema->getTable(CoreRequestBuilder::TABLE_SERVER_NOTES);
+ $table->changeColumn(
+ 'source', [
+ 'notnull' => true,
+ 'length' => CoreRequestBuilder::SOURCE_LENGTH,
+ ]
+ );
+
+ $table = $schema->getTable(CoreRequestBuilder::TABLE_REQUEST_QUEUE);
+ $table->changeColumn(
+ 'activity', [
+ 'notnull' => true,
+ 'length' => CoreRequestBuilder::SOURCE_LENGTH,
+ ]
+ );
+
+ return $schema;
+ }
+}
diff --git a/lib/Service/ActorService.php b/lib/Service/ActorService.php
index 2e4c22fb..174a3732 100644
--- a/lib/Service/ActorService.php
+++ b/lib/Service/ActorService.php
@@ -45,7 +45,6 @@ use OCA\Social\Model\ActivityPub\Person;
use OCA\Social\Service\ActivityPub\DocumentService;
use OCA\Social\Service\ActivityPub\PersonService;
use OCP\Accounts\IAccountManager;
-use OCP\Accounts\PropertyDoesNotExistException;
use OCP\IUserManager;
@@ -297,14 +296,17 @@ class ActorService {
if ($user === null) {
throw new NoUserException();
}
- $account = $this->accountManager->getAccount($user);
try {
+ $account = $this->accountManager->getAccount($user);
$displayNameProperty = $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME);
if ($displayNameProperty->getScope() === IAccountManager::VISIBILITY_PUBLIC) {
$actor->setName($displayNameProperty->getValue());
}
- } catch (PropertyDoesNotExistException $e) {
+ } catch (Exception $e) {
+ $this->miscService->log(
+ 'Issue while trying to updateCacheLocalActorName: ' . $e->getMessage(), 1
+ );
}
}
diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php
index f87b0b4b..73072a7e 100644
--- a/lib/Service/ImportService.php
+++ b/lib/Service/ImportService.php
@@ -235,7 +235,7 @@ class ImportService {
$service->parse($activity);
} catch (Exception $e) {
$this->miscService->log(
- 2, 'Cannot parse ' . $activity->getType() . ': ' . $e->getMessage()
+ 'Cannot parse ' . $activity->getType() . ': ' . $e->getMessage()
);
}
}