2017-01-24 06:47:14 +00:00
|
|
|
<?php
|
2021-03-04 11:29:49 +00:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
2021-06-04 19:52:51 +00:00
|
|
|
|
2017-01-24 06:47:14 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
*
|
2019-12-03 18:57:53 +00:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2021-06-04 19:52:51 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-01-24 06:47:14 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2021-06-04 19:52:51 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-01-24 06:47:14 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 18:57:53 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-01-24 06:47:14 +00:00
|
|
|
*
|
|
|
|
*/
|
2021-10-14 08:19:40 +00:00
|
|
|
|
2017-01-24 06:47:14 +00:00
|
|
|
namespace OC\Contacts\ContactsMenu;
|
|
|
|
|
2017-04-03 16:04:14 +00:00
|
|
|
use Exception;
|
|
|
|
use OC\App\AppManager;
|
2017-01-24 06:47:14 +00:00
|
|
|
use OC\Contacts\ContactsMenu\Providers\EMailProvider;
|
2023-01-04 09:41:31 +00:00
|
|
|
use OC\Contacts\ContactsMenu\Providers\LocalTimeProvider;
|
2021-10-14 08:19:40 +00:00
|
|
|
use OC\Contacts\ContactsMenu\Providers\ProfileProvider;
|
2017-01-24 06:47:14 +00:00
|
|
|
use OCP\AppFramework\QueryException;
|
|
|
|
use OCP\Contacts\ContactsMenu\IProvider;
|
|
|
|
use OCP\IServerContainer;
|
2017-04-03 16:04:14 +00:00
|
|
|
use OCP\IUser;
|
2021-03-04 11:29:49 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2017-01-24 06:47:14 +00:00
|
|
|
|
|
|
|
class ActionProviderStore {
|
2022-03-22 11:39:23 +00:00
|
|
|
private IServerContainer $serverContainer;
|
|
|
|
private AppManager $appManager;
|
|
|
|
private LoggerInterface $logger;
|
2017-01-24 06:47:14 +00:00
|
|
|
|
2021-03-04 11:29:49 +00:00
|
|
|
public function __construct(IServerContainer $serverContainer, AppManager $appManager, LoggerInterface $logger) {
|
2017-01-24 06:47:14 +00:00
|
|
|
$this->serverContainer = $serverContainer;
|
2017-04-03 16:04:14 +00:00
|
|
|
$this->appManager = $appManager;
|
2017-01-24 06:47:14 +00:00
|
|
|
$this->logger = $logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-03 16:04:14 +00:00
|
|
|
* @param IUser $user
|
2017-01-24 06:47:14 +00:00
|
|
|
* @return IProvider[]
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-04 11:29:49 +00:00
|
|
|
public function getProviders(IUser $user): array {
|
2017-04-03 16:04:14 +00:00
|
|
|
$appClasses = $this->getAppProviderClasses($user);
|
2017-01-24 06:47:14 +00:00
|
|
|
$providerClasses = $this->getServerProviderClasses();
|
2017-04-03 16:04:14 +00:00
|
|
|
$allClasses = array_merge($providerClasses, $appClasses);
|
2017-01-24 06:47:14 +00:00
|
|
|
$providers = [];
|
|
|
|
|
2017-04-03 16:04:14 +00:00
|
|
|
foreach ($allClasses as $class) {
|
2017-01-24 06:47:14 +00:00
|
|
|
try {
|
2022-03-22 11:39:23 +00:00
|
|
|
$providers[] = $this->serverContainer->get($class);
|
2017-01-24 06:47:14 +00:00
|
|
|
} catch (QueryException $ex) {
|
2021-10-14 08:19:40 +00:00
|
|
|
$this->logger->error(
|
|
|
|
'Could not load contacts menu action provider ' . $class,
|
2021-03-04 11:29:49 +00:00
|
|
|
[
|
|
|
|
'app' => 'core',
|
|
|
|
'exception' => $ex,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
throw new Exception('Could not load contacts menu action provider');
|
2017-01-24 06:47:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $providers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2021-03-04 11:29:49 +00:00
|
|
|
private function getServerProviderClasses(): array {
|
2017-01-24 06:47:14 +00:00
|
|
|
return [
|
2021-10-14 08:19:40 +00:00
|
|
|
ProfileProvider::class,
|
2023-01-04 09:41:31 +00:00
|
|
|
LocalTimeProvider::class,
|
2017-01-24 06:47:14 +00:00
|
|
|
EMailProvider::class,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:04:14 +00:00
|
|
|
/**
|
|
|
|
* @param IUser $user
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2021-03-04 11:29:49 +00:00
|
|
|
private function getAppProviderClasses(IUser $user): array {
|
2020-04-09 11:53:40 +00:00
|
|
|
return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) {
|
2017-04-03 16:04:14 +00:00
|
|
|
$info = $this->appManager->getAppInfo($appId);
|
|
|
|
|
2021-03-04 11:29:49 +00:00
|
|
|
if (!isset($info['contactsmenu'])) {
|
2017-04-03 16:04:14 +00:00
|
|
|
// Nothing to add
|
|
|
|
return $all;
|
|
|
|
}
|
|
|
|
|
2020-04-09 11:53:40 +00:00
|
|
|
$providers = array_reduce($info['contactsmenu'], function ($all, $provider) {
|
2017-04-03 16:04:14 +00:00
|
|
|
return array_merge($all, [$provider]);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return array_merge($all, $providers);
|
|
|
|
}, []);
|
|
|
|
}
|
2017-01-24 06:47:14 +00:00
|
|
|
}
|