[owncloud-devel] Database table

Pierre Jochem pierrejochem at msn.com
Fri Dec 19 07:47:11 GMT 2014


You do not need to query the database directly. Have a look in this
function:

 

        /**

         * Calculate the disc space for the given path

         *

         * @param string $path

         * @param \OCP\Files\FileInfo $rootInfo (optional)

         * @return array

         */

        public static function getStorageInfo($path, $rootInfo = null) {

                // return storage info without adding mount points

                $includeExtStorage =
\OC_Config::getValue('quota_include_external_storage', false);

 

                if (!$rootInfo) {

                        $rootInfo = \OC\Files\Filesystem::getFileInfo($path,
false);

                }

                $used = $rootInfo->getSize();

                if ($used < 0) {

                        $used = 0;

                }

                $quota = 0;

                $storage = $rootInfo->getStorage();

                if ($includeExtStorage &&
$storage->instanceOfStorage('\OC\Files\Storage\Shared')) {

                        $includeExtStorage = false;

                }

                if ($includeExtStorage) {

                        $quota =
OC_Util::getUserQuota(\OCP\User::getUser());

                        if ($quota !== \OC\Files\SPACE_UNLIMITED) {

                                // always get free space / total space from
root + mount points

                                $path = '';

                                return self::getGlobalStorageInfo();

                        }

                }

 

                // TODO: need a better way to get total space from storage

                if
($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) {

                        $quota = $storage->getQuota();

                }

                $free = $storage->free_space('');

                if ($free >= 0) {

                        $total = $free + $used;

                } else {

                        $total = $free; //either unknown or unlimited

                }

                if ($total > 0) {

                        if ($quota > 0 && $total > $quota) {

                                $total = $quota;

                        }

                        // prevent division by zero or error codes (negative
values)

                        $relative = round(($used / $total) * 10000) / 100;

                } else {

                        $relative = 0;

                }

 

                return array('free' => $free, 'used' => $used, 'total' =>
$total, 'relative' => $relative);

        }

 

Cheers 

Pierre

 

Von: devel-bounces at owncloud.org [mailto:devel-bounces at owncloud.org] Im
Auftrag von Ibai Ibai
Gesendet: Donnerstag, 18. Dezember 2014 15:36
An: devel at owncloud.org
Betreff: [owncloud-devel] Database table

 

Hi,

I would like to know how can I get the storage information in the database.
I mean, I want to know which is the maximum capacity of each user and how
much of that have they used.

I see that there is a table called oc_storages, but it have only the id and
the numeric_id...

Thank you very much in advance for the information.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.owncloud.org/pipermail/devel/attachments/20141219/49984f2d/attachment-0001.html>


More information about the Devel mailing list