Test Failed
Push — master ( 8c47c2...3acf9f )
by Steve
12:37
created

actions/avatar/upload.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Avatar upload action
4
 */
5
6
$guid = get_input('guid');
7
$owner = get_entity($guid);
8
9 View Code Duplication
if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
	register_error(elgg_echo('avatar:upload:fail'));
11
	forward(REFERER);
12
}
13
14
$error = elgg_get_friendly_upload_error($_FILES['avatar']['error']);
15
if ($error) {
16
	register_error($error);
17
	forward(REFERER);
18
}
19
20
if (!$owner->saveIconFromUploadedFile('avatar')) {
21
	register_error(elgg_echo('avatar:resize:fail'));
22
	forward(REFERER);
23
}
24
25
if (elgg_trigger_event('profileiconupdate', $owner->type, $owner)) {
26
	system_message(elgg_echo("avatar:upload:success"));
27
	
28
	// River
29
	$view = 'river/user/default/profileiconupdate';
30
	// remove old river items
31
	elgg_delete_river(['subject_guid' => $owner->guid, 'view' => $view, 'limit' => false]);
32
	// create new river entry
33
	elgg_create_river_item([
34
		'view' => $view,
35
		'action_type' => 'update',
36
		'subject_guid' => $owner->guid,
37
		'object_guid' => $owner->guid,
38
	]);
39
}
40
41
forward(REFERER);
42