Remove deprecated methods Util::writeLog and DIContainer::log

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2023-09-21 17:25:52 +02:00
parent 8a65cf44cb
commit f68d4f7300
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
8 changed files with 25 additions and 66 deletions

View File

@ -32,13 +32,14 @@
namespace OC\Core\Controller; namespace OC\Core\Controller;
use OC\Setup; use OC\Setup;
use OCP\ILogger; use Psr\Log\LoggerInterface;
class SetupController { class SetupController {
private string $autoConfigFile; private string $autoConfigFile;
public function __construct( public function __construct(
protected Setup $setupHelper, protected Setup $setupHelper,
protected LoggerInterface $logger,
) { ) {
$this->autoConfigFile = \OC::$configDir.'autoconfig.php'; $this->autoConfigFile = \OC::$configDir.'autoconfig.php';
} }
@ -78,7 +79,7 @@ class SetupController {
} }
} }
private function displaySetupForbidden() { private function displaySetupForbidden(): void {
\OC_Template::printGuestPage('', 'installation_forbidden'); \OC_Template::printGuestPage('', 'installation_forbidden');
} }
@ -98,7 +99,7 @@ class SetupController {
\OC_Template::printGuestPage('', 'installation', $parameters); \OC_Template::printGuestPage('', 'installation', $parameters);
} }
private function finishSetup() { private function finishSetup(): void {
if (file_exists($this->autoConfigFile)) { if (file_exists($this->autoConfigFile)) {
unlink($this->autoConfigFile); unlink($this->autoConfigFile);
} }
@ -114,7 +115,7 @@ class SetupController {
public function loadAutoConfig(array $post): array { public function loadAutoConfig(array $post): array {
if (file_exists($this->autoConfigFile)) { if (file_exists($this->autoConfigFile)) {
\OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO); $this->logger->info('Autoconfig file found, setting up Nextcloud…');
$AUTOCONFIG = []; $AUTOCONFIG = [];
include $this->autoConfigFile; include $this->autoConfigFile;
$post = array_merge($post, $AUTOCONFIG); $post = array_merge($post, $AUTOCONFIG);

View File

@ -37,8 +37,8 @@ declare(strict_types=1);
namespace OC; namespace OC;
use \OCP\AutoloadNotAllowedException; use \OCP\AutoloadNotAllowedException;
use OCP\ILogger;
use OCP\ICache; use OCP\ICache;
use Psr\Log\LoggerInterface;
class Autoloader { class Autoloader {
/** @var bool */ /** @var bool */
@ -105,7 +105,7 @@ class Autoloader {
* Remove "apps/" from inclusion path for smooth migration to multi app dir * Remove "apps/" from inclusion path for smooth migration to multi app dir
*/ */
if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) {
\OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', ILogger::DEBUG); \OCP\Server::get(LoggerInterface::class)->debug('include path for class "' . $class . '" starts with "apps/"', ['app' => 'core']);
$paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]);
} }
} elseif (strpos($class, 'OC_') === 0) { } elseif (strpos($class, 'OC_') === 0) {

View File

@ -988,16 +988,17 @@ class OC {
// Check if Nextcloud is installed or in maintenance (update) mode // Check if Nextcloud is installed or in maintenance (update) mode
if (!$systemConfig->getValue('installed', false)) { if (!$systemConfig->getValue('installed', false)) {
\OC::$server->getSession()->clear(); \OC::$server->getSession()->clear();
$logger = Server::get(\Psr\Log\LoggerInterface::class);
$setupHelper = new OC\Setup( $setupHelper = new OC\Setup(
$systemConfig, $systemConfig,
Server::get(\bantu\IniGetWrapper\IniGetWrapper::class), Server::get(\bantu\IniGetWrapper\IniGetWrapper::class),
Server::get(\OCP\L10N\IFactory::class)->get('lib'), Server::get(\OCP\L10N\IFactory::class)->get('lib'),
Server::get(\OCP\Defaults::class), Server::get(\OCP\Defaults::class),
Server::get(\Psr\Log\LoggerInterface::class), $logger,
Server::get(\OCP\Security\ISecureRandom::class), Server::get(\OCP\Security\ISecureRandom::class),
Server::get(\OC\Installer::class) Server::get(\OC\Installer::class)
); );
$controller = new OC\Core\Controller\SetupController($setupHelper); $controller = new OC\Core\Controller\SetupController($setupHelper, $logger);
$controller->run($_POST); $controller->run($_POST);
exit(); exit();
} }

View File

@ -403,33 +403,6 @@ class DIContainer extends SimpleContainer implements IAppContainer {
return $this->getServer()->getSession()->get('user_id'); return $this->getServer()->getSession()->get('user_id');
} }
/**
* @deprecated use the ILogger instead
* @param string $message
* @param string $level
* @return mixed
*/
public function log($message, $level) {
switch ($level) {
case 'debug':
$level = ILogger::DEBUG;
break;
case 'info':
$level = ILogger::INFO;
break;
case 'warn':
$level = ILogger::WARN;
break;
case 'fatal':
$level = ILogger::FATAL;
break;
default:
$level = ILogger::ERROR;
break;
}
\OCP\Util::writeLog($this->getAppName(), $message, $level);
}
/** /**
* Register a capability * Register a capability
* *

View File

@ -529,7 +529,7 @@ class Tags implements ITags {
if (is_string($tag) && !is_numeric($tag)) { if (is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag); $tag = trim($tag);
if ($tag === '') { if ($tag === '') {
\OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', ILogger::DEBUG); $this->logger->debug(__METHOD__.', Cannot add an empty tag');
return false; return false;
} }
if (!$this->hasTag($tag)) { if (!$this->hasTag($tag)) {
@ -569,7 +569,7 @@ class Tags implements ITags {
if (is_string($tag) && !is_numeric($tag)) { if (is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag); $tag = trim($tag);
if ($tag === '') { if ($tag === '') {
\OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', ILogger::DEBUG); $this->logger->debug(__METHOD__.', Tag name is empty');
return false; return false;
} }
$tagId = $this->getTagId($tag); $tagId = $this->getTagId($tag);
@ -609,8 +609,7 @@ class Tags implements ITags {
$names = array_map('trim', $names); $names = array_map('trim', $names);
array_filter($names); array_filter($names);
\OCP\Util::writeLog('core', __METHOD__ . ', before: ' $this->logger->debug(__METHOD__ . ', before: ' . print_r($this->tags, true));
. print_r($this->tags, true), ILogger::DEBUG);
foreach ($names as $name) { foreach ($names as $name) {
$id = null; $id = null;
@ -625,8 +624,7 @@ class Tags implements ITags {
unset($this->tags[$key]); unset($this->tags[$key]);
$this->mapper->delete($tag); $this->mapper->delete($tag);
} else { } else {
\OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name $this->logger->error(__METHOD__ . 'Cannot delete tag ' . $name . ': not found.');
. ': not found.', ILogger::ERROR);
} }
if (!is_null($id) && $id !== false) { if (!is_null($id) && $id !== false) {
try { try {

View File

@ -56,7 +56,6 @@ use OCP\App\IAppManager;
use OCP\App\ManagerEvent; use OCP\App\ManagerEvent;
use OCP\Authentication\IAlternativeLogin; use OCP\Authentication\IAlternativeLogin;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OC\AppFramework\Bootstrap\Coordinator; use OC\AppFramework\Bootstrap\Coordinator;
use OC\App\DependencyAnalyzer; use OC\App\DependencyAnalyzer;
use OC\App\Platform; use OC\App\Platform;
@ -292,7 +291,7 @@ class OC_App {
} }
} }
\OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR); \OCP\Server::get(LoggerInterface::class)->error('No application directories are marked as writable.', ['app' => 'core']);
return null; return null;
} }
@ -517,7 +516,7 @@ class OC_App {
foreach (OC::$APPSROOTS as $apps_dir) { foreach (OC::$APPSROOTS as $apps_dir) {
if (!is_readable($apps_dir['path'])) { if (!is_readable($apps_dir['path'])) {
\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN); \OCP\Server::get(LoggerInterface::class)->warning('unable to read app folder : ' . $apps_dir['path'], ['app' => 'core']);
continue; continue;
} }
$dh = opendir($apps_dir['path']); $dh = opendir($apps_dir['path']);
@ -568,12 +567,12 @@ class OC_App {
if (array_search($app, $blacklist) === false) { if (array_search($app, $blacklist) === false) {
$info = $appManager->getAppInfo($app, false, $langCode); $info = $appManager->getAppInfo($app, false, $langCode);
if (!is_array($info)) { if (!is_array($info)) {
\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR); \OCP\Server::get(LoggerInterface::class)->error('Could not read app info file for app "' . $app . '"', ['app' => 'core']);
continue; continue;
} }
if (!isset($info['name'])) { if (!isset($info['name'])) {
\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR); \OCP\Server::get(LoggerInterface::class)->error('App id "' . $app . '" has no name in appinfo', ['app' => 'core']);
continue; continue;
} }
@ -870,11 +869,11 @@ class OC_App {
} }
return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
} else { } else {
\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR); \OCP\Server::get(LoggerInterface::class)->error('Can\'t get app storage, app ' . $appId . ', user not logged in', ['app' => 'core']);
return false; return false;
} }
} else { } else {
\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR); \OCP\Server::get(LoggerInterface::class)->error('Can\'t get app storage, app ' . $appId . ' not enabled', ['app' => 'core']);
return false; return false;
} }
} }

View File

@ -38,10 +38,10 @@
use OC\User\LoginException; use OC\User\LoginException;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\User\Events\BeforeUserLoggedInEvent; use OCP\User\Events\BeforeUserLoggedInEvent;
use OCP\User\Events\UserLoggedInEvent; use OCP\User\Events\UserLoggedInEvent;
use Psr\Log\LoggerInterface;
/** /**
* This class provides wrapper methods for user management. Multiple backends are * This class provides wrapper methods for user management. Multiple backends are
@ -93,7 +93,7 @@ class OC_User {
case 'database': case 'database':
case 'mysql': case 'mysql':
case 'sqlite': case 'sqlite':
\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG); \OCP\Server::get(LoggerInterface::class)->debug('Adding user backend ' . $backend . '.', ['app' => 'core']);
self::$_usedBackends[$backend] = new \OC\User\Database(); self::$_usedBackends[$backend] = new \OC\User\Database();
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
break; break;
@ -102,7 +102,7 @@ class OC_User {
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
break; break;
default: default:
\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG); \OCP\Server::get(LoggerInterface::class)->debug('Adding default user backend ' . $backend . '.', ['app' => 'core']);
$className = 'OC_USER_' . strtoupper($backend); $className = 'OC_USER_' . strtoupper($backend);
self::$_usedBackends[$backend] = new $className(); self::$_usedBackends[$backend] = new $className();
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
@ -147,10 +147,10 @@ class OC_User {
self::useBackend($backend); self::useBackend($backend);
self::$_setupedBackends[] = $i; self::$_setupedBackends[] = $i;
} else { } else {
\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG); \OCP\Server::get(LoggerInterface::class)->debug('User backend ' . $class . ' already initialized.', ['app' => 'core']);
} }
} else { } else {
\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR); \OCP\Server::get(LoggerInterface::class)->error('User backend ' . $class . ' not found.', ['app' => 'core']);
} }
} }
} }

View File

@ -104,19 +104,6 @@ class Util {
return \OC_Util::getChannel(); return \OC_Util::getChannel();
} }
/**
* write a message in the log
* @param string $app
* @param string $message
* @param int $level
* @since 4.0.0
* @deprecated 13.0.0 use log of \OCP\ILogger
*/
public static function writeLog($app, $message, $level) {
$context = ['app' => $app];
\OC::$server->getLogger()->log($level, $message, $context);
}
/** /**
* check if sharing is disabled for the current user * check if sharing is disabled for the current user
* *