Browse Source

upgrade all, add migration from framadate v1

master
Tykayn 1 year ago committed by tykayn
parent
commit
21c594a2fd
  1. 9
      .env
  2. 9
      .gitignore
  3. 13
      README.md
  4. 14
      assets/app.js
  5. 13
      bin/console
  6. 155
      composer.json
  7. 5350
      composer.lock
  8. 23
      config/bootstrap.php
  9. 13
      config/bundles.php
  10. 3
      config/packages/assets.yaml
  11. 6
      config/packages/cache.yaml
  12. 0
      config/packages/dev/jms_serializer.yaml
  13. 2
      config/packages/dev/swiftmailer.yaml
  14. 41
      config/packages/doctrine.yaml
  15. 9
      config/packages/doctrine_migrations.yaml
  16. 31
      config/packages/fos_rest.yaml
  17. 1
      config/packages/framework.yaml
  18. 10
      config/packages/graphql.yaml
  19. 0
      config/packages/jms_serializer.yaml
  20. 3
      config/packages/mailer.yaml
  21. 9
      config/packages/nelmio_api_doc.yaml
  22. 15
      config/packages/nelmio_cors.yaml
  23. 24
      config/packages/prod/doctrine.yaml
  24. 0
      config/packages/prod/jms_serializer.yaml
  25. 0
      config/packages/prod/routing.yaml
  26. 4
      config/packages/prod/webpack_encore.yaml
  27. 4
      config/packages/routing.yaml
  28. 2
      config/packages/sensio_framework_extra.yaml
  29. 0
      config/packages/swiftmailer.yaml
  30. 12
      config/packages/test/doctrine.yaml
  31. 3
      config/packages/test/framework.yaml
  32. 0
      config/packages/test/swiftmailer.yaml
  33. 0
      config/packages/test/twig.yaml
  34. 3
      config/packages/test/validator.yaml
  35. 2
      config/packages/test/webpack_encore.yaml
  36. 8
      config/packages/twig.yaml
  37. 8
      config/packages/validator.yaml
  38. 25
      config/packages/webpack_encore.yaml
  39. 5
      config/preload.php
  40. 0
      config/routes.yaml
  41. 4
      config/routes/annotations.yaml
  42. 3
      config/routes/dev/framework.yaml
  43. 3
      config/routes/dev/twig.yaml
  44. 3
      config/routes/graphql.yaml
  45. 12
      config/routes/nelmio_api_doc.yaml
  46. 17
      config/services.yaml
  47. 15
      doc/evolutions.md
  48. 16
      doc/migration.md
  49. 0
      migrations/.gitignore
  50. 31
      migrations/Version20210419202522.php
  51. 40
      package.json
  52. 15
      public/index.php
  53. 0
      src/Controller/.gitignore
  54. 235
      src/Controller/MigrationController.php
  55. 9
      src/Controller/PollController.php
  56. 34
      src/Controller/api/PollController.php
  57. 0
      src/Entity/.gitignore
  58. 89
      src/Entity/Comment.php
  59. 1037
      src/Entity/Poll.php
  60. 53
      src/Kernel.php
  61. 0
      src/Repository/.gitignore
  62. 6
      src/Repository/PollRepository.php
  63. 374
      symfony.lock
  64. 20
      templates/admin/index.html.twig
  65. 20
      templates/default/index.html.twig
  66. 20
      templates/migration/index.html.twig
  67. 20
      templates/owner/index.html.twig
  68. 14
      templates/pages/funky.html.twig
  69. 82
      templates/pages/migration.html.twig
  70. 20
      templates/vote/index.html.twig
  71. 74
      webpack.config.js

9
.env

@ -32,11 +32,6 @@ WEBSITE_LOGO=logo.svg
# IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=mysql://framadate-admin:framadate-admin-password@127.0.0.1:3306/framadate_api
###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
###< nelmio/cors-bundle ###
###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
@ -45,7 +40,3 @@ MAILER_URL=sendmail://YOUR_WEBSITE
# set the support email who will answer users in case of emergency
SUPPORT_EMAIL=YOUR_EMAIL
###< symfony/swiftmailer-bundle ###
###> symfony/mailer ###
MAILER_DSN=smtp://localhost
###< symfony/mailer ###

9
.gitignore vendored

