Skip to content

Commit

Permalink
[ticket/15833] Add core.avatar_manager_avatar_delete_after event
Browse files Browse the repository at this point in the history
PHPBB3-15833
  • Loading branch information
senky committed Oct 28, 2018
1 parent 001f32d commit 6a35385
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions phpBB/config/default/container/services_avatar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
class: phpbb\avatar\manager
arguments:
- '@config'
- '@dispatcher'
- '@avatar.driver_collection'

# ----- Avatar drivers -----
Expand Down
23 changes: 22 additions & 1 deletion phpBB/phpbb/avatar/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class manager
*/
protected $config;

/**
* phpBB event dispatcher
* @var \phpbb\event\dispatcher_interface
*/
protected $phpbb_dispatcher;

/**
* Array that contains a list of enabled drivers
* @var array
Expand Down Expand Up @@ -49,11 +55,13 @@ class manager
* Construct an avatar manager object
*
* @param \phpbb\config\config $config phpBB configuration
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher phpBB event dispatcher
* @param array $avatar_drivers Avatar drivers passed via the service container
*/
public function __construct(\phpbb\config\config $config, $avatar_drivers)
public function __construct(\phpbb\config\config $config, \phpbb\event\dispatcher_interface $phpbb_dispatcher, $avatar_drivers)
{
$this->config = $config;
$this->phpbb_dispatcher = $phpbb_dispatcher;
$this->register_avatar_drivers($avatar_drivers);
}

Expand Down Expand Up @@ -331,6 +339,19 @@ public function handle_avatar_delete(\phpbb\db\driver\driver_interface $db, \php
WHERE user_avatar = '" . $db->sql_escape($avatar_data['avatar']) . "'";
$db->sql_query($sql);
}

/**
* Event is triggered after user avatar has been deleted
*
* @event core.avatar_manager_avatar_delete_after
* @var \phpbb\user user phpBB user object
* @var array avatar_data Normalised avatar-related user data
* @var string table Table to delete avatar from
* @var string prefix Column prefix to delete avatar from
* @since 3.2.4-RC1
*/
$vars = array('user', 'avatar_data', 'table', 'prefix');
extract($this->phpbb_dispatcher->trigger_event('core.avatar_manager_avatar_delete_after', compact($vars)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/avatar/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function setUp()
$this->config['allow_avatar_' . get_class($this->avatar_barfoo)] = false;

// Set up avatar manager
$this->manager = new \phpbb\avatar\manager($this->config, $avatar_drivers, $phpbb_container);
$this->manager = new \phpbb\avatar\manager($this->config, $dispatcher, $avatar_drivers);
$this->db = $this->new_dbal();
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
Expand Down

0 comments on commit 6a35385

Please sign in to comment.