Completed
Push — master ( 3b83d2...39a0ee )
by Aimeos
03:34
created

Cache::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Common\Decorator;
12
13
14
/**
15
 * Cache cleanup decorator for JQAdm clients
16
 *
17
 * @package Admin
18
 * @subpackage JQAdm
19
 */
20
class Cache extends Base
21
{
22
	/**
23
	 * Clears the cache after deleting the item
24
	 *
25
	 * @return string|null admin output to display or null for redirecting to the list
26
	 */
27
	public function delete()
28
	{
29
		$result = $this->getClient()->delete();
30
31
		$ids = (array) $this->getView()->param( 'id' );
32
		$tags = array( 'product' );
33
34
		foreach( $ids as $id ) {
35
			$tags[] = 'product-' . $id;
36
		}
37
38
		$this->getContext()->getCache()->deleteByTags( $tags );
39
40
		return $result;
41
	}
42
43
44
	/**
45
	 * Clears the cache after saving the item
46
	 *
47
	 * @return string|null admin output to display or null for redirecting to the list
48
	 */
49
	public function save()
50
	{
51
		$result = $this->getClient()->save();
52
		$item = $this->getView()->item;
53
54
		if( $item->getId() !== null )
55
		{
56
			$idtag = 'product-' . $item->getId();
57
			$this->getContext()->getCache()->deleteByTags( array( 'product', $idtag ) );
58
		}
59
60
		return $result;
61
	}
62
}
63