Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextcloud 31 compatibility and some code cleanup #1056

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
49 changes: 11 additions & 38 deletions lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,14 @@
use OCP\ICacheFactory;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
use OCA\Onlyoffice\AppInfo\Application;

/**
* Application configutarion
*
* @package OCA\Onlyoffice
*/
class AppConfig {

/**
* Application name
*
* @var string
*/
private $appName;

/**
* Config service
*
* @var IConfig
*/
private $config;

/**
* Logger
*
* @var LoggerInterface
*/
private $logger;

/**
* The config key for the demo server
*
Expand Down Expand Up @@ -361,22 +340,16 @@ class AppConfig {

/**
* The config key for store cache
*
* @var ICache
*/
private $cache;

/**
* @param string $AppName - application name
*/
public function __construct($AppName) {

$this->appName = $AppName;
private ICache $cache;

$this->config = \OC::$server->getConfig();
$this->logger = \OC::$server->get(LoggerInterface::class);
$cacheFactory = \OC::$server->get(ICacheFactory::class);
$this->cache = $cacheFactory->createLocal($this->appName);
public function __construct(
private string $appName,
private IConfig $config,
private LoggerInterface $logger,
ICacheFactory $cacheFactory,
) {
$this->cache = $cacheFactory->createLocal(Application::APP_ID);
}

/**
Expand Down Expand Up @@ -1195,7 +1168,7 @@ public function isUserAllowedToUse($userId = null) {
// group unknown -> error and allow nobody
$group = \OC::$server->getGroupManager()->get($groupName);
if ($group === null) {
\OC::$server->getLogger()->error("Group is unknown $groupName", ["app" => $this->appName]);
\OCP\Log\logger('onlyoffice')->error("Group is unknown $groupName", ["app" => $this->appName]);
$this->setLimitGroups(array_diff($groups, [$groupName]));
} else {
if ($group->inGroup($user)) {
Expand Down Expand Up @@ -1437,7 +1410,7 @@ private function buildOnlyofficeFormats() {
}
return $result;
} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "Format matrix error", "app" => $this->appName]);
$this->logger->error("Format matrix error", ['exception' => $e]);
return [];
}
}
Expand Down
150 changes: 4 additions & 146 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
use OCA\Onlyoffice\Listeners\DirectEditorListener;
use OCA\Onlyoffice\Listeners\ViewerListener;
use OCA\Onlyoffice\Listeners\WidgetListener;
use OCA\Onlyoffice\Crypt;
use OCA\Onlyoffice\DirectEditor;
use OCA\Onlyoffice\Hooks;
use OCA\Onlyoffice\Notifier;
Expand All @@ -76,28 +75,14 @@
use Psr\Log\LoggerInterface;

class Application extends App implements IBootstrap {
public const APP_ID = "onlyoffice";

/**
* Application configuration
*
* @var AppConfig
*/
public $appConfig;

/**
* Hash generator
*
* @var Crypt
*/
public $crypt;
private AppConfig $appConfig;

public function __construct(array $urlParams = []) {
$appName = "onlyoffice";

parent::__construct($appName, $urlParams);
parent::__construct(self::APP_ID, $urlParams);

$this->appConfig = new AppConfig($appName);
$this->crypt = new Crypt($this->appConfig);
$this->appConfig = \OCP\Server::get(AppConfig::class);
}

public function register(IRegistrationContext $context): void {
Expand Down Expand Up @@ -126,133 +111,6 @@ public function register(IRegistrationContext $context): void {
// Set the leeway for the JWT library in case the system clock is a second off
\Firebase\JWT\JWT::$leeway = $this->appConfig->getJwtLeeway();

$context->registerService("L10N", function (ContainerInterface $c) {
return $c->get("ServerContainer")->getL10N($c->get("AppName"));
});

$context->registerService("RootStorage", function (ContainerInterface $c) {
return $c->get("ServerContainer")->getRootFolder();
});

$context->registerService("UserSession", function (ContainerInterface $c) {
return $c->get("ServerContainer")->getUserSession();
});

$context->registerService("UserManager", function (ContainerInterface $c) {
return $c->get("ServerContainer")->getUserManager();
});

$context->registerService("URLGenerator", function (ContainerInterface $c) {
return $c->get("ServerContainer")->getURLGenerator();
});

$context->registerService("DirectEditor", function (ContainerInterface $c) {
return new DirectEditor(
$c->get("AppName"),
$c->get("URLGenerator"),
$c->get("L10N"),
$c->get(LoggerInterface::class),
$this->appConfig,
$this->crypt
);
});

$context->registerService("SettingsData", function (ContainerInterface $c) {
return new SettingsData($this->appConfig);
});

// Controllers
$context->registerService("SettingsController", function (ContainerInterface $c) {
return new SettingsController(
$c->get("AppName"),
$c->get("Request"),
$c->get("URLGenerator"),
$c->get("L10N"),
$c->get(LoggerInterface::class),
$this->appConfig,
$this->crypt,
$c->get(IMimeIconProvider::class)
);
});

$context->registerService("EditorController", function (ContainerInterface $c) {
return new EditorController(
$c->get("AppName"),
$c->get("Request"),
$c->get("RootStorage"),
$c->get("UserSession"),
$c->get("UserManager"),
$c->get("URLGenerator"),
$c->get("L10N"),
$c->get(LoggerInterface::class),
$this->appConfig,
$this->crypt,
$c->get("IManager"),
$c->get("Session"),
$c->get("GroupManager"),
$c->get(IMailer::class)
);
});

$context->registerService("SharingApiController", function (ContainerInterface $c) {
return new SharingApiController(
$c->get("AppName"),
$c->get("Request"),
$c->get("RootStorage"),
$c->get(LoggerInterface::class),
$c->get("UserSession"),
$c->get("UserManager"),
$c->get("IManager"),
$this->appConfig
);
});

$context->registerService("EditorApiController", function (ContainerInterface $c) {
return new EditorApiController(
$c->get("AppName"),
$c->get("Request"),
$c->get("RootStorage"),
$c->get("UserSession"),
$c->get("UserManager"),
$c->get("URLGenerator"),
$c->get("L10N"),
$c->get(LoggerInterface::class),
$this->appConfig,
$this->crypt,
$c->get("IManager"),
$c->get("Session"),
$c->get(ITagManager::class),
$c->get(ILockManager::class)
);
});

$context->registerService("CallbackController", function (ContainerInterface $c) {
return new CallbackController(
$c->get("AppName"),
$c->get("Request"),
$c->get("RootStorage"),
$c->get("UserSession"),
$c->get("UserManager"),
$c->get("L10N"),
$c->get(LoggerInterface::class),
$this->appConfig,
$this->crypt,
$c->get("IManager"),
$c->get(ILockManager::class)
);
});

$context->registerService("TemplateController", function (ContainerInterface $c) {
return new TemplateController(
$c->get("AppName"),
$c->get("Request"),
$c->get("L10N"),
$c->get(LoggerInterface::class),
$c->get(IPreview::class),
$c->get(IMimeIconProvider::class)
);
});

$context->registerEventListener(FileCreatedFromTemplateEvent::class, CreateFromTemplateListener::class);
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesListener::class);
$context->registerEventListener(RegisterDirectEditorEvent::class, DirectEditorListener::class);
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/JobListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct($AppName, IRequest $request, AppConfig $config, IJob
private function addJob($job) {
if (!$this->jobList->has($job, null)) {
$this->jobList->add($job);
\OC::$server->getLogger()->debug("Job '".$job."' added to JobList.", ["app" => $this->appName]);
\OCP\Log\logger('onlyoffice')->debug("Job '".$job."' added to JobList.", ["app" => $this->appName]);
}
}

Expand All @@ -91,7 +91,7 @@ private function addJob($job) {
private function removeJob($job) {
if ($this->jobList->has($job, null)) {
$this->jobList->remove($job);
\OC::$server->getLogger()->debug("Job '".$job."' removed from JobList.", ["app" => $this->appName]);
\OCP\Log\logger('onlyoffice')->debug("Job '".$job."' removed from JobList.", ["app" => $this->appName]);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Cron/EditorsCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public function __construct(
$this->appName = $AppName;
$this->urlGenerator = $urlGenerator;

$this->logger = \OC::$server->get(LoggerInterface::class);
$this->logger = \OCP\Server::get(LoggerInterface::class);
$this->config = $config;
$this->trans = $trans;
$this->crypt = $crypt;
$this->groupManager = $groupManager;
$this->setInterval($this->config->getEditorsCheckInterval());
$this->setTimeSensitivity(IJob::TIME_SENSITIVE);
$mailer = \OC::$server->get(IMailer::class);
$userManager = \OC::$server->get(IUserManager::class);
$mailer = \OCP\Server::get(IMailer::class);
$userManager = \OCP\Server::get(IUserManager::class);
$this->emailManager = new EmailManager($AppName, $trans, $logger, $mailer, $userManager, $urlGenerator);
}

Expand Down
12 changes: 6 additions & 6 deletions lib/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public function request($url, $method = "get", $opts = null) {
* @return array
*/
public function checkDocServiceUrl($urlGenerator, $crypt) {
$logger = \OC::$server->getLogger();
$logger = \OCP\Log\logger('onlyoffice');
$version = null;

try {
Expand All @@ -411,7 +411,7 @@ public function checkDocServiceUrl($urlGenerator, $crypt) {
throw new \Exception($this->trans->t("Mixed Active Content is not allowed. HTTPS address for ONLYOFFICE Docs is required."));
}
} catch (\Exception $e) {
$logger->logException($e, ["message" => "Protocol on check error", "app" => self::$appName]);
$logger->error("Protocol on check error", ['exception' => $e]);
return [$e->getMessage(), $version];
}

Expand All @@ -421,7 +421,7 @@ public function checkDocServiceUrl($urlGenerator, $crypt) {
throw new \Exception($this->trans->t("Bad healthcheck status"));
}
} catch (\Exception $e) {
$logger->logException($e, ["message" => "healthcheckRequest on check error", "app" => self::$appName]);
$logger->error("healthcheckRequest on check error", ['exception' => $e]);
return [$e->getMessage(), $version];
}

Expand All @@ -437,7 +437,7 @@ public function checkDocServiceUrl($urlGenerator, $crypt) {
throw new \Exception($this->trans->t("Not supported version"));
}
} catch (\Exception $e) {
$logger->logException($e, ["message" => "commandRequest on check error", "app" => self::$appName]);
$logger->error("commandRequest on check error", ['exception' => $e]);
return [$e->getMessage(), $version];
}

Expand All @@ -455,14 +455,14 @@ public function checkDocServiceUrl($urlGenerator, $crypt) {
$logger->debug("getConvertedUri skipped", ["app" => self::$appName]);
}
} catch (\Exception $e) {
$logger->logException($e, ["message" => "getConvertedUri on check error", "app" => self::$appName]);
$logger->error("getConvertedUri on check error", ['exception' => $e]);
return [$e->getMessage(), $version];
}

try {
$this->request($convertedFileUri);
} catch (\Exception $e) {
$logger->logException($e, ["message" => "Request converted file on check error", "app" => self::$appName]);
$logger->error("Request converted file on check error", ['exception' => $e]);
return [$e->getMessage(), $version];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/EmailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private function sendEmailNotification(IEMailTemplate $template, string $email,
return false;
}
} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "Send email", "app" => $this->appName]);
$this->logger->error("Send email", ['exception' => $e]);
return false;
}

Expand Down
Loading
Loading