adding some plumbing to auto refresh weather, integrated it into local concurrently command
This commit is contained in:
@@ -35,3 +35,10 @@ DEFAULT_URI=http://localhost
|
||||
# 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 ###
|
||||
|
||||
###> symfony/messenger ###
|
||||
# Choose one of the transports below
|
||||
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
|
||||
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
|
||||
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
|
||||
###< symfony/messenger ###
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
"symfony/form": "8.1.*",
|
||||
"symfony/framework-bundle": "8.1.*",
|
||||
"symfony/http-client": "8.1.*",
|
||||
"symfony/messenger": "8.1.*",
|
||||
"symfony/runtime": "8.1.*",
|
||||
"symfony/scheduler": "8.1.*",
|
||||
"symfony/security-bundle": "8.1.*",
|
||||
"symfony/twig-bundle": "8.1.*",
|
||||
"symfony/validator": "8.1.*",
|
||||
|
||||
Generated
+178
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "2d5ff7449d92b622be5a4168fbc982b1",
|
||||
"content-hash": "97253ca2b47f72fd845cd6bc2d00edb6",
|
||||
"packages": [
|
||||
{
|
||||
"name": "doctrine/collections",
|
||||
@@ -3275,6 +3275,98 @@
|
||||
],
|
||||
"time": "2026-06-27T09:27:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/messenger",
|
||||
"version": "v8.1.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/messenger.git",
|
||||
"reference": "fa890d0632db0b5e8bc547560b412de824b3b9cd"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/messenger/zipball/fa890d0632db0b5e8bc547560b412de824b3b9cd",
|
||||
"reference": "fa890d0632db0b5e8bc547560b412de824b3b9cd",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.4.1",
|
||||
"psr/log": "^1|^2|^3",
|
||||
"symfony/clock": "^7.4|^8.0",
|
||||
"symfony/deprecation-contracts": "^2.5|^3"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/console": "<7.4",
|
||||
"symfony/dependency-injection": "<8.1",
|
||||
"symfony/event-dispatcher-contracts": "<2.5",
|
||||
"symfony/lock": "<7.4",
|
||||
"symfony/serializer": "<7.4.4|>=8.0,<8.0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"psr/cache": "^1.0|^2.0|^3.0",
|
||||
"symfony/console": "^7.4|^8.0",
|
||||
"symfony/dependency-injection": "^8.1",
|
||||
"symfony/event-dispatcher": "^7.4|^8.0",
|
||||
"symfony/http-kernel": "^7.4|^8.0",
|
||||
"symfony/lock": "^7.4|^8.0",
|
||||
"symfony/process": "^7.4|^8.0",
|
||||
"symfony/property-access": "^7.4|^8.0",
|
||||
"symfony/rate-limiter": "^7.4|^8.0",
|
||||
"symfony/routing": "^7.4|^8.0",
|
||||
"symfony/serializer": "^7.4.4|^8.0.4",
|
||||
"symfony/service-contracts": "^2.5|^3",
|
||||
"symfony/stopwatch": "^7.4|^8.0",
|
||||
"symfony/validator": "^7.4|^8.0",
|
||||
"symfony/var-dumper": "^7.4|^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Messenger\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Samuel Roze",
|
||||
"email": "samuel.roze@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Helps applications send and receive messages to/from other applications or via message queues",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/messenger/tree/v8.1.5"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-08-21T20:43:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/options-resolver",
|
||||
"version": "v8.1.0",
|
||||
@@ -4257,6 +4349,91 @@
|
||||
],
|
||||
"time": "2026-05-29T05:06:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/scheduler",
|
||||
"version": "v8.1.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/scheduler.git",
|
||||
"reference": "9791e381ac09bad9986da24eb15f24fe49e220d3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/scheduler/zipball/9791e381ac09bad9986da24eb15f24fe49e220d3",
|
||||
"reference": "9791e381ac09bad9986da24eb15f24fe49e220d3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.4.1",
|
||||
"symfony/clock": "^7.4|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dragonmantank/cron-expression": "^3.1",
|
||||
"symfony/cache": "^7.4.8|^8.0.8",
|
||||
"symfony/console": "^7.4|^8.0",
|
||||
"symfony/dependency-injection": "^7.4|^8.0",
|
||||
"symfony/event-dispatcher": "^7.4|^8.0",
|
||||
"symfony/lock": "^7.4|^8.0",
|
||||
"symfony/messenger": "^7.4|^8.0",
|
||||
"symfony/serializer": "^7.4|^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Scheduler\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sergey Rabochiy",
|
||||
"email": "upyx.00@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Provides scheduling through Symfony Messenger",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"cron",
|
||||
"schedule",
|
||||
"scheduler"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/scheduler/tree/v8.1.5"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-08-21T17:47:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/security-bundle",
|
||||
"version": "v8.1.1",
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
framework:
|
||||
messenger:
|
||||
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
|
||||
# failure_transport: failed
|
||||
|
||||
transports:
|
||||
# https://symfony.com/doc/current/messenger.html#transport-configuration
|
||||
# async: '%env(MESSENGER_TRANSPORT_DSN)%'
|
||||
# failed: 'doctrine://default?queue_name=failed'
|
||||
sync: 'sync://'
|
||||
|
||||
routing:
|
||||
# Route your messages to the transports
|
||||
# 'App\Message\YourMessage': async
|
||||
|
||||
# when@test:
|
||||
# framework:
|
||||
# messenger:
|
||||
# transports:
|
||||
# # replace with your transport name here (e.g., my_transport: 'in-memory://')
|
||||
# # For more Messenger testing tools, see https://github.com/zenstruck/messenger-test
|
||||
# async: 'in-memory://'
|
||||
@@ -427,7 +427,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
||||
* resources?: string|array<string, scalar|Param|null>,
|
||||
* },
|
||||
* messenger?: bool|array{ // Messenger configuration
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* enabled?: bool|Param, // Default: true
|
||||
* routing?: array<string, string|list<scalar|Param|null>>,
|
||||
* serializer?: array{
|
||||
* default_serializer?: scalar|Param|null, // Service id to use as the default serializer for the transports. // Default: "messenger.transport.native_php_serializer"
|
||||
@@ -467,7 +467,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
||||
* }>,
|
||||
* },
|
||||
* scheduler?: bool|array{ // Scheduler configuration
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* enabled?: bool|Param, // Default: true
|
||||
* },
|
||||
* disallow_search_engine_index?: bool|Param, // Enabled by default when debug is enabled. // Default: true
|
||||
* http_client?: bool|array{ // HTTP Client configuration
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260825103258 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE user_settings (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, label VARCHAR(255) NOT NULL, value VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci`');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP TABLE user_settings');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260825104115 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user_settings CHANGE user_id user_id_id INT NOT NULL');
|
||||
$this->addSql('ALTER TABLE user_settings ADD CONSTRAINT FK_5C844C59D86650F FOREIGN KEY (user_id_id) REFERENCES `user` (id)');
|
||||
$this->addSql('CREATE INDEX IDX_5C844C59D86650F ON user_settings (user_id_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user_settings DROP FOREIGN KEY FK_5C844C59D86650F');
|
||||
$this->addSql('DROP INDEX IDX_5C844C59D86650F ON user_settings');
|
||||
$this->addSql('ALTER TABLE user_settings CHANGE user_id_id user_id INT NOT NULL');
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,10 +1,12 @@
|
||||
{
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev-server": "encore dev-server",
|
||||
"dev:webpack": "encore dev",
|
||||
"watch": "encore dev --watch",
|
||||
"dev": "concurrently --names server,assets \"frankenphp run\" \"npm run watch\"",
|
||||
"build": "encore production --progress"
|
||||
"dev": "concurrently --names server,assets,scheduler \"frankenphp run\" \"npm run watch\" \"frankenphp php-cli bin/console messenger:consume scheduler_scheduler_weather -vv\"",
|
||||
"build": "encore production --progress",
|
||||
"scheduler": "frankenphp php-cli bin/console messenger:consume scheduler_scheduler_weather"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource/noto-sans": "^5.3.0",
|
||||
|
||||
@@ -4,28 +4,63 @@ namespace App\Command;
|
||||
|
||||
use App\Repository\SettingsRepository;
|
||||
use App\Service\WeatherService;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Scheduler\Attribute\AsPeriodicTask;
|
||||
|
||||
#[AsCommand(name: 'app:weather:refresh', description: 'Refresh cached Open-Meteo forecasts for saved locations.')]
|
||||
#[AsCommand(
|
||||
name: 'app:weather:refresh',
|
||||
description: 'Refresh cached Open-Meteo forecasts for saved locations.',
|
||||
)]
|
||||
#[AsPeriodicTask(
|
||||
frequency: '12 hours',
|
||||
schedule: 'scheduler_weather',
|
||||
)]
|
||||
final class RefreshWeatherCommand extends Command
|
||||
{
|
||||
public function __construct(private SettingsRepository $settings, private WeatherService $weather)
|
||||
{
|
||||
public function __construct(
|
||||
private SettingsRepository $settings,
|
||||
private WeatherService $weather,
|
||||
private LoggerInterface $logger,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$startedAt = microtime(true);
|
||||
|
||||
$this->logger->info('Scheduled weather refresh started.');
|
||||
|
||||
$locations = $this->settings->findWithLocation();
|
||||
$locationCount = count($locations);
|
||||
$rows = 0;
|
||||
foreach ($this->settings->findWithLocation() as $settings) {
|
||||
|
||||
$this->logger->info(sprintf(
|
||||
'Found %d location(s) with weather settings.',
|
||||
$locationCount
|
||||
));
|
||||
|
||||
foreach ($locations as $settings) {
|
||||
$rows += $this->weather->refresh($settings);
|
||||
}
|
||||
|
||||
$output->writeln(sprintf('Refreshed %d daily weather forecasts.', $rows));
|
||||
$duration = microtime(true) - $startedAt;
|
||||
|
||||
$message = sprintf(
|
||||
'Weather refresh completed: %d location(s), %d daily forecast(s) refreshed in %.2f seconds.',
|
||||
$locationCount,
|
||||
$rows,
|
||||
$duration,
|
||||
);
|
||||
|
||||
$output->writeln($message);
|
||||
|
||||
$this->logger->info($message);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ use App\Entity\Settings;
|
||||
use App\Entity\User;
|
||||
|
||||
use App\Entity\Task;
|
||||
use App\Entity\UserSettings;
|
||||
use App\Form\TaskType;
|
||||
use App\Repository\TaskRepository;
|
||||
use App\Service\TaskRecommendationService;
|
||||
@@ -202,5 +203,12 @@ final class TaskController extends AbstractController
|
||||
|
||||
return $this->redirectToRoute('app_task_index');
|
||||
}
|
||||
|
||||
public function getUserSettings(string $label): Settings{
|
||||
$user = $this->getUser();
|
||||
$settings = $user->getSettings();
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\UserSettings;
|
||||
use App\Form\UserSettings1Type;
|
||||
use App\Repository\UserSettingsRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/user/settings')]
|
||||
final class UserSettingsController extends AbstractController
|
||||
{
|
||||
#[Route(name: 'app_user_settings_index', methods: ['GET'])]
|
||||
public function index(UserSettingsRepository $userSettingsRepository): Response
|
||||
{
|
||||
return $this->render('user_settings/index.html.twig', [
|
||||
'user_settings' => $userSettingsRepository->findAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/new', name: 'app_user_settings_new', methods: ['GET', 'POST'])]
|
||||
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$userSetting = new UserSettings();
|
||||
$form = $this->createForm(UserSettings1Type::class, $userSetting);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->persist($userSetting);
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_user_settings_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('user_settings/new.html.twig', [
|
||||
'user_setting' => $userSetting,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_user_settings_show', methods: ['GET'])]
|
||||
public function show(UserSettings $userSetting): Response
|
||||
{
|
||||
return $this->render('user_settings/show.html.twig', [
|
||||
'user_setting' => $userSetting,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}/edit', name: 'app_user_settings_edit', methods: ['GET', 'POST'])]
|
||||
public function edit(Request $request, UserSettings $userSetting, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$form = $this->createForm(UserSettings1Type::class, $userSetting);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_user_settings_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
|
||||
return $this->render('user_settings/edit.html.twig', [
|
||||
'user_setting' => $userSetting,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_user_settings_delete', methods: ['POST'])]
|
||||
public function delete(Request $request, UserSettings $userSetting, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
if ($this->isCsrfTokenValid('delete'.$userSetting->getId(), $request->getPayload()->getString('_token'))) {
|
||||
$entityManager->remove($userSetting);
|
||||
$entityManager->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_user_settings_index', [], Response::HTTP_SEE_OTHER);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
@@ -35,6 +37,17 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
|
||||
private ?Settings $settings = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, UserSettings>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: UserSettings::class, mappedBy: 'user_id', orphanRemoval: true)]
|
||||
private Collection $userSettings;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->userSettings = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -128,4 +141,34 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, UserSettings>
|
||||
*/
|
||||
public function getUserSettings(): Collection
|
||||
{
|
||||
return $this->userSettings;
|
||||
}
|
||||
|
||||
public function addUserSetting(UserSettings $userSetting): static
|
||||
{
|
||||
if (!$this->userSettings->contains($userSetting)) {
|
||||
$this->userSettings->add($userSetting);
|
||||
$userSetting->setUserId($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeUserSetting(UserSettings $userSetting): static
|
||||
{
|
||||
if ($this->userSettings->removeElement($userSetting)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($userSetting->getUserId() === $this) {
|
||||
$userSetting->setUserId(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\UserSettingsRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserSettingsRepository::class)]
|
||||
class UserSettings
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
// #[ORM\Column]
|
||||
// private ?int $user_id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $label = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $value = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'userSettings')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $user_id = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): static
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getValue(): ?string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function setValue(string $value): static
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUserId(): ?User
|
||||
{
|
||||
return $this->user_id;
|
||||
}
|
||||
|
||||
public function setUserId(?User $user_id): static
|
||||
{
|
||||
$this->user_id = $user_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserSettings;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class UserSettings1Type extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('label')
|
||||
->add('value')
|
||||
->add('user_id', EntityType::class, [
|
||||
'class' => User::class,
|
||||
'choice_label' => 'id',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => UserSettings::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\UserSettings;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class UserSettingsType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('user_id')
|
||||
->add('label')
|
||||
->add('value')
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => UserSettings::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\UserSettings;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<UserSettings>
|
||||
*/
|
||||
class UserSettingsRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, UserSettings::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return UserSettings[] Returns an array of UserSettings objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('u')
|
||||
// ->andWhere('u.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('u.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?UserSettings
|
||||
// {
|
||||
// return $this->createQueryBuilder('u')
|
||||
// ->andWhere('u.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Component\Scheduler\Attribute\AsSchedule;
|
||||
use Symfony\Component\Scheduler\Schedule as SymfonySchedule;
|
||||
use Symfony\Component\Scheduler\ScheduleProviderInterface;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
#[AsSchedule]
|
||||
class Schedule implements ScheduleProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private CacheInterface $cache,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getSchedule(): SymfonySchedule
|
||||
{
|
||||
return (new SymfonySchedule())
|
||||
->stateful($this->cache) // ensure missed tasks are executed
|
||||
->processOnlyLastMissedRun(true) // ensure only last missed task is run
|
||||
|
||||
// add your own tasks here
|
||||
// see https://symfony.com/doc/current/scheduler.html#attaching-recurring-messages-to-a-schedule
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,18 @@
|
||||
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
|
||||
}
|
||||
},
|
||||
"symfony/messenger": {
|
||||
"version": "8.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "6.0",
|
||||
"ref": "d8936e2e2230637ef97e5eecc0eea074eecae58b"
|
||||
},
|
||||
"files": [
|
||||
"config/packages/messenger.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/property-info": {
|
||||
"version": "8.1",
|
||||
"recipe": {
|
||||
@@ -126,6 +138,18 @@
|
||||
"config/routes.yaml"
|
||||
]
|
||||
},
|
||||
"symfony/scheduler": {
|
||||
"version": "8.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "7.2",
|
||||
"ref": "caea3c928ee9e1b21288fd76aef36f16ea355515"
|
||||
},
|
||||
"files": [
|
||||
"src/Schedule.php"
|
||||
]
|
||||
},
|
||||
"symfony/security-bundle": {
|
||||
"version": "8.1",
|
||||
"recipe": {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<form method="post" action="{{ path('app_user_settings_delete', {'id': user_setting.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ user_setting.id) }}">
|
||||
<button class="btn">Delete</button>
|
||||
</form>
|
||||
@@ -0,0 +1,4 @@
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form) }}
|
||||
<button class="btn">{{ button_label|default('Save') }}</button>
|
||||
{{ form_end(form) }}
|
||||
@@ -0,0 +1,13 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Edit UserSettings{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Edit UserSettings</h1>
|
||||
|
||||
{{ include('user_settings/_form.html.twig', {'button_label': 'Update'}) }}
|
||||
|
||||
<a href="{{ path('app_user_settings_index') }}">back to list</a>
|
||||
|
||||
{{ include('user_settings/_delete_form.html.twig') }}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,37 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}UserSettings index{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>UserSettings index</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Label</th>
|
||||
<th>Value</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user_setting in user_settings %}
|
||||
<tr>
|
||||
<td>{{ user_setting.id }}</td>
|
||||
<td>{{ user_setting.label }}</td>
|
||||
<td>{{ user_setting.value }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_user_settings_show', {'id': user_setting.id}) }}">show</a>
|
||||
<a href="{{ path('app_user_settings_edit', {'id': user_setting.id}) }}">edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="4">no records found</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{{ path('app_user_settings_new') }}">Create new</a>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,11 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}New UserSettings{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Create new UserSettings</h1>
|
||||
|
||||
{{ include('user_settings/_form.html.twig') }}
|
||||
|
||||
<a href="{{ path('app_user_settings_index') }}">back to list</a>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,30 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}UserSettings{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>UserSettings</h1>
|
||||
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<td>{{ user_setting.id }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Label</th>
|
||||
<td>{{ user_setting.label }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Value</th>
|
||||
<td>{{ user_setting.value }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{{ path('app_user_settings_index') }}">back to list</a>
|
||||
|
||||
<a href="{{ path('app_user_settings_edit', {'id': user_setting.id}) }}">edit</a>
|
||||
|
||||
{{ include('user_settings/_delete_form.html.twig') }}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user