diff --git a/src/Routes/Attachments.php b/components/Attachment/Attachment.php
similarity index 73%
rename from src/Routes/Attachments.php
rename to components/Attachment/Attachment.php
index c88717a111..06110778e2 100644
--- a/src/Routes/Attachments.php
+++ b/components/Attachment/Attachment.php
@@ -3,7 +3,6 @@
declare(strict_types = 1);
// {{{ License
-
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
@@ -18,35 +17,23 @@ declare(strict_types = 1);
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see .
-
// }}}
-/**
- * Define social's attachment routes
- *
- * @package GNUsocial
- * @category Router
- *
- * @author Diogo Cordeiro
- * @author Hugo Sales
- * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
- * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
- */
+namespace Component\Attachment;
-namespace App\Routes;
-
-use App\Controller as C;
+use App\Core\Event;
+use App\Core\Modules\Component;
use App\Core\Router\RouteLoader;
+use Component\Attachment\Controller as C;
-abstract class Attachments
+class Attachment extends Component
{
- public const LOAD_ORDER = 20;
-
- public static function load(RouteLoader $r): void
+ public function onAddRoute(RouteLoader $r): bool
{
$r->connect('attachment_show', '/attachment/{id<\d+>}', [C\Attachment::class, 'attachment_show']);
$r->connect('attachment_view', '/attachment/{id<\d+>}/view', [C\Attachment::class, 'attachment_view']);
$r->connect('attachment_download', '/attachment/{id<\d+>}/download', [C\Attachment::class, 'attachment_download']);
$r->connect('attachment_thumbnail', '/attachment/{id<\d+>}/thumbnail/{size}', [C\Attachment::class, 'attachment_thumbnail']);
+ return Event::next;
}
}
diff --git a/src/Controller/Attachment.php b/components/Attachment/Controller/Attachment.php
similarity index 98%
rename from src/Controller/Attachment.php
rename to components/Attachment/Controller/Attachment.php
index d12fa3c7ed..153b41dfa9 100644
--- a/src/Controller/Attachment.php
+++ b/components/Attachment/Controller/Attachment.php
@@ -21,7 +21,7 @@ declare(strict_types = 1);
// }}}
-namespace App\Controller;
+namespace Component\Attachment\Controller;
use App\Core\Controller;
use App\Core\DB\DB;
@@ -30,7 +30,7 @@ use App\Core\GSFile;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Router\Router;
-use App\Entity\AttachmentThumbnail;
+use Component\Attachment\Entity\AttachmentThumbnail;
use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Exception\NoSuchFileException;
diff --git a/src/Entity/ActorToAttachment.php b/components/Attachment/Entity/ActorToAttachment.php
similarity index 98%
rename from src/Entity/ActorToAttachment.php
rename to components/Attachment/Entity/ActorToAttachment.php
index 9f116e31fe..7c959b8f80 100644
--- a/src/Entity/ActorToAttachment.php
+++ b/components/Attachment/Entity/ActorToAttachment.php
@@ -17,7 +17,7 @@
// along with GNU social. If not, see .
// }}}
-namespace App\Entity;
+namespace Component\Attachment\Entity;
use App\Core\Entity;
use DateTimeInterface;
diff --git a/src/Entity/Attachment.php b/components/Attachment/Entity/Attachment.php
similarity index 99%
rename from src/Entity/Attachment.php
rename to components/Attachment/Entity/Attachment.php
index 8143b18f47..bd648c5367 100644
--- a/src/Entity/Attachment.php
+++ b/components/Attachment/Entity/Attachment.php
@@ -19,13 +19,14 @@
// }}}
-namespace App\Entity;
+namespace Component\Attachment\Entity;
use App\Core\Cache;
use App\Core\DB\DB;
use App\Core\Entity;
use App\Core\Event;
use App\Core\GSFile;
+use App\Entity\Note;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Router\Router;
diff --git a/src/Entity/AttachmentThumbnail.php b/components/Attachment/Entity/AttachmentThumbnail.php
similarity index 99%
rename from src/Entity/AttachmentThumbnail.php
rename to components/Attachment/Entity/AttachmentThumbnail.php
index db86e4b7f6..83b674e2ef 100644
--- a/src/Entity/AttachmentThumbnail.php
+++ b/components/Attachment/Entity/AttachmentThumbnail.php
@@ -21,7 +21,7 @@ declare(strict_types = 1);
// }}}
-namespace App\Entity;
+namespace Component\Attachment\Entity;
use App\Core\Cache;
use App\Core\DB\DB;
diff --git a/src/Entity/AttachmentToLink.php b/components/Attachment/Entity/AttachmentToLink.php
similarity index 98%
rename from src/Entity/AttachmentToLink.php
rename to components/Attachment/Entity/AttachmentToLink.php
index ebe8c5b8da..576bb6e9a9 100644
--- a/src/Entity/AttachmentToLink.php
+++ b/components/Attachment/Entity/AttachmentToLink.php
@@ -17,7 +17,7 @@
// along with GNU social. If not, see .
// }}}
-namespace App\Entity;
+namespace Component\Attachment\Entity;
use App\Core\Entity;
use DateTimeInterface;
diff --git a/src/Entity/AttachmentToNote.php b/components/Attachment/Entity/AttachmentToNote.php
similarity index 98%
rename from src/Entity/AttachmentToNote.php
rename to components/Attachment/Entity/AttachmentToNote.php
index 84b17e126e..6d039098f1 100644
--- a/src/Entity/AttachmentToNote.php
+++ b/components/Attachment/Entity/AttachmentToNote.php
@@ -17,7 +17,7 @@
// along with GNU social. If not, see .
// }}}
-namespace App\Entity;
+namespace Component\Attachment\Entity;
use App\Core\Entity;
use DateTimeInterface;
diff --git a/components/Avatar/Avatar.php b/components/Avatar/Avatar.php
index 37d887527a..0da330cbc8 100644
--- a/components/Avatar/Avatar.php
+++ b/components/Avatar/Avatar.php
@@ -123,7 +123,7 @@ class Avatar extends Component
function () use ($actor_id) {
return DB::dql(
'select f.id, f.filename, a.title, f.mimetype '
- . 'from App\Entity\Attachment f '
+ . 'from Component\Attachment\Entity\Attachment f '
. 'join Component\Avatar\Entity\Avatar a with f.id = a.attachment_id '
. 'where a.actor_id = :actor_id',
['actor_id' => $actor_id],
diff --git a/components/Avatar/Entity/Avatar.php b/components/Avatar/Entity/Avatar.php
index 03cf9a010f..05e47d6bf1 100644
--- a/components/Avatar/Entity/Avatar.php
+++ b/components/Avatar/Entity/Avatar.php
@@ -27,7 +27,7 @@ use App\Core\Cache;
use App\Core\DB\DB;
use App\Core\Entity;
use App\Core\Router\Router;
-use App\Entity\Attachment;
+use Component\Attachment\Entity\Attachment;
use App\Util\Common;
use DateTimeInterface;
diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php
index edd19fb297..db51381096 100644
--- a/components/Posting/Posting.php
+++ b/components/Posting/Posting.php
@@ -34,9 +34,9 @@ use App\Core\Router\Router;
use App\Core\Security;
use App\Entity\Activity;
use App\Entity\Actor;
-use App\Entity\ActorToAttachment;
-use App\Entity\Attachment;
-use App\Entity\AttachmentToNote;
+use Component\Attachment\Entity\ActorToAttachment;
+use Component\Attachment\Entity\Attachment;
+use Component\Attachment\Entity\AttachmentToNote;
use App\Entity\Language;
use App\Entity\Note;
use App\Util\Common;
diff --git a/docs/developer/src/cache.md b/docs/developer/src/cache.md
index af7f08863d..6561367185 100644
--- a/docs/developer/src/cache.md
+++ b/docs/developer/src/cache.md
@@ -35,7 +35,7 @@ public static function getAvatarFileInfo(int $gsactor_id): array
Cache::get("avatar-file-info-{$gsactor_id}",
function () use ($gsactor_id) {
return DB::dql('select f.file_hash, f.mimetype, f.title ' .
- 'from App\Entity\Attachment f ' .
+ 'from Component\Attachment\Entity\Attachment f ' .
'join App\Entity\Avatar a with f.id = a.attachment_id ' .
'where a.gsactor_id = :gsactor_id',
['gsactor_id' => $gsactor_id]);
diff --git a/docs/developer/src/storage.md b/docs/developer/src/storage.md
index 462e8351a0..4754b17464 100644
--- a/docs/developer/src/storage.md
+++ b/docs/developer/src/storage.md
@@ -68,7 +68,7 @@ Simple enough.
### Attachments: Storing a reference in database
Finally, you need a way to refer to previous files.
-GNU social calls that representation of `App\Entity\Attachment`.
+GNU social calls that representation of `Component\Attachment\Entity\Attachment`.
If a note refers to an `Attachment` then you can link them
using the entity `AttachmentToNote`.
@@ -97,7 +97,7 @@ can be generated from files. And `StoreRemoteMedia` to understand how to generat
them from URLs.
The controller asking for them is the `App\Controller\Attachment::attachment_thumbnail` with
-a call to `App\Entity\AttachmentThumbnail::getOrCreate()`.
+a call to `Component\Attachment\Entity\AttachmentThumbnail::getOrCreate()`.
## Trade-offs between decoupling and complexity
diff --git a/plugins/ActivityPub/Util/Model/AS2ToEntity/AS2ToNote.php b/plugins/ActivityPub/Util/Model/AS2ToEntity/AS2ToNote.php
index 981ad7a42e..af24d89328 100644
--- a/plugins/ActivityPub/Util/Model/AS2ToEntity/AS2ToNote.php
+++ b/plugins/ActivityPub/Util/Model/AS2ToEntity/AS2ToNote.php
@@ -29,7 +29,7 @@ abstract class AS2ToNote
'created' => new DateTime($object['published'] ?? 'now'),
'content' => $object['content'] ?? null,
'content_type' => 'text/html',
- 'language_id' => $object['contentLang'] ?? null,
+ 'language_id' => $object['contentLang'] ?? null,
'url' => \array_key_exists('url', $object) ? $object['url'] : $object['id'],
'actor_id' => $actor_id,
'modified' => new DateTime(),
@@ -59,6 +59,9 @@ abstract class AS2ToNote
$set = Formatting::snakeCaseToCamelCase("set_{$prop}");
$obj->{$set}($val);
}
+
+ Event::handle('NewNoteFromActivityStreamsTwo', [$source, $obj, $actor_id]);
+
return $obj;
}
}
diff --git a/plugins/ActivityPub/Util/Model/EntityToType/GSActorToType.php b/plugins/ActivityPub/Util/Model/EntityToType/GSActorToType.php
index b86ac843e2..a6fab9da07 100644
--- a/plugins/ActivityPub/Util/Model/EntityToType/GSActorToType.php
+++ b/plugins/ActivityPub/Util/Model/EntityToType/GSActorToType.php
@@ -4,7 +4,6 @@ declare(strict_types = 1);
namespace Plugin\ActivityPub\Util\Model\EntityToType;
-use App\Core\Event;
use App\Core\Router\Router;
use App\Entity\Actor;
use Component\Avatar\Avatar;
diff --git a/plugins/Cover/Entity/Cover.php b/plugins/Cover/Entity/Cover.php
index 7c0ed3c23b..85aba67c85 100644
--- a/plugins/Cover/Entity/Cover.php
+++ b/plugins/Cover/Entity/Cover.php
@@ -25,7 +25,7 @@ namespace Plugin\Cover\Entity;
use App\Core\DB\DB;
use App\Core\Entity;
-use App\Entity\Attachment;
+use Component\Attachment\Entity\Attachment;
use App\Util\Common;
use DateTimeInterface;
diff --git a/plugins/Embed/Embed.php b/plugins/Embed/Embed.php
index 6960b4ec50..d73c61734b 100644
--- a/plugins/Embed/Embed.php
+++ b/plugins/Embed/Embed.php
@@ -47,7 +47,7 @@ use App\Core\Log;
use App\Core\Modules\Plugin;
use App\Core\Router\RouteLoader;
use App\Core\Router\Router;
-use App\Entity\Attachment;
+use Component\Attachment\Entity\Attachment;
use App\Entity\Link;
use App\Entity\Note;
use App\Util\Common;
diff --git a/plugins/Embed/Entity/AttachmentEmbed.php b/plugins/Embed/Entity/AttachmentEmbed.php
index 84a44607a5..474bd92f67 100644
--- a/plugins/Embed/Entity/AttachmentEmbed.php
+++ b/plugins/Embed/Entity/AttachmentEmbed.php
@@ -36,7 +36,7 @@ namespace Plugin\Embed\Entity;
use App\Core\DB\DB;
use App\Core\Entity;
-use App\Entity\Attachment;
+use Component\Attachment\Entity\Attachment;
use DateTimeInterface;
/**
diff --git a/plugins/StoreRemoteMedia/StoreRemoteMedia.php b/plugins/StoreRemoteMedia/StoreRemoteMedia.php
index 5fde625420..3edfc7585a 100644
--- a/plugins/StoreRemoteMedia/StoreRemoteMedia.php
+++ b/plugins/StoreRemoteMedia/StoreRemoteMedia.php
@@ -27,9 +27,9 @@ use App\Core\HTTPClient;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Modules\Plugin;
-use App\Entity\AttachmentThumbnail;
-use App\Entity\AttachmentToLink;
-use App\Entity\AttachmentToNote;
+use Component\Attachment\Entity\AttachmentThumbnail;
+use Component\Attachment\Entity\AttachmentToLink;
+use Component\Attachment\Entity\AttachmentToNote;
use App\Entity\Link;
use App\Entity\Note;
use App\Util\Common;
diff --git a/src/Core/GSFile.php b/src/Core/GSFile.php
index f03da2953c..cbd0a11bfc 100644
--- a/src/Core/GSFile.php
+++ b/src/Core/GSFile.php
@@ -25,7 +25,7 @@ namespace App\Core;
use App\Core\DB\DB;
use function App\Core\I18n\_m;
-use App\Entity\Attachment;
+use Component\Attachment\Entity\Attachment;
use App\Util\Common;
use App\Util\Exception\DuplicateFoundException;
use App\Util\Exception\FileNotAllowedException;
@@ -229,7 +229,7 @@ class GSFile
function () use ($id) {
return DB::dql(
'select at.filename, at.mimetype '
- . 'from App\\Entity\\Attachment at '
+ . 'from Component\Attachment\Entity\Attachment at '
. 'where at.id = :id',
['id' => $id],
);
diff --git a/src/Entity/Note.php b/src/Entity/Note.php
index c1de2d09a6..ebc2b57bea 100644
--- a/src/Entity/Note.php
+++ b/src/Entity/Note.php
@@ -29,7 +29,6 @@ use App\Core\Entity;
use App\Core\Event;
use App\Core\VisibilityScope;
use Component\Avatar\Avatar;
-use Component\Notification\Entity\Notification;
use DateTimeInterface;
/**
diff --git a/tests/Entity/AttachmentTest.php b/tests/Entity/AttachmentTest.php
index 9f1a2ea3b6..6b67eede65 100644
--- a/tests/Entity/AttachmentTest.php
+++ b/tests/Entity/AttachmentTest.php
@@ -24,7 +24,7 @@ namespace App\Tests\Entity;
use App\Core\DB\DB;
use App\Core\Event;
use App\Core\GSFile;
-use App\Entity\AttachmentToNote;
+use Component\Attachment\Entity\AttachmentToNote;
use App\Entity\Note;
use App\Util\GNUsocialTestCase;
use App\Util\TemporaryFile;
diff --git a/tests/Entity/AttachmentThumbnailTest.php b/tests/Entity/AttachmentThumbnailTest.php
index 7c3998680e..6318bbf455 100644
--- a/tests/Entity/AttachmentThumbnailTest.php
+++ b/tests/Entity/AttachmentThumbnailTest.php
@@ -23,7 +23,7 @@ namespace App\Tests\Entity;
use App\Core\DB\DB;
use App\Core\Event;
-use App\Entity\AttachmentThumbnail;
+use Component\Attachment\Entity\AttachmentThumbnail;
use App\Util\Exception\NotStoredLocallyException;
use App\Util\GNUsocialTestCase;
use Functional as F;