diff --git a/phpBB/config/default/container/services_assets.yml b/phpBB/config/default/container/services_assets.yml index 1370a62062..6ba3a7ea27 100644 --- a/phpBB/config/default/container/services_assets.yml +++ b/phpBB/config/default/container/services_assets.yml @@ -4,4 +4,5 @@ services: arguments: - '@dbal.conn' - '@ext.manager' + - '@log' - '%core.root_path%' diff --git a/phpBB/develop/create_iconify_bundle.php b/phpBB/develop/create_iconify_bundle.php index 8d1c33fe8d..b71b2f30bd 100644 --- a/phpBB/develop/create_iconify_bundle.php +++ b/phpBB/develop/create_iconify_bundle.php @@ -34,9 +34,7 @@ $iconify_bundler->find_icons([ $phpbb_root_path . 'styles/', $phpbb_root_path . 'adm/style/', ]); -$output = $iconify_bundler->with_extensions() - ->with_styles() - ->run(); +$output = $iconify_bundler->get_bundle(); // Save to file file_put_contents($target, $output); diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 1a30d38d61..4e6b143713 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -270,6 +270,10 @@ class acp_extensions ), array($this->phpbb_root_path . 'adm/style')); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name)); + + // Force rebuild of iconify bundle + $iconify_bundler = new \phpbb\assets\iconify_bundler($this->db, $this->ext_manager, $this->log, $this->phpbb_root_path); + $iconify_bundler->get_bundle(true); } catch (\phpbb\db\migration\exception $e) { @@ -316,6 +320,10 @@ class acp_extensions } $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_DISABLE', time(), array($ext_name)); + // Force rebuild of iconify bundle + $iconify_bundler = new \phpbb\assets\iconify_bundler($this->db, $this->ext_manager, $this->log, $this->phpbb_root_path); + $iconify_bundler->get_bundle(true); + $this->tpl_name = 'acp_ext_disable'; $this->template->assign_vars([ diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index a1b1e62a3b..6da638379c 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -65,6 +65,9 @@ class acp_styles /** @var \phpbb\event\dispatcher_interface */ protected $dispatcher; + /** @var \phpbb\assets\iconify_bundler */ + protected $iconify_bundler; + public function main($id, $mode) { global $db, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_container; @@ -80,6 +83,7 @@ class acp_styles $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; $this->dispatcher = $phpbb_dispatcher; + $this->iconify_bundler = $phpbb_container->get('assets.iconify_bundler'); $this->default_style = $config['default_style']; $this->styles_path = $this->phpbb_root_path . $this->styles_path_absolute . '/'; @@ -240,6 +244,9 @@ class acp_styles $this->text_formatter_cache->invalidate(); } + // Force rebuild of iconify bundle + $this->iconify_bundler->get_bundle(true); + // Show message if (!count($messages)) { @@ -331,7 +338,7 @@ class acp_styles $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); - // Uinstall each style + // Uninstall each style $uninstalled = array(); foreach ($rows as $style) { @@ -367,6 +374,9 @@ class acp_styles // Clear cache $this->cache->purge(); + // Force rebuild of iconify bundle + $this->iconify_bundler->get_bundle(true); + // Show message trigger_error(implode('
', $messages) . adm_back_link($this->u_action), E_USER_NOTICE); } diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index aeab0af262..bbe8b7fafa 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -671,6 +671,8 @@ $lang = array_merge($lang, array( 'LOG_USERS_APPROVED' => 'Users approved in usergroup %1$s
» %2$s', 'LOG_USERS_PENDING' => 'Users requested to join group “%1$s” and need to be approved
» %2$s', + 'LOG_ICON_INVALID' => 'Invalid icon supplied: Icon %1$s:%2$s does not seem to exist.', + 'LOG_ICON_COLLECTION_INVALID' => 'Invalid icon collection supplied: Icon collection with prefix %1$s does not seem to exist.', 'LOG_IMAGE_GENERATION_ERROR' => 'Error while creating image
» Error in %1$s on line %2$s: %3$s', 'LOG_INACTIVE_ACTIVATE' => 'Activated inactive users
» %s', diff --git a/phpBB/phpbb/assets/iconify_bundler.php b/phpBB/phpbb/assets/iconify_bundler.php index 8bb77ea605..70e5d5f83b 100644 --- a/phpBB/phpbb/assets/iconify_bundler.php +++ b/phpBB/phpbb/assets/iconify_bundler.php @@ -19,21 +19,35 @@ use Symfony\Component\Finder\Finder; class iconify_bundler { + protected const BUNDLE_PATH = 'assets/iconify/iconify_bundle.js'; + protected $db; protected $ext_manager; + /** @var \phpbb\log\log_interface */ + protected $log; + + /** @var \phpbb\filesystem\filesystem_interface */ + protected $filesystem; + protected $root_path = ''; + + protected $bundle_path = ''; protected $icons_list = []; - public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\extension\manager $ext_manager, string $root_path) + public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\extension\manager $ext_manager, \phpbb\log\log_interface $log, string $root_path) { $this->db = $db; $this->ext_manager = $ext_manager; + $this->filesystem = new \phpbb\filesystem\filesystem(); + $this->log = $log; $this->root_path = $root_path; + + $this->bundle_path = $root_path . self::BUNDLE_PATH; } - public function run() + protected function run() { // Sort icons first sort($this->icons_list, SORT_NATURAL); @@ -62,6 +76,22 @@ class iconify_bundler return $output; } + public function get_bundle(bool $force_rebuild = false): string + { + if (!$force_rebuild && $this->is_dumped()) + { + return file_get_contents($this->bundle_path); + } + + $iconify_bundle = $this->with_extensions() + ->with_styles() + ->run(); + + $this->filesystem->dump_file($this->bundle_path, $iconify_bundle); + + return $iconify_bundle; + } + /** * @param array $paths Icon paths * @@ -157,6 +187,11 @@ class iconify_bundler return $this; } + protected function is_dumped(): bool + { + return $this->filesystem->exists($this->bundle_path) && $this->filesystem->is_readable($this->bundle_path); + } + protected function add_icon(string $icon_name): void { if (!in_array($icon_name, $this->icons_list)) @@ -276,18 +311,16 @@ class iconify_bundler { // Load icon set $collection = new Collection($prefix); - if (!$collection->loadIconifyCollection($prefix)) { - throw new \Error( - 'Icons with prefix "' . $prefix . '" do not exist in Iconify. Update iconify/json?' - ); + if (!$collection->loadIconifyCollection($prefix)) + { + $this->log->add('critical', ANONYMOUS, '', 'LOG_ICON_COLLECTION_INVALID', false, [$prefix]); } // Make sure all icons exist foreach ($iconsList as $name) { - if (!$collection->iconExists($name)) { - // Uncomment next line to throw error if an icon does not exist - // throw new Error('Could not find icon: "' . $prefix . ':' . $name . '"'); - echo 'Could not find icon: "', $prefix, ':', $name, "\"\n"; + if (!$collection->iconExists($name)) + { + $this->log->add('critical', ANONYMOUS, '', 'LOG_ICON_INVALID', false, [$prefix, $name]); } } diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index e095b3af2d..035748bc10 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -76,7 +76,7 @@ - +