Skip to content

Commit d9f3512

Browse files
committed
feat: move woocommerce logs directory to private cloud storage
1 parent 71477ae commit d9f3512

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Subscriber/Compatibility/WooCommerceSubscriber.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace Ymir\Plugin\Subscriber\Compatibility;
1515

16+
use Ymir\Plugin\CloudStorage\PrivateCloudStorageStreamWrapper;
17+
use Ymir\Plugin\CloudStorage\PublicCloudStorageStreamWrapper;
1618
use Ymir\Plugin\EventManagement\SubscriberInterface;
1719
use Ymir\Plugin\Support\Collection;
1820

@@ -61,11 +63,22 @@ public static function getSubscribedEvents(): array
6163
'transient_woocommerce_blocks_asset_api_script_data' => 'fixAssetUrlPathsInCachedScriptData',
6264
'transient_woocommerce_blocks_asset_api_script_data_ssl' => 'fixAssetUrlPathsInCachedScriptData',
6365
'woocommerce_csv_importer_check_import_file_path' => 'disableCheckImportFilePath',
66+
'woocommerce_log_directory' => 'changeLogDirectory',
6467
'woocommerce_product_csv_importer_check_import_file_path' => 'disableCheckImportFilePath',
6568
'woocommerce_resize_images' => 'disableImageResizeWithImageProcessing',
6669
];
6770
}
6871

72+
/**
73+
* Change the log directory to point to the private cloud storage.
74+
*/
75+
public function changeLogDirectory($logDirectory)
76+
{
77+
return is_string($logDirectory) && str_starts_with($logDirectory, PublicCloudStorageStreamWrapper::getProtocol())
78+
? sprintf('%s:///wc-logs/', PrivateCloudStorageStreamWrapper::getProtocol())
79+
: $logDirectory;
80+
}
81+
6982
/**
7083
* Disable "check import file path" so that imports work with S3 storage.
7184
*/

tests/Unit/Subscriber/Compatibility/WooCommerceSubscriberTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace Ymir\Plugin\Tests\Unit\Subscriber\Compatibility;
1515

16+
use Ymir\Plugin\CloudStorage\PrivateCloudStorageStreamWrapper;
17+
use Ymir\Plugin\CloudStorage\PublicCloudStorageStreamWrapper;
1618
use Ymir\Plugin\Subscriber\Compatibility\WooCommerceSubscriber;
1719
use Ymir\Plugin\Tests\Mock\EventManagerMockTrait;
1820
use Ymir\Plugin\Tests\Mock\FunctionMockTrait;
@@ -26,6 +28,25 @@ class WooCommerceSubscriberTest extends TestCase
2628
use EventManagerMockTrait;
2729
use FunctionMockTrait;
2830

31+
public function testChangeLogDirectoryWhenLogDirectoryIsAStringThatDoesntStartWithThePublicCloudStorageProtocol()
32+
{
33+
$logDirectory = '/var/logs';
34+
35+
$this->assertSame($logDirectory, (new WooCommerceSubscriber('https://foo.com'))->changeLogDirectory($logDirectory));
36+
}
37+
38+
public function testChangeLogDirectoryWhenLogDirectoryIsAStringThatStartsWithThePublicCloudStorageProtocol()
39+
{
40+
$this->assertSame(sprintf('%s:///wc-logs/', PrivateCloudStorageStreamWrapper::getProtocol()), (new WooCommerceSubscriber('https://foo.com'))->changeLogDirectory(sprintf('%s:///uploads', PublicCloudStorageStreamWrapper::getProtocol())));
41+
}
42+
43+
public function testChangeLogDirectoryWhenLogDirectoryIsntAString()
44+
{
45+
$logDirectory = 42;
46+
47+
$this->assertSame($logDirectory, (new WooCommerceSubscriber('https://foo.com'))->changeLogDirectory($logDirectory));
48+
}
49+
2950
public function testDisableCheckImportFilePath()
3051
{
3152
$this->assertFalse((new WooCommerceSubscriber('https://foo.com'))->disableCheckImportFilePath());
@@ -135,6 +156,7 @@ public function testGetSubscribedEvents()
135156
'transient_woocommerce_blocks_asset_api_script_data' => 'fixAssetUrlPathsInCachedScriptData',
136157
'transient_woocommerce_blocks_asset_api_script_data_ssl' => 'fixAssetUrlPathsInCachedScriptData',
137158
'woocommerce_csv_importer_check_import_file_path' => 'disableCheckImportFilePath',
159+
'woocommerce_log_directory' => 'changeLogDirectory',
138160
'woocommerce_product_csv_importer_check_import_file_path' => 'disableCheckImportFilePath',
139161
'woocommerce_resize_images' => 'disableImageResizeWithImageProcessing',
140162
];

0 commit comments

Comments
 (0)