Merge pull request #9106 from nextcloud/feature/7488/run_federated_discoverjob_in_cron
Run federated discoverjob in cron
This commit is contained in:
commit
307a2a17c3
|
@ -9,7 +9,7 @@
|
||||||
Turning the feature off removes shared files and folders on the server for all share recipients, and also on the sync clients and mobile apps. More information is available in the Nextcloud Documentation.
|
Turning the feature off removes shared files and folders on the server for all share recipients, and also on the sync clients and mobile apps. More information is available in the Nextcloud Documentation.
|
||||||
|
|
||||||
</description>
|
</description>
|
||||||
<version>1.6.0</version>
|
<version>1.6.1</version>
|
||||||
<licence>agpl</licence>
|
<licence>agpl</licence>
|
||||||
<author>Michael Gapczynski</author>
|
<author>Michael Gapczynski</author>
|
||||||
<author>Bjoern Schiessle</author>
|
<author>Bjoern Schiessle</author>
|
||||||
|
@ -29,6 +29,7 @@ Turning the feature off removes shared files and folders on the server for all s
|
||||||
<background-jobs>
|
<background-jobs>
|
||||||
<job>OCA\Files_Sharing\DeleteOrphanedSharesJob</job>
|
<job>OCA\Files_Sharing\DeleteOrphanedSharesJob</job>
|
||||||
<job>OCA\Files_Sharing\ExpireSharesJob</job>
|
<job>OCA\Files_Sharing\ExpireSharesJob</job>
|
||||||
|
<job>OCA\Files_Sharing\BackgroundJob\FederatedSharesDiscoverJob</job>
|
||||||
</background-jobs>
|
</background-jobs>
|
||||||
|
|
||||||
<repair-steps>
|
<repair-steps>
|
||||||
|
|
|
@ -17,6 +17,7 @@ return array(
|
||||||
'OCA\\Files_Sharing\\Activity\\Settings\\RemoteShare' => $baseDir . '/../lib/Activity/Settings/RemoteShare.php',
|
'OCA\\Files_Sharing\\Activity\\Settings\\RemoteShare' => $baseDir . '/../lib/Activity/Settings/RemoteShare.php',
|
||||||
'OCA\\Files_Sharing\\Activity\\Settings\\Shared' => $baseDir . '/../lib/Activity/Settings/Shared.php',
|
'OCA\\Files_Sharing\\Activity\\Settings\\Shared' => $baseDir . '/../lib/Activity/Settings/Shared.php',
|
||||||
'OCA\\Files_Sharing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
|
'OCA\\Files_Sharing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
|
||||||
|
'OCA\\Files_Sharing\\BackgroundJob\\FederatedSharesDiscoverJob' => $baseDir . '/../lib/BackgroundJob/FederatedSharesDiscoverJob.php',
|
||||||
'OCA\\Files_Sharing\\Cache' => $baseDir . '/../lib/Cache.php',
|
'OCA\\Files_Sharing\\Cache' => $baseDir . '/../lib/Cache.php',
|
||||||
'OCA\\Files_Sharing\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
|
'OCA\\Files_Sharing\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
|
||||||
'OCA\\Files_Sharing\\Collaboration\\ShareRecipientSorter' => $baseDir . '/../lib/Collaboration/ShareRecipientSorter.php',
|
'OCA\\Files_Sharing\\Collaboration\\ShareRecipientSorter' => $baseDir . '/../lib/Collaboration/ShareRecipientSorter.php',
|
||||||
|
|
|
@ -32,6 +32,7 @@ class ComposerStaticInitFiles_Sharing
|
||||||
'OCA\\Files_Sharing\\Activity\\Settings\\RemoteShare' => __DIR__ . '/..' . '/../lib/Activity/Settings/RemoteShare.php',
|
'OCA\\Files_Sharing\\Activity\\Settings\\RemoteShare' => __DIR__ . '/..' . '/../lib/Activity/Settings/RemoteShare.php',
|
||||||
'OCA\\Files_Sharing\\Activity\\Settings\\Shared' => __DIR__ . '/..' . '/../lib/Activity/Settings/Shared.php',
|
'OCA\\Files_Sharing\\Activity\\Settings\\Shared' => __DIR__ . '/..' . '/../lib/Activity/Settings/Shared.php',
|
||||||
'OCA\\Files_Sharing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
|
'OCA\\Files_Sharing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
|
||||||
|
'OCA\\Files_Sharing\\BackgroundJob\\FederatedSharesDiscoverJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/FederatedSharesDiscoverJob.php',
|
||||||
'OCA\\Files_Sharing\\Cache' => __DIR__ . '/..' . '/../lib/Cache.php',
|
'OCA\\Files_Sharing\\Cache' => __DIR__ . '/..' . '/../lib/Cache.php',
|
||||||
'OCA\\Files_Sharing\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
|
'OCA\\Files_Sharing\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
|
||||||
'OCA\\Files_Sharing\\Collaboration\\ShareRecipientSorter' => __DIR__ . '/..' . '/../lib/Collaboration/ShareRecipientSorter.php',
|
'OCA\\Files_Sharing\\Collaboration\\ShareRecipientSorter' => __DIR__ . '/..' . '/../lib/Collaboration/ShareRecipientSorter.php',
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
|
*
|
||||||
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
namespace OCA\Files_Sharing\BackgroundJob;
|
||||||
|
|
||||||
|
use OC\BackgroundJob\TimedJob;
|
||||||
|
use OCP\IDBConnection;
|
||||||
|
use OCP\OCS\IDiscoveryService;
|
||||||
|
|
||||||
|
class FederatedSharesDiscoverJob extends TimedJob {
|
||||||
|
/** @var IDBConnection */
|
||||||
|
private $connection;
|
||||||
|
/** @var IDiscoveryService */
|
||||||
|
private $discoveryService;
|
||||||
|
|
||||||
|
public function __construct(IDBConnection $connection,
|
||||||
|
IDiscoveryService $discoveryService) {
|
||||||
|
$this->connection = $connection;
|
||||||
|
$this->discoveryService = $discoveryService;
|
||||||
|
|
||||||
|
$this->setInterval(86400);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run($argument) {
|
||||||
|
$qb = $this->connection->getQueryBuilder();
|
||||||
|
|
||||||
|
$qb->selectDistinct('remote')
|
||||||
|
->from('share_external');
|
||||||
|
|
||||||
|
$result = $qb->execute();
|
||||||
|
while($row = $result->fetch()) {
|
||||||
|
$this->discoveryService->discover($row['remote'], 'FEDERATED_SHARING', true);
|
||||||
|
}
|
||||||
|
$result->closeCursor();
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,10 +59,12 @@ class DiscoveryService implements IDiscoveryService {
|
||||||
*
|
*
|
||||||
* @param string $remote
|
* @param string $remote
|
||||||
* @param string $service the service you want to discover
|
* @param string $service the service you want to discover
|
||||||
|
* @param bool $skipCache We won't check if the data is in the cache. This is usefull if a background job is updating the status
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function discover(string $remote, string $service): array {
|
public function discover(string $remote, string $service, bool $skipCache = false): array {
|
||||||
// Check the cache first
|
// Check the cache first
|
||||||
|
if ($skipCache === false) {
|
||||||
$cacheData = $this->cache->get($remote . '#' . $service);
|
$cacheData = $this->cache->get($remote . '#' . $service);
|
||||||
if ($cacheData) {
|
if ($cacheData) {
|
||||||
$data = json_decode($cacheData, true);
|
$data = json_decode($cacheData, true);
|
||||||
|
@ -70,6 +72,7 @@ class DiscoveryService implements IDiscoveryService {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$discoveredServices = [];
|
$discoveredServices = [];
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,9 @@ interface IDiscoveryService {
|
||||||
*
|
*
|
||||||
* @param string $remote
|
* @param string $remote
|
||||||
* @param string $service the service you want to discover
|
* @param string $service the service you want to discover
|
||||||
|
* @param bool $skipCache We won't check if the data is in the cache. This is useful if a background job is updating the status - Added in 14.0.0
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function discover(string $remote, string $service): array;
|
public function discover(string $remote, string $service, bool $skipCache = false): array;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue