[Attachment] Move Controller and Entities to a Component

There's no problem in having the templates in the core
This commit is contained in:
Diogo Peralta Cordeiro 2021-12-02 15:12:31 +00:00
parent 37ef8cddfa
commit eeaad19754
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
22 changed files with 37 additions and 48 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
// }}}
/**
* Define social's attachment routes
*
* @package GNUsocial
* @category Router
*
* @author Diogo Cordeiro <mail@diogo.site>
* @author Hugo Sales <hugo@hsal.es>
* @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<big|medium|small>}', [C\Attachment::class, 'attachment_thumbnail']);
return Event::next;
}
}

View File

@ -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;

View File

@ -17,7 +17,7 @@
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace App\Entity;
namespace Component\Attachment\Entity;
use App\Core\Entity;
use DateTimeInterface;

View File

@ -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;

View File

@ -21,7 +21,7 @@ declare(strict_types = 1);
// }}}
namespace App\Entity;
namespace Component\Attachment\Entity;
use App\Core\Cache;
use App\Core\DB\DB;

View File

@ -17,7 +17,7 @@
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace App\Entity;
namespace Component\Attachment\Entity;
use App\Core\Entity;
use DateTimeInterface;

View File

@ -17,7 +17,7 @@
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace App\Entity;
namespace Component\Attachment\Entity;
use App\Core\Entity;
use DateTimeInterface;

View File

@ -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],

View File

@ -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;

View File

@ -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;

View File

@ -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]);

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
/**

View File

@ -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;

View File

@ -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],
);

View File

@ -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;
/**

View File

@ -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;

View File

@ -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;