2017-01-24 09:47:14 +03:00
|
|
|
<?php
|
2021-03-04 14:29:49 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
2017-01-24 09:47:14 +03:00
|
|
|
/**
|
|
|
|
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-01-24 09:47:14 +03: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
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-01-24 09:47:14 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Contacts\ContactsMenu;
|
|
|
|
|
2017-04-03 19:04:14 +03:00
|
|
|
use Exception;
|
|
|
|
use OC\App\AppManager;
|
2017-01-24 09:47:14 +03:00
|
|
|
use OC\Contacts\ContactsMenu\Providers\EMailProvider;
|
|
|
|
use OCP\AppFramework\QueryException;
|
|
|
|
use OCP\Contacts\ContactsMenu\IProvider;
|
|
|
|
use OCP\IServerContainer;
|
2017-04-03 19:04:14 +03:00
|
|
|
use OCP\IUser;
|
2021-03-04 14:29:49 +03:00
|
|
|
use Psr\Log\LoggerInterface;
|
2017-01-24 09:47:14 +03:00
|
|
|
|
|
|
|
class ActionProviderStore {
|
|
|
|
|
|
|
|
/** @var IServerContainer */
|
|
|
|
private $serverContainer;
|
|
|
|
|
2017-04-03 19:04:14 +03:00
|
|
|
/** @var AppManager */
|
|
|
|
private $appManager;
|
|
|
|
|
2021-03-04 14:29:49 +03:00
|
|
|
/** @var LoggerInterface */
|
2017-01-24 09:47:14 +03:00
|
|
|
private $logger;
|
|
|
|
|
2021-03-04 14:29:49 +03:00
|
|
|
public function __construct(IServerContainer $serverContainer, AppManager $appManager, LoggerInterface $logger) {
|
2017-01-24 09:47:14 +03:00
|
|
|
$this->serverContainer = $serverContainer;
|
2017-04-03 19:04:14 +03:00
|
|
|
$this->appManager = $appManager;
|
2017-01-24 09:47:14 +03:00
|
|
|
$this->logger = $logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-03 19:04:14 +03:00
|
|
|
* @param IUser $user
|
2017-01-24 09:47:14 +03:00
|
|
|
* @return IProvider[]
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-04 14:29:49 +03:00
|
|
|
public function getProviders(IUser $user): array {
|
2017-04-03 19:04:14 +03:00
|
|
|
$appClasses = $this->getAppProviderClasses($user);
|
2017-01-24 09:47:14 +03:00
|
|
|
$providerClasses = $this->getServerProviderClasses();
|
2017-04-03 19:04:14 +03:00
|
|
|
$allClasses = array_merge($providerClasses, $appClasses);
|
2017-01-24 09:47:14 +03:00
|
|
|
$providers = [];
|
|
|
|
|
2017-04-03 19:04:14 +03:00
|
|
|
foreach ($allClasses as $class) {
|
2017-01-24 09:47:14 +03:00
|
|
|
try {
|
|
|
|
$providers[] = $this->serverContainer->query($class);
|
|
|
|
} catch (QueryException $ex) {
|
2021-03-04 14:29:49 +03:00
|
|
|
$this->logger->error('Could not load contacts menu action provider ' . $class,
|
|
|
|
[
|
|
|
|
'app' => 'core',
|
|
|
|
'exception' => $ex,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
throw new Exception('Could not load contacts menu action provider');
|
2017-01-24 09:47:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $providers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2021-03-04 14:29:49 +03:00
|
|
|
private function getServerProviderClasses(): array {
|
2017-01-24 09:47:14 +03:00
|
|
|
return [
|
|
|
|
EMailProvider::class,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-04-03 19:04:14 +03:00
|
|
|
/**
|
|
|
|
* @param IUser $user
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2021-03-04 14:29:49 +03:00
|
|
|
private function getAppProviderClasses(IUser $user): array {
|
2020-04-09 14:53:40 +03:00
|
|
|
return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) {
|
2017-04-03 19:04:14 +03:00
|
|
|
$info = $this->appManager->getAppInfo($appId);
|
|
|
|
|
2021-03-04 14:29:49 +03:00
|
|
|
if (!isset($info['contactsmenu'])) {
|
2017-04-03 19:04:14 +03:00
|
|
|
// Nothing to add
|
|
|
|
return $all;
|
|
|
|
}
|
|
|
|
|
2020-04-09 14:53:40 +03:00
|
|
|
$providers = array_reduce($info['contactsmenu'], function ($all, $provider) {
|
2017-04-03 19:04:14 +03:00
|
|
|
return array_merge($all, [$provider]);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return array_merge($all, $providers);
|
|
|
|
}, []);
|
|
|
|
}
|
2017-01-24 09:47:14 +03:00
|
|
|
}
|