@ -1,4 +1,3 @@
###> symfony/framework-bundle ###
.env.local
/.env.local.php
@ -41,12 +40,4 @@ public/*
###< symfony/phpunit-bridge ###
node_modules
###> symfony/webpack-encore-bundle ###
/node_modules/
/public/build/
npm-debug.log
yarn-error.log
###< symfony/webpack-encore-bundle ###
funky-framadate-front

13
README.md

@ -1,5 +1,5 @@
#Funky Framadate API
Experimental REST backend in symfony 4 for Funky framadate frontend.
Experimental REST backend in symfony 5 for Funky framadate frontend.
https://framagit.org/framasoft/framadate/funky-framadate-front
Follow this guide to setup.
@ -14,7 +14,7 @@ return stack of votes when we want to get the configuration of one poll (see [do
***
### Requirements
You MUST have php version 7+ and [Composer](https://getcomposer.org/download/), and a database like Mysql, or postgresql, or mongodb, or any database that Doctrine can handle.
You MUST have php version 8+ and [Composer](https://getcomposer.org/download/), and a database like Mysql, or postgresql, or mongodb, or any database that Doctrine can handle.
Setup access to database by creating a .env.local file, and fill the database user and password data.
you can check that the database connection works with the command:
```bash
@ -37,8 +37,10 @@ composer check-platform-reqs
### install the vendors
```bash
composer install
```#Funky Framadate API
Experimental REST backend in symfony 4 for Funky framadate frontend.
```
#Funky Framadate API
Experimental REST backend in symfony 5 for Funky framadate frontend.
https://framagit.org/framasoft/framadate/funky-framadate-front
Follow this guide to setup.
@ -53,7 +55,7 @@ return stack of votes when we want to get the configuration of one poll (see [do
***
### Requirements
You MUST have php version 7+ and [Composer](https://getcomposer.org/download/), and a database like Mysql, or postgresql, or mongodb, or any database that Doctrine can handle.
You MUST have php version 8+ and [Composer](https://getcomposer.org/download/), and a database like Mysql, or postgresql, or mongodb, or any database that Doctrine can handle.
Setup access to database by creating a .env.local file, and fill the database user and password data.
you can check that the database connection works with the command:
```bash
@ -125,6 +127,5 @@ made by B. Lemoine, aka Tykayn, for the framadate funky front end project, a pol
## contacts
* contact@cipherbliss.com
* https://mastodon.cipherbliss.com/@tykayn
* https://keybase.io/tykayn
* https://twitter.com/tykayn
* https://cipherbliss.com

14
assets/app.js

@ -1,14 +0,0 @@
/*
* Welcome to your app's main JavaScript file!
*
* We recommend including the built version of this JavaScript file
* (and its CSS file) in your base layout (base.html.twig).
*/
// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.scss';
// Need jQuery? Install it with "yarn add jquery", then uncomment to import it.
// import $ from 'jquery';
console.log('Hello Webpack Encore! Edit me in assets/app.js');

13
bin/console

@ -4,18 +4,19 @@
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}
set_time_limit(0);
require dirname(__DIR__).'/vendor/autoload.php';
if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}
$input = new ArgvInput();
@ -27,7 +28,7 @@ if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}
require dirname(__DIR__).'/config/bootstrap.php';
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) {
umask(0000);

155
composer.json

@ -1,90 +1,75 @@
{
"type": "project",
"license": "AGPLv3",
"require": {
"php": ">=7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"ext-pdo_mysql": "*",
"friendsofsymfony/rest-bundle": "^2.6",
"jms/serializer-bundle": "^3.4",
"nelmio/api-doc-bundle": "^4.0",
"nelmio/cors-bundle": "^2.0",
"overblog/graphql-bundle": "^0.13.4",
"sensio/framework-extra-bundle": "^5.5",
"swiftmailer/swiftmailer": "^6.0",
"symfony/config": "4.3.*",
"symfony/console": "4.3.*",
"symfony/dependency-injection": "4.3.*",
"symfony/dotenv": "4.3.*",
"symfony/expression-language": "4.3.*",
"symfony/flex": "^1.3.1",
"symfony/form": "4.3.*",
"symfony/framework-bundle": "4.3.*",
"symfony/intl": "4.3.*",
"symfony/mailer": "4.3.*",
"symfony/maker-bundle": "^1.14",
"symfony/orm-pack": "^1.0",
"symfony/security-csrf": "4.3.*",
"symfony/swiftmailer-bundle": "^3.4",
"symfony/twig-bundle": "4.3.*",
"symfony/validator": "4.3.*",
"symfony/webpack-encore-bundle": "^1.7",
"symfony/yaml": "4.3.*"
},
"require-dev": {
"ext-mbstring": "*",
"ext-pdo_sqlite": "*",
"doctrine/doctrine-fixtures-bundle": "^3.2",
"liip/test-fixtures-bundle": "^1.0.0",
"symfony/browser-kit": "4.3.*",
"symfony/phpunit-bridge": "^5.0",
"symfony/web-server-bundle": "4.3.*"
},
"config": {
"preferred-install": {
"*": "dist"
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1",
"doctrine/annotations": "^1.12",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^2.8",
"friendsofsymfony/rest-bundle": "^3.0",
"jms/serializer-bundle": "^3.9",
"sensio/framework-extra-bundle": "^6.1",
"symfony/asset": "5.2.*",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
"symfony/flex": "^1.3.1",
"symfony/form": "5.2.*",
"symfony/framework-bundle": "5.2.*",
"symfony/proxy-manager-bridge": "5.2.*",
"symfony/swiftmailer-bundle": "^3.5",
"symfony/twig-bundle": "5.2.*",
"symfony/yaml": "5.2.*"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.2.*"
}
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.3.*"
"require-dev": {
"symfony/maker-bundle": "^1.30"
}
}
}

5350
composer.lock generated

File diff suppressed because it is too large Load Diff

23
config/bootstrap.php

@ -1,23 +0,0 @@
<?php
use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__).'/vendor/autoload.php';
// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
foreach ($env as $k => $v) {
$_ENV[$k] = $_ENV[$k] ?? (isset($_SERVER[$k]) && 0 !== strpos($k, 'HTTP_') ? $_SERVER[$k] : $v);
}
} elseif (!class_exists(Dotenv::class)) {
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
// load all the .env files
(new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
}
$_SERVER += $_ENV;
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

13
config/bundles.php

@ -2,19 +2,12 @@
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
FOS\RestBundle\FOSRestBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
FOS\RestBundle\FOSRestBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Liip\TestFixturesBundle\LiipTestFixturesBundle::class => ['test' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Overblog\GraphQLBundle\OverblogGraphQLBundle::class => ['all' => true],
];

3
config/packages/assets.yaml

@ -1,3 +0,0 @@
framework:
assets:
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'

6
config/packages/cache.yaml

@ -1,10 +1,10 @@
framework:
cache:
# Put the unique name of your app here: the prefix seed
# is used to compute stable namespaces for cache keys.
# Unique name of your app: used to compute stable namespaces for cache keys.
#prefix_seed: your_vendor_name/app_name
# The app cache caches to the filesystem by default.
# The "app" cache stores to the filesystem by default.
# The data in this cache should persist between deploys.
# Other options include:
# Redis

0
config/packages/dev/jms_serializer.yaml

2
config/packages/dev/swiftmailer.yaml

@ -1,4 +1,4 @@
# See https://symfony.com/doc/current/email/dev_environment.html
swiftmailer:
# send all emails to a specific address
# delivery_addresses: ['contact@cipherbliss.com']
#delivery_addresses: ['me@example.com']

41
config/packages/doctrine.yaml

@ -1,26 +1,19 @@
doctrine:
dbal:
# configure these for your database server
# use postgresql for PostgreSQL
# use sqlite for SQLite
driver: 'mysql_pdo'
server_version: '8.0.22'
dbal:
override_url: true
url: '%env(resolve:DATABASE_URL)%'
# only needed for MySQL
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App

9
config/packages/doctrine_migrations.yaml

@ -1,5 +1,6 @@
doctrine_migrations:
dir_name: '%kernel.project_dir%/src/Migrations'
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
namespace: DoctrineMigrations
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: '%kernel.debug%'

31
config/packages/fos_rest.yaml

@ -1,18 +1,15 @@
# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest:
# param_fetcher_listener: true
# allowed_methods_listener: true
# view:
# view_response_listener: true
# exception:
# codes:
# App\Exception\MyException: 403
# messages:
# App\Exception\MyException: Forbidden area.
routing_loader: true
format_listener:
rules:
- { path: '^/',
prefer_extension: true,
fallback_format: json,
priorities: [ json, html ] }
fos_rest: null
# param_fetcher_listener: true
# allowed_methods_listener: true
# routing_loader: true
# view:
# view_response_listener: true
# exception:
# codes:
# App\Exception\MyException: 403
# messages:
# App\Exception\MyException: Forbidden area.
# format_listener:
# rules:
# - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json, html ] }

1
config/packages/framework.yaml

@ -1,3 +1,4 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: '%env(APP_SECRET)%'
#csrf_protection: true

10
config/packages/graphql.yaml

@ -1,10 +0,0 @@
overblog_graphql:
definitions:
schema:
query: Query
mappings:
types:
-
type: yaml
dir: "%kernel.project_dir%/config/graphql/types"
suffix: null

0
config/packages/jms_serializer.yaml

3
config/packages/mailer.yaml

@ -1,3 +0,0 @@
framework:
mailer:
dsn: '%env(MAILER_DSN)%'

9
config/packages/nelmio_api_doc.yaml

@ -1,9 +0,0 @@
nelmio_api_doc:
documentation:
info:
title: Poll Bliss
description: Sondages à la framadate par CipherBliss
version: 1.0.0
areas: # to filter documented areas
path_patterns:
- ^/api(?!/doc$) # Accepts routes under /api except /api/doc

15
config/packages/nelmio_cors.yaml

@ -1,15 +0,0 @@
nelmio_cors:
defaults:
origin_regex: true
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['Content-Type', 'Authorization']
expose_headers: ['Link']
max_age: 3600
paths:
'^/': null
'^/api/':
allow_origin: ['*']
allow_headers: ['Content-Type', 'Authorization']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
max_age: 3600

24
config/packages/prod/doctrine.yaml

@ -2,26 +2,14 @@ doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver:
type: service
id: doctrine.system_cache_provider
type: pool
pool: doctrine.system_cache_pool
query_cache_driver:
type: service
id: doctrine.system_cache_provider
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: service
id: doctrine.result_cache_provider
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '@doctrine.result_cache_pool'
doctrine.system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '@doctrine.system_cache_pool'
type: pool
pool: doctrine.result_cache_pool
framework:
cache:

0
config/packages/prod/jms_serializer.yaml

0
config/packages/prod/routing.yaml

4
config/packages/prod/webpack_encore.yaml

@ -1,4 +0,0 @@
#webpack_encore:
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
# Available in version 1.2
#cache: true

4
config/packages/routing.yaml

@ -1,3 +1,7 @@
framework:
router:
utf8: true
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
#default_uri: http://localhost

2
config/packages/sensio_framework_extra.yaml

@ -1,5 +1,3 @@
sensio_framework_extra:
router:
annotations: false
request:
converters: true

0
config/packages/swiftmailer.yaml

12
config/packages/test/doctrine.yaml

@ -1,5 +1,7 @@
doctrine:
dbal:
driver: pdo_sqlite
path: "%kernel.cache_dir%/test.db"
url: null
#doctrine:
# dbal:
# # Overrides the database name in the test environment only
# # "host", "port", "username", & "password" can also be set to override their respective url parts
# #
# # If you're using ParaTest, "TEST_TOKEN" is set by ParaTest otherwise nothing is appended to the database name.
# dbname: main_test%env(default::TEST_TOKEN)%

3
config/packages/test/framework.yaml

@ -2,6 +2,3 @@ framework:
test: true
session:
storage_id: session.storage.mock_file
liip_test_fixtures:
cache_db:
sqlite: liip_test_fixtures.services_database_backup.sqlite

0
config/packages/test/swiftmailer.yaml

0
config/packages/test/twig.yaml

3
config/packages/test/validator.yaml

@ -1,3 +0,0 @@
framework:
validation:
not_compromised_password: false

2
config/packages/test/webpack_encore.yaml

@ -1,2 +0,0 @@
#webpack_encore:
# strict_mode: false

8
config/packages/twig.yaml

@ -1,8 +1,2 @@
twig:
default_path: '%kernel.project_dir%/templates'
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
globals:
BASE_URL: '%env(BASE_URL)%'
WEBSITE_NAME: '%env(WEBSITE_NAME)%'
WEBSITE_LOGO: '%env(WEBSITE_LOGO)%'
default_path: '%kernel.project_dir%/templates'

8
config/packages/validator.yaml

@ -1,8 +0,0 @@
framework:
validation:
email_validation_mode: html5
# Enables validator auto-mapping support.
# For instance, basic validation constraints will be inferred from Doctrine's metadata.
#auto_mapping:
# App\Entity\: []

25
config/packages/webpack_encore.yaml

@ -1,25 +0,0 @@
webpack_encore:
# The path where Encore is building the assets - i.e. Encore.setOutputPath()
output_path: '%kernel.project_dir%/public/build'
# If multiple builds are defined (as shown below), you can disable the default build:
# output_path: false
# if using Encore.enableIntegrityHashes() and need the crossorigin attribute (default: false, or use 'anonymous' or 'use-credentials')
# crossorigin: 'anonymous'
# preload all rendered script and link tags automatically via the http2 Link header
# preload: true
# Throw an exception if the entrypoints.json file is missing or an entry is missing from the data
# strict_mode: false
# if you have multiple builds:
# builds:
# pass "frontend" as the 3rg arg to the Twig functions
# {{ encore_entry_script_tags('entry1', null, 'frontend') }}
# frontend: '%kernel.project_dir%/public/frontend/build'
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
# Put in config/packages/prod/webpack_encore.yaml
# cache: true

5
config/preload.php

@ -0,0 +1,5 @@
<?php
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}

0
config/routes.yaml

4
config/routes/annotations.yaml

@ -1,3 +1,7 @@
controllers:
resource: ../../src/Controller/
type: annotation
kernel:
resource: ../../src/Kernel.php
type: annotation

3
config/routes/dev/framework.yaml

@ -0,0 +1,3 @@
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error

3
config/routes/dev/twig.yaml

@ -1,3 +0,0 @@
_errors:
resource: '@TwigBundle/Resources/config/routing/errors.xml'
prefix: /_error

3
config/routes/graphql.yaml

@ -1,3 +0,0 @@
overblog_graphql_endpoint:
resource: "@OverblogGraphQLBundle/Resources/config/routing/graphql.yml"
prefix: api/graphql

12
config/routes/nelmio_api_doc.yaml

@ -1,12 +0,0 @@
# Expose your documentation as JSON swagger compliant
app.swagger:
path: /api/doc.json
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger }
## Requires the Asset component and the Twig bundle
## $ composer require twig asset
#app.swagger_ui:
# path: /api/doc
# methods: GET
# defaults: { _controller: nelmio_api_doc.controller.swagger_ui }

17
config/services.yaml

@ -4,8 +4,10 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
admin_token: '%env(resolve:ADMIN_TOKEN)%'
OLD_DATABASE_NAME: '%env(OLD_DATABASE_NAME)%'
OLD_DATABASE_USER: '%env(OLD_DATABASE_USER)%'
OLD_DATABASE_PASS: '%env(OLD_DATABASE_PASS)%'
UNIQ_INSTALL_KEY: '%env(UNIQ_INSTALL_KEY)%'
services:
# default configuration for services in *this* file
_defaults:
@ -15,15 +17,18 @@ services:
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
resource: '../src/Controller/'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
Doctrine\ORM\EntityManager: "@doctrine.orm.default_entity_manager"

