Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit f78ceae

Browse files
committed
ENH: refs #0377. Add a non-filtered getSize method to folder model
This will allow the quota module to find out how much space is actually being used under a given root folder.
1 parent 209ed73 commit f78ceae

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

core/models/base/FolderModelBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ abstract function getByUuid($uuid);
6767
abstract function getRoot($folder);
6868
abstract function getAll();
6969
abstract function isDeleteable($folder);
70+
abstract function getSize($folder);
7071

7172
/** Increment the view count */
7273
function incrementViewCount($folder)

core/models/pdo/FolderModel.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function policyCheck($folderDao, $userDao = null, $policy = 0)
103103
return true;
104104
}//end policyCheck
105105

106-
/** get the size and the number of item in a folder*/
106+
/** get the size and the number of item in a folder*/
107107
public function getSizeFiltered($folders, $userDao = null, $policy = 0)
108108
{
109109
$isAdmin = false;
@@ -214,6 +214,37 @@ public function getSizeFiltered($folders, $userDao = null, $policy = 0)
214214
return $folders;
215215
}
216216

217+
/** get the total size for a folder (with no filtered results) */
218+
public function getSize($folder)
219+
{
220+
if(!$folder instanceof FolderDao)
221+
{
222+
throw new Zend_Exception("Should be a folder");
223+
}
224+
$folders = $this->database->select()
225+
->setIntegrityCheck(false)
226+
->from(array('f' => 'folder'), array('folder_id'))
227+
->where('left_indice > ?', $folder->getLeftIndice())
228+
->where('right_indice < ?', $folder->getRightIndice());
229+
230+
$sql = $this->database->select()
231+
->distinct()
232+
->setIntegrityCheck(false)
233+
->from(array('i' => 'item'))
234+
->join(array('i2f' => 'item2folder'),
235+
'( '.$this->database->getDB()->quoteInto('i2f.folder_id IN (?)', $folders).'
236+
OR i2f.folder_id = '.$folder->getKey().'
237+
)
238+
AND i2f.item_id = i.item_id', array());
239+
240+
$sql = $this->database->select()
241+
->setIntegrityCheck(false)
242+
->from(array('i' => $sql), array('sum' => 'sum(i.sizebytes)'));
243+
244+
$row = $this->database->fetchRow($sql);
245+
return $row['sum'];
246+
}
247+
217248
/** Get the root folder */
218249
function getRoot($folder)
219250
{

modules/sizequota/Notification.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public function getSimpleuploadExtraHtml($args)
8787
}
8888
else
8989
{
90-
$usedSpace = $folderModel->getSizeFiltered($rootFolder, $this->userSession->Dao, MIDAS_POLICY_READ);
91-
$freeSpace = $quota->getQuota() - $usedSpace[0]->size;
90+
$freeSpace = $quota->getQuota() - $folderModel->getSize($rootFolder);
9291
return '<div id="sizequotaFreeSpace" style="display:none;">'.$freeSpace.'</div>';
9392
}
9493
}

modules/sizequota/controllers/ConfigController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function folderAction()
117117
$formArray['quota']->setValue($currentQuota->getQuota());
118118
$this->view->quota = $currentQuota->getQuota();
119119
}
120-
$usedSpace = $this->Folder->getSizeFiltered($folder, $this->userSession->Dao);
120+
$usedSpace = $this->Folder->getSize($folder);
121121
$this->view->usedSpace = $usedSpace[0]->size;
122122
$this->view->hUsedSpace = UtilityComponent::formatSize($this->view->usedSpace);
123123
if($this->view->quota == '')
@@ -189,8 +189,7 @@ public function getfreespaceAction()
189189
}
190190
else
191191
{
192-
$usedSpace = $this->Folder->getSizeFiltered($rootFolder, $this->userSession->Dao, MIDAS_POLICY_READ);
193-
$freeSpace = $quota->getQuota() - $usedSpace[0]->size;
192+
$freeSpace = $quota->getQuota() - $this->Folder->getSize($rootFolder);
194193
}
195194
echo JsonComponent::encode(array('status' => true, 'freeSpace' => $freeSpace));
196195
}

modules/sizequota/controllers/components/ApiComponent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function userGet($args)
7878
}
7979
$quotaModel = $modelLoader->loadModel('FolderQuota', 'sizequota');
8080
$quota = $quotaModel->getUserQuota($user);
81-
$used = $folderModel->getSizeFiltered($user->getFolder(), $requestUser, MIDAS_POLICY_READ);
81+
$used = $folderModel->getSize($user->getFolder());
8282
return array('quota' => $quota, 'used' => $used[0]->size);
8383
}
8484

@@ -110,7 +110,7 @@ public function communityGet($args)
110110
}
111111
$quotaModel = $modelLoader->loadModel('FolderQuota', 'sizequota');
112112
$quota = $quotaModel->getCommunityQuota($comm);
113-
$used = $folderModel->getSizeFiltered($comm->getFolder(), $requestUser, MIDAS_POLICY_READ);
113+
$used = $folderModel->getSize($comm->getFolder());
114114
return array('quota' => $quota, 'used' => $used[0]->size);
115115
}
116116

modules/sizequota/public/js/common/common.notify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ midas.sizequota.resetTotal = function()
4242
midas.sizequota.folderChanged = function(args)
4343
{
4444
$.ajax({
45-
type: "POST",
45+
type: 'POST',
4646
url: json.global.webroot+'/sizequota/config/getfreespace',
4747
data: {folderId: args.folderId},
4848
success: function(jsonContent) {

0 commit comments

Comments
 (0)