Skip to content

Commit

Permalink
Merge pull request #13 from GDATASoftwareAG/apply-plugin-check-sugges…
Browse files Browse the repository at this point in the history
…tions

Apply plugin check suggestions
  • Loading branch information
unglaublicherdude authored Jul 19, 2024
2 parents 2a8aadc + 636cc52 commit 97df598
Show file tree
Hide file tree
Showing 35 changed files with 361 additions and 242 deletions.
14 changes: 8 additions & 6 deletions .devcontainer/configureWordPress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ 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"
until docker exec -it --user www-data 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"
docker exec -it --user www-data gdata-antivirus-app-1 bash -c "wp plugin uninstall hello"
docker exec -it --user www-data gdata-antivirus-app-1 bash -c "wp plugin uninstall akismet"
docker exec -it --user www-data gdata-antivirus-app-1 bash -c "wp plugin install wp-crontrol"
docker exec -it --user www-data gdata-antivirus-app-1 bash -c "wp plugin activate wp-crontrol"
docker exec -it --user www-data gdata-antivirus-app-1 bash -c "wp plugin install plugin-check"
docker exec -it --user www-data gdata-antivirus-app-1 bash -c "wp plugin activate plugin-check"
docker exec -it --user www-data gdata-antivirus-app-1 bash -c "wp plugin activate gdata-antivirus"
12 changes: 6 additions & 6 deletions .github/workflows/github-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ jobs:
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')
PLUGIN_VERSION=$(cat 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=$(cat 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=$(cat 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"
Expand Down Expand Up @@ -67,12 +67,12 @@ jobs:
- 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
run: zip -r 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
path: gdata-antivirus-${{needs.get-version.outputs.plugin_version}}.zip

release:
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -88,7 +88,7 @@ jobs:
- name: Release
uses: softprops/action-gh-release@v2
with:
files: wordpress-gdata-antivirus-${{needs.get-version.outputs.plugin_version}}.zip
files: 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 }}
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
!/local-env/wp-content/
!/local-env/wp-content/.gitkeep
!/local-env/wp-content/plugins/.gitkeep
!/local-env/wp-content/plugins/wordpress-gdata-antivirus/
!/local-env/wp-content/plugins/wordpress-gdata-antivirus/.gitkeep
!/local-env/wp-content/plugins/gdata-antivirus/
!/local-env/wp-content/plugins/gdata-antivirus/.gitkeep
/wordpress/
test.sh
test.sh
gdata-antivirus.zip
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"port": 9080,
"pathMappings": {
"/var/www/html/": "${workspaceFolder}/wordpress",
"/var/www/html/wp-content/plugins/wordpress-gdata-antivirus": "${workspaceFolder}/",
"/var/www/html/wp-content/plugins/gdata-antivirus": "${workspaceFolder}/",
},
"runtimeArgs": [
"-dxdebug.mode=debug",
Expand Down
6 changes: 4 additions & 2 deletions .zipignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
.devcontainer/*
.vscode/*
.git/*
wordpress/*
tests/*
compose*
Dockerfile
test.sh
wordpress/*
xdebug.ini
xdebug.php
info.php
Dockerfile.WordPress
renovate.json
renovate.json
local-build.sh
2 changes: 1 addition & 1 deletion Dockerfile.WordPress
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM wordpress:6-php8.3
FROM wordpress:6.6.0-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 \
Expand Down
44 changes: 44 additions & 0 deletions GdataAntivirusPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Gdatacyberdefenseag\GdataAntivirus;

use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\Database\IGdataAntivirusDatabase;
use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\Database\WordPressDatabase;
use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem\IGdataAntivirusFileSystem;
use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem\WordPressFileSystem;
use Gdatacyberdefenseag\GdataAntivirus\PluginPage\AdminNotices;
use Gdatacyberdefenseag\GdataAntivirus\PluginPage\Findings\FindingsMenuPage;
use Gdatacyberdefenseag\GdataAntivirus\PluginPage\FullScan\FullScanMenuPage;
use Gdatacyberdefenseag\GdataAntivirus\PluginPage\OnDemandScan\OnDemandScan;
use Gdatacyberdefenseag\GdataAntivirus\PluginPage\GdataAntivirusMenuPage;
use Gdatacyberdefenseag\GdataAntivirus\Vaas\ScanClient;
use Illuminate\Container\Container;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

if (! class_exists('GdataAntivirusPlugin')) {
class GdataAntivirusPlugin extends Container {
public function __construct( LoggerInterface $logger = new NullLogger() ) {
$logger->info('GdataAntivirusPlugin::__construct');
$this->singleton(FindingsMenuPage::class, FindingsMenuPage::class);
$this->singleton(FullScanMenuPage::class, FullScanMenuPage::class);
$this->singleton(OnDemandScan::class, OnDemandScan::class);
$this->singleton(IGdataAntivirusFileSystem::class, WordPressFileSystem::class);
$this->singleton(IGdataAntivirusDatabase::class, WordPressDatabase::class);
$this->singleton(GdataAntivirusMenuPage::class, GdataAntivirusMenuPage::class);
$this->singleton(ScanClient::class, ScanClient::class);
$this->singleton(AdminNotices::class, AdminNotices::class);
$this->singleton(LoggerInterface::class, function () use ( $logger ) {
return $logger;
});

$this->make(GdataAntivirusMenuPage::class);
$findings_menu = $this->make(FindingsMenuPage::class);
$this->make(FullScanMenuPage::class);
$this->make(OnDemandScan::class);

\assert($findings_menu instanceof FindingsMenuPage);
$findings_menu->validate_findings();
}
}
}
2 changes: 1 addition & 1 deletion Infrastructure/Database/IGdataAntivirusDatabase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Gdatacyberdefenseag\WordpressGdataAntivirus\Infrastructure\Database;
namespace Gdatacyberdefenseag\GdataAntivirus\Infrastructure\Database;

interface IGdataAntivirusDatabase {
public function query( string $query, ...$args ): int|bool;
Expand Down
2 changes: 1 addition & 1 deletion Infrastructure/Database/WordPressDatabase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Gdatacyberdefenseag\WordpressGdataAntivirus\Infrastructure\Database;
namespace Gdatacyberdefenseag\GdataAntivirus\Infrastructure\Database;

use wpdb;

Expand Down
24 changes: 24 additions & 0 deletions Infrastructure/FileSystem/FileSystemBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem;

use Amp\ByteStream\ReadableResourceStream;
use function Amp\ByteStream\Internal\tryToCreateReadableStreamFromResource;

/**
* this implements the functions that some filesystems have in common
* for example, there is no proper replacement for fopen (where you get a stream from)
* in the WP_Filesystem_Base class, so we need to implement it here
*/
trait FileSystemBase {
public function get_resource_stream_from_string(string $content): ReadableResourceStream {
$stream = fopen('php://temp', 'r+');
fwrite($stream, $content);
rewind($stream);
return tryToCreateReadableStreamFromResource($stream);
}

public function open(string $path): ReadableResourceStream {
return tryToCreateReadableStreamFromResource(fopen($path, 'r'));
}
}
15 changes: 10 additions & 5 deletions Infrastructure/FileSystem/IGdataAntivirusFileSystem.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?php

namespace Gdatacyberdefenseag\WordpressGdataAntivirus\Infrastructure\FileSystem;
namespace Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem;

use Amp\ByteStream\ReadableResourceStream;

interface IGdataAntivirusFileSystem {
public function read( $path ): string;
public function write( $path, $content );
public function delete( $path );
public function is_writable( $path ): bool;
public function open( string $path ): ReadableResourceStream;
public function read( string $path ): string;
public function write( string $path, string $content ): bool;
public function delete( string $path ): bool;
public function is_writable( string $path ): bool;

public function get_resource_stream_from_string( string $content ): ReadableResourceStream;
}
21 changes: 0 additions & 21 deletions Infrastructure/FileSystem/PlainPhpFileSystem.php

This file was deleted.

8 changes: 5 additions & 3 deletions Infrastructure/FileSystem/WordPressFileSystem.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

namespace Gdatacyberdefenseag\WordpressGdataAntivirus\Infrastructure\FileSystem;
namespace Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem;

require_once ABSPATH . 'wp-admin/includes/file.php';

use WP_Filesystem_Base;

class WordPressFileSystem implements IGdataAntivirusFileSystem {
use FileSystemBase;

private WP_Filesystem_Base $files_system;

public function __construct() {
Expand All @@ -19,11 +21,11 @@ public function read( $path ): string {
return $this->files_system->get_contents($path);
}

public function write( $path, $content ) {
public function write( $path, $content ): bool {
return $this->files_system->put_contents($path, $content);
}

public function delete( $path ) {
public function delete( $path ): bool {
return $this->files_system->delete($path);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

namespace Gdatacyberdefenseag\WordpressGdataAntivirus\Infrastructure\Logging;
namespace Gdatacyberdefenseag\GdataAntivirus\Infrastructure\Logging;

use Gdatacyberdefenseag\WordpressGdataAntivirus\Infrastructure\FileSystem\IGdataAntivirusFileSystem;
use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem\IGdataAntivirusFileSystem;
use Psr\Log\LoggerInterface;

if (!class_exists('WordpressGdataAntivirusPluginDebugLogger')) {
class WordpressGdataAntivirusPluginDebugLogger implements LoggerInterface {
if (!class_exists('GdataAntivirusPluginDebugLogger')) {
class GdataAntivirusPluginDebugLogger implements LoggerInterface {
private IGdataAntivirusFileSystem $files_system;

public function __construct( IGdataAntivirusFileSystem $file_system ) {
$this->files_system = $file_system;

$this->info('WordpressGdataAntivirusPluginDebugLogger::__construct');
$this->info('GdataAntivirusPluginDebugLogger::__construct');
}

public function emergency( string|\Stringable $message, array $context = array() ): void {
Expand Down
8 changes: 4 additions & 4 deletions PluginPage/AdminNotices.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Gdatacyberdefenseag\WordpressGdataAntivirus\PluginPage;
namespace Gdatacyberdefenseag\GdataAntivirus\PluginPage;

use Psr\Log\LoggerInterface;

Expand All @@ -19,11 +19,11 @@ public static function add_notice( $text ) {
}

public function save_notices() {
update_option('WordpressGdataAntivirusMenuNotices', self::$notices);
update_option('GdataAntivirusMenuNotices', self::$notices);
}

public function output_notices() {
$notices = maybe_unserialize(get_option('WordpressGdataAntivirusMenuNotices'));
$notices = maybe_unserialize(get_option('GdataAntivirusMenuNotices'));

if (! empty($notices)) {
echo '<div id="notice" class="notice notice-info is-dismissible">';
Expand All @@ -34,7 +34,7 @@ public function output_notices() {

echo '</div>';

delete_option('WordpressGdataAntivirusMenuNotices');
delete_option('GdataAntivirusMenuNotices');
}
}
}
Expand Down
Loading

0 comments on commit 97df598

Please sign in to comment.