[CORE][DB] Fix uses of db tables after previous restructure

This commit is contained in:
Hugo Sales 2020-08-13 01:23:22 +00:00 committed by Hugo Sales
parent 1111ee95f1
commit 8716d700a6
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
8 changed files with 38 additions and 31 deletions

View File

@ -36,9 +36,10 @@ class Avatar extends Controller
{
switch ($size) {
case 'full':
$result = DB::createQuery('select f.file_hash, f.mimetype, f.title from ' .
'App\\Entity\\File f join App\\Entity\\Avatar a with f.id = a.file_id ' .
'join App\\Entity\\Profile p with p.id = a.profile_id ' .
$result = DB::createQuery('select f.file_hash, f.mimetype, f.title ' .
'from App\\Entity\\File f ' .
'join App\\Entity\\Avatar a with f.id = a.file_id ' .
'join App\\Entity\\GSActor p with p.id = a.gsactor_id ' .
'where p.nickname = :nickname')
->setParameter('nickname', $nickname)
->getResult();

View File

@ -6,8 +6,8 @@ use App\Core\Controller;
use App\Core\DB\DB;
use App\Core\Form;
use function App\Core\I18n\_m;
use App\Entity\GSActor;
use App\Entity\LocalUser;
use App\Entity\Profile;
use App\Security\Authenticator;
use App\Security\EmailVerifier;
use app\Util\Common;
@ -81,11 +81,11 @@ class Security extends Controller
throw new \Exception(_m('Invalid nickname'));
}
$profile = Profile::create(['nickname' => $data['nickname']]);
$user = LocalUser::create(['nickname' => $data['nickname'], 'email' => $data['email'], 'password' => $data['password']]);
$actor = GSActor::create(['nickname' => $data['nickname']]);
$user = LocalUser::create(['nickname' => $data['nickname'], 'email' => $data['email'], 'password' => $data['password']]);
DB::persist($user);
DB::persist($profile);
DB::persist($actor);
DB::flush();
// generate a signed url and email it to the user

View File

@ -66,8 +66,8 @@ class UserPanel extends AbstractController
public function personal_info(Request $request)
{
$user = Common::user();
$profile = $user->getProfile();
$extra = ['self_tags' => $profile->getSelfTags()];
$actor = $user->getActor();
$extra = ['self_tags' => $actor->getSelfTags()];
$form_definition = [
['nickname', TextType::class, ['label' => _m('Nickname'), 'required' => true, 'help' => _m('1-64 lowercase letters or numbers, no punctuation or spaces.')]],
['full_name', TextType::class, ['label' => _m('Full Name'), 'required' => false, 'help' => _m('A full name is required, if empty it will be set to your nickname.')]],
@ -78,7 +78,7 @@ class UserPanel extends AbstractController
['save', SubmitType::class, ['label' => _m('Save')]],
];
$extra_step = function ($data, $extra_args) use ($user) { $user->setNickname($data['nickname']); };
$form = Form::handle($form_definition, $request, $profile, $extra, $extra_step, [['self_tags' => $extra['self_tags']]]);
$form = Form::handle($form_definition, $request, $actor, $extra, $extra_step, [['self_tags' => $extra['self_tags']]]);
return ['_template' => 'settings/profile.html.twig', 'prof' => $form->createView()];
}
@ -139,18 +139,18 @@ class UserPanel extends AbstractController
} else {
throw new ClientException('Invalid form');
}
$profile_id = Common::profile()->getId();
$file = Media::validateAndStoreFile($sfile, Common::config('avatar', 'dir'), $file_title);
$avatar = null;
$actor_id = Common::actor()->getId();
$file = Media::validateAndStoreFile($sfile, Common::config('avatar', 'dir'), $file_title);
$avatar = null;
try {
$avatar = DB::find('avatar', ['profile_id' => $profile_id]);
$avatar = DB::find('avatar', ['actor_id' => $actor_id]);
} catch (Exception $e) {
}
if ($avatar != null) {
$avatar->delete();
} else {
DB::persist($file);
DB::persist(Avatar::create(['profile_id' => $profile_id, 'file_id' => $file->getId()]));
DB::persist(Avatar::create(['actor_id' => $actor_id, 'file_id' => $file->getId()]));
}
DB::flush();
// Only delete files if the commit went through
@ -173,12 +173,12 @@ class UserPanel extends AbstractController
$label = str_replace('_', ' ', ucfirst($name));
$labels = [
'target_profile_id' => 'Target Profiles',
'dm' => 'DM',
'target_actor_id' => 'Target Actors',
'dm' => 'DM',
];
$help = [
'target_profile_id' => 'If specified, these settings apply only to these profiles (comma- or space-separated list)',
'target_actor_id' => 'If specified, these settings apply only to these profiles (comma- or space-separated list)',
'activity_by_followed' => 'Notify me when someone I follow has new activity',
'mention' => 'Notify me when mentions me in a notice',
'reply' => 'Notify me when someone replies to a notice made by me',
@ -195,8 +195,8 @@ class UserPanel extends AbstractController
$form_defs['placeholder'][$name] = [$name, CheckboxType::class, ['data' => $val, 'label' => _m($labels[$name] ?? $label), 'help' => _m($help[$name])]];
break;
case Types::INTEGER:
if ($name == 'target_profile_id') {
$form_defs['placeholder'][$name] = ['target_profiles', TextType::class, ['data' => $val, 'label' => _m($labels[$name]), 'help' => _m($help[$name])], 'transformer' => ProfileArrayTransformer::class];
if ($name == 'target_actor_id') {
$form_defs['placeholder'][$name] = ['target_actors', TextType::class, ['data' => $val, 'label' => _m($labels[$name]), 'help' => _m($help[$name])], 'transformer' => ActorArrayTransformer::class];
break;
}
// no break

View File

@ -62,7 +62,7 @@ class Controller extends AbstractController implements EventSubscriberInterface
$controller = $event->getController();
$request = $event->getRequest();
if (($user = Common::user()) !== null && ($avatar = DB::find('avatar', ['profile_id' => $user->getProfile()->getId()])) != null) {
if (($user = Common::user()) !== null && ($avatar = DB::find('avatar', ['gsactor_id' => $user->getActor()->getId()])) != null) {
$avatar_filename = $avatar->getUrl();
} else {
$avatar_filename = '/public/assets/default_avatar.svg';

View File

@ -100,6 +100,9 @@ abstract class DB
$args[0] = '\App\Entity\\' . ucfirst(Formatting::snakeCaseToCamelCase($args[0]));
}
}
if (($args[0] ?? '') === '\App\Entity\Gsactor') {
$args[0] = '\App\Entity\GSActor';
}
return self::$em->{$name}(...$args);
}

View File

@ -35,8 +35,8 @@ namespace App\Util;
use App\Core\DB\DB;
use App\Core\Router;
use App\Core\Security;
use App\Entity\GSActor;
use App\Entity\LocalUser;
use App\Entity\Profile;
use Functional as F;
abstract class Common
@ -75,9 +75,9 @@ abstract class Common
return Security::getUser();
}
public static function profile(): ?Profile
public static function actor(): ?GSActor
{
return self::user()->getProfile();
return self::user()->getActor();
}
/**

View File

@ -32,7 +32,7 @@
namespace App\Util\Form;
class ProfileArrayTransformer extends ArrayTransformer
class ActorArrayTransformer extends ArrayTransformer
{
/**
* @param array $a

View File

@ -22,6 +22,9 @@
namespace App\Util;
use App\Core\DB\DB;
use App\Entity\GSActor;
use App\Entity\LocalGroup;
use App\Entity\LocalUser;
use Normalizer;
/**
@ -146,9 +149,9 @@ class Nickname
} elseif (self::isReserved($nickname) || Common::isSystemPath($nickname)) {
throw new NicknameReservedException();
} elseif ($check_already_used) {
$profile = self::isTaken($nickname);
if ($profile instanceof Profile) {
throw new NicknameTakenException($profile);
$actor = self::isTaken($nickname);
if ($actor instanceof GSActor) {
throw new NicknameTakenException($actor);
}
}
@ -197,9 +200,9 @@ class Nickname
/**
* Is the nickname already in use locally? Checks the User table.
*
* @return null|Profile Returns Profile if nickname found, otherwise null
* @return null|GSActor Returns GSActor if nickname found
*/
public static function isTaken(string $nickname): ?Profile
public static function isTaken(string $nickname): ?GSActor
{
$found = DB::findBy('local_user', ['nickname' => $nickname]);
if ($found instanceof LocalUser) {
@ -207,7 +210,7 @@ class Nickname
}
$found = DB::findBy('local_group', ['nickname' => $nickname]);
if ($found instanceof Local_group) {
if ($found instanceof LocalGroup) {
return $found->getProfile();
}