Skip to content

Commit

Permalink
Merge pull request #12 from GDATASoftwareAG/11-update-plugin-to-be-co…
Browse files Browse the repository at this point in the history
…mpatible-to-the-current-backend

11 update plugin to be compatible to the current backend
  • Loading branch information
unglaublicherdude authored Jul 19, 2024
2 parents 6ab0d5c + cebe935 commit 3e6dd7b
Show file tree
Hide file tree
Showing 48 changed files with 5,821 additions and 2,020 deletions.
16 changes: 16 additions & 0 deletions .devcontainer/configureWordPress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
docker compose kill
docker compose rm --force --stop --volumes
docker compose up --build --quiet-pull --wait -d --force-recreate --renew-anon-volumes --remove-orphans

until docker exec -it --user www-data wordpress-gdata-antivirus-app-1 bash -c "wp core install --url=http://127.0.0.1:8080 --title=testsite --admin_user=admin [email protected] --admin_password=admin"
do
echo "waiting for WordPress to be installed"
sleep 2
done
composer install

docker exec -it --user www-data wordpress-gdata-antivirus-app-1 bash -c "wp plugin uninstall hello"
docker exec -it --user www-data wordpress-gdata-antivirus-app-1 bash -c "wp plugin uninstall akismet"
docker exec -it --user www-data wordpress-gdata-antivirus-app-1 bash -c "wp plugin install wp-crontrol"
docker exec -it --user www-data wordpress-gdata-antivirus-app-1 bash -c "wp plugin activate wp-crontrol"
docker exec -it --user www-data wordpress-gdata-antivirus-app-1 bash -c "wp plugin activate wordpress-gdata-antivirus"
72 changes: 30 additions & 42 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
// For format details, https://containers.dev/implementors/json_reference/.
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/php
{
"name": "WordPress Development Environment",
"dockerComposeFile": "../compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-azuretools.vscode-docker"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
8080,
3306
],
// Maps a port number, "host:port" value, range, or regular expression to a set of default options. See port attributes for available options
"portsAttributes": {
"8080": {
"label": "WordPress Development/Testing Site"
},
"3306": {
"label": "MariaDB"
}
},
"containerEnv": {
"SHELL": "/bin/bash"
},
// Use `onCreateCommand` to run commands as part of the container creation.
//"onCreateCommand": "chmod +x .devcontainer/install.sh && .devcontainer/install.sh",
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "chmod +x .devcontainer/setup.sh && .devcontainer/setup.sh",
// Use 'postStartCommand' to run commands after the container has started.
"remoteUser": "www-data",
// A set of name-value pairs that sets or overrides environment variables for the devcontainer.json supporting service / tool (or sub-processes like terminals) but not the container as a whole.
"remoteEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
}
"name": "PHP",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/php:1-8.2-bullseye",
"customizations": {
"vscode": {
"extensions": [
"recca0120.vscode-phpunit",
"github.vscode-github-actions"
]
}
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Configure tool-specific properties.
// "customizations": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"postStartCommand": ".devcontainer/postCreateCommands.sh",
"forwardPorts": [
8080,
9003
]
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html"
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
12 changes: 12 additions & 0 deletions .devcontainer/postCreateCommands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -ex

sudo apt-get update
sudo apt-get install -y bash-completion vim iputils-ping telnet

sudo bash -c "docker completion bash > /usr/share/bash-completion/completions/docker"
sudo bash -c "composer completion bash > /usr/share/bash-completion/completions/composer"

echo ". /usr/share/bash-completion/bash_completion" >> /home/vscode/.bashrcsource

source ./configureWordPress.sh
23 changes: 0 additions & 23 deletions .devcontainer/setup.sh

This file was deleted.

1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
**/values.dev.yaml
LICENSE
README.md
wordpress/**
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
95 changes: 95 additions & 0 deletions .github/workflows/github-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: github release

on:
push:
branches: [
"main",
# this should be mainly branch releases for created issues
"[0-9]-*"
]
tags: ["*"]
pull_request:
branches: ["*"]

jobs:
get-version:
runs-on: ubuntu-latest
outputs:
plugin_version: ${{ steps.get-version.outputs.plugin_version }}
plugin_prerelease: ${{ steps.get-version.outputs.plugin_prerelease }}
steps:
- uses: actions/checkout@v4
- id: get-version
run: |
if [[ $GITHUB_REF == refs/tags/v* ]]; then
echo "running tag version extract"
echo "plugin_version=${GITHUB_REF_NAME}" | tee -a "$GITHUB_OUTPUT"
echo "plugin_prerelease=false" | tee -a "$GITHUB_OUTPUT"
elif [[ $GITHUB_REF == refs/head/main ]]; then
echo "running main version extract from file"
PLUGIN_VERSION=$(cat wordpress-gdata-antivirus.php | sed -nE 's/^.*Version: ([0-9a-z\.\-])/\1/p')
echo "plugin_version=v$PLUGIN_VERSION" | tee -a "$GITHUB_OUTPUT"
echo "plugin_prerelease=false" | tee -a "$GITHUB_OUTPUT"
elif [[ $GITHUB_REF == refs/pull/* ]]; then
echo "running pull request version extract from file"
PLUGIN_VERSION=$(cat wordpress-gdata-antivirus.php | sed -nE 's/^.*Version: ([0-9a-z\.\-])/\1/p')
PLUGIN_VERSION_SUFFIX=${GITHUB_HEAD_REF}-${{ github.run_id }}
echo "plugin_version=v$PLUGIN_VERSION-$PLUGIN_VERSION_SUFFIX" | tee -a "$GITHUB_OUTPUT"
echo "plugin_prerelease=true" | tee -a "$GITHUB_OUTPUT"
else
echo "running branch version extract from file"
PLUGIN_VERSION=$(cat wordpress-gdata-antivirus.php | sed -nE 's/^.*Version: ([0-9a-z\.\-])/\1/p')
PLUGIN_VERSION_SUFFIX=${GITHUB_REF_NAME}-${{ github.run_id }}
echo "plugin_version=v$PLUGIN_VERSION-$PLUGIN_VERSION_SUFFIX" | tee -a "$GITHUB_OUTPUT"
echo "plugin_prerelease=true" | tee -a "$GITHUB_OUTPUT"
fi
test:
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/devcontainers/php:1-8.2-bullseye
steps:
- uses: actions/checkout@v4
- name: composer install
run: composer install
- name: phpunit
run: ./vendor/bin/phpunit --testdox tests/

build:
runs-on: ubuntu-latest
needs:
- get-version
- test
container:
image: mcr.microsoft.com/devcontainers/php:1-8.2-bullseye
steps:
- uses: actions/checkout@v4
- name: composer install
run: composer install --no-dev
- name: zip it
run: zip wordpress-gdata-antivirus-${{needs.get-version.outputs.plugin_version}}.zip * --exclude @.zipignore
- uses: actions/upload-artifact@master
if: startsWith(github.ref, 'refs/tags/v')
with:
name: plugin-zip
path: wordpress-gdata-antivirus-${{needs.get-version.outputs.plugin_version}}.zip

release:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs:
- get-version
- build
steps:
- name: download artifact
uses: actions/download-artifact@master
with:
name: plugin-zip
- name: Release
uses: softprops/action-gh-release@v2
with:
files: wordpress-gdata-antivirus-${{needs.get-version.outputs.plugin_version}}.zip
tag_name: ${{needs.get-version.outputs.plugin_version}}
prerelease: ${{needs.get-version.outputs.plugin_prerelease}}
token: ${{ secrets.GITHUB_TOKEN }}
generate_release_notes: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
!/local-env/wp-content/plugins/.gitkeep
!/local-env/wp-content/plugins/wordpress-gdata-antivirus/
!/local-env/wp-content/plugins/wordpress-gdata-antivirus/.gitkeep
/wordpress/
test.sh
36 changes: 36 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>The coding standard for PHP_CodeSniffer itself.</description>

<file>.</file>

<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>wordpress/*</exclude-pattern>


<arg name="parallel" value="8"/>
<arg value="n" />

<rule ref="WordPress">
<exclude name="WordPress.Files.FileName" />
<exclude name="Generic.WhiteSpace" />
<exclude name="PEAR.Functions.FunctionCallSignature" />
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing" />
<exclude name="WordPress.WhiteSpace.OperatorSpacing" />
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Squiz.Commenting.FileComment.Missing" />
<exclude name="Squiz.Commenting.VariableComment.Missing" />
<exclude name="Squiz.Strings.ConcatenationSpacing" />
<exclude name="Squiz.Strings.DoubleQuoteUsage.NotRequired" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="WordPress.PHP.YodaConditions.NotYoda" />
</rule>
<rule ref="PSR12">
<exclude name="PSR12.Operators.OperatorSpacing" />
<exclude name="PSR1.Methods.CamelCapsMethodName" />
</rule>
<rule ref="Modernize" />


</ruleset>
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug remote",
"type": "php",
"request": "launch",
"port": 9080,
"pathMappings": {
"/var/www/html/wp-content/plugins/wordpress-gdata-antivirus": "${workspaceFolder}/",
},
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-dxdebug.client_host=172.20.128.2",
"-dxdebug.client_port=9080",
"-S",
"localhost:0"
],
},
{
"name": "Launch application",
"type": "php",
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"phpSniffer.autoDetect": true,
"phpSniffer.run": "onSave",
"editor.formatOnPaste": false,
}
10 changes: 10 additions & 0 deletions .zipignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.devcontainer/*
.vscode/*
.git/*
compose*
Dockerfile
test.sh
wordpress/*
xdebug.ini
xdebug.php
info.php
9 changes: 9 additions & 0 deletions Dockerfile.WordPress
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM wordpress:6-php8.3

RUN apt update && apt install -y less vim
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd xdebug
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
14 changes: 14 additions & 0 deletions Infrastructure/Database/IGdataAntivirusDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Gdatacyberdefenseag\WordpressGdataAntivirus\Infrastructure\Database;

interface IGdataAntivirusDatabase {
public function query( string $query, ...$args ): int|bool;
public function get_charset_collate(): string;
public function db_delta( string $query, bool $execute = true ): array;
public function get_var( string $query, ...$args ): string|null;
public function insert( string $table, array $data ): string;
public function delete( string $table, array $where ): string;
public function get_results( string $query, string $output, ...$args ): array|object|null;
public function get_prefix(): string;
}
32 changes: 32 additions & 0 deletions Infrastructure/Database/NoopDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Gdatacyberdefenseag\WordpressGdataAntivirus\Infrastructure\Database;

class NoopDatabase implements IGdataAntivirusDatabase {
public function query( $query, ...$args ): int|bool {
return true;
}

public function get_charset_collate(): string {
return '';
}

public function db_delta( string $query, bool $execute = true ): array {
return array();
}
public function get_var( string $query, ...$args ): string|null {
return null;
}
public function insert( string $table, array $data ): string {
return '';
}
public function delete( string $table, array $where ): string {
return '';
}
public function get_results( string $query, string $output, ...$args ): array|object|null {
return array();
}
public function get_prefix(): string {
return '';
}
}
Loading

0 comments on commit 3e6dd7b

Please sign in to comment.