本文整理汇总了PHP中OCP\Util::computerFileSize方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::computerFileSize方法的具体用法?PHP Util::computerFileSize怎么用?PHP Util::computerFileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\Util
的用法示例。
在下文中一共展示了Util::computerFileSize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateQuota
private function updateQuota($dn)
{
$quota = null;
if (!empty($this->connection->ldapQuotaDefault)) {
$quota = $this->connection->ldapQuotaDefault;
}
if (!empty($this->connection->ldapQuotaAttribute)) {
$aQuota = $this->readAttribute($dn, $this->connection->ldapQuotaAttribute);
if ($aQuota && count($aQuota) > 0) {
$quota = $aQuota[0];
}
}
if (!is_null($quota)) {
\OCP\Config::setUserValue($this->dn2username($dn), 'files', 'quota', \OCP\Util::computerFileSize($quota));
}
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$toBeSet = [];
if ($input->getOption('enable')) {
$toBeSet['log_type'] = 'owncloud';
}
if ($file = $input->getOption('file')) {
$toBeSet['logfile'] = $file;
}
if (($rotateSize = $input->getOption('rotate-size')) !== null) {
$rotateSize = \OCP\Util::computerFileSize($rotateSize);
$this->validateRotateSize($rotateSize);
$toBeSet['log_rotate_size'] = $rotateSize;
}
// set config
foreach ($toBeSet as $option => $value) {
$this->config->setSystemValue($option, $value);
}
// display config
if ($this->config->getSystemValue('log_type', 'owncloud') === 'owncloud') {
$enabledText = 'enabled';
} else {
$enabledText = 'disabled';
}
$output->writeln('Log backend ownCloud: ' . $enabledText);
$dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
$defaultLogFile = rtrim($dataDir, '/') . '/owncloud.log';
$output->writeln('Log file: ' . $this->config->getSystemValue('logfile', $defaultLogFile));
$rotateSize = $this->config->getSystemValue('log_rotate_size', 0);
if ($rotateSize) {
$rotateString = \OCP\Util::humanFileSize($rotateSize);
} else {
$rotateString = 'disabled';
}
$output->writeln('Rotate at: ' . $rotateString);
}
示例3: expire
/**
* @brief Erase a file's versions which exceed the set quota
*/
private static function expire($filename, $versionsSize = null, $offset = 0)
{
if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
list($uid, $filename) = self::getUidAndFilename($filename);
$versionsFileview = new \OC\Files\View('/' . $uid . '/files_versions');
// get available disk space for user
$softQuota = true;
$quota = \OC_Preferences::getValue($uid, 'files', 'quota');
if ($quota === null || $quota === 'default') {
$quota = \OC_Appconfig::getValue('files', 'default_quota');
}
if ($quota === null || $quota === 'none') {
$quota = \OC\Files\Filesystem::free_space('/');
$softQuota = false;
} else {
$quota = \OCP\Util::computerFileSize($quota);
}
// make sure that we have the current size of the version history
if ($versionsSize === null) {
$versionsSize = self::getVersionsSize($uid);
if ($versionsSize === false || $versionsSize < 0) {
$versionsSize = self::calculateSize($uid);
}
}
// calculate available space for version history
// subtract size of files and current versions size from quota
if ($softQuota) {
$files_view = new \OC\Files\View('/' . $uid . '/files');
$rootInfo = $files_view->getFileInfo('/');
$free = $quota - $rootInfo['size'];
// remaining free space for user
if ($free > 0) {
$availableSpace = $free * self::DEFAULTMAXSIZE / 100 - ($versionsSize + $offset);
// how much space can be used for versions
} else {
$availableSpace = $free - $versionsSize - $offset;
}
} else {
$availableSpace = $quota - $offset;
}
// with the probability of 0.1% we reduce the number of all versions not only for the current file
$random = rand(0, 1000);
if ($random == 0) {
$allFiles = true;
} else {
$allFiles = false;
}
$allVersions = Storage::getVersions($uid, $filename);
$versionsByFile[$filename] = $allVersions;
$sizeOfDeletedVersions = self::delOldVersions($versionsByFile, $allVersions, $versionsFileview);
$availableSpace = $availableSpace + $sizeOfDeletedVersions;
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
// if still not enough free space we rearrange the versions from all files
if ($availableSpace <= 0 || $allFiles) {
$result = Storage::getAllVersions($uid);
$versionsByFile = $result['by_file'];
$allVersions = $result['all'];
$sizeOfDeletedVersions = self::delOldVersions($versionsByFile, $allVersions, $versionsFileview);
$availableSpace = $availableSpace + $sizeOfDeletedVersions;
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
}
// Check if enough space is available after versions are rearranged.
// If not we delete the oldest versions until we meet the size limit for versions,
// but always keep the two latest versions
$numOfVersions = count($allVersions) - 2;
$i = 0;
while ($availableSpace < 0 && $i < $numOfVersions) {
$version = current($allVersions);
$versionsFileview->unlink($version['path'] . '.v' . $version['version']);
$versionsSize -= $version['size'];
$availableSpace += $version['size'];
next($allVersions);
$i++;
}
return $versionsSize;
// finally return the new size of the version history
}
return false;
}
示例4: update_quota
private static function update_quota($uid, $quota)
{
if (!empty($quota)) {
\OCP\Config::setUserValue($uid, 'files', 'quota', \OCP\Util::computerFileSize($quota));
}
}
示例5: calculateFreeSpace
/**
* calculate remaining free space for trash bin
*
* @param integer $trashbinSize current size of the trash bin
* @param string $user
* @return int available free space for trash bin
*/
private static function calculateFreeSpace($trashbinSize, $user)
{
$softQuota = true;
$quota = \OC_Preferences::getValue($user, 'files', 'quota');
$view = new \OC\Files\View('/' . $user);
if ($quota === null || $quota === 'default') {
$quota = \OC::$server->getAppConfig()->getValue('files', 'default_quota');
}
if ($quota === null || $quota === 'none') {
$quota = \OC\Files\Filesystem::free_space('/');
$softQuota = false;
} else {
$quota = \OCP\Util::computerFileSize($quota);
}
// calculate available space for trash bin
// subtract size of files and current trash bin size from quota
if ($softQuota) {
$rootInfo = $view->getFileInfo('/files/', false);
$free = $quota - $rootInfo['size'];
// remaining free space for user
if ($free > 0) {
$availableSpace = $free * self::DEFAULTMAXSIZE / 100 - $trashbinSize;
// how much space can be used for versions
} else {
$availableSpace = $free - $trashbinSize;
}
} else {
$availableSpace = $quota;
}
return $availableSpace;
}
示例6: expire
/**
* Expire versions which exceed the quota
*
* @param string $filename
* @return bool|int|null
*/
public static function expire($filename)
{
$config = \OC::$server->getConfig();
$expiration = self::getExpiration();
if ($config->getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true' && $expiration->isEnabled()) {
if (!Filesystem::file_exists($filename)) {
return false;
}
list($uid, $filename) = self::getUidAndFilename($filename);
if (empty($filename)) {
// file maybe renamed or deleted
return false;
}
$versionsFileview = new View('/' . $uid . '/files_versions');
// get available disk space for user
$user = \OC::$server->getUserManager()->get($uid);
$softQuota = true;
$quota = $user->getQuota();
if ($quota === null || $quota === 'none') {
$quota = Filesystem::free_space('/');
$softQuota = false;
} else {
$quota = \OCP\Util::computerFileSize($quota);
}
// make sure that we have the current size of the version history
$versionsSize = self::getVersionsSize($uid);
// calculate available space for version history
// subtract size of files and current versions size from quota
if ($quota >= 0) {
if ($softQuota) {
$files_view = new View('/' . $uid . '/files');
$rootInfo = $files_view->getFileInfo('/', false);
$free = $quota - $rootInfo['size'];
// remaining free space for user
if ($free > 0) {
$availableSpace = $free * self::DEFAULTMAXSIZE / 100 - $versionsSize;
// how much space can be used for versions
} else {
$availableSpace = $free - $versionsSize;
}
} else {
$availableSpace = $quota;
}
} else {
$availableSpace = PHP_INT_MAX;
}
$allVersions = Storage::getVersions($uid, $filename);
$time = time();
list($toDelete, $sizeOfDeletedVersions) = self::getExpireList($time, $allVersions, $availableSpace <= 0);
$availableSpace = $availableSpace + $sizeOfDeletedVersions;
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
// if still not enough free space we rearrange the versions from all files
if ($availableSpace <= 0) {
$result = Storage::getAllVersions($uid);
$allVersions = $result['all'];
foreach ($result['by_file'] as $versions) {
list($toDeleteNew, $size) = self::getExpireList($time, $versions, $availableSpace <= 0);
$toDelete = array_merge($toDelete, $toDeleteNew);
$sizeOfDeletedVersions += $size;
}
$availableSpace = $availableSpace + $sizeOfDeletedVersions;
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
}
foreach ($toDelete as $key => $path) {
\OC_Hook::emit('\\OCP\\Versions', 'preDelete', array('path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
self::deleteVersion($versionsFileview, $path);
\OC_Hook::emit('\\OCP\\Versions', 'delete', array('path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
unset($allVersions[$key]);
// update array with the versions we keep
\OCP\Util::writeLog('files_versions', "Expire: " . $path, \OCP\Util::DEBUG);
}
// Check if enough space is available after versions are rearranged.
// If not we delete the oldest versions until we meet the size limit for versions,
// but always keep the two latest versions
$numOfVersions = count($allVersions) - 2;
$i = 0;
// sort oldest first and make sure that we start at the first element
ksort($allVersions);
reset($allVersions);
while ($availableSpace < 0 && $i < $numOfVersions) {
$version = current($allVersions);
\OC_Hook::emit('\\OCP\\Versions', 'preDelete', array('path' => $version['path'] . '.v' . $version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
self::deleteVersion($versionsFileview, $version['path'] . '.v' . $version['version']);
\OC_Hook::emit('\\OCP\\Versions', 'delete', array('path' => $version['path'] . '.v' . $version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED));
\OCP\Util::writeLog('files_versions', 'running out of space! Delete oldest version: ' . $version['path'] . '.v' . $version['version'], \OCP\Util::DEBUG);
$versionsSize -= $version['size'];
$availableSpace += $version['size'];
next($allVersions);
$i++;
}
return $versionsSize;
// finally return the new size of the version history
}
return false;
//.........这里部分代码省略.........
示例7: calculateFreeSpace
/**
* calculate remaining free space for trash bin
*
* @param integer $trashbinSize current size of the trash bin
* @param string $user
* @return int available free space for trash bin
*/
private static function calculateFreeSpace($trashbinSize, $user)
{
$softQuota = true;
$userObject = \OC::$server->getUserManager()->get($user);
if (is_null($userObject)) {
return 0;
}
$quota = $userObject->getQuota();
if ($quota === null || $quota === 'none') {
$quota = Filesystem::free_space('/');
$softQuota = false;
// inf or unknown free space
if ($quota < 0) {
$quota = PHP_INT_MAX;
}
} else {
$quota = \OCP\Util::computerFileSize($quota);
}
// calculate available space for trash bin
// subtract size of files and current trash bin size from quota
if ($softQuota) {
$userFolder = \OC::$server->getUserFolder($user);
if (is_null($userFolder)) {
return 0;
}
$free = $quota - $userFolder->getSize();
// remaining free space for user
if ($free > 0) {
$availableSpace = $free * self::DEFAULTMAXSIZE / 100 - $trashbinSize;
// how much space can be used for versions
} else {
$availableSpace = $free - $trashbinSize;
}
} else {
$availableSpace = $quota;
}
return $availableSpace;
}
示例8: expire
/**
* Erase a file's versions which exceed the set quota
*/
private static function expire($filename, $versionsSize = null, $offset = 0)
{
if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
list($uid, $filename) = self::getUidAndFilename($filename);
$versionsFileview = new \OC\Files\View('/' . $uid . '/files_versions');
// get available disk space for user
$softQuota = true;
$quota = \OC_Preferences::getValue($uid, 'files', 'quota');
if ($quota === null || $quota === 'default') {
$quota = \OC::$server->getAppConfig()->getValue('files', 'default_quota');
}
if ($quota === null || $quota === 'none') {
$quota = \OC\Files\Filesystem::free_space('/');
$softQuota = false;
} else {
$quota = \OCP\Util::computerFileSize($quota);
}
// make sure that we have the current size of the version history
if ($versionsSize === null) {
$versionsSize = self::getVersionsSize($uid);
}
// calculate available space for version history
// subtract size of files and current versions size from quota
if ($softQuota) {
$files_view = new \OC\Files\View('/' . $uid . '/files');
$rootInfo = $files_view->getFileInfo('/', false);
$free = $quota - $rootInfo['size'];
// remaining free space for user
if ($free > 0) {
$availableSpace = $free * self::DEFAULTMAXSIZE / 100 - ($versionsSize + $offset);
// how much space can be used for versions
} else {
$availableSpace = $free - $versionsSize - $offset;
}
} else {
$availableSpace = $quota - $offset;
}
$allVersions = Storage::getVersions($uid, $filename);
$time = time();
list($toDelete, $sizeOfDeletedVersions) = self::getExpireList($time, $allVersions);
$availableSpace = $availableSpace + $sizeOfDeletedVersions;
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
// if still not enough free space we rearrange the versions from all files
if ($availableSpace <= 0) {
$result = Storage::getAllVersions($uid);
$allVersions = $result['all'];
foreach ($result['by_file'] as $versions) {
list($toDeleteNew, $size) = self::getExpireList($time, $versions);
$toDelete = array_merge($toDelete, $toDeleteNew);
$sizeOfDeletedVersions += $size;
}
$availableSpace = $availableSpace + $sizeOfDeletedVersions;
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
}
foreach ($toDelete as $key => $path) {
\OC_Hook::emit('\\OCP\\Versions', 'preDelete', array('path' => $path));
self::deleteVersion($versionsFileview, $path);
\OC_Hook::emit('\\OCP\\Versions', 'delete', array('path' => $path));
unset($allVersions[$key]);
// update array with the versions we keep
\OCP\Util::writeLog('files_versions', "Expire: " . $path, \OCP\Util::DEBUG);
}
// Check if enough space is available after versions are rearranged.
// If not we delete the oldest versions until we meet the size limit for versions,
// but always keep the two latest versions
$numOfVersions = count($allVersions) - 2;
$i = 0;
while ($availableSpace < 0 && $i < $numOfVersions) {
$version = current($allVersions);
\OC_Hook::emit('\\OCP\\Versions', 'preDelete', array('path' => $version['path'] . '.v' . $version['version']));
self::deleteVersion($versionsFileview, $version['path'] . '.v' . $version['version']);
\OC_Hook::emit('\\OCP\\Versions', 'delete', array('path' => $version['path'] . '.v' . $version['version']));
\OCP\Util::writeLog('files_versions', 'running out of space! Delete oldest version: ' . $version['path'] . '.v' . $version['version'], \OCP\Util::DEBUG);
$versionsSize -= $version['size'];
$availableSpace += $version['size'];
next($allVersions);
$i++;
}
return $versionsSize;
// finally return the new size of the version history
}
return false;
}
示例9: editUser
/**
* edit users
*
* @param array $parameters
* @return OC_OCS_Result
*/
public function editUser($parameters)
{
/** @var string $targetUserId */
$targetUserId = $parameters['userid'];
// Check if user is logged in
$currentLoggedInUser = $this->userSession->getUser();
if ($currentLoggedInUser === null) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
}
$targetUser = $this->userManager->get($targetUserId);
if ($targetUser === null) {
return new OC_OCS_Result(null, 997);
}
if ($targetUserId === $currentLoggedInUser->getUID()) {
// Editing self (display, email)
$permittedFields[] = 'display';
$permittedFields[] = 'email';
$permittedFields[] = 'password';
// If admin they can edit their own quota
if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
$permittedFields[] = 'quota';
}
} else {
// Check if admin / subadmin
$subAdminManager = $this->groupManager->getSubAdmin();
if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
// They have permissions over the user
$permittedFields[] = 'display';
$permittedFields[] = 'quota';
$permittedFields[] = 'password';
$permittedFields[] = 'email';
} else {
// No rights
return new OC_OCS_Result(null, 997);
}
}
// Check if permitted to edit this field
if (!in_array($parameters['_put']['key'], $permittedFields)) {
return new OC_OCS_Result(null, 997);
}
// Process the edit
switch ($parameters['_put']['key']) {
case 'display':
$targetUser->setDisplayName($parameters['_put']['value']);
break;
case 'quota':
$quota = $parameters['_put']['value'];
if ($quota !== 'none' and $quota !== 'default') {
if (is_numeric($quota)) {
$quota = floatval($quota);
} else {
$quota = \OCP\Util::computerFileSize($quota);
}
if ($quota === false) {
return new OC_OCS_Result(null, 103, "Invalid quota value {$parameters['_put']['value']}");
}
if ($quota === 0) {
$quota = 'default';
} else {
if ($quota === -1) {
$quota = 'none';
} else {
$quota = \OCP\Util::humanFileSize($quota);
}
}
}
$this->config->setUserValue($targetUserId, 'files', 'quota', $quota);
break;
case 'password':
$targetUser->setPassword($parameters['_put']['value']);
break;
case 'email':
if (filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) {
$this->config->setUserValue($targetUserId, 'settings', 'email', $parameters['_put']['value']);
} else {
return new OC_OCS_Result(null, 102);
}
break;
default:
return new OC_OCS_Result(null, 103);
break;
}
return new OC_OCS_Result(null, 100);
}
示例10: generateHashes
/**
* Returns an array of ['filename' => 'SHA512-hash-of-file'] for all files found
* in the iterator.
*
* @param \RecursiveIteratorIterator $iterator
* @param string $path
* @return array Array of hashes.
*/
private function generateHashes(\RecursiveIteratorIterator $iterator, $path)
{
$hashes = [];
$copiedWebserverSettingFiles = false;
$tmpFolder = '';
$baseDirectoryLength = strlen($path);
foreach ($iterator as $filename => $data) {
/** @var \DirectoryIterator $data */
if ($data->isDir()) {
continue;
}
$relativeFileName = substr($filename, $baseDirectoryLength);
$relativeFileName = ltrim($relativeFileName, '/');
// Exclude signature.json files in the appinfo and root folder
if ($relativeFileName === 'appinfo/signature.json') {
continue;
}
// Exclude signature.json files in the appinfo and core folder
if ($relativeFileName === 'core/signature.json') {
continue;
}
// The .user.ini and the .htaccess file of ownCloud can contain some
// custom modifications such as for example the maximum upload size
// to ensure that this will not lead to false positives this will
// copy the file to a temporary folder and reset it to the default
// values.
if ($filename === $this->environmentHelper->getServerRoot() . '/.htaccess' || $filename === $this->environmentHelper->getServerRoot() . '/.user.ini') {
if (!$copiedWebserverSettingFiles) {
$tmpFolder = rtrim($this->tempManager->getTemporaryFolder(), '/');
copy($this->environmentHelper->getServerRoot() . '/.htaccess', $tmpFolder . '/.htaccess');
copy($this->environmentHelper->getServerRoot() . '/.user.ini', $tmpFolder . '/.user.ini');
\OC_Files::setUploadLimit(\OCP\Util::computerFileSize('513MB'), ['.htaccess' => $tmpFolder . '/.htaccess', '.user.ini' => $tmpFolder . '/.user.ini']);
}
}
// The .user.ini file can contain custom modifications to the file size
// as well.
if ($filename === $this->environmentHelper->getServerRoot() . '/.user.ini') {
$fileContent = file_get_contents($tmpFolder . '/.user.ini');
$hashes[$relativeFileName] = hash('sha512', $fileContent);
continue;
}
// The .htaccess file in the root folder of ownCloud can contain
// custom content after the installation due to the fact that dynamic
// content is written into it at installation time as well. This
// includes for example the 404 and 403 instructions.
// Thus we ignore everything below the first occurrence of
// "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####" and have the
// hash generated based on this.
if ($filename === $this->environmentHelper->getServerRoot() . '/.htaccess') {
$fileContent = file_get_contents($tmpFolder . '/.htaccess');
$explodedArray = explode('#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####', $fileContent);
if (count($explodedArray) === 2) {
$hashes[$relativeFileName] = hash('sha512', $explodedArray[0]);
continue;
}
}
$hashes[$relativeFileName] = hash_file('sha512', $filename);
}
return $hashes;
}
示例11: calculateFreeSpace
/**
* calculate remaining free space for trash bin
*
* @param integer $trashbinSize current size of the trash bin
* @param string $user
* @return int available free space for trash bin
*/
private static function calculateFreeSpace($trashbinSize, $user)
{
$config = \OC::$server->getConfig();
$softQuota = true;
$quota = \OC::$server->getUserManager()->get($user)->getQuota();
$view = new \OC\Files\View('/' . $user);
if ($quota === null || $quota === 'none') {
$quota = \OC\Files\Filesystem::free_space('/');
$softQuota = false;
// inf or unknown free space
if ($quota < 0) {
$quota = PHP_INT_MAX;
}
} else {
$quota = \OCP\Util::computerFileSize($quota);
}
// calculate available space for trash bin
// subtract size of files and current trash bin size from quota
if ($softQuota) {
$rootInfo = $view->getFileInfo('/files/', false);
$free = $quota - $rootInfo['size'];
// remaining free space for user
if ($free > 0) {
$availableSpace = $free * self::DEFAULTMAXSIZE / 100 - $trashbinSize;
// how much space can be used for versions
} else {
$availableSpace = $free - $trashbinSize;
}
} else {
$availableSpace = $quota;
}
return $availableSpace;
}
示例12: updateQuota
/**
* @brief update a user's quota
* @param uid the login name of an external Shibboleth user
*/
private static function updateQuota($uid)
{
$quota = \OCP\Config::getAppValue('user_shibboleth', 'external_user_quota', '');
if ($quota !== '') {
\OCP\Config::setUserValue($uid, 'files', 'quota', \OCP\Util::computerFileSize($quota));
}
}