Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 4 additions & 101 deletions lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCP\IBinaryFinder;
use OCP\ICacheFactory;
use OCP\IUser;
use OCP\Server;
use OCP\Util;
use Psr\Log\LoggerInterface;

Expand All @@ -35,32 +36,6 @@ class OC_Helper {
private static ?ICacheFactory $cacheFactory = null;
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
* @deprecated 4.0.0 replaced with \OCP\Util::humanFileSize
*
* Makes 2048 to 2 kB.
*/
public static function humanFileSize(int|float $bytes): string {
return \OCP\Util::humanFileSize($bytes);
}

/**
* Make a computer file size
* @param string $str file size in human readable format
* @return false|int|float a file size in bytes
* @deprecated 4.0.0 Use \OCP\Util::computerFileSize
*
* 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 {
return \OCP\Util::computerFileSize($str);
}

/**
* Recursive copying of folders
* @param string $src source folder
Expand Down Expand Up @@ -91,17 +66,6 @@ public static function copyr($src, $dest) {
}
}

/**
* 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
* @deprecated 5.0.0 use \OCP\Files::rmdirr instead
*/
public static function rmdirr($dir, $deleteSelf = true) {
return \OCP\Files::rmdirr($dir, $deleteSelf);
}

/**
* @deprecated 18.0.0
* @return \OC\Files\Type\TemplateManager
Expand Down Expand Up @@ -245,82 +209,21 @@ public static function buildNotExistingFileNameForView($path, $filename, \OC\Fil
return $newpath;
}

/**
* 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
*
* @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
* @deprecated 4.5.0 use \OCP\Util::mb_array_change_key_case instead
*/
public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
return \OCP\Util::mb_array_change_key_case($input, $case, $encoding);
}

/**
* Performs a search in a nested array.
* Taken from https://www.php.net/manual/en/function.array-search.php#97645
*
* @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
* @deprecated 4.5.0 - use \OCP\Util::recursiveArraySearch
*/
public static function recursiveArraySearch($haystack, $needle, $index = null) {
return \OCP\Util::recursiveArraySearch($haystack, $needle, $index);
}

/**
* 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
* @deprecated 5.0.0 - use \OCP\Util::maxUploadFilesize
*/
public static function maxUploadFilesize($dir, $freeSpace = null) {
return \OCP\Util::maxUploadFilesize($dir, $freeSpace);
}

/**
* 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
* @deprecated 7.0.0 - use \OCP\Util::freeSpace
*/
public static function freeSpace($dir) {
return \OCP\Util::freeSpace($dir);
}

/**
* Calculate PHP upload limit
*
* @return int|float PHP upload file size limit
* @deprecated 7.0.0 - use \OCP\Util::uploadLimit
*/
public static function uploadLimit() {
return \OCP\Util::uploadLimit();
}

/**
* 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
*/
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;
}

