From bc4aa38aa5062011d3d8d325c0a768d5ac6bbf98 Mon Sep 17 00:00:00 2001 From: PT-ATA No One Date: Wed, 16 Oct 2024 11:37:47 +0000 Subject: [PATCH] fix namespaceing in scoped code --- .devcontainer/configureWordPress.sh | 2 +- PluginPage/FullScan/FullScanMenuPage.php | 2 +- Vaas/ScanClient.php | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.devcontainer/configureWordPress.sh b/.devcontainer/configureWordPress.sh index e081a54..c68b788 100644 --- a/.devcontainer/configureWordPress.sh +++ b/.devcontainer/configureWordPress.sh @@ -19,4 +19,4 @@ docker exec -it --user www-data gdata-antivirus-app-1 bash -c "wp plugin install 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" -svn co https://plugins.svn.wordpress.org/gdata-antivirus/ +svn co https://plugins.svn.wordpress.org/gdata-antivirus/ svn diff --git a/PluginPage/FullScan/FullScanMenuPage.php b/PluginPage/FullScan/FullScanMenuPage.php index 43fd418..fa620e5 100644 --- a/PluginPage/FullScan/FullScanMenuPage.php +++ b/PluginPage/FullScan/FullScanMenuPage.php @@ -235,7 +235,7 @@ public function full_scan(): void { $this->admin_notices->add_notice(__('Full Scan started', 'gdata-antivirus')); $batch_size = get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100); - $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ABSPATH, \FilesystemIterator::SKIP_DOTS)); + $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ABSPATH, \FilesystemIterator::SKIP_DOTS)); $files = array(); foreach ($it as $file_path) { if (! ( $file_path instanceof \SplFileInfo )) { diff --git a/Vaas/ScanClient.php b/Vaas/ScanClient.php index 11eda20..3a4ff57 100644 --- a/Vaas/ScanClient.php +++ b/Vaas/ScanClient.php @@ -8,6 +8,7 @@ use VaasSdk\Vaas; use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator; use VaasSdk\Authentication\ResourceOwnerPasswordGrantAuthenticator; +use VaasSdk\Exceptions\VaasInvalidStateException; use VaasSdk\Message\Verdict; use VaasSdk\VaasOptions as VaasParameters; @@ -103,9 +104,15 @@ public function scan_post( $data, $postdata, $unsanitized_postarr ) { try { $verdict = $this->vaas->ForStream($stream); - } catch (\VaasSdk\Exceptions\VaasInvalidStateException $e) { - $this->connect(); - $verdict = $this->vaas->ForStream($stream); + } catch (VaasInvalidStateException $e) { + try { + $this->connect(); + $verdict = $this->vaas->ForStream($stream); + } catch (\Exception $e) { + $this->admin_notices->add_notice(esc_html__('virus scan failed', 'gdata-antivirus')); + $this->logger->debug($e->getMessage()); + return $data; + } } catch (\Exception $e) { $this->admin_notices->add_notice(esc_html__('virus scan failed', 'gdata-antivirus')); $this->logger->debug($e->getMessage()); @@ -149,9 +156,14 @@ public function scan_comment( $commentdata ) { $stream = $this->file_system->get_resource_stream_from_string($commend_content); try { $verdict = $this->vaas->ForStream($stream); - } catch (\VaasSdk\Exceptions\VaasInvalidStateException $e) { - $this->connect(); - $verdict = $this->vaas->ForStream($stream); + } catch (VaasInvalidStateException $e) { + try { + $this->connect(); + $verdict = $this->vaas->ForStream($stream); + } catch (\Exception $e) { + $this->admin_notices->add_notice(esc_html__('virus scan failed', 'gdata-antivirus')); + $this->logger->debug($e->getMessage()); + } } catch (\Exception $e) { $this->admin_notices->add_notice(esc_html__('virus scan failed', 'gdata-antivirus')); $this->logger->debug($e->getMessage());