aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/legacy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/legacy')
-rw-r--r--lib/private/legacy/OC_App.php22
-rw-r--r--lib/private/legacy/OC_Helper.php247
-rw-r--r--lib/private/legacy/OC_Util.php5
3 files changed, 14 insertions, 260 deletions
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index ecceafa65b3..abac0d2635e 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -768,28 +768,6 @@ class OC_App {
}
}
- /**
- * @param string $appId
- * @return \OC\Files\View|false
- */
- public static function getStorage(string $appId) {
- if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
- if (\OC::$server->getUserSession()->isLoggedIn()) {
- $view = new \OC\Files\View('/' . OC_User::getUser());
- if (!$view->file_exists($appId)) {
- $view->mkdir($appId);
- }
- return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
- } else {
- \OCP\Server::get(LoggerInterface::class)->error('Can\'t get app storage, app ' . $appId . ', user not logged in', ['app' => 'core']);
- return false;
- }
- } else {
- \OCP\Server::get(LoggerInterface::class)->error('Can\'t get app storage, app ' . $appId . ' not enabled', ['app' => 'core']);
- return false;
- }
- }
-
protected static function findBestL10NOption(array $options, string $lang): string {
// only a single option
if (isset($options['@value'])) {
diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php
index a89cbe1bb3a..87c820dcd53 100644
--- a/lib/private/legacy/OC_Helper.php
+++ b/lib/private/legacy/OC_Helper.php
@@ -12,6 +12,7 @@ use OCP\Files\Mount\IMountPoint;
use OCP\IBinaryFinder;
use OCP\ICacheFactory;
use OCP\IUser;
+use OCP\Server;
use OCP\Util;
use Psr\Log\LoggerInterface;
@@ -36,85 +37,11 @@ class OC_Helper {
private static ?bool $quotaIncludeExternalStorage = null;
/**
- * Make a human file size
- * @param int|float $bytes file size in bytes
- * @return string a human readable file size
- *
- * Makes 2048 to 2 kB.
- */
- public static function humanFileSize(int|float $bytes): string {
- if ($bytes < 0) {
- return '?';
- }
- if ($bytes < 1024) {
- return "$bytes B";
- }
- $bytes = round($bytes / 1024, 0);
- if ($bytes < 1024) {
- return "$bytes KB";
- }
- $bytes = round($bytes / 1024, 1);
- if ($bytes < 1024) {
- return "$bytes MB";
- }
- $bytes = round($bytes / 1024, 1);
- if ($bytes < 1024) {
- return "$bytes GB";
- }
- $bytes = round($bytes / 1024, 1);
- if ($bytes < 1024) {
- return "$bytes TB";
- }
-
- $bytes = round($bytes / 1024, 1);
- return "$bytes PB";
- }
-
- /**
- * Make a computer file size
- * @param string $str file size in human readable format
- * @return false|int|float a file size in bytes
- *
- * Makes 2kB to 2048.
- *
- * Inspired by: https://www.php.net/manual/en/function.filesize.php#92418
- */
- public static function computerFileSize(string $str): false|int|float {
- $str = strtolower($str);
- if (is_numeric($str)) {
- return Util::numericToNumber($str);
- }
-
- $bytes_array = [
- 'b' => 1,
- 'k' => 1024,
- 'kb' => 1024,
- 'mb' => 1024 * 1024,
- 'm' => 1024 * 1024,
- 'gb' => 1024 * 1024 * 1024,
- 'g' => 1024 * 1024 * 1024,
- 'tb' => 1024 * 1024 * 1024 * 1024,
- 't' => 1024 * 1024 * 1024 * 1024,
- 'pb' => 1024 * 1024 * 1024 * 1024 * 1024,
- 'p' => 1024 * 1024 * 1024 * 1024 * 1024,
- ];
-
- $bytes = (float)$str;
-
- if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && isset($bytes_array[$matches[1]])) {
- $bytes *= $bytes_array[$matches[1]];
- } else {
- return false;
- }
-
- return Util::numericToNumber(round($bytes));
- }
-
- /**
* Recursive copying of folders
* @param string $src source folder
* @param string $dest target folder
* @return void
+ * @deprecated 32.0.0 - use \OCP\Files\Folder::copy
*/
public static function copyr($src, $dest) {
if (!file_exists($src)) {
@@ -140,44 +67,6 @@ class OC_Helper {
}
/**
- * Recursive deletion of folders
- * @param string $dir path to the folder
- * @param bool $deleteSelf if set to false only the content of the folder will be deleted
- * @return bool
- */
- public static function rmdirr($dir, $deleteSelf = true) {
- if (is_dir($dir)) {
- $files = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
- RecursiveIteratorIterator::CHILD_FIRST
- );
-
- foreach ($files as $fileInfo) {
- /** @var SplFileInfo $fileInfo */
- if ($fileInfo->isLink()) {
- unlink($fileInfo->getPathname());
- } elseif ($fileInfo->isDir()) {
- rmdir($fileInfo->getRealPath());
- } else {
- unlink($fileInfo->getRealPath());
- }
- }
- if ($deleteSelf) {
- rmdir($dir);
- }
- } elseif (file_exists($dir)) {
- if ($deleteSelf) {
- unlink($dir);
- }
- }
- if (!$deleteSelf) {
- return true;
- }
-
- return !file_exists($dir);
- }
-
- /**
* @deprecated 18.0.0
* @return \OC\Files\Type\TemplateManager
*/
@@ -196,6 +85,7 @@ class OC_Helper {
* @internal param string $program name
* @internal param string $optional search path, defaults to $PATH
* @return bool true if executable program found in path
+ * @deprecated 32.0.0 use the \OCP\IBinaryFinder
*/
public static function canExecute($name, $path = false) {
// path defaults to PATH from environment if not set
@@ -206,7 +96,7 @@ class OC_Helper {
$exts = [''];
$check_fn = 'is_executable';
// Default check will be done with $path directories :
- $dirs = explode(PATH_SEPARATOR, $path);
+ $dirs = explode(PATH_SEPARATOR, (string)$path);
// WARNING : We have to check if open_basedir is enabled :
$obd = OC::$server->get(IniGetWrapper::class)->getString('open_basedir');
if ($obd != 'none') {
@@ -233,31 +123,10 @@ class OC_Helper {
* @param resource $source
* @param resource $target
* @return array the number of bytes copied and result
+ * @deprecated 5.0.0 - Use \OCP\Files::streamCopy
*/
public static function streamCopy($source, $target) {
- if (!$source or !$target) {
- return [0, false];
- }
- $bufSize = 8192;
- $result = true;
- $count = 0;
- while (!feof($source)) {
- $buf = fread($source, $bufSize);
- $bytesWritten = fwrite($target, $buf);
- if ($bytesWritten !== false) {
- $count += $bytesWritten;
- }
- // note: strlen is expensive so only use it when necessary,
- // on the last block
- if ($bytesWritten === false
- || ($bytesWritten < $bufSize && $bytesWritten < strlen($buf))
- ) {
- // write error, could be disk full ?
- $result = false;
- break;
- }
- }
- return [$count, $result];
+ return \OCP\Files::streamCopy($source, $target, true);
}
/**
@@ -320,115 +189,20 @@ class OC_Helper {
}
/**
- * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
- *
- * @param array $input The array to work on
- * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
- * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
- * @return array
- *
- * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
- * based on https://www.php.net/manual/en/function.array-change-key-case.php#107715
- *
- */
- public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
- $case = ($case != MB_CASE_UPPER) ? MB_CASE_LOWER : MB_CASE_UPPER;
- $ret = [];
- foreach ($input as $k => $v) {
- $ret[mb_convert_case($k, $case, $encoding)] = $v;
- }
- return $ret;
- }
-
- /**
- * performs a search in a nested array
- * @param array $haystack the array to be searched
- * @param string $needle the search string
- * @param mixed $index optional, only search this key name
- * @return mixed the key of the matching field, otherwise false
- *
- * performs a search in a nested array
- *
- * taken from https://www.php.net/manual/en/function.array-search.php#97645
- */
- public static function recursiveArraySearch($haystack, $needle, $index = null) {
- $aIt = new RecursiveArrayIterator($haystack);
- $it = new RecursiveIteratorIterator($aIt);
-
- while ($it->valid()) {
- if (((isset($index) and ($it->key() == $index)) or !isset($index)) and ($it->current() == $needle)) {
- return $aIt->key();
- }
-
- $it->next();
- }
-
- return false;
- }
-
- /**
- * calculates the maximum upload size respecting system settings, free space and user quota
- *
- * @param string $dir the current folder where the user currently operates
- * @param int|float $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
- * @return int|float number of bytes representing
- */
- public static function maxUploadFilesize($dir, $freeSpace = null) {
- if (is_null($freeSpace) || $freeSpace < 0) {
- $freeSpace = self::freeSpace($dir);
- }
- return min($freeSpace, self::uploadLimit());
- }
-
- /**
- * Calculate free space left within user quota
- *
- * @param string $dir the current folder where the user currently operates
- * @return int|float number of bytes representing
- */
- public static function freeSpace($dir) {
- $freeSpace = \OC\Files\Filesystem::free_space($dir);
- if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
- $freeSpace = max($freeSpace, 0);
- return $freeSpace;
- } else {
- return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
- }
- }
-
- /**
- * Calculate PHP upload limit
- *
- * @return int|float PHP upload file size limit
- */
- public static function uploadLimit() {
- $ini = \OC::$server->get(IniGetWrapper::class);
- $upload_max_filesize = Util::computerFileSize($ini->get('upload_max_filesize')) ?: 0;
- $post_max_size = Util::computerFileSize($ini->get('post_max_size')) ?: 0;
- if ($upload_max_filesize === 0 && $post_max_size === 0) {
- return INF;
- } elseif ($upload_max_filesize === 0 || $post_max_size === 0) {
- return max($upload_max_filesize, $post_max_size); //only the non 0 value counts
- } else {
- return min($upload_max_filesize, $post_max_size);
- }
- }
-
- /**
* Checks if a function is available
*
* @deprecated 25.0.0 use \OCP\Util::isFunctionEnabled instead
*/
public static function is_function_enabled(string $function_name): bool {
- return \OCP\Util::isFunctionEnabled($function_name);
+ return Util::isFunctionEnabled($function_name);
}
/**
* Try to find a program
- * @deprecated 25.0.0 Use \OC\BinaryFinder directly
+ * @deprecated 25.0.0 Use \OCP\IBinaryFinder directly
*/
public static function findBinaryPath(string $program): ?string {
- $result = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath($program);
+ $result = Server::get(IBinaryFinder::class)->findBinaryPath($program);
return $result !== false ? $result : null;
}
@@ -448,7 +222,7 @@ class OC_Helper {
*/
public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) {
if (!self::$cacheFactory) {
- self::$cacheFactory = \OC::$server->get(ICacheFactory::class);
+ self::$cacheFactory = Server::get(ICacheFactory::class);
}
$memcache = self::$cacheFactory->createLocal('storage_info');
@@ -641,6 +415,7 @@ class OC_Helper {
/**
* Returns whether the config file is set manually to read-only
* @return bool
+ * @deprecated 32.0.0 use the `config_is_read_only` system config directly
*/
public static function isReadOnlyConfigEnabled() {
return \OC::$server->getConfig()->getSystemValueBool('config_is_read_only', false);
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index 580fec7b5b3..9444da4f36d 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -98,6 +98,7 @@ class OC_Util {
*
* @param IUser|null $user
* @return int|\OCP\Files\FileInfo::SPACE_UNLIMITED|false|float Quota bytes
+ * @deprecated 9.0.0 - Use \OCP\IUser::getQuota
*/
public static function getUserQuota(?IUser $user) {
if (is_null($user)) {
@@ -107,7 +108,7 @@ class OC_Util {
if ($userQuota === 'none') {
return \OCP\Files\FileInfo::SPACE_UNLIMITED;
}
- return OC_Helper::computerFileSize($userQuota);
+ return \OCP\Util::computerFileSize($userQuota);
}
/**
@@ -331,7 +332,7 @@ class OC_Util {
}
// Check if config folder is writable.
- if (!OC_Helper::isReadOnlyConfigEnabled()) {
+ if (!(bool)$config->getValue('config_is_read_only', false)) {
if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
$errors[] = [
'error' => $l->t('Cannot write into "config" directory.'),