Passed
Branch 3.3 (508034)
by Jeroen
22:33 queued 25s
created

Delete   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 23
ccs 7
cts 8
cp 0.875
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A deleteLikes() 0 14 2
1
<?php
2
3
namespace Elgg\Likes;
4
5
use Elgg\Database\Delete as DbDelete;
6
7
/**
8
 * Listen to 'delete' events to cleanup likes
9
 *
10
 * @internal
11
 * @since 3.3
12
 */
13
class Delete {
14
	
15
	/**
16
	 * Cleanup likes annotations on delete of an entity
17
	 *
18
	 * @param \Elgg\Event $event 'delete', 'group'|'object'|'site'|'user'
19
	 *
20
	 *  @return void
21
	 */
22 384
	public static function deleteLikes(\Elgg\Event $event) {
23
		
24 384
		$entity = $event->getObject();
25 384
		if (!$entity instanceof \ElggEntity) {
26
			return;
27
		}
28
		
29
		// Let's do a bulk delete of all likes annotations, instead of for each individually
30
		// this will save performance
31 384
		$delete = DbDelete::fromTable('annotations');
32 384
		$delete->where($delete->compare('entity_guid', '=', $entity->guid, ELGG_VALUE_GUID))
33 384
			->andWhere($delete->compare('name', '=', 'likes', ELGG_VALUE_STRING));
34
		
35 384
		elgg()->db->deleteData($delete);
36 384
	}
37
}
38