diff --git a/.env b/.env new file mode 100755 index 0000000..c874846 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +MODULE_NAME=dpl_pretix diff --git a/.github/workflows/changelog.yaml b/.github/workflows/changelog.yaml new file mode 100644 index 0000000..fead572 --- /dev/null +++ b/.github/workflows/changelog.yaml @@ -0,0 +1,29 @@ +# Do not edit this file! Make a pull request on changing +# github/workflows/changelog.yaml in +# https://github.com/itk-dev/devops_itkdev-docker if need be. + +### ### Changelog +### +### Checks that changelog has been updated + +name: Changelog + +on: + pull_request: + +jobs: + changelog: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + fetch-depth: 2 + + - name: Git fetch + run: git fetch + + - name: Check that changelog has been updated. + run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0 diff --git a/.github/workflows/composer.yaml b/.github/workflows/composer.yaml new file mode 100644 index 0000000..b6ae002 --- /dev/null +++ b/.github/workflows/composer.yaml @@ -0,0 +1,80 @@ +# Do not edit this file! Make a pull request on changing +# github/workflows/composer.yaml in +# https://github.com/itk-dev/devops_itkdev-docker if need be. + +### ### Composer +### +### Validates composer.json and checks that it's normalized. +### +### #### Assumptions +### +### 1. A docker compose service named `phpfpm` can be run and `composer` can be +### run inside the `phpfpm` service. +### 2. [ergebnis/composer-normalize](https://github.com/ergebnis/composer-normalize) +### is a dev requirement in `composer.json`: +### +### ``` shell +### docker compose run --rm phpfpm composer require --dev ergebnis/composer-normalize +### ``` +### +### Normalize `composer.json` by running +### +### ``` shell +### docker compose run --rm phpfpm composer normalize +### ``` + +name: Composer + +env: + COMPOSE_USER: runner + +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + composer-validate: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v5 + + - name: Create docker network + run: | + docker network create frontend + + - run: | + docker compose run --rm phpfpm composer validate --strict + + composer-normalized: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v5 + + - name: Create docker network + run: | + docker network create frontend + + - run: | + docker compose run --rm phpfpm composer install + docker compose run --rm phpfpm composer normalize --dry-run + + composer-audit: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v5 + + - name: Create docker network + run: | + docker network create frontend + + - run: | + docker compose run --rm phpfpm composer audit diff --git a/.github/workflows/markdown.yaml b/.github/workflows/markdown.yaml new file mode 100644 index 0000000..ae83163 --- /dev/null +++ b/.github/workflows/markdown.yaml @@ -0,0 +1,44 @@ +# Do not edit this file! Make a pull request on changing +# github/workflows/markdown.yaml in +# https://github.com/itk-dev/devops_itkdev-docker if need be. + +### ### Markdown +### +### Lints Markdown files (`**/*.md`) in the project. +### +### [markdownlint-cli configuration +### files](https://github.com/igorshubovych/markdownlint-cli?tab=readme-ov-file#configuration), +### `.markdownlint.jsonc` and `.markdownlintignore`, control what is actually +### linted and how. +### +### #### Assumptions +### +### 1. A docker compose service named `markdownlint` for running `markdownlint` +### (from +### [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli)) +### exists. + +name: Markdown + +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + markdown-lint: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Create docker network + run: | + docker network create frontend + + - run: | + docker compose run --rm markdownlint markdownlint '**/*.md' diff --git a/.github/workflows/php.yaml b/.github/workflows/php.yaml new file mode 100644 index 0000000..f9253cd --- /dev/null +++ b/.github/workflows/php.yaml @@ -0,0 +1,59 @@ +# Do not edit this file! Make a pull request on changing +# github/workflows/drupal-module/php.yaml in +# https://github.com/itk-dev/devops_itkdev-docker if need be. + +### ### Drupal module PHP +### +### Checks that PHP code adheres to the [Drupal coding +### standards](https://www.drupal.org/docs/develop/standards). +### +### #### Assumptions +### +### 1. A docker compose service named `phpfpm` can be run and `composer` can be +### run inside the `phpfpm` service. +### 2. [drupal/coder](https://www.drupal.org/project/coder) is a dev requirement +### in `composer.json`: +### +### ``` shell +### docker compose run --rm phpfpm composer require --dev drupal/coder +### ``` +### +### Clean up and check code by running +### +### ``` shell +### docker compose run --rm phpfpm vendor/bin/phpcbf +### docker compose run --rm phpfpm vendor/bin/phpcs +### ``` +### +### > [!NOTE] +### > The template adds `.phpcs.xml.dist` as [a configuration file for +### > PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file) +### > and this makes it possible to override the actual configuration used in a +### > project by adding a more important configuration file, e.g. `.phpcs.xml`. + +name: PHP + +env: + COMPOSE_USER: runner + +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + coding-standards: + name: PHP - Check Coding Standards + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - name: Create docker network + run: | + docker network create frontend + + - run: | + docker compose run --rm phpfpm composer install + docker compose run --rm phpfpm vendor/bin/phpcs diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index e83f6c9..0000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,120 +0,0 @@ -on: - push: - branches: - - '**' - pull_request: - -name: Review - -jobs: - changelog: - runs-on: ubuntu-latest - name: Changelog should be updated - if: github.event_name == 'pull_request' - strategy: - fail-fast: false - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Git fetch - run: git fetch - - - name: Check that changelog has been updated. - run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0 - - documentation: - runs-on: ubuntu-latest - name: Documentation should be updated - if: github.event_name == 'pull_request' - strategy: - fail-fast: false - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Git fetch - run: git fetch - - - name: Check that documentation (Markdown files) has been updated. - run: git diff --exit-code origin/${{ github.base_ref }} -- git ls-files '*.md' ':!:CHANGELOG.md' ':!:.github/' && exit 1 || exit 0 - - markdown-coding-standards: - name: Markdown coding standards - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Coding standards - run: | - docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore LICENSE.md --ignore vendor/ '**/*.md' --dot - - composer-normalize: - name: composer-normalize - runs-on: ubuntu-latest - strategy: - fail-fast: false - steps: - - uses: actions/checkout@v4 - - run: | - docker compose run --user root --rm php composer install - docker compose run --user root --rm php composer normalize - - coding-standards-php-cs-fixer: - name: coding-standards-check/php-cs-fixer - runs-on: ubuntu-latest - strategy: - fail-fast: false - steps: - - uses: actions/checkout@v4 - - run: | - docker compose run --user root --rm php composer install - docker compose run --user root --rm php vendor/bin/phpcs - - coding-standards-shellcheck: - name: coding-standards-check/shellcheck - runs-on: ubuntu-latest - strategy: - fail-fast: false - steps: - - uses: actions/checkout@v4 - - run: | - docker run --rm --volume "$PWD:/mnt" koalaman/shellcheck:stable scripts/create-release scripts/code-analysis - - code-analysis-phpstan: - name: code-analysis/phpstan - runs-on: ubuntu-latest - strategy: - fail-fast: false - env: - # https://getcomposer.org/doc/03-cli.md#composer-auth - COMPOSER_AUTH: | - { - "github-oauth": { - "github.com": "${{ github.TOKEN }}" - } - } - steps: - - uses: actions/checkout@v4 - - run: | - docker compose build - docker compose run --user root --rm php composer install - docker compose run --user root --rm --env COMPOSER_AUTH php scripts/code-analysis - - check-create-release: - runs-on: ubuntu-latest - name: Test create release - strategy: - fail-fast: false - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Create test release - run: | - docker compose run --user root --rm php scripts/create-release dev-test diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml deleted file mode 100644 index 2c681a1..0000000 --- a/.github/workflows/pre-release.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: pre-release - -on: - push: - branches: - - '**' - -permissions: - contents: write - -jobs: - release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Build and create release - env: - GH_TOKEN: ${{ github.TOKEN }} - # https://stackoverflow.com/a/71158878/2502647 - BRANCH_NAME: ${{ github.head_ref || github.ref_name }} - run: | - # Get a valid file name - branch_name=${BRANCH_NAME//\//-} - tag_name=dev-${branch_name} - release_name=release-${branch_name} - - docker compose run --user root --rm php scripts/create-release $tag_name - - # Delete release if it already exists. - gh release view $release_name 2>&1 > /dev/null && gh release delete $release_name --yes - # The package name contains the tag name with any leading `dev-` removed - gh release create $release_name --prerelease --generate-notes *-${tag_name#dev-}.tar.gz - shell: bash diff --git a/.github/workflows/project.yaml b/.github/workflows/project.yaml new file mode 100644 index 0000000..eda2324 --- /dev/null +++ b/.github/workflows/project.yaml @@ -0,0 +1,54 @@ +on: + pull_request: + push: + branches: + - "**" + +name: Project + +jobs: + documentation: + runs-on: ubuntu-latest + name: Documentation should be updated + if: github.event_name == 'pull_request' + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + fetch-depth: 1 + + - name: Git fetch + run: git fetch + + - name: Check that documentation (Markdown files) has been updated. + run: git diff --exit-code origin/${{ github.base_ref }} -- git ls-files '*.md' ':!:CHANGELOG.md' ':!:.github/' && exit 1 || exit 0 + + coding-standards-shellcheck: + name: coding-standards-check/shellcheck + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v5 + - run: | + docker run --rm --volume "$PWD:/mnt" koalaman/shellcheck:stable scripts/code-analysis + + code-analysis-phpstan: + name: code-analysis/phpstan + runs-on: ubuntu-latest + strategy: + fail-fast: false + env: + # https://getcomposer.org/doc/03-cli.md#composer-auth + COMPOSER_AUTH: | + { + "github-oauth": { + "github.com": "${{ github.TOKEN }}" + } + } + steps: + - uses: actions/checkout@v5 + - run: | + ./scripts/code-analysis diff --git a/.github/workflows/yaml.yaml b/.github/workflows/yaml.yaml new file mode 100644 index 0000000..631e525 --- /dev/null +++ b/.github/workflows/yaml.yaml @@ -0,0 +1,41 @@ +# Do not edit this file! Make a pull request on changing +# github/workflows/yaml.yaml in +# https://github.com/itk-dev/devops_itkdev-docker if need be. + +### ### YAML +### +### Validates YAML files. +### +### #### Assumptions +### +### 1. A docker compose service named `prettier` for running +### [Prettier](https://prettier.io/) exists. +### +### #### Symfony YAML +### +### Symfony's YAML config files use 4 spaces for indentation and single quotes. +### Therefore we use a [Prettier configuration +### file](https://prettier.io/docs/configuration), `.prettierrc.yaml`, to make +### Prettier format YAML files in the `config/` folder like Symfony expects. + +name: YAML + +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + yaml-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - name: Create docker network + run: | + docker network create frontend + + - run: | + docker compose run --rm prettier '**/*.{yml,yaml}' --check diff --git a/.markdownlint.jsonc b/.markdownlint.jsonc index a28c580..0253096 100644 --- a/.markdownlint.jsonc +++ b/.markdownlint.jsonc @@ -1,3 +1,7 @@ +// This file is copied from config/markdown/.markdownlint.jsonc in https://github.com/itk-dev/devops_itkdev-docker. +// Feel free to edit the file, but consider making a pull request if you find a general issue with the file. + +// markdownlint-cli configuration file (cf. https://github.com/igorshubovych/markdownlint-cli?tab=readme-ov-file#configuration) { "default": true, // https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md @@ -9,5 +13,10 @@ // https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md "no-duplicate-heading": { "siblings_only": true + }, + // https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/organizing-information-with-collapsed-sections#creating-a-collapsed-section + // https://github.com/DavidAnson/markdownlint/blob/main/doc/md033.md + "no-inline-html": { + "allowed_elements": ["details", "summary"] } } diff --git a/.markdownlintignore b/.markdownlintignore new file mode 100644 index 0000000..d143ace --- /dev/null +++ b/.markdownlintignore @@ -0,0 +1,12 @@ +# This file is copied from config/markdown/.markdownlintignore in https://github.com/itk-dev/devops_itkdev-docker. +# Feel free to edit the file, but consider making a pull request if you find a general issue with the file. + +# https://github.com/igorshubovych/markdownlint-cli?tab=readme-ov-file#ignoring-files +vendor/ +node_modules/ +LICENSE.md +# Drupal +web/*.md +web/core/ +web/libraries/ +web/*/contrib/ diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..11cb642 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,28 @@ + + + + The coding standard. + + . + css/ + vendor/ + vendor_release/ + src/Pretix/ApiClient/ + + + + + + + + + + + + + + + + + + diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 0000000..a97dd83 --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,31 @@ + + + + + + The coding standard. + + . + + + node_modules + vendor + *.css + *.js + + + + + + + + + + + + + + + + + diff --git a/Dockerfile b/Dockerfile index be7f2c5..d9408f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM itkdev/php8.1-fpm:latest +# At the time of writing, dpl-cms requires PHP 8.3 (!) (cf. +# https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/composer.json#L102) +FROM itkdev/php8.3-fpm:latest USER root diff --git a/Taskfile.yml b/Taskfile.yml index c291cf1..649ab7c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,56 +1,48 @@ # https://taskfile.dev -version: '3' +version: "3" tasks: - dev:coding-standards:markdown:apply: + coding-standards:markdown:apply: desc: Apply Markdown coding standards cmds: - - docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore LICENSE.md --ignore vendor/ '**/*.md' --dot --fix + - task: compose + vars: + TASK_ARGS: run --rm markdownlint markdownlint '**/*.md' --fix - dev:coding-standards:markdown:check: + coding-standards:markdown:check: desc: Apply and check Markdown coding standards cmds: - - task: dev:coding-standards:markdown:apply - - docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore LICENSE.md --ignore vendor/ '**/*.md' --dot + - task: coding-standards:markdown:apply + - task: compose + vars: + TASK_ARGS: run --rm markdownlint markdownlint '**/*.md' - dev:coding-standards:php:apply: + coding-standards:php:apply: desc: Apply PHP coding standards cmds: - - task: dev:php + - task: php vars: - ARGS: vendor/bin/phpcbf + TASK_ARGS: vendor/bin/phpcbf - dev:coding-standards:php:check: + coding-standards:php:check: desc: Apply and check PHP coding standards cmds: - - task: dev:coding-standards:php:apply - - task: dev:php + - task: coding-standards:php:apply + - task: php vars: - ARGS: vendor/bin/phpcs + TASK_ARGS: vendor/bin/phpcs - dev:coding-standards:check: + coding-standards:check: desc: Apply and check coding standards cmds: - - task dev:coding-standards:markdown:apply - - task dev:coding-standards:markdown:check - - task dev:coding-standards:php:apply - - task dev:coding-standards:php:check + - task: coding-standards:markdown:check + - task: coding-standards:php:check - dev:code-analysis: + code-analysis: desc: Analyse code cmds: - - task: dev:php - vars: - ARGS: scripts/code-analysis - - dev:php: - internal: true - desc: Run php command - cmds: - - docker compose build - - docker compose run --rm php composer install - - docker compose run --rm --interactive --tty php {{.ARGS}} + - ./scripts/code-analysis build:pretix-api-client: desc: Build customized version of https://github.com/itk-dev/pretix-api-client-php/ @@ -65,3 +57,25 @@ tasks: - patch --strip=1 < src/Pretix/ApiClient/patches/pretix-api-client.patch # Add missing functions - patch --strip=1 < src/Pretix/ApiClient/patches/pretix-api-client-functions.patch + + compose: + cmds: + - docker compose {{.TASK_ARGS}} {{.CLI_ARGS}} + internal: true + + php: + desc: Run php command + cmds: + - task: compose + vars: + TASK_ARGS: pull --ignore-buildable + - task: compose + vars: + TASK_ARGS: build + - task: compose + vars: + TASK_ARGS: run --rm phpfpm composer install + - task: compose + vars: + TASK_ARGS: run --rm --interactive --tty phpfpm {{.TASK_ARGS}} {{.CLI_ARGS}} + internal: true diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index fa79389..0000000 --- a/compose.yaml +++ /dev/null @@ -1,9 +0,0 @@ -services: - php: - build: . - volumes: - - .:/app - environment: - # Apparently, code analysis will report "Some parallel worker jobs have not finished." if running out of memory - # (cf. https://github.com/phpstan/phpstan/discussions/11137#discussioncomment-9651169). - - PHP_MEMORY_LIMIT=512M diff --git a/composer.json b/composer.json index 0c85384..7242168 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,11 @@ { "name": "itk-dev/dpl_pretix", + "description": "pretix for DPL CMS", + "license": "GPL-2.0-or-later", "type": "drupal-module", + "homepage": "https://www.drupal.org/project/dpl_pretix", "require": { - "php": "^8.1", + "php": "^8.3", "drupal/core-recommended": "^10" }, "require-dev": { @@ -18,19 +21,5 @@ "ergebnis/composer-normalize": true, "phpstan/extension-installer": true } - }, - "scripts": { - "coding-standards-apply": [ - "@coding-standards-apply/phpcs" - ], - "coding-standards-apply/phpcs": [ - "vendor/bin/phpcbf --standard=phpcs.xml.dist" - ], - "coding-standards-check": [ - "@coding-standards-check/phpcs" - ], - "coding-standards-check/phpcs": [ - "vendor/bin/phpcs --standard=phpcs.xml.dist" - ] } } diff --git a/config/install/dpl_pretix.settings.yml b/config/install/dpl_pretix.settings.yml index c1efa1b..41cf3f1 100644 --- a/config/install/dpl_pretix.settings.yml +++ b/config/install/dpl_pretix.settings.yml @@ -15,8 +15,8 @@ pretix: api_token: ~ # Template event short form template_events: ~ - event_slug_template: '{id}' - default_language_code: 'en' + event_slug_template: "{id}" + default_language_code: "en" test: domain: ~ @@ -27,8 +27,8 @@ pretix: api_token: ~ # Template event short form template_events: ~ - event_slug_template: 'test-{id}' - default_language_code: 'en' + event_slug_template: "test-{id}" + default_language_code: "en" libraries: {} # - diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..30a8b90 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,9 @@ +services: + phpfpm: + # At the time of writing, dpl-cms requires PHP 8.3 (!) (cf. + # https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/composer.json#L102) + image: itkdev/php8.3-fpm:latest + profiles: + - dev + environment: + PHP_MEMORY_LIMIT: 512M diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0b9f650 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +# itk-version: 3.2.4 + +services: + phpfpm: + image: itkdev/php8.4-fpm:latest + user: ${COMPOSE_USER:-deploy} + volumes: + - .:/app + + # Code checks tools + markdownlint: + image: itkdev/markdownlint + profiles: + - dev + volumes: + - ./:/md + + prettier: + # Prettier does not (yet, fcf. + # https://github.com/prettier/prettier/issues/15206) have an official + # docker image. + # https://hub.docker.com/r/jauderho/prettier is good candidate (cf. https://hub.docker.com/search?q=prettier&sort=updated_at&order=desc) + image: jauderho/prettier + profiles: + - dev + volumes: + - ./:/work diff --git a/dpl_pretix.module b/dpl_pretix.module index b5f4a07..185c2fa 100644 --- a/dpl_pretix.module +++ b/dpl_pretix.module @@ -1,5 +1,10 @@ $events_to_create - * The events to create. - * @param \Drupal\recurring_events\Entity\EventSeries $event - * The event. */ function dpl_pretix_recurring_events_event_instances_pre_create_alter(array $events_to_create, EventSeries $event): array { return _dpl_pretix_entity_helper()->recurringEventsEventInstancesPreCreateAlter($events_to_create, $event); diff --git a/dpl_pretix.permissions.yml b/dpl_pretix.permissions.yml index 543950c..7b20ebe 100644 --- a/dpl_pretix.permissions.yml +++ b/dpl_pretix.permissions.yml @@ -1,3 +1,3 @@ -'administer dpl_pretix settings': - 'title': 'Administer pretix settings' - 'description': 'Perform administration tasks for dpl_pretix.' +"administer dpl_pretix settings": + "title": "Administer pretix settings" + "description": "Perform administration tasks for dpl_pretix." diff --git a/dpl_pretix.routing.yml b/dpl_pretix.routing.yml index 4bca18d..e6a23f5 100644 --- a/dpl_pretix.routing.yml +++ b/dpl_pretix.routing.yml @@ -1,28 +1,28 @@ dpl_pretix.settings: - path: '/admin/config/dpl_pretix' + path: "/admin/config/dpl_pretix" defaults: - _title: 'pretix' + _title: "pretix" _form: '\Drupal\dpl_pretix\Form\SettingsForm' requirements: - _permission: 'administer dpl_pretix settings' + _permission: "administer dpl_pretix settings" dpl_pretix.settings_debug: - path: '/admin/config/dpl_pretix/admin/{action}' + path: "/admin/config/dpl_pretix/admin/{action}" defaults: - _title: 'pretix debug' + _title: "pretix debug" _controller: '\Drupal\dpl_pretix\Controller\AdminController::main' action: ~ options: no_cache: true requirements: - _permission: 'administer dpl_pretix settings' + _permission: "administer dpl_pretix settings" dpl_pretix.pretix_webhook: - path: '/dpl_pretix/pretix/webhook' + path: "/dpl_pretix/pretix/webhook" defaults: _controller: '\Drupal\dpl_pretix\Controller\PretixWebhookController::main' # @see https://docs.pretix.eu/en/latest/api/webhooks.html - _title: 'pretix webhook' + _title: "pretix webhook" methods: [POST] requirements: - _permission: 'access content' + _permission: "access content" diff --git a/dpl_pretix.services.yml b/dpl_pretix.services.yml index 569baed..ddfc0bb 100644 --- a/dpl_pretix.services.yml +++ b/dpl_pretix.services.yml @@ -1,7 +1,7 @@ services: logger.channel.dpl_pretix: parent: logger.channel_base - arguments: ['dpl_pretix'] + arguments: ["dpl_pretix"] Drupal\dpl_pretix\Settings: autowire: true @@ -12,7 +12,7 @@ services: Drupal\dpl_pretix\EntityHelper: autowire: true arguments: - $logger: '@logger.channel.dpl_pretix' + $logger: "@logger.channel.dpl_pretix" Drupal\dpl_pretix\FormHelper: autowire: true diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index 4668afe..0000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,17 +0,0 @@ - - - PHP CodeSniffer configuration - - . - css/ - vendor/ - vendor_release/ - src/Pretix/ApiClient/ - - - - - - - - diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 8319df5..c79f59d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,8 +9,11 @@ parameters: - vendor ignoreErrors: - '#(Function|Method) (Drupal\\dpl_pretix\\|dpl_pretix_).+ return type has no value type specified in iterable type array.#' - - '#(Function|Method) (Drupal\\dpl_pretix\\|dpl_pretix_).+ has parameter \$(element|form|options) with no value type specified in iterable type array.#' + - '#(Function|Method) (Drupal\\dpl_pretix\\|dpl_pretix_).+ has parameter \$(element|form|complete_form|events_to_create|options) with no value type specified in iterable type array.#' + # https://github.com/drush-ops/drush/issues/6334 + scanDirectories: + - ../../../../../../vendor/drush/drush/src-symfony-compatibility # Local Variables: # mode: yaml diff --git a/scripts/.env b/scripts/.env new file mode 100644 index 0000000..d407654 --- /dev/null +++ b/scripts/.env @@ -0,0 +1 @@ +COMPOSE_PROJECT_NAME=dpl_pretix_scripts diff --git a/scripts/build-exclude.txt b/scripts/build-exclude.txt deleted file mode 100644 index 5858f88..0000000 --- a/scripts/build-exclude.txt +++ /dev/null @@ -1,13 +0,0 @@ -*.tar.gz -.editorconfig -.git* -.markdownlint.jsonc -scripts -checksum.txt -composer.* -composer-*.* -node_modules -package.json -phpcs.xml -release/ -vendor/ diff --git a/scripts/code-analysis b/scripts/code-analysis index f47d410..f4ca8aa 100755 --- a/scripts/code-analysis +++ b/scripts/code-analysis @@ -1,38 +1,29 @@ #!/usr/bin/env bash +set -o errexit -o errtrace -o noclobber -o nounset -o pipefail +IFS=$'\n\t' -script_dir=$PWD -module_name=dpl_pretix -drupal_dir=vendor/drupal-module-code-analysis -# Relative to $drupal_dir -module_path=web/sites/default/files/modules_local/$module_name +script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) cd "$script_dir" || exit -drupal_composer() { - composer --working-dir="$drupal_dir" --no-interaction "$@" +compose() { + docker compose "$@" } -set -x - -rm -fr "$drupal_dir" -git clone --branch=develop --depth=1 https://github.com/danskernesdigitalebibliotek/dpl-cms "$drupal_dir" - -# Copy our code into the modules folder -mkdir -p "$drupal_dir/$module_path" +composer() { + compose exec dpl-cms composer "$@" +} -# https://stackoverflow.com/a/15373763 -rsync --archive --delete --compress . --filter=':- .gitignore' --exclude "$drupal_dir" --exclude .git "$drupal_dir/$module_path" +drush() { + compose exec dpl-cms vendor/bin/drush "$@" +} -drupal_composer config minimum-stability dev +shell() { + compose exec dpl-cms "$@" +} -# Allow ALL plugins -# https://getcomposer.org/doc/06-config.md#allow-plugins -drupal_composer config --no-plugins allow-plugins true +compose up --detach --build -drupal_composer require wikimedia/composer-merge-plugin -drupal_composer config extra.merge-plugin.include "$module_path/composer.json" -# https://www.drupal.org/project/drupal/issues/3220043#comment-14845434 -drupal_composer require --dev symfony/phpunit-bridge +shell vendor/bin/phpstan --configuration=web/sites/default/files/modules_local/dpl_pretix/phpstan.neon.dist -# Run PHPStan -(cd "$drupal_dir/$module_path" && "$script_dir/$drupal_dir/vendor/bin/phpstan" --configuration=phpstan.neon.dist -vvv --debug) +compose down diff --git a/scripts/compose.yaml b/scripts/compose.yaml new file mode 100644 index 0000000..a8998d0 --- /dev/null +++ b/scripts/compose.yaml @@ -0,0 +1,64 @@ +services: + dpl-cms: + # image: itkdev/php8.3-fpm:latest + build: + # context: . + dockerfile_inline: | + # syntax=docker/dockerfile:1 + # check=skip=SecretsUsedInArgOrEnv + + FROM itkdev/php8.3-fpm:latest + ENV PHP_MEMORY_LIMIT=512M + + # https://stackoverflow.com/a/33439625 + SHELL ["/bin/bash", "-c"] + + WORKDIR /app + + RUN curl --location https://github.com/danskernesdigitalebibliotek/dpl-cms/archive/refs/heads/main.tar.gz --output main.tar.gz \ + && tar xvf main.tar.gz --strip-components=1 \ + && rm main.tar.gz \ + && composer install + + # Add the sqlite module to the existing config + RUN sed --in-place '/dpl_event: 0/a \ \ sqlite: 0' config/sync/core.extension.yml \ + && cat <<'EOF' > web/sites/default/settings.local.php + 'sqlite', + 'database' => 'sites/default/files/.ht.sqlite', + ]; + EOF + + ENV BNF_GRAPHQL_CONSUMER_SECRET=this_is_not_a_real_secret + ENV GO_GRAPHQL_CONSUMER_SECRET=this_is_not_a_real_secret + ENV BNF_GRAPHQL_CONSUMER_USER_PASSWORD==this_is_not_a_real_password + ENV NEXT_PUBLIC_GO_GRAPHQL_CONSUMER_USER_PASSWORD=this_is_not_a_real_password + + ENV GO_DOMAIN=dpl_pretix.example.com + ENV LAGOON_ROUTE=https://dpl_pretix.example.com + + RUN vendor/bin/drush site:install --existing-config --yes --account-mail itkdev+dpl_pretix@mkb.aarhus.dk --site-mail itkdev+dpl_pretix@mkb.aarhus.dk + + # profiles: + # - dev + user: root + volumes: + # - ./settings.local.php:/app/web/sites/default/settings.local.php + # Mount our code into the web/modules/contrib folder + - ../:/app/web/sites/default/files/modules_local/dpl_pretix + environment: + # Let the module path, i.e. the mounted path, be known in the container + MODULE_PATH: web/sites/default/files/modules_local/dpl_pretix + + PHP_MAX_EXECUTION_TIME: 60 + PHP_MEMORY_LIMIT: 512M + + BNF_GRAPHQL_CONSUMER_SECRET: this_is_not_a_real_secret + GO_GRAPHQL_CONSUMER_SECRET: this_is_not_a_real_secret + BNF_GRAPHQL_CONSUMER_USER_PASSWORD: =this_is_not_a_real_password + NEXT_PUBLIC_GO_GRAPHQL_CONSUMER_USER_PASSWORD: this_is_not_a_real_password + + GO_DOMAIN: dpl_pretix.example.com + LAGOON_ROUTE: https://dpl_pretix.example.com diff --git a/scripts/create-release b/scripts/create-release deleted file mode 100755 index de8e4a7..0000000 --- a/scripts/create-release +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash -set -o errexit -o errtrace -o noclobber -o nounset -o pipefail -IFS=$'\n\t' - -script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -project_dir=$(cd "$(dirname "$script_dir")" && pwd) - -tag=${1:-} -if [ -z "$tag" ]; then - (>&2 echo "Usage: $0 tag") - exit -fi - -set -x - -cd "$project_dir" - -# Configuration start - -module_name=dpl_pretix - -# Configuration end - -git config --global --add safe.directory "$PWD" -if ! git diff --exit-code composer.json; then - (>&2 echo; echo composer.json is changed. Aborting.) - exit 1 -fi - -# Make sure that `composer.json` has the correct version. -composer config version "${tag}" - -# Build release start - -# Build release end - -# Package release -release_dir=release -target_dir="$release_dir/$module_name" -mkdir -p "$target_dir" - -rsync --delete --archive --compress --exclude-from "$script_dir/build-exclude.txt" . "$target_dir" - -# Replace %%VERSION%% with actual version in build -find $target_dir -type f -print0 | xargs -0 sed -i "s@%%VERSION%%@${tag}@g" - -# Strip any leading `dev-` from tag name in package name. -name="${module_name}-${tag#dev-}.tar.gz" -tar --create --file "$name" -C "$release_dir" $module_name -sha256sum "$name" >| checksum.txt - -# Clean up -rm -fr $release_dir - -git checkout composer.json - -echo -echo "Release content ($name)" -echo -tar tvf "$name" | grep -v '/$' -echo diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php index 1c31bac..62f67db 100644 --- a/src/Form/SettingsForm.php +++ b/src/Form/SettingsForm.php @@ -17,6 +17,7 @@ use Drupal\dpl_pretix\Settings; use Drupal\dpl_pretix\Settings\EventFormSettings; use Drupal\dpl_pretix\Settings\PretixSettings; +use Drupal\field\FieldConfigInterface; use Drupal\user\RoleInterface; use Drupal\user\RoleStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -477,9 +478,13 @@ private function buildFormEventForm(array &$form): void { $section = self::SECTION_EVENT_FORM; $defaults = $this->settings->getEventForm(); + $fieldRelevantTicketManagerLabel = EventFormSettings::FIELD_RELEVANT_TICKET_MANAGER; + $eventSeriesFields = $this->entityFieldManager->getFieldDefinitions('eventseries', 'default'); - $fieldRelevantTicketManagerLabel = $eventSeriesFields[EventFormSettings::FIELD_RELEVANT_TICKET_MANAGER]?->label() - ?? EventFormSettings::FIELD_RELEVANT_TICKET_MANAGER; + $fieldRelevantTicketManager = $eventSeriesFields[EventFormSettings::FIELD_RELEVANT_TICKET_MANAGER] ?? NULL; + if ($fieldRelevantTicketManager instanceof FieldConfigInterface) { + $fieldRelevantTicketManagerLabel = $fieldRelevantTicketManager->label(); + } // @todo Get the label from the actual field group. $ticketsGroupLabel = $this->t('Tickets'); diff --git a/src/FormHelper.php b/src/FormHelper.php index 4fdce1a..3e60903 100644 --- a/src/FormHelper.php +++ b/src/FormHelper.php @@ -118,7 +118,7 @@ public function fieldGroupFormProcessBuildAlter(array &$element, FormStateInterf /** * Hide the Dates group depending on event series state. */ - private function hideDatesGroup(array &$form, FormStateInterface $formState) { + private function hideDatesGroup(array &$form, FormStateInterface $formState): void { if ($event = $this->getEventSeriesEntity($formState)) { $maintainCopy = (bool) $this->eventDataHelper->getEventData($event)?->maintainCopy; if ($event->isNew() || !$maintainCopy) { @@ -140,7 +140,7 @@ private function hideDatesGroup(array &$form, FormStateInterface $formState) { // instance on the event series form (cf. // https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/web/modules/custom/dpl_event/src/Plugin/EventInstanceCreator/DplEventInstanceCreator.php#L31-L34). $datesGroupKey = 'group_dates'; - if ((int) $event?->getInstanceCount() > 1 + if ($event->getInstanceCount() > 1 && isset($form['#fieldgroups'][$datesGroupKey]) && isset($form[$datesGroupKey])) { $weight = $form['#fieldgroups'][$datesGroupKey]->weight; // unset($form['#fieldgroups'][$datesGroupKey]); diff --git a/src/Settings/EventFormSettings.php b/src/Settings/EventFormSettings.php index eb670f2..af23202 100644 --- a/src/Settings/EventFormSettings.php +++ b/src/Settings/EventFormSettings.php @@ -35,6 +35,8 @@ class EventFormSettings extends AbstractSettings { /** * Roles that can delete event instances. + * + * @var array */ public array $rolesThatCanDeleteEventInstances = [];