use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\Job;
-use OCP\ILogger;
/**
* Class RetryJob
use OCP\HintException;
use OCP\Http\Client\IClientService;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUserSession;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use Psr\Log\LoggerInterface;
/**
* Class MountPublicLinkController
* @package OCA\FederatedFileSharing\Controller
*/
class MountPublicLinkController extends Controller {
-
- /** @var FederatedShareProvider */
- private $federatedShareProvider;
-
- /** @var AddressHandler */
- private $addressHandler;
-
- /** @var IManager */
- private $shareManager;
-
- /** @var ISession */
- private $session;
-
- /** @var IL10N */
- private $l;
-
- /** @var IUserSession */
- private $userSession;
-
- /** @var IClientService */
- private $clientService;
-
- /** @var ICloudIdManager */
- private $cloudIdManager;
-
/**
* MountPublicLinkController constructor.
- *
- * @param string $appName
- * @param IRequest $request
- * @param FederatedShareProvider $federatedShareProvider
- * @param IManager $shareManager
- * @param AddressHandler $addressHandler
- * @param ISession $session
- * @param IL10N $l
- * @param IUserSession $userSession
- * @param IClientService $clientService
- * @param ICloudIdManager $cloudIdManager
*/
- public function __construct($appName,
- IRequest $request,
- FederatedShareProvider $federatedShareProvider,
- IManager $shareManager,
- AddressHandler $addressHandler,
- ISession $session,
- IL10N $l,
- IUserSession $userSession,
- IClientService $clientService,
- ICloudIdManager $cloudIdManager
+ public function __construct(
+ string $appName,
+ IRequest $request,
+ private FederatedShareProvider $federatedShareProvider,
+ private IManager $shareManager,
+ private AddressHandler $addressHandler,
+ private ISession $session,
+ private IL10N $l,
+ private IUserSession $userSession,
+ private IClientService $clientService,
+ private ICloudIdManager $cloudIdManager,
+ private LoggerInterface $logger,
) {
parent::__construct($appName, $request);
-
- $this->federatedShareProvider = $federatedShareProvider;
- $this->shareManager = $shareManager;
- $this->addressHandler = $addressHandler;
- $this->session = $session;
- $this->l = $l;
- $this->userSession = $userSession;
- $this->clientService = $clientService;
- $this->cloudIdManager = $cloudIdManager;
}
/**
try {
$this->federatedShareProvider->create($share);
} catch (\Exception $e) {
- \OC::$server->getLogger()->logException($e, [
- 'level' => ILogger::WARN,
+ $this->logger->warning($e->getMessage(), [
'app' => 'federatedfilesharing',
+ 'exception' => $e,
]);
return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
}
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IUserManager;
use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
+use Psr\Log\LoggerInterface;
/**
* Class FederatedShareProvider
class FederatedShareProvider implements IShareProvider {
public const SHARE_TYPE_REMOTE = 6;
- /** @var IDBConnection */
- private $dbConnection;
-
- /** @var AddressHandler */
- private $addressHandler;
-
- /** @var Notifications */
- private $notifications;
-
- /** @var TokenHandler */
- private $tokenHandler;
-
- /** @var IL10N */
- private $l;
-
- /** @var ILogger */
- private $logger;
-
- /** @var IRootFolder */
- private $rootFolder;
-
- /** @var IConfig */
- private $config;
-
/** @var string */
private $externalShareTable = 'share_external';
- /** @var IUserManager */
- private $userManager;
-
- /** @var ICloudIdManager */
- private $cloudIdManager;
-
- /** @var \OCP\GlobalScale\IConfig */
- private $gsConfig;
-
- /** @var ICloudFederationProviderManager */
- private $cloudFederationProviderManager;
-
/** @var array list of supported share types */
private $supportedShareType = [IShare::TYPE_REMOTE_GROUP, IShare::TYPE_REMOTE, IShare::TYPE_CIRCLE];
/**
* DefaultShareProvider constructor.
- *
- * @param IDBConnection $connection
- * @param AddressHandler $addressHandler
- * @param Notifications $notifications
- * @param TokenHandler $tokenHandler
- * @param IL10N $l10n
- * @param ILogger $logger
- * @param IRootFolder $rootFolder
- * @param IConfig $config
- * @param IUserManager $userManager
- * @param ICloudIdManager $cloudIdManager
- * @param \OCP\GlobalScale\IConfig $globalScaleConfig
- * @param ICloudFederationProviderManager $cloudFederationProviderManager
*/
public function __construct(
- IDBConnection $connection,
- AddressHandler $addressHandler,
- Notifications $notifications,
- TokenHandler $tokenHandler,
- IL10N $l10n,
- ILogger $logger,
- IRootFolder $rootFolder,
- IConfig $config,
- IUserManager $userManager,
- ICloudIdManager $cloudIdManager,
- \OCP\GlobalScale\IConfig $globalScaleConfig,
- ICloudFederationProviderManager $cloudFederationProviderManager
+ private IDBConnection $dbConnection,
+ private AddressHandler $addressHandler,
+ private Notifications $notifications,
+ private TokenHandler $tokenHandler,
+ private IL10N $l,
+ private IRootFolder $rootFolder,
+ private IConfig $config,
+ private IUserManager $userManager,
+ private ICloudIdManager $cloudIdManager,
+ private \OCP\GlobalScale\IConfig $gsConfig,
+ private ICloudFederationProviderManager $cloudFederationProviderManager,
+ private LoggerInterface $logger,
) {
- $this->dbConnection = $connection;
- $this->addressHandler = $addressHandler;
- $this->notifications = $notifications;
- $this->tokenHandler = $tokenHandler;
- $this->l = $l10n;
- $this->logger = $logger;
- $this->rootFolder = $rootFolder;
- $this->config = $config;
- $this->userManager = $userManager;
- $this->cloudIdManager = $cloudIdManager;
- $this->gsConfig = $globalScaleConfig;
- $this->cloudFederationProviderManager = $cloudFederationProviderManager;
}
/**
$failure = true;
}
} catch (\Exception $e) {
- $this->logger->logException($e, [
- 'message' => 'Failed to notify remote server of federated share, removing share.',
- 'level' => ILogger::ERROR,
+ $this->logger->error('Failed to notify remote server of federated share, removing share.', [
'app' => 'federatedfilesharing',
+ 'exception' => $e,
]);
$failure = true;
}
* @throws ShareNotFound
*/
private function getRawShare($id) {
-
// Now fetch the inserted share and create a complete share object
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('*')
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Http\Client\IClientService;
-use OCP\ILogger;
use OCP\OCS\IDiscoveryService;
+use Psr\Log\LoggerInterface;
class Notifications {
public const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
- /** @var AddressHandler */
- private $addressHandler;
-
- /** @var IClientService */
- private $httpClientService;
-
- /** @var IDiscoveryService */
- private $discoveryService;
-
- /** @var IJobList */
- private $jobList;
-
- /** @var ICloudFederationProviderManager */
- private $federationProviderManager;
-
- /** @var ICloudFederationFactory */
- private $cloudFederationFactory;
-
- /** @var IEventDispatcher */
- private $eventDispatcher;
-
- /** @var ILogger */
- private $logger;
-
public function __construct(
- AddressHandler $addressHandler,
- IClientService $httpClientService,
- IDiscoveryService $discoveryService,
- ILogger $logger,
- IJobList $jobList,
- ICloudFederationProviderManager $federationProviderManager,
- ICloudFederationFactory $cloudFederationFactory,
- IEventDispatcher $eventDispatcher
+ private AddressHandler $addressHandler,
+ private IClientService $httpClientService,
+ private IDiscoveryService $discoveryService,
+ private IJobList $jobList,
+ private ICloudFederationProviderManager $federationProviderManager,
+ private ICloudFederationFactory $cloudFederationFactory,
+ private IEventDispatcher $eventDispatcher,
+ private LoggerInterface $logger,
) {
- $this->addressHandler = $addressHandler;
- $this->httpClientService = $httpClientService;
- $this->discoveryService = $discoveryService;
- $this->jobList = $jobList;
- $this->logger = $logger;
- $this->federationProviderManager = $federationProviderManager;
- $this->cloudFederationFactory = $cloudFederationFactory;
- $this->eventDispatcher = $eventDispatcher;
}
/**
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
-use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Share\IManager;
use OCP\Share\IShare;
use OCP\Util;
-use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;
class CloudFederationProviderFiles implements ICloudFederationProvider {
-
- /** @var IAppManager */
- private $appManager;
-
- /** @var FederatedShareProvider */
- private $federatedShareProvider;
-
- /** @var AddressHandler */
- private $addressHandler;
-
- /** @var ILogger */
- private $logger;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var IManager */
- private $shareManager;
-
- /** @var ICloudIdManager */
- private $cloudIdManager;
-
- /** @var IActivityManager */
- private $activityManager;
-
- /** @var INotificationManager */
- private $notificationManager;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /** @var ICloudFederationFactory */
- private $cloudFederationFactory;
-
- /** @var ICloudFederationProviderManager */
- private $cloudFederationProviderManager;
-
- /** @var IDBConnection */
- private $connection;
-
- /** @var IGroupManager */
- private $groupManager;
-
- /** @var IConfig */
- private $config;
-
- /** @var Manager */
- private $externalShareManager;
-
/**
* CloudFederationProvider constructor.
- *
- * @param IAppManager $appManager
- * @param FederatedShareProvider $federatedShareProvider
- * @param AddressHandler $addressHandler
- * @param ILogger $logger
- * @param IUserManager $userManager
- * @param IManager $shareManager
- * @param ICloudIdManager $cloudIdManager
- * @param IActivityManager $activityManager
- * @param INotificationManager $notificationManager
- * @param IURLGenerator $urlGenerator
- * @param ICloudFederationFactory $cloudFederationFactory
- * @param ICloudFederationProviderManager $cloudFederationProviderManager
- * @param IDBConnection $connection
- * @param IGroupManager $groupManager
- * @param IConfig $config
- * @param Manager $externalShareManager
*/
public function __construct(
- IAppManager $appManager,
- FederatedShareProvider $federatedShareProvider,
- AddressHandler $addressHandler,
- ILogger $logger,
- IUserManager $userManager,
- IManager $shareManager,
- ICloudIdManager $cloudIdManager,
- IActivityManager $activityManager,
- INotificationManager $notificationManager,
- IURLGenerator $urlGenerator,
- ICloudFederationFactory $cloudFederationFactory,
- ICloudFederationProviderManager $cloudFederationProviderManager,
- IDBConnection $connection,
- IGroupManager $groupManager,
- IConfig $config,
- Manager $externalShareManager
+ private IAppManager $appManager,
+ private FederatedShareProvider $federatedShareProvider,
+ private AddressHandler $addressHandler,
+ private IUserManager $userManager,
+ private IManager $shareManager,
+ private ICloudIdManager $cloudIdManager,
+ private IActivityManager $activityManager,
+ private INotificationManager $notificationManager,
+ private IURLGenerator $urlGenerator,
+ private ICloudFederationFactory $cloudFederationFactory,
+ private ICloudFederationProviderManager $cloudFederationProviderManager,
+ private IDBConnection $connection,
+ private IGroupManager $groupManager,
+ private IConfig $config,
+ private Manager $externalShareManager,
+ private LoggerInterface $logger,
) {
- $this->appManager = $appManager;
- $this->federatedShareProvider = $federatedShareProvider;
- $this->addressHandler = $addressHandler;
- $this->logger = $logger;
- $this->userManager = $userManager;
- $this->shareManager = $shareManager;
- $this->cloudIdManager = $cloudIdManager;
- $this->activityManager = $activityManager;
- $this->notificationManager = $notificationManager;
- $this->urlGenerator = $urlGenerator;
- $this->cloudFederationFactory = $cloudFederationFactory;
- $this->cloudFederationProviderManager = $cloudFederationProviderManager;
- $this->connection = $connection;
- $this->groupManager = $groupManager;
- $this->config = $config;
- $this->externalShareManager = $externalShareManager;
}
-
-
/**
* @return string
*/
$this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);
if (!$this->userManager->userExists($shareWith)) {
- throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST);
+ throw new ProviderCouldNotAddShareException('User does not exists', '', Http::STATUS_BAD_REQUEST);
}
\OC_Util::setupFS($shareWith);
}
if ($shareType === IShare::TYPE_GROUP && !$this->groupManager->groupExists($shareWith)) {
- throw new ProviderCouldNotAddShareException('Group does not exists', '',Http::STATUS_BAD_REQUEST);
+ throw new ProviderCouldNotAddShareException('Group does not exists', '', Http::STATUS_BAD_REQUEST);
}
try {
- $this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId);
+ $this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType, false, $shareWith, $remoteId);
$shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');
// get DisplayName about the owner of the share
}
return $shareId;
} catch (\Exception $e) {
- $this->logger->logException($e, [
- 'message' => 'Server can not add remote share.',
- 'level' => ILogger::ERROR,
- 'app' => 'files_sharing'
+ $this->logger->error('Server can not add remote share.', [
+ 'app' => 'files_sharing',
+ 'exception' => $e,
]);
throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR);
}
use OCP\IUserSession;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use Psr\Log\LoggerInterface;
+use PHPUnit\Framework\MockObject\MockObject;
class MountPublicLinkControllerTest extends \Test\TestCase {
- /** @var IContactsManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IContactsManager|MockObject */
protected $contactsManager;
- /** @var MountPublicLinkController */
+ /** @var MountPublicLinkController */
private $controller;
- /** @var \OCP\IRequest | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IRequest|MockObject */
private $request;
- /** @var FederatedShareProvider | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var FederatedShareProvider|MockObject */
private $federatedShareProvider;
- /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IManager|MockObject */
private $shareManager;
- /** @var AddressHandler | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var AddressHandler|MockObject */
private $addressHandler;
- /** @var IRootFolder | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IRootFolder|MockObject */
private $rootFolder;
- /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserManager|MockObject */
private $userManager;
- /** @var ISession | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var ISession|MockObject */
private $session;
- /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IL10N|MockObject */
private $l10n;
- /** @var IUserSession | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserSession|MockObject */
private $userSession;
- /** @var IClientService | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IClientService|MockObject */
private $clientService;
- /** @var IShare */
+ /** @var IShare */
private $share;
- /** @var ICloudIdManager */
+ /** @var ICloudIdManager */
private $cloudIdManager;
protected function setUp(): void {
$this->l10n,
$this->userSession,
$this->clientService,
- $this->cloudIdManager
+ $this->cloudIdManager,
+ $this->createMock(LoggerInterface::class),
);
}
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Share\IManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
/**
* Class FederatedShareProviderTest
* @group DB
*/
class FederatedShareProviderTest extends \Test\TestCase {
-
/** @var IDBConnection */
protected $connection;
- /** @var AddressHandler | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var AddressHandler|MockObject */
protected $addressHandler;
- /** @var Notifications | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var Notifications|MockObject */
protected $notifications;
- /** @var TokenHandler|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var TokenHandler|MockObject */
protected $tokenHandler;
/** @var IL10N */
protected $l;
- /** @var ILogger */
+ /** @var LoggerInterface */
protected $logger;
- /** @var IRootFolder | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IRootFolder|MockObject */
protected $rootFolder;
- /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
protected $config;
- /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserManager|MockObject */
protected $userManager;
- /** @var \OCP\GlobalScale\IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var \OCP\GlobalScale\IConfig|MockObject */
protected $gsConfig;
/** @var IManager */
protected $shareManager;
/** @var FederatedShareProvider */
protected $provider;
- /** @var IContactsManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IContactsManager|MockObject */
protected $contactsManager;
/** @var ICloudIdManager */
private $cloudIdManager;
- /** @var \PHPUnit\Framework\MockObject\MockObject|ICloudFederationProviderManager */
+ /** @var MockObject|ICloudFederationProviderManager */
private $cloudFederationProviderManager;
protected function setUp(): void {
->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
});
- $this->logger = $this->getMockBuilder(ILogger::class)->getMock();
+ $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
$this->notifications,
$this->tokenHandler,
$this->l,
- $this->logger,
$this->rootFolder,
$this->config,
$this->userManager,
$this->cloudIdManager,
$this->gsConfig,
- $this->cloudFederationProviderManager
+ $this->cloudFederationProviderManager,
+ $this->logger,
);
$this->shareManager = \OC::$server->getShareManager();
$this->notifications,
$this->tokenHandler,
$this->l,
- $this->logger,
$this->rootFolder,
$this->config,
$this->userManager,
$this->cloudIdManager,
$this->gsConfig,
- $this->cloudFederationProviderManager
+ $this->cloudFederationProviderManager,
+ $this->logger,
]
)->setMethods(['sendPermissionUpdate'])->getMock();
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Http\Client\IClientService;
-use OCP\ILogger;
use OCP\OCS\IDiscoveryService;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
class NotificationsTest extends \Test\TestCase {
-
- /** @var AddressHandler | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var AddressHandler|MockObject */
private $addressHandler;
- /** @var IClientService | \PHPUnit\Framework\MockObject\MockObject*/
+ /** @var IClientService|MockObject*/
private $httpClientService;
- /** @var IDiscoveryService | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IDiscoveryService|MockObject */
private $discoveryService;
- /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IJobList|MockObject */
private $jobList;
- /** @var ICloudFederationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ICloudFederationProviderManager|MockObject */
private $cloudFederationProviderManager;
- /** @var ICloudFederationFactory|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ICloudFederationFactory|MockObject */
private $cloudFederationFactory;
- /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IEventDispatcher|MockObject */
private $eventDispatcher;
- /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var LoggerInterface|MockObject */
private $logger;
protected function setUp(): void {
$this->httpClientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->getMock();
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')
->disableOriginalConstructor()->getMock();
- $this->logger = $this->createMock(ILogger::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->addressHandler,
$this->httpClientService,
$this->discoveryService,
- $this->logger,
$this->jobList,
$this->cloudFederationProviderManager,
$this->cloudFederationFactory,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->logger,
);
} else {
$instance = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications')
$this->addressHandler,
$this->httpClientService,
$this->discoveryService,
- $this->logger,
$this->jobList,
$this->cloudFederationProviderManager,
$this->cloudFederationFactory,
- $this->eventDispatcher
+ $this->eventDispatcher,
+ $this->logger,
]
)->setMethods($mockedMethods)->getMock();
}
$addressHandler,
$this->serverContainer->getHTTPClientService(),
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),
- $this->serverContainer->getLogger(),
$this->serverContainer->getJobList(),
\OC::$server->getCloudFederationProviderManager(),
\OC::$server->getCloudFederationFactory(),
- $this->serverContainer->query(IEventDispatcher::class)
+ $this->serverContainer->query(IEventDispatcher::class),
+ $this->serverContainer->get(LoggerInterface::class),
);
$tokenHandler = new TokenHandler(
$this->serverContainer->getSecureRandom()
$notifications,
$tokenHandler,
$l,
- $this->serverContainer->getLogger(),
$this->serverContainer->getLazyRootFolder(),
$this->serverContainer->getConfig(),
$this->serverContainer->getUserManager(),
$this->serverContainer->getCloudIdManager(),
$this->serverContainer->getGlobalScaleConfig(),
- $this->serverContainer->getCloudFederationProviderManager()
+ $this->serverContainer->getCloudFederationProviderManager(),
+ $this->serverContainer->get(LoggerInterface::class),
);
}