Expand All @@ -340,7 +243,7 @@ public static function findBinaryPath(string $program): ?string {
*/
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');

Expand Down
4 changes: 2 additions & 2 deletions lib/public/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class Template extends \OC_Template implements ITemplate {
/**
* Make OC_Helper::imagePath available as a simple function
* Make \OCP\IURLGenerator::imagePath available as a simple function
*
* @see \OCP\IURLGenerator::imagePath
*
Expand All @@ -39,7 +39,7 @@ public static function image_path($app, $image) {


/**
* Make OC_Helper::mimetypeIcon available as a simple function
* Make IMimeTypeDetector->mimeTypeIcon available as a simple function
*
* @param string $mimetype
* @return string to the image of this file type.
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Files/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
use OC\User\NoUserException;
use OCP\Files;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
Expand Down Expand Up @@ -74,7 +75,7 @@ protected function setUp(): void {

protected function tearDown(): void {
foreach ($this->tmpDirs as $dir) {
\OC_Helper::rmdirr($dir);
Files::rmdirr($dir);
}

$this->logout();
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Files/Storage/CommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files;
use OCP\Files\IFilenameValidator;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidPathException;
Expand Down Expand Up @@ -37,7 +38,7 @@ protected function setUp(): void {
}

protected function tearDown(): void {
\OC_Helper::rmdirr($this->tmpDir);
Files::rmdirr($this->tmpDir);
$this->restoreService(IFilenameValidator::class);
parent::tearDown();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Files/Storage/HomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Test\Files\Storage;

use OC\User\User;
use OCP\Files;

class DummyUser extends User {
private $home;
Expand Down Expand Up @@ -62,7 +63,7 @@ protected function setUp(): void {
}

protected function tearDown(): void {
\OC_Helper::rmdirr($this->tmpDir);
Files::rmdirr($this->tmpDir);
parent::tearDown();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Files/Storage/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Test\Files\Storage;

use OC\Files\Storage\Wrapper\Jail;
use OCP\Files;

/**
* Class LocalTest
Expand All @@ -30,7 +31,7 @@ protected function setUp(): void {
}

protected function tearDown(): void {
\OC_Helper::rmdirr($this->tmpDir);
Files::rmdirr($this->tmpDir);
parent::tearDown();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Files/Storage/Wrapper/QuotaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//ensure the constants are loaded
use OC\Files\Cache\CacheEntry;
use OC\Files\Storage\Local;
use OCP\Files;

\OC::$loader->load('\OC\Files\Filesystem');

Expand All @@ -35,7 +36,7 @@ protected function setUp(): void {
}

protected function tearDown(): void {
\OC_Helper::rmdirr($this->tmpDir);
Files::rmdirr($this->tmpDir);
parent::tearDown();
}

Expand Down
4 changes: 3 additions & 1 deletion tests/lib/Files/Storage/Wrapper/WrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Test\Files\Storage\Wrapper;

use OCP\Files;

class WrapperTest extends \Test\Files\Storage\Storage {
/**
* @var string tmpDir
Expand All @@ -22,7 +24,7 @@ protected function setUp(): void {
}

protected function tearDown(): void {
\OC_Helper::rmdirr($this->tmpDir);
Files::rmdirr($this->tmpDir);
parent::tearDown();
}

Expand Down
42 changes: 42 additions & 0 deletions tests/lib/FilesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace Test;

use OCP\Files;
use OCP\ITempManager;
use OCP\Server;

class FilesTest extends TestCase {

/**
* Tests recursive folder deletion with rmdirr()
*/
public function testRecursiveFolderDeletion(): void {
$baseDir = Server::get(ITempManager::class)->getTemporaryFolder() . '/';
mkdir($baseDir . 'a/b/c/d/e', 0777, true);
mkdir($baseDir . 'a/b/c1/d/e', 0777, true);
mkdir($baseDir . 'a/b/c2/d/e', 0777, true);
mkdir($baseDir . 'a/b1/c1/d/e', 0777, true);
mkdir($baseDir . 'a/b2/c1/d/e', 0777, true);
mkdir($baseDir . 'a/b3/c1/d/e', 0777, true);
mkdir($baseDir . 'a1/b', 0777, true);
mkdir($baseDir . 'a1/c', 0777, true);
file_put_contents($baseDir . 'a/test.txt', 'Hello file!');
file_put_contents($baseDir . 'a/b1/c1/test one.txt', 'Hello file one!');
file_put_contents($baseDir . 'a1/b/test two.txt', 'Hello file two!');
Files::rmdirr($baseDir . 'a');

$this->assertFalse(file_exists($baseDir . 'a'));
$this->assertTrue(file_exists($baseDir . 'a1'));

Files::rmdirr($baseDir);
$this->assertFalse(file_exists($baseDir));
}
}
1 change: 1 addition & 0 deletions tests/lib/HelperStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function testGetStorageInfo(): void {
$this->assertEquals(5, $storageInfo['used']);
$this->assertEquals(17, $storageInfo['total']);
}

private function getIncludeExternalStorage(): bool {
$class = new \ReflectionClass(\OC_Helper::class);
$prop = $class->getProperty('quotaIncludeExternalStorage');
Expand Down
Loading
Loading