15
doc/evolutions.md

@ -0,0 +1,15 @@
# Évolutions
Après avoir modifié le modèle de données dans les Entity, lancez la commande pour mettre à jour les getter et setters
```bash
php bin/console make:entity --regenerate
```
et pour mettre à jour le schéma en base de données
```bash
php bin/console doctrine:schema:update --force
```
# Ressources
les types de champ Doctrine:
https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/reference/basic-mapping.html#doctrine-mapping-types

16
doc/migration.md

@ -0,0 +1,16 @@
# Migration depuis la version 1 de Framadate
Cela va importer vos anciens sondages dans les tables de la nouvelle version.
* Remplissez les accès en base de données concernant la version 1 de Framadate dans votre fichier [.env](../.env) à la racine de ce dossier.
* Choisissez une chaine unique dans votre fichier .env à la place de superCaliFragilistiExpialidousiousse
* Une fois votre application accessible via navigateur, rendez vous sur votre point d'accès web à l'addresse /migration-from-v1/superCaliFragilistiExpialidousiousse en changeant __superCaliFragilistiExpialidousiousse__ par votre variable unique.
* tadam, vous aurez un message indiquant si vous avez réussi la migration.
## Comparaison de schémas
pour information, voici les schémas des bases de données des deux versions:
### Ancien
![old](../public/assets/img/framadate_v1_schema.svg)
### Nouveau
![old](../public/assets/img/framadate_funky_schema.svg)

0
config/graphql/types/.gitignore → migrations/.gitignore vendored

31
migrations/Version20210419202522.php

@ -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 Version20210419202522 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
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
}
}

40
package.json

@ -1,40 +0,0 @@
{
"name": "date-poll-api",
"version": "1.0.0",
"description": "API date to make surveys, kind of the new Framadate",
"main": "index.js",
"directories": {
"doc": "doc",
"test": "tests"
},
"dependencies": {
"@symfony/webpack-encore": "^0.31.0",
"font-awesome": "^4.7.0",
"tailwindcss": "^1.9.6"
},
"devDependencies": {
"node-sass": "^4.14.1",
"sass-loader": "^9.0.0",
"webpack-notifier": "1.6.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production"
},
"repository": {
"type": "git",
"url": "https://framagit.org/tykayn/date-poll-api.git"
},
"keywords": [
"survey",
"poll",
"sondage",
"api",
"symfony"
],
"author": "tykayn",
"license": "AGPL-3.0-or-later"
}

15
public/index.php

@ -1,10 +1,13 @@
<?php
use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
require dirname(__DIR__).'/vendor/autoload.php';
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) {
umask(0000);
@ -12,14 +15,6 @@ if ($_SERVER['APP_DEBUG']) {
Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);

0
src/Controller/.gitignore vendored

235
src/Controller/MigrationController.php

@ -0,0 +1,235 @@
<?php
namespace App\Controller;
//use FOS\RestBundle\Controller\Annotations\Get;
//use FOS\RestBundle\Controller\Annotations\Route;
use App\Entity\Choice;
use App\Entity\Comment;
use App\Entity\StackOfVotes;
use App\Entity\Vote;
use App\Repository\PollRepository;
use App\Service\MailService;
use FOS\RestBundle\Controller\Annotations\Get;
use FOS\RestBundle\Controller\Annotations\Route;
use JMS\Serializer\Type\Exception\Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Entity\Owner;
use App\Entity\Poll;
/**
* Class DefaultController
* @package App\Controller
* @Route("/migration-from-v1",name="admin_homepage")
*/
class MigrationController extends FramadateController {
/**
* @Get(path ="/{unique_key}",
* name = "_migrate_from_v1")
*/
public function indexAction( $unique_key ) {
// get env vars
// check uniq key is good
if ( $unique_key !== $this->getParameter( 'UNIQ_INSTALL_KEY' ) ) {
return new JsonResponse( [
'error' => 'NOPE! veuillez vérifier votre fichier .env',
] );
};
// fetch old Database
$debug = '';
$em = $this->getDoctrine()->getManager();
$pollsBySlug = [];
$pdo_options[ \PDO::ATTR_ERRMODE ] = \PDO::ERRMODE_EXCEPTION;
$bdd = new \PDO( 'mysql:host=localhost;dbname=' . $this->getParameter( 'OLD_DATABASE_NAME' ),
$this->getParameter( 'OLD_DATABASE_USER' ),
$this->getParameter( 'OLD_DATABASE_PASS' ),
$pdo_options );
$res_polls = $bdd->query( 'SELECT * FROM fd_poll' );
while ( $d = $res_polls->fetch( \PDO::FETCH_OBJ ) ) {
$debug .= " <br> ajout de sondage : ".$d->title .' - '. $d->id ;
$newPoll = new Poll();
$owner = new Owner();
$owner->setEmail( $d->admin_mail )
->setPseudo( $d->admin_name )
->addPoll($newPoll);
$newPoll
->setOwner( $owner )
->setCustomURL( $d->id )
->setKind( $d->id === 'D' ? 'date' : 'text' )
->setHideResults( ! $d->results_publicly_visible )
->setAdminKey( $d->admin_id )
->setTitle( $d->title )
->setVotesAllowed( $d->receiveNewVotes )
->setCommentsAllowed( $d->receiveNewComments )
->setChoicesMax( $d->ValueMax )
->setPassword( $d->password_hash )
->setDescription( $d->description )
->setCreationDate( date_create( $d->creation_date ) );
$pollsBySlug[ $d->id ] = $newPoll;
$em->persist( $owner );
$em->persist( $newPoll );
}
// get choices, slots and link them with poll by their slug
$res_slots = $bdd->query( 'SELECT * FROM fd_slot' );
$pollChoicesOrderedBySlug = [];
$choicesCreated = [];
while ( $d = $res_slots->fetch( \PDO::FETCH_OBJ ) ) {
$debug .= " <br> ajout de slot, converti en choix de réponse : ".$d->poll_id. ' : '. $d->moments;
$pollSlug = $d->poll_id;
$poll = $pollsBySlug[$pollSlug];
$moments = explode(',' , $d->moments);
foreach ( $moments as $moment ) {
$newChoice = new Choice();
$newChoice
->setPoll($poll)
->setDateTime(date_create( strtotime( $d->title)))
->setName($moment);
$pollChoicesOrderedBySlug[$pollSlug][] = $newChoice;
$poll->addChoice($newChoice);
$em->persist( $newChoice );
$em->persist( $newPoll );
$choicesCreated[] = $newChoice;
}
}
// get votes
$stacksOfVote = [];
$res_votes = $bdd->query( 'SELECT * FROM fd_vote' );
while ( $d = $res_votes->fetch( \PDO::FETCH_OBJ ) ) {
$debug .= " <br> ajout de stack de vote : ".$d->name;
$pollSlug = $d->poll_id;
$poll = $pollsBySlug[ $pollSlug ];
$newStack = new StackOfVotes();
$newOwner = new Owner();
$newOwner
->setPseudo($d->name)
->setEmail('the_anonymous_email_from_@_migration_offramadate.org')
->setModifierToken($d->uniqId)
;
$newStack->setPoll($poll)
->setOwner($newOwner)
->setPseudo($d->name)
;
// each choice answer is encoded in a value :
$voteCodes = str_split($d->choices);
// get choices of the poll and answer accordingly
$ii=0;
foreach ( $voteCodes as $vote_code ) {
if($vote_code !== ' '){
$choice = $pollChoicesOrderedBySlug[$pollSlug][$ii];
$newVote = new Vote();
$newVote
->setChoice($choice)
->setStacksOfVotes($newStack)
->setPoll($poll)
->setValue( $this->mapAnswerNumberToWord($vote_code))
;
$newStack->addVote($newVote);
$em->persist( $newVote );
$votes[] = $newVote;
}
$ii++;
}
$poll->addStackOfVote($newStack);
$em->persist( $newStack );
$stacksOfVote[] = $newStack;
}
$comments = [];
$res_comments = $bdd->query( 'SELECT * FROM fd_comment' );
while ( $d = $res_comments->fetch( \PDO::FETCH_OBJ ) ) {
$debug .= " <br> ajout de commentaire : ".$d->name. ' '. $d->comment;
$pollSlug = $d->poll_id;
$poll = $pollsBySlug[ $pollSlug ];
$newComment = new Comment();
$poll->addComment($newComment);
$newComment->setPoll($poll)
->setCreatedAt( date_create($d->date))
->setText( $d->comment)
// TODO update entities
->setPseudo( $d->name);
$em->persist( $newComment );
$comments[] = $newComment;
}
// gather objects
// create new polls
$em->flush();
// success
// failure notice
$debug .= " <br> <br> ça c'est fait. ";
return $this->render('pages/migration.html.twig' , [
"message" => "welcome to the framadate migration endpoint, it has yet to be done",
"debug" => $debug,
"OLD_DATABASE_NAME" => $this->getParameter( 'OLD_DATABASE_NAME' ),
"OLD_DATABASE_USER" => $this->getParameter( 'OLD_DATABASE_USER' ),
"counters" =>[
'polls' => count($pollsBySlug),
'comments' => count($comments),
'choices' => count($choicesCreated),
'stacks_of_votes' => count($stacksOfVote),
'votes' => count($votes),
]
]);
}
/**
* @param $numberToConvert
* conversion of answer:
* space character : no answer, 0 : no , 1 : maybe , 2 : yes
* @return string
*/
public function mapAnswerNumberToWord($numberToConvert){
$word = '';
switch ($numberToConvert){
case 0:
$word = 'no';
break;
case 1:
$word = 'maybe';
break;
case 2:
$word = 'yes';
break;
default:
$word = 'no';
}
return $word;
}
}

9
src/Controller/PollController.php

@ -21,8 +21,15 @@ class PollController extends AbstractController
*/
public function index(PollRepository $pollRepository): Response
{
$polls = $pollRepository->findAll();
$titles=[];
foreach ( $polls as $poll ) {
$titles[] = $poll->getTitle();
}
return $this->render('poll/index.html.twig', [
'polls' => count($pollRepository->findAll()),
'count' => count($polls),
'polls' => $titles,
]);
}

34
src/Controller/api/PollController.php

@ -6,6 +6,7 @@ use App\Controller\FramadateController;
use App\Entity\Choice;
use App\Entity\Owner;
use App\Entity\Poll;
use App\Repository\PollRepository;
use JMS\Serializer\Exception\RuntimeException;
use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\SerializerInterface;
@ -33,15 +34,32 @@ class PollController extends FramadateController {
* name = "get_all_polls"
* )
*/
public function getAllPollsAction() {
$repository = $this->getDoctrine()->getRepository( Poll::class );
$data = $repository->findAll();
public function getAllPollsAction(PollRepository $pollRepository): Response {
$data = $pollRepository->findAll();
return $this->json( [
$polls = $data;
$titles=[];
$pollData = [
'message' => 'here are your polls',
'poll' => count( $data ),
] );
'count' => count($polls),
];
$debug=1;
if($debug){
foreach ( $polls as $poll ) {
$titles[] = ['title' => $poll->getTitle(),
'slug' => $poll->getCustomUrl()
];
}
$pollData['polls'] = $titles;
}
return $this->json( $pollData);
}
/**
@ -49,7 +67,7 @@ class PollController extends FramadateController {
* message when the poll is not found
* @return JsonResponse
*/
public function notFoundPoll($id){
public function notFoundPoll($id): Response{
return $this->json( [
'message' => $id . ' : poll not found',
],
@ -72,7 +90,7 @@ class PollController extends FramadateController {
SerializerInterface $serializer,
$id,
Request $request
) {
): Response {
$repository = $this->getDoctrine()->getRepository( Poll::class );
$poll = $repository->findOneByCustomUrl( $id );

0
src/Entity/.gitignore vendored

89
src/Entity/Comment.php

@ -25,6 +25,13 @@ class Comment {
*/
private $owner;
/**
* @ORM\Column(type="string")
* @Serializer\Type("string")
* @Serializer\Expose()
*/
private $pseudo;
/**
* @ORM\Column(type="text")
* @Serializer\Type("string")
@ -45,59 +52,71 @@ class Comment {
private $poll;
function display() {
return [
'id' => $this->getId(),
'text' => $this->getText(),
'pseudo' => $this->getOwner()->getPseudo(),
'date' => $this->getCreatedAt(),
];
}
return [
'id' => $this->getId(),
'text' => $this->getText(),
'pseudo' => $this->getOwner()->getPseudo(),
'date' => $this->getCreatedAt(),
];
}
function __construct() {
$this->setCreatedAt( new \DateTime() );
}
$this->setCreatedAt( new \DateTime() );
}
public function getId(): ?int {
return $this->id;
}
return $this->id;
}
public function getOwner(): ?Owner {
return $this->owner;
}
return $this->owner;
}
public function setOwner( ?Owner $owner ): self {
$this->owner = $owner;
return $this;
}
$this->owner = $owner;
return $this;
}
public function getText(): ?string {
return $this->text;
}
return $this->text;
}
public function setText( string $text ): self {
$this->text = $text;
return $this;
}
$this->text = $text;
return $this;
}
public function getCreatedAt(): ?DateTimeInterface {
return $this->createdAt;
}
return $this->createdAt;
}
public function setCreatedAt( DateTimeInterface $createdAt ): self {
$this->createdAt = $createdAt;
return $this;
}
$this->createdAt = $createdAt;
return $this;
}
public function getPoll(): ?Poll {
return $this->poll;
}
return $this->poll;
}
public function setPoll( ?Poll $poll ): self {
$this->poll = $poll;
return $this;
}
$this->poll = $poll;
return $this;
}
public function getPseudo(): ?string
{
return $this->pseudo;
}
public function setPseudo(string $pseudo): self
{
$this->pseudo = $pseudo;
return $this;
}
}

1037
src/Entity/Poll.php

File diff suppressed because it is too large Load Diff

53
src/Kernel.php

@ -3,51 +3,36 @@
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function registerBundles(): iterable
protected function configureContainer(ContainerConfigurator $container): void
{
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
$container->import('../config/{packages}/*.yaml');
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
$container->import('../config/services.yaml');
$container->import('../config/{services}_'.$this->environment.'.yaml');
} elseif (is_file($path = \dirname(__DIR__).'/config/services.php')) {
(require $path)($container->withPath($path), $this);
}
}
public function getProjectDir(): string
protected function configureRoutes(RoutingConfigurator $routes): void
{
return \dirname(__DIR__);
}
$routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
$routes->import('../config/{routes}/*.yaml');
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');