本文整理汇总了PHP中OCA\Files_Versions\Storage::getAllVersions方法的典型用法代码示例。如果您正苦于以下问题:PHP Storage::getAllVersions方法的具体用法?PHP Storage::getAllVersions怎么用?PHP Storage::getAllVersions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCA\Files_Versions\Storage
的用法示例。
在下文中一共展示了Storage::getAllVersions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
//.........这里部分代码省略.........