diff --git a/adm/style/acp_pwakit.html b/adm/style/acp_pwakit.html index 896ae29..0381ed8 100644 --- a/adm/style/acp_pwakit.html +++ b/adm/style/acp_pwakit.html @@ -69,36 +69,40 @@
{{ lang('ACP_PWA_KIT_APP_ICONS_EXPLAIN') }}
diff --git a/config/services.yml b/config/services.yml index 68d00f2..9482f57 100644 --- a/config/services.yml +++ b/config/services.yml @@ -16,6 +16,7 @@ services: - '@phpbb.pwakit.storage' - '@phpbb.pwakit.file_tracker' - '@storage.helper' + - '@storage.provider_collection' - '%core.root_path%' phpbb.pwakit.upload: diff --git a/controller/admin_controller.php b/controller/admin_controller.php index 534676f..a8dcebd 100644 --- a/controller/admin_controller.php +++ b/controller/admin_controller.php @@ -189,6 +189,9 @@ protected function display_settings(): void 'PWA_IMAGES_DIR' => $this->helper->get_storage_path(), 'PWA_KIT_ICONS' => $this->helper->get_icons($this->phpbb_root_path), 'STYLES' => $this->get_styles(), + + 'S_STORAGE_LOCAL' => $this->helper->is_storage_local(), + 'U_BOARD_SETTINGS' => append_sid("{$this->phpbb_admin_path}index.$this->php_ext", 'i=acp_board&mode=settings'), 'U_STORAGE_SETTINGS'=> append_sid("{$this->phpbb_admin_path}index.$this->php_ext", 'i=acp_storage&mode=settings'), 'U_ACTION' => $this->u_action, diff --git a/helper/helper.php b/helper/helper.php index 11c719c..93ecee3 100644 --- a/helper/helper.php +++ b/helper/helper.php @@ -11,12 +11,14 @@ namespace phpbb\pwakit\helper; use FastImageSize\FastImageSize; +use phpbb\di\service_collection; use phpbb\exception\runtime_exception; use phpbb\extension\manager as ext_manager; use phpbb\pwakit\storage\file_tracker; use phpbb\storage\storage; use phpbb\storage\exception\storage_exception; use phpbb\storage\helper as storage_helper; +use RuntimeException; class helper { @@ -35,6 +37,9 @@ class helper /** @var storage_helper */ protected storage_helper $storage_helper; + /** @var service_collection $provider_collection */ + protected service_collection $provider_collection; + /** @var string */ protected string $root_path; @@ -46,18 +51,41 @@ class helper * @param storage $storage * @param file_tracker $file_tracker * @param storage_helper $storage_helper + * @param service_collection $provider_collection * @param string $root_path */ - public function __construct(ext_manager $extension_manager, FastImageSize $imagesize, storage $storage, file_tracker $file_tracker, storage_helper $storage_helper, string $root_path) + public function __construct(ext_manager $extension_manager, FastImageSize $imagesize, storage $storage, file_tracker $file_tracker, storage_helper $storage_helper, service_collection $provider_collection, string $root_path) { $this->extension_manager = $extension_manager; $this->imagesize = $imagesize; $this->storage = $storage; $this->file_tracker = $file_tracker; $this->storage_helper = $storage_helper; + $this->provider_collection = $provider_collection; $this->root_path = $root_path; } + /** + * Storage compatibility requires the local provider + * + * @return bool + */ + public function is_storage_local(): bool + { + try + { + $storage_name = $this->storage->get_name(); + $provider_class = $this->storage_helper->get_current_provider($storage_name); + $current_provider = $this->provider_collection->get_by_class($provider_class); + + return $current_provider && $current_provider->get_name() === 'local'; + } + catch (RuntimeException) + { + return false; + } + } + /** * Get the storage path for the current storage definition * diff --git a/language/en/acp_pwa.php b/language/en/acp_pwa.php index 8f20f39..edab16f 100644 --- a/language/en/acp_pwa.php +++ b/language/en/acp_pwa.php @@ -54,6 +54,7 @@ 'ACP_PWA_KIT_APP_ICONS_EXPLAIN' => 'Used to specify the touch-icon for your web application. This icon will be used when your web application is added to the home screen. Multiple sizes are preferred for compatibility with various devices. Note that when adding or removing icons, you may need to clear your web app/browser cache to see them update.', 'ACP_PWA_KIT_ICONS' => 'Web application icons', 'ACP_PWA_KIT_ICONS_EXPLAIN' => 'PNG image files that represent your web application. Multiple sizes are preferred for compatibility with various devices.', + 'ACP_PWA_STORAGE_INCOMPATIBLE' => 'To manage icons you must set Web app icons storage to Local in General » Storage settings.', 'ACP_PWA_KIT_NO_ICONS' => 'No icons are available. Click Upload to add new icons or click Resync to find existing icons that were previously uploaded. Recommended PNG sizes include 180x180, 192x192 and 512x512.', 'ACP_PWA_IMG_UPLOAD' => 'Upload web application icons', 'ACP_PWA_IMG_UPLOAD_EXPLAIN' => 'Upload PNG images. Images are currently being stored in %1$s. This can be changed at any time to another location in General » Storage settings.', diff --git a/tests/unit/admin_controller_test.php b/tests/unit/admin_controller_test.php index c4db19b..529a241 100644 --- a/tests/unit/admin_controller_test.php +++ b/tests/unit/admin_controller_test.php @@ -83,6 +83,7 @@ protected function setUp(): void $this->helper = $this->getMockBuilder(helper::class) ->disableOriginalConstructor() ->getMock(); + $this->helper->method('is_storage_local')->willReturn(true); $this->helper->method('get_storage_path')->willReturn('images/site_icons'); $this->helper->method('get_icons')->willReturn([]); @@ -239,6 +240,7 @@ public function test_display_settings($configs, $expected) 'PWA_IMAGES_DIR' => 'images/site_icons', 'PWA_KIT_ICONS' => [], 'STYLES' => $expected_style_data, + 'S_STORAGE_LOCAL' => true, 'U_BOARD_SETTINGS' => "{$this->phpbb_root_path}adm/index.php?i=acp_board&mode=settings", 'U_STORAGE_SETTINGS'=> "{$this->phpbb_root_path}adm/index.php?i=acp_storage&mode=settings", 'U_ACTION' => '', diff --git a/tests/unit/helper_test.php b/tests/unit/helper_test.php index 69295cd..f9e56e7 100644 --- a/tests/unit/helper_test.php +++ b/tests/unit/helper_test.php @@ -129,6 +129,7 @@ protected function setUp(): void $provider_collection, $adapter_collection ), + $provider_collection, $phpbb_root_path ); @@ -154,6 +155,17 @@ public function test_get_tracked_files() $this->assertEquals(['foo.png'], $this->file_tracker->get_tracked_files()); } + public function test_is_storage_local() + { + $this->assertTrue($this->helper->is_storage_local()); + } + + public function test_is_storage_not_local() + { + $this->config->set('storage\phpbb_pwakit\provider', 'foo'); + $this->assertFalse($this->helper->is_storage_local()); + } + public function test_get_storage_path() { $this->assertEquals($this->storage_path, $this->helper->get_storage_path());