Passed
Push — master ( 7a09b7...f1e2fb )
by Robin
14:09 queued 14s
created

MoveFromCacheTrait::copyFromCache()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Robin Appelman <[email protected]>
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license AGPL-3.0
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License, version 3,
20
 * along with this program. If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OC\Files\Cache;
25
26
use OCP\Files\Cache\ICache;
27
use OCP\Files\Cache\ICacheEntry;
28
29
/**
30
 * Fallback implementation for moveFromCache
31
 */
32
trait MoveFromCacheTrait {
33
	/**
34
	 * store meta data for a file or folder
35
	 *
36
	 * @param string $file
37
	 * @param array $data
38
	 *
39
	 * @return int file id
40
	 * @throws \RuntimeException
41
	 */
42
	abstract public function put($file, array $data);
43
44
	abstract public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int;
45
46
	/**
47
	 * Move a file or folder in the cache
48
	 *
49
	 * @param \OCP\Files\Cache\ICache $sourceCache
50
	 * @param string $sourcePath
51
	 * @param string $targetPath
52
	 */
53
	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
54
		$sourceEntry = $sourceCache->get($sourcePath);
55
56
		$this->copyFromCache($sourceCache, $sourceEntry, $targetPath);
57
58
		$sourceCache->remove($sourcePath);
59
	}
60
}
61