-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
132 additions
and
19 deletions.
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,101 @@ | ||
<?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 move_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() | ||
{ | ||
$filesystem = $this->get_filesystem(); | ||
$root_path = $this->container->getParameter('core.root_path'); | ||
|
||
$user = $this->container->get('user'); | ||
|
||
$small_icon = $this->config->offsetGet('pwa_icon_small'); | ||
$large_icon = $this->config->offsetGet('pwa_icon_large'); | ||
|
||
try | ||
{ | ||
// Create the new site_icons directory | ||
if (!$filesystem->exists($root_path . self::NEW_ICON_DIR)) | ||
{ | ||
$filesystem->mkdir($root_path . self::NEW_ICON_DIR); | ||
} | ||
|
||
// Copy existing PWA icons to the new site_icons directory | ||
foreach ([$small_icon, $large_icon] as $icon) | ||
{ | ||
if (!$filesystem->exists($root_path . self::OLD_ICON_DIR . '/' . $icon)) | ||
{ | ||
continue; | ||
} | ||
|
||
$filesystem->copy( | ||
$root_path . self::OLD_ICON_DIR . '/' . $icon, | ||
$root_path . self::NEW_ICON_DIR . '/' . $icon | ||
); | ||
} | ||
|
||
$this->container->get('log')->add('admin', $user->data['user_id'], $user->ip, 'LOG_WEBPUSH_ICON_DIR_SUCCESS', false, [self::NEW_ICON_DIR]); | ||
} | ||
catch (filesystem_exception $e) | ||
{ | ||
$this->container->get('log')->add('critical', $user->data['user_id'], $user->ip, 'LOG_WEBPUSH_ICON_DIR_FAIL', false, [$e->get_filename()]); | ||
} | ||
} | ||
|
||
/** | ||
* 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