-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a unique images/icons directory #100
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a839f7
Move PWA icons to unique images dir
iMattPro d876789
Rename migration
iMattPro b65e539
Add an empty index.htm to prevent unwanted peeping in new dir
iMattPro a46a715
Improve unfound valid image text
iMattPro 890e2a2
Reword missing image text
iMattPro 732a9ad
Make lang keys consistent
iMattPro d8a667d
Improve code readability
iMattPro 7bfe60a
Create new dir with more secure permissions
iMattPro 2df220d
Fix log message (accidentally changed param value)
iMattPro bef1503
Update language/ru/info_acp_webpushnotifications.php
iMattPro 6c87f5b
Update language/ru/webpushnotifications_common_acp.php
iMattPro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
/** | ||
* | ||
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package. | ||
* | ||
* @copyright (c) 2024, phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
*/ | ||
|
||
namespace phpbb\webpushnotifications\migrations; | ||
|
||
use phpbb\db\migration\container_aware_migration; | ||
use phpbb\filesystem\exception\filesystem_exception; | ||
use phpbb\filesystem\filesystem; | ||
|
||
class setup_site_icons extends container_aware_migration | ||
{ | ||
private const NEW_ICON_DIR = 'images/site_icons'; | ||
private const OLD_ICON_DIR = 'images/icons'; | ||
|
||
/* @var filesystem $filesystem */ | ||
private $filesystem; | ||
|
||
public function effectively_installed() | ||
{ | ||
return $this->get_filesystem()->exists($this->container->getParameter('core.root_path') . self::NEW_ICON_DIR); | ||
} | ||
|
||
public static function depends_on() | ||
{ | ||
return ['\phpbb\webpushnotifications\migrations\add_acp_pwa_configs']; | ||
} | ||
|
||
public function update_data(): array | ||
{ | ||
return [ | ||
['custom', [[$this, 'configure_site_icons']]], | ||
]; | ||
} | ||
|
||
/** | ||
* Create a site_icons directory in the images directory (and copy existing PWA the icons there) | ||
* | ||
* @return void | ||
*/ | ||
public function configure_site_icons() | ||
{ | ||
// Cache frequently used services and values | ||
$filesystem = $this->get_filesystem(); | ||
$root_path = $this->container->getParameter('core.root_path'); | ||
$user = $this->container->get('user'); | ||
$log = $this->container->get('log'); | ||
|
||
// Prepare paths once | ||
$new_icon_path = $root_path . self::NEW_ICON_DIR; | ||
$old_icon_path = $root_path . self::OLD_ICON_DIR; | ||
|
||
// Batch get config values | ||
$icons = [ | ||
'small' => $this->config->offsetGet('pwa_icon_small'), | ||
'large' => $this->config->offsetGet('pwa_icon_large') | ||
]; | ||
|
||
try | ||
{ | ||
// Create directory only if needed (give an empty index.htm too) | ||
if (!$filesystem->exists($new_icon_path)) | ||
{ | ||
$filesystem->mkdir($new_icon_path, 0755); | ||
$filesystem->touch($new_icon_path . '/index.htm'); | ||
} | ||
|
||
// Process icons | ||
$copied = false; | ||
foreach ($icons as $icon) | ||
{ | ||
$old_file = $old_icon_path . '/' . $icon; | ||
$new_file = $new_icon_path . '/' . $icon; | ||
|
||
if (!empty($icon) && $filesystem->exists($old_file)) | ||
{ | ||
$filesystem->copy($old_file, $new_file); | ||
$copied = true; | ||
} | ||
} | ||
|
||
// Set up a log message result | ||
$result = [ | ||
'lang_key' => $copied ? 'LOG_WEBPUSH_ICON_COPY_SUCCESS' : 'LOG_WEBPUSH_ICON_DIR_SUCCESS', | ||
'params' => [self::NEW_ICON_DIR], | ||
]; | ||
} | ||
catch (filesystem_exception $e) | ||
{ | ||
$result = [ | ||
'lang_key' => 'LOG_WEBPUSH_ICON_DIR_FAIL', | ||
'params' => [$e->get_filename(), $e->getMessage()] | ||
]; | ||
} | ||
|
||
// Log result | ||
$log->add('admin', $user->data['user_id'], $user->ip, $result['lang_key'], false, $result['params']); | ||
} | ||
|
||
/** | ||
* Get the filesystem object | ||
* | ||
* @return filesystem | ||
*/ | ||
protected function get_filesystem() | ||
{ | ||
if ($this->filesystem === null) | ||
{ | ||
$this->filesystem = $this->container->get('filesystem'); | ||
} | ||
|
||
return $this->filesystem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rxu can you help with these?