# matsen-tool-be

# Most needed commands
    ddev exec bin/console make:migration
    ddev exec bin/console doctrine:migration:migrate
    ddev exec bin/console doctrine:fixtures:load
    ddev exec php bin/console doctrine:fixtures:load --append (nur neue Datensaätz, nicht Datenbank löschen!)
    ddev exec bin/console make:entity
    ddev exec bin/console make:factory
    ddev exec php bin/phpunit
    ddev exec php bin/phpunit --filter=testPostToCreateNewUserPost

# Installation:

    gehe ins root Verzeichnis des Projekts und für aus: ddev config

    gehe den Installationsprozess durch (3x Enter drücken)

    starte danach ddev mit: ddev start

    projekt installieren: ddev composer install

# Troubleshooting:

    Unable to listen on required ports, port 443 is already in use:
    -> setze andere Ports in .ddev/config.yaml z.B.
    router_http_port: 8080
    router_https_port: 8443

    - https://stackoverflow.com/questions/76507208/symfony-6-3-migration-causes-problems-with-stateless-authenticators-forcing-requ

    Xdebug not working at all:
    ddev logs -> xdebug problems? like:
        "NOTICE: PHP message: Xdebug: [Step Debug] Could not connect to debugging client. Tried: 172.27.0.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port)."

    - https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container/43541732#43541732
    -> create folder "php" in ".ddev"-folder, create a file "xdebug.ini" (here could be also a php.ini - settings made override ddev php.ini) and insert this line into xdebug.ini: xdebug.client_host=docker.for.mac.localhost
        -> ddev restart afterwards

    Xdebug: When one is not working, use the other.
      xdebug.client_host=host.docker.internal
      ;xdebug.client_host=docker.for.mac.localhost

telnet: Unable to connect to remote host: Connection refused

# PHPMyAdmin installieren:

    ddev get ddev/ddev-phpmyadmin

    ddev restart

# Symfony Konsolenbefehle mit Ddev ausführen, z.B.:

    ddev exec php bin/console make:migration

# Ddev Commands:

    ddev describe - zeigt Urls und installierte Komponenten

# Xdebug
    ddev ssh -> export XDEBUG_CONFIG="idekey=PHPSTORM"

- Cli Skript xebug läuft nicht korrekt:
    - ddev ssh
    - in Terminal:  PHP_IDE_CONFIG="serverName=matsen-tool-be.ddev.site"
    - Servername ist hier konfiguriert: ![](/Users/danielknudsen/Documents/GIT/matsen-tool-be/.docs/phpstorm_cli_xdebug_config.png)
-------------------------
# Symfony:

# User with Maker Bundle:
    - https://symfonycasts.com/screencast/api-platform/user-entity
    ddev composer require maker-bundle --dev
    ddev exec bin/console make:user -> erstellt user entity und schreibt in die security.yaml

# Entity erzeugen oder erweitern:
    ddev exec bin/console make:entity

# Foundry fixtures:
    ddev exec composer require foundry orm-fixtures --dev
    ddev exec bin/console make:factory
    ddev exec bin/console doctrine:fixtures:load

# Doctrine:
    ddev exec bin/console doctrine:database:drop --force
    ddev exec bin/console doctrine:database:create

    - Testdatenbank anlegen:
        ddev exec bin/console doctrine:database:create --env=test
        ddev exec bin/console doctrine:schema:create --env=test

    - Migrations:
    ddev exec bin/console make:migration
    ddev exec bin/console doctrine:migration:migrate

# Profiler
    ddev composer require debug

# Php Unit
    - https://symfony.com/doc/current/testing.html#configuring-a-database-for-tests
    Setup:
        # .env.test.local -> "mysql://root:root@db:3306/db?serverVersion=10.4.30-MariaDB-1:10.4.30+maria~ubu2004-log - mariadb.org binary distribution"
            -> this creates a db named db_test (it takes the name of the main database "db" and adds "_test" to its name)
        # Create db and create schema
            php bin/console --env=test doctrine:database:create
            php bin/console --env=test doctrine:schema:create

    - https://symfonycasts.com/screencast/api-platform-security/test-setup
    ddev composer require test -> testpack incl. phpunit
    ddev composer require zenstruck/browser --dev -> browser test package to imporve testing
        -> add extension to phpunit.xml.dist
                <extensions>
                    <extension class="Zenstruck\Browser\Test\BrowserExtension" />
                </extensions>

    ddev exec php bin/phpunit --filter=testPostToCreateNewUserPost

    ddev composer require --dev mtdowling/jmespath.php

    
# Api Platform
    - https://api-platform.com/docs/core/dto/
    - https://api-platform.com/docs/distribution/
    - https://api-platform.com/docs/core/extending/

    Installation: ddev composer require api

    Micro Mapper: ddev composer require symfonycasts/micro-mapper

    Vich Uploader bundle: ddev composer require vich/uploader-bundle

    Foundry: composer require --dev foundry orm-fixtures

    Ausführen, um openApi.yaml und openApi.json zu generieren:
    - cd export
    - php exportApi.php
    openApi.yaml und openApi.json in Frontend-Projekt (root) kopieren

# Lexik JWT
    - https://symfony.com/bundles/LexikJWTAuthenticationBundle/current/index.html
    - Nur bei NEU Installation:
        - php bin/console lexik:jwt:generate-keypair
    
    - Open Api export:
        ddev exec bin/console api:openapi:export --yaml >> openapi.yaml
    - File Uploading:
        https://api-platform.com/docs/core/file-upload/
        https://github.com/dustin10/VichUploaderBundle/blob/master/docs/index.md

    - TOKEN auf Terminal generieren: bin/console lexik:jwt:generate-token {user-email}

# List Routes and Service Tags
    - ddev exec bin/console debug:router
    - ddev exec bin/console debug:container

# Constraints
    - https://symfony.com/doc/current/validation.html

# LIVE DEPLOYMENT
    - URL is https://matsen.spawntree.de
    - Clear DB: https://spawntree.de:8443
    - Run shell script in: /var/www/vhosts/spawntree.de/matsen-api.spawntree.de/httpdocs
    - (If JWT PEM files don't exist in /config/jwt: bin/console lexik:jwt:generate-keypair)
    - Frontend: ng build --configuration=development --aot
    - Delete all files in /matsen.spawntree.de/matsen-tool/browser via FTP
    - Copy content of /matsen-tool/dist/matsen-tool/browser into /matsen.spawntree.de/matsen-tool/browser

# Gecko Firefox driver
    - WICHTIG: chmod +x .ddev/post-start.sh (die Datei muss ausführbar sein)
    - beim live deployment muss der driver per Linux installiert werden

    - manuell mit ddev ssh:
        sudo apt-get install -y firefox-esr

        wget -q https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER_VERSION/geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz \
        && tar -xzf geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz -C /usr/local/bin \
        && rm geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz \
        && chmod +x /usr/local/bin/geckodriver

# Nord vpn
    - https://support.nordvpn.com/hc/de/articles/20398283005457-Installation-und-Gebrauch-von-NordVPN-unter-RHEL-und-CentOS-Linux


# apache 403 beim sortieren nach "profile" 
    Ja, wenn Sie Plesk verwenden, gibt es tatsächlich Möglichkeiten, Whitelist-Regeln für ModSecurity einzurichten. Hier sind die Schritte, die Sie in Plesk unternehmen können:
    
    Öffnen Sie das Plesk Control Panel.
    Navigieren Sie zu "Websites & Domains" und wählen Sie die betroffene Domain aus.
    Suchen Sie nach "Apache & nginx Settings" oder "Web-Server-Einstellungen" (je nach Ihrer Plesk-Version).
    Scrollen Sie nach unten zum Abschnitt "Additional Apache directives" oder "Zusätzliche Apache-Direktiven".
    Hier können Sie benutzerdefinierte Apache-Konfigurationen hinzufügen, einschließlich ModSecurity-Regeln.
    Fügen Sie eine Whitelist-Regel wie folgt hinzu:
    
    <IfModule mod_security2.c>
      SecRule REQUEST_URI "^/api/game_accounts" \
        "id:1000,\
        phase:1,\
        pass,\
        nolog,\
        ctl:ruleRemoveById=210580"
    </IfModule>