-
Notifications
You must be signed in to change notification settings - Fork 2
/
requestservice.php
92 lines (76 loc) · 2.33 KB
/
requestservice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* ownCloud - User Files Migrate
*
* @author Patrick Paysant <ppaysant@linagora.com>
* @copyright 2014 CNRS DSI
* @license This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
*/
namespace OCA\User_Files_Migrate\Service;
class RequestService
{
protected $requestMapper;
protected $userId;
public function __construct(\OCA\User_Files_Migrate\Db\RequestMapper $requestMapper, $userId)
{
$this->requestMapper = $requestMapper;
$this->userId = $userId;
}
/**
* Returns owned and external migration requests
* @return array
*/
public function getInfos()
{
$ownRequest = $this->requestMapper->findOwnRequest($this->userId);
$extRequest = $this->requestMapper->findExtRequest($this->userId);
$infos = array(
'ownRequest' => $ownRequest,
'extRequest' => $extRequest,
);
return $infos;
}
/**
* Returns the total size of a user folder (files only)
* @param string $uid User ID
* @return int|false
*/
function getRequesterUsedSpace($uid)
{
$view = new \OC\Files\View();
$this->getFilesSize($view, '/' . $uid . '/files', $requesterFileSize);
return $requesterFileSize;
}
/**
* Returns the free space size for the current user
* @return int
*/
public function getFreeSpace()
{
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
$storageInfo = \OC_Helper::getStorageInfo('/', $dirInfo);
$fileSize = $storageInfo['free'];
return $fileSize;
}
/**
* Get some user informations on files and folders
* @param \OC\Files\View $view
* @param string $path the path
* @param int $fileSize to store the total filesize
*/
protected function getFilesSize($view, $path='', &$fileSize) {
$dc = $view->getDirectoryContent($path);
foreach($dc as $item) {
if ($item->isShared()) {
continue;
}
// if folder, recurse
if ($item->getType() == \OCP\Files\FileInfo::TYPE_FOLDER) {
$this->getFilesSize($view, $item->getPath(), $fileSize);
}
else {
$fileSize += $item->getSize();
}
}
}
}