parent
109e7a35d6
commit
21c594a2fd
@ -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');
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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';
|
@ -1,3 +0,0 @@
|
||||
framework:
|
||||
assets:
|
||||
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
|
@ -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']
|
||||
|
@ -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
|
||||
|
@ -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%'
|
||||
|
@ -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,10 +0,0 @@
|
||||
overblog_graphql:
|
||||
definitions:
|
||||
schema:
|
||||
query: Query
|
||||
mappings:
|
||||
types:
|
||||
-
|
||||
type: yaml
|
||||
dir: "%kernel.project_dir%/config/graphql/types"
|
||||
suffix: null
|
@ -1,3 +0,0 @@
|
||||
framework:
|
||||
mailer:
|
||||
dsn: '%env(MAILER_DSN)%'
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
||||
|
@ -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)%
|
||||
|
@ -1,3 +0,0 @@
|
||||
framework:
|
||||
validation:
|
||||
not_compromised_password: false
|
@ -1,2 +0,0 @@
|
||||
#webpack_encore:
|
||||
# strict_mode: false
|
@ -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'
|
||||
|
@ -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\: []
|
@ -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
|
@ -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';
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
controllers:
|
||||
resource: ../../src/Controller/
|
||||
type: annotation
|
||||
|
||||
kernel:
|
||||
resource: ../../src/Kernel.php
|
||||
type: annotation
|
||||
|
@ -0,0 +1,3 @@
|
||||
_errors:
|
||||
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
|
||||
prefix: /_error
|
@ -1,3 +0,0 @@
|
||||
_errors:
|
||||
resource: '@TwigBundle/Resources/config/routing/errors.xml'
|
||||
prefix: /_error
|
@ -1,3 +0,0 @@
|
||||
overblog_graphql_endpoint:
|
||||
resource: "@OverblogGraphQLBundle/Resources/config/routing/graphql.yml"
|
||||
prefix: api/graphql
|
@ -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 }
|
@ -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
|
@ -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
|
||||

|
||||
### Nouveau
|
||||

|
@ -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
|
||||
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff