From 644036ab4e3d1d6f175a485ed7ae4883c668ff48 Mon Sep 17 00:00:00 2001
From: Côme Chilliet <come.chilliet@nextcloud.com>
Date: Wed, 6 Mar 2024 11:54:58 +0100
Subject: fix: Migrate away from OC_App toward the IAppManager
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
---
 core/Command/App/GetPath.php | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

(limited to 'core/Command/App/GetPath.php')

diff --git a/core/Command/App/GetPath.php b/core/Command/App/GetPath.php
index ea614070e7d..844e14ffdde 100644
--- a/core/Command/App/GetPath.php
+++ b/core/Command/App/GetPath.php
@@ -1,4 +1,7 @@
 <?php
+
+declare(strict_types=1);
+
 /**
  * @copyright Copyright (c) 2016, ownCloud, Inc.
  *
@@ -23,12 +26,20 @@
 namespace OC\Core\Command\App;
 
 use OC\Core\Command\Base;
+use OCP\App\AppPathNotFoundException;
+use OCP\App\IAppManager;
 use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class GetPath extends Base {
+	public function __construct(
+		protected IAppManager $appManager,
+	) {
+		parent::__construct();
+	}
+
 	protected function configure(): void {
 		parent::configure();
 
@@ -52,14 +63,14 @@ class GetPath extends Base {
 	 */
 	protected function execute(InputInterface $input, OutputInterface $output): int {
 		$appName = $input->getArgument('app');
-		$path = \OC_App::getAppPath($appName);
-		if ($path !== false) {
-			$output->writeln($path);
-			return 0;
+		try {
+			$path = $this->appManager->getAppPath($appName);
+		} catch (AppPathNotFoundException) {
+			// App not found, exit with non-zero
+			return self::FAILURE;
 		}
-
-		// App not found, exit with non-zero
-		return 1;
+		$output->writeln($path);
+		return self::SUCCESS;
 	}
 
 	/**
@@ -69,7 +80,7 @@ class GetPath extends Base {
 	 */
 	public function completeArgumentValues($argumentName, CompletionContext $context): array {
 		if ($argumentName === 'app') {
-			return \OC_App::getAllApps();
+			return $this->appManager->getInstalledApps();
 		}
 		return [];
 	}
-- 
cgit v1.2.3