mirror of
https://framagit.org/tom79/fediplan.git
synced 2025-04-09 15:41:49 +02:00
- migration to Symfony 7
This commit is contained in:
parent
26a50e3ec5
commit
f10b894447
18 changed files with 1590 additions and 251 deletions
10
.env
10
.env
|
@ -19,3 +19,13 @@ APP_ENV=dev
|
|||
APP_SECRET=7189792ca5da6b84aff72ec1c63d95ae
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
|
||||
###> doctrine/doctrine-bundle ###
|
||||
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
|
||||
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
|
||||
#
|
||||
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
|
||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
|
||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
"ext-iconv": "*",
|
||||
"craue/formflow-bundle": "*",
|
||||
"curl/curl": "^2.5",
|
||||
"doctrine/dbal": "^3",
|
||||
"doctrine/doctrine-bundle": "^2.12",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.3",
|
||||
"doctrine/orm": "^3.1",
|
||||
"friendsofsymfony/jsrouting-bundle": "*",
|
||||
"phpdocumentor/reflection-docblock": "^5.4",
|
||||
"phpstan/phpdoc-parser": "^1.29",
|
||||
|
|
1568
composer.lock
generated
1568
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -13,4 +13,6 @@ return [
|
|||
Symfony\UX\Turbo\TurboBundle::class => ['all' => true],
|
||||
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
|
||||
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
|
||||
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
|
||||
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
|
||||
];
|
||||
|
|
52
config/packages/doctrine.yaml
Normal file
52
config/packages/doctrine.yaml
Normal file
|
@ -0,0 +1,52 @@
|
|||
doctrine:
|
||||
dbal:
|
||||
url: '%env(resolve:DATABASE_URL)%'
|
||||
|
||||
# IMPORTANT: You MUST configure your server version,
|
||||
# either here or in the DATABASE_URL env var (see .env file)
|
||||
#server_version: '16'
|
||||
|
||||
profiling_collect_backtrace: '%kernel.debug%'
|
||||
use_savepoints: true
|
||||
orm:
|
||||
auto_generate_proxy_classes: true
|
||||
enable_lazy_ghost_objects: true
|
||||
report_fields_where_declared: true
|
||||
validate_xml_mapping: true
|
||||
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
|
||||
auto_mapping: true
|
||||
mappings:
|
||||
App:
|
||||
type: attribute
|
||||
is_bundle: false
|
||||
dir: '%kernel.project_dir%/src/Entity'
|
||||
prefix: 'App\Entity'
|
||||
alias: App
|
||||
controller_resolver:
|
||||
auto_mapping: true
|
||||
|
||||
when@test:
|
||||
doctrine:
|
||||
dbal:
|
||||
# "TEST_TOKEN" is typically set by ParaTest
|
||||
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
|
||||
|
||||
when@prod:
|
||||
doctrine:
|
||||
orm:
|
||||
auto_generate_proxy_classes: false
|
||||
proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
|
||||
query_cache_driver:
|
||||
type: pool
|
||||
pool: doctrine.system_cache_pool
|
||||
result_cache_driver:
|
||||
type: pool
|
||||
pool: doctrine.result_cache_pool
|
||||
|
||||
framework:
|
||||
cache:
|
||||
pools:
|
||||
doctrine.result_cache_pool:
|
||||
adapter: cache.app
|
||||
doctrine.system_cache_pool:
|
||||
adapter: cache.system
|
6
config/packages/doctrine_migrations.yaml
Normal file
6
config/packages/doctrine_migrations.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
doctrine_migrations:
|
||||
migrations_paths:
|
||||
# namespace is arbitrary but should be different from App\Migrations
|
||||
# as migrations classes should NOT be autoloaded
|
||||
'DoctrineMigrations': '%kernel.project_dir%/migrations'
|
||||
enable_profiler: false
|
|
@ -4,14 +4,16 @@ security:
|
|||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
|
||||
providers:
|
||||
users_in_memory: { memory: null }
|
||||
# used to reload user from session & other features (e.g. switch_user)
|
||||
app_user_provider:
|
||||
id: App\Security\UserProvider
|
||||
firewalls:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
main:
|
||||
lazy: true
|
||||
provider: users_in_memory
|
||||
provider: app_user_provider
|
||||
logout:
|
||||
path: logout
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ namespace App\Controller;
|
|||
|
||||
use App\Form\ComposeType;
|
||||
use App\Form\ConnectMastodonAccountFlow;
|
||||
use App\Security\MastodonAccount;
|
||||
use App\Services\Mastodon_api;
|
||||
use App\SocialEntity\Client;
|
||||
use App\SocialEntity\Compose;
|
||||
use App\SocialEntity\MastodonAccount;
|
||||
use App\SocialEntity\PollOption;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
|
@ -102,7 +102,7 @@ class FediPlanController extends AbstractController
|
|||
$account = $mastodon_api->getSingleAccount($accountReply['response']);
|
||||
$account->setInstance($host);
|
||||
$account->setToken($token_type . " " . $access_token);
|
||||
$token = new UsernamePasswordToken($account, null, array('ROLE_USER'));
|
||||
$token = new UsernamePasswordToken($account, 'main', array('ROLE_USER'));
|
||||
try {
|
||||
$this->container->get('security.token_storage')->setToken($token);
|
||||
$event = new InteractiveLoginEvent($request, $token);
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
namespace App\Form;
|
||||
|
||||
|
||||
use App\Security\MastodonAccount;
|
||||
use App\SocialEntity\Compose;
|
||||
use App\SocialEntity\MastodonAccount;
|
||||
use DateTime;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\SocialEntity;
|
||||
|
||||
namespace App\Security;
|
||||
|
||||
use App\SocialEntity\Client;
|
||||
use App\SocialEntity\CustomField;
|
||||
use App\SocialEntity\Emoji;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
@ -10,15 +12,13 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
|||
|
||||
class MastodonAccount implements UserInterface
|
||||
{
|
||||
|
||||
private $acct;
|
||||
private $id;
|
||||
|
||||
private $account_id;
|
||||
|
||||
private $username;
|
||||
|
||||
private $acct;
|
||||
|
||||
private $display_name;
|
||||
|
||||
private $locked;
|
||||
|
@ -122,12 +122,12 @@ class MastodonAccount implements UserInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?DateTimeInterface
|
||||
public function getCreatedAt(): ?\DateTime
|
||||
{
|
||||
return $this->created_at;
|
||||
}
|
||||
|
||||
public function setCreatedAt(DateTimeInterface $created_at): self
|
||||
public function setCreatedAt(\DateTime $created_at): self
|
||||
{
|
||||
$this->created_at = $created_at;
|
||||
|
||||
|
@ -419,20 +419,52 @@ class MastodonAccount implements UserInterface
|
|||
{
|
||||
$this->default_visibility = $default_visibility;
|
||||
}
|
||||
/**
|
||||
* @var list<string> The user roles
|
||||
*/
|
||||
private $roles = [];
|
||||
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
// TODO: Implement getRoles() method.
|
||||
}
|
||||
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
// TODO: Implement eraseCredentials() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* A visual identifier that represents this user.
|
||||
*
|
||||
* @see UserInterface
|
||||
*/
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
// TODO: Implement getUserIdentifier() method.
|
||||
return (string) $this->acct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserInterface
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getRoles(): array
|
||||
{
|
||||
$roles = $this->roles;
|
||||
// guarantee every user at least has ROLE_USER
|
||||
$roles[] = 'ROLE_USER';
|
||||
|
||||
return array_unique($roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $roles
|
||||
*/
|
||||
public function setRoles(array $roles): static
|
||||
{
|
||||
$this->roles = $roles;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UserInterface
|
||||
*/
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
// If you store any temporary, sensitive data on the user, clear it here
|
||||
// $this->plainPassword = null;
|
||||
}
|
||||
}
|
79
src/Security/UserProvider.php
Normal file
79
src/Security/UserProvider.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace App\Security;
|
||||
|
||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
|
||||
class UserProvider implements UserProviderInterface, PasswordUpgraderInterface
|
||||
{
|
||||
/**
|
||||
* Symfony calls this method if you use features like switch_user
|
||||
* or remember_me.
|
||||
*
|
||||
* If you're not using these features, you do not need to implement
|
||||
* this method.
|
||||
*
|
||||
* @throws UserNotFoundException if the user is not found
|
||||
*/
|
||||
public function loadUserByIdentifier($identifier): UserInterface
|
||||
{
|
||||
// Load a User object from your data source or throw UserNotFoundException.
|
||||
// The $identifier argument may not actually be a username:
|
||||
// it is whatever value is being returned by the getUserIdentifier()
|
||||
// method in your User class.
|
||||
throw new \Exception('TODO: fill in loadUserByIdentifier() inside '.__FILE__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 5.3, loadUserByIdentifier() is used instead
|
||||
*/
|
||||
public function loadUserByUsername($username): UserInterface
|
||||
{
|
||||
return $this->loadUserByIdentifier($username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the user after being reloaded from the session.
|
||||
*
|
||||
* When a user is logged in, at the beginning of each request, the
|
||||
* User object is loaded from the session and then this method is
|
||||
* called. Your job is to make sure the user's data is still fresh by,
|
||||
* for example, re-querying for fresh User data.
|
||||
*
|
||||
* If your firewall is "stateless: true" (for a pure API), this
|
||||
* method is not called.
|
||||
*/
|
||||
public function refreshUser(UserInterface $user): UserInterface
|
||||
{
|
||||
if (!$user instanceof MastodonAccount) {
|
||||
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', $user::class));
|
||||
}
|
||||
|
||||
// Return a User object after making sure its data is "fresh".
|
||||
// Or throw a UsernameNotFoundException if the user no longer exists.
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells Symfony to use this provider for this User class.
|
||||
*/
|
||||
public function supportsClass(string $class): bool
|
||||
{
|
||||
return MastodonAccount::class === $class || is_subclass_of($class, MastodonAccount::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades the hashed password of a user, typically for using a better hash algorithm.
|
||||
*/
|
||||
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
|
||||
{
|
||||
// TODO: when hashed passwords are in use, this method should:
|
||||
// 1. persist the new password in the user storage
|
||||
// 2. update the $user object with $user->setPassword($newHashedPassword);
|
||||
}
|
||||
}
|
|
@ -11,12 +11,12 @@
|
|||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Security\MastodonAccount;
|
||||
use App\Services\Curl as Curl;
|
||||
use App\SocialEntity\Application;
|
||||
use App\SocialEntity\Attachment;
|
||||
use App\SocialEntity\CustomField;
|
||||
use App\SocialEntity\Emoji;
|
||||
use App\SocialEntity\MastodonAccount;
|
||||
use App\SocialEntity\Mention;
|
||||
use App\SocialEntity\Notification;
|
||||
use App\SocialEntity\Poll;
|
||||
|
@ -1241,13 +1241,13 @@ class Mastodon_api
|
|||
return $MastodonAccount;
|
||||
}
|
||||
|
||||
public function stringToDate($string_date)
|
||||
public function stringToDate($string_date): DateTime
|
||||
{
|
||||
try {
|
||||
return new DateTime($string_date);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
return "";
|
||||
return new DateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\SocialEntity;
|
||||
|
||||
|
||||
use App\Security\MastodonAccount;
|
||||
use DateTimeInterface;
|
||||
|
||||
class CustomField
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\SocialEntity;
|
||||
|
||||
|
||||
use App\Security\MastodonAccount;
|
||||
|
||||
class Emoji
|
||||
{
|
||||
private $id;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\SocialEntity;
|
||||
|
||||
|
||||
use App\Security\MastodonAccount;
|
||||
use DateTime;
|
||||
|
||||
class Notification
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\SocialEntity;
|
||||
|
||||
|
||||
use App\Security\MastodonAccount;
|
||||
use DateTime;
|
||||
|
||||
class Status
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace App\Twig;
|
||||
|
||||
use App\SocialEntity\MastodonAccount;
|
||||
use App\Security\MastodonAccount;
|
||||
use App\SocialEntity\Status;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
|
27
symfony.lock
27
symfony.lock
|
@ -2,6 +2,33 @@
|
|||
"craue/formflow-bundle": {
|
||||
"version": "3.7.0"
|
||||
},
|
||||
"doctrine/doctrine-bundle": {
|
||||
"version": "2.12",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "2.12",
|
||||
"ref": "7b1b0b637b337f6beb895589948cd119da705524"
|
||||
},
|
||||
"files": [
|
||||
"./config/packages/doctrine.yaml",
|
||||
"./src/Entity/.gitignore",
|
||||
"./src/Repository/.gitignore"
|
||||
]
|
||||
},
|
||||
"doctrine/doctrine-migrations-bundle": {
|
||||
"version": "3.3",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "3.1",
|
||||
"ref": "1d01ec03c6ecbd67c3375c5478c9a423ae5d6a33"
|
||||
},
|
||||
"files": [
|
||||
"./config/packages/doctrine_migrations.yaml",
|
||||
"./migrations/.gitignore"
|
||||
]
|
||||
},
|
||||
"friendsofsymfony/jsrouting-bundle": {
|
||||
"version": "3.5",
|
||||
"recipe": {
|
||||
|
|
Loading…
Add table
Reference in a new issue