aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2015-08-08 22:23:03 +0200
committerMarc Alexander <admin@m-a-styles.de>2015-08-08 22:23:03 +0200
commit47b32f1da9edca7945bbc82ad65cdc30cb969890 (patch)
tree83aeeb3b8d79eda198d153fe5e03598bc23935ec
parent46ffafd0c6805f3903235d5c6f55d6848ed60859 (diff)
parentb7e4d0b0a5e5264da3e65418d8e7ac2f92dc8cbc (diff)
downloadforums-47b32f1da9edca7945bbc82ad65cdc30cb969890.tar
forums-47b32f1da9edca7945bbc82ad65cdc30cb969890.tar.gz
forums-47b32f1da9edca7945bbc82ad65cdc30cb969890.tar.bz2
forums-47b32f1da9edca7945bbc82ad65cdc30cb969890.tar.xz
forums-47b32f1da9edca7945bbc82ad65cdc30cb969890.zip
Merge branch '3.1.x'
Conflicts: phpBB/phpbb/avatar/driver/upload.php tests/avatar/manager_test.php
-rw-r--r--phpBB/config/default/container/services_avatar.yml1
-rw-r--r--phpBB/phpbb/avatar/driver/upload.php74
-rw-r--r--tests/avatar/manager_test.php4
3 files changed, 71 insertions, 8 deletions
diff --git a/phpBB/config/default/container/services_avatar.yml b/phpBB/config/default/container/services_avatar.yml
index c74bef3d66..1b0c109298 100644
--- a/phpBB/config/default/container/services_avatar.yml
+++ b/phpBB/config/default/container/services_avatar.yml
@@ -64,6 +64,7 @@ services:
- @filesystem
- @path_helper
- @mimetype.guesser
+ - @dispatcher
- @cache.driver
calls:
- [set_name, [avatar.driver.upload]]
diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php
index 60c9e9cc95..1939a91cfe 100644
--- a/phpBB/phpbb/avatar/driver/upload.php
+++ b/phpBB/phpbb/avatar/driver/upload.php
@@ -29,6 +29,11 @@ class upload extends \phpbb\avatar\driver\driver
protected $mimetype_guesser;
/**
+ * @var \phpbb\event\dispatcher_interface
+ */
+ protected $dispatcher;
+
+ /**
* Construct a driver object
*
* @param \phpbb\config\config $config phpBB configuration
@@ -37,9 +42,10 @@ class upload extends \phpbb\avatar\driver\driver
* @param \phpbb\filesystem\filesystem_interface phpBB filesystem helper
* @param \phpbb\path_helper $path_helper phpBB path helper
* @param \phpbb\mimetype\guesser $mimetype_guesser Mimetype guesser
+ * @param \phpbb\event\dispatcher_interface $dispatcher phpBB Event dispatcher object
* @param \phpbb\cache\driver\driver_interface $cache Cache driver
*/
- public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\filesystem\filesystem_interface $filesystem, \phpbb\path_helper $path_helper, \phpbb\mimetype\guesser $mimetype_guesser, \phpbb\cache\driver\driver_interface $cache = null)
+ public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\filesystem\filesystem_interface $filesystem, \phpbb\path_helper $path_helper, \phpbb\mimetype\guesser $mimetype_guesser, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\cache\driver\driver_interface $cache = null)
{
$this->config = $config;
$this->phpbb_root_path = $phpbb_root_path;
@@ -47,6 +53,7 @@ class upload extends \phpbb\avatar\driver\driver
$this->filesystem = $filesystem;
$this->path_helper = $path_helper;
$this->mimetype_guesser = $mimetype_guesser;
+ $this->dispatcher = $dispatcher;
$this->cache = $cache;
}
@@ -144,6 +151,15 @@ class upload extends \phpbb\avatar\driver\driver
$prefix = $this->config['avatar_salt'] . '_';
$file->clean_filename('avatar', $prefix, $row['id']);
+ // If there was an error during upload, then abort operation
+ if (sizeof($file->error))
+ {
+ $file->remove();
+ $error = $file->error;
+ return false;
+ }
+
+ // Calculate new destination
$destination = $this->config['avatar_path'];
// Adjust destination path (no trailing slash)
@@ -158,13 +174,35 @@ class upload extends \phpbb\avatar\driver\driver
$destination = '';
}
- // Move file and overwrite any existing image
- $file->move_file($destination, true);
+ /**
+ * Before moving new file in place (and eventually overwriting the existing avatar with the newly uploaded avatar)
+ *
+ * @event core.avatar_driver_upload_move_file_before
+ * @var string destination Destination directory where the file is going to be moved
+ * @var string prefix Prefix for the avatar filename
+ * @var array row Array with avatar row data
+ * @var array error Array of errors, if filled in by this event file will not be moved
+ * @since 3.1.6-RC1
+ */
+ $vars = array(
+ 'destination',
+ 'prefix',
+ 'row',
+ 'error',
+ );
+ extract($this->dispatcher->trigger_event('core.avatar_driver_upload_move_file_before', compact($vars)));
- if (sizeof($file->error))
+ if (!sizeof($error))
+ {
+ // Move file and overwrite any existing image
+ $file->move_file($destination, true);
+ }
+
+ // If there was an error during move, then clean up leftovers
+ $error = array_merge($error, $file->error);
+ if (sizeof($error))
{
$file->remove();
- $error = array_merge($error, $file->error);
return false;
}
@@ -199,10 +237,32 @@ class upload extends \phpbb\avatar\driver\driver
*/
public function delete($row)
{
+
+ $error = array();
+ $destination = $this->config['avatar_path'];
+ $prefix = $this->config['avatar_salt'] . '_';
$ext = substr(strrchr($row['avatar'], '.'), 1);
- $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext;
+ $filename = $this->phpbb_root_path . $destination . '/' . $prefix . $row['id'] . '.' . $ext;
+
+ /**
+ * Before deleting an existing avatar
+ *
+ * @event core.avatar_driver_upload_delete_before
+ * @var string destination Destination directory where the file is going to be deleted
+ * @var string prefix Prefix for the avatar filename
+ * @var array row Array with avatar row data
+ * @var array error Array of errors, if filled in by this event file will not be deleted
+ * @since 3.1.6-RC1
+ */
+ $vars = array(
+ 'destination',
+ 'prefix',
+ 'row',
+ 'error',
+ );
+ extract($this->dispatcher->trigger_event('core.avatar_driver_upload_delete_before', compact($vars)));
- if (file_exists($filename))
+ if (!sizeof($error) && file_exists($filename))
{
@unlink($filename);
}
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
index 71f40c0b13..6d77f2ed3a 100644
--- a/tests/avatar/manager_test.php
+++ b/tests/avatar/manager_test.php
@@ -59,6 +59,8 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
$guesser = new \phpbb\mimetype\guesser($guessers);
$imagesize = new \fastImageSize\fastImageSize();
+ $dispatcher = new phpbb_mock_event_dispatcher();
+
// $this->avatar_foobar will be needed later on
$this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($this->config, $imagesize, $phpbb_root_path, $phpEx, $path_helper, $cache));
$this->avatar_foobar->expects($this->any())
@@ -79,7 +81,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
}
else
{
- $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $filesystem, $path_helper, $guesser, $cache));
+ $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $filesystem, $path_helper, $guesser, $dispatcher, $cache));
}
$cur_avatar->expects($this->any())
->method('get_name')