@@ -31,45 +31,45 @@ |
||
31 | 31 | * @package OCA\AdminAudit\Actions |
32 | 32 | */ |
33 | 33 | class Security extends Action { |
34 | - /** |
|
35 | - * Log twofactor auth enabled |
|
36 | - * |
|
37 | - * @param IUser $user |
|
38 | - * @param array $params |
|
39 | - */ |
|
40 | - public function twofactorFailed(IUser $user, array $params) { |
|
41 | - $params['uid'] = $user->getUID(); |
|
42 | - $params['displayName'] = $user->getDisplayName(); |
|
34 | + /** |
|
35 | + * Log twofactor auth enabled |
|
36 | + * |
|
37 | + * @param IUser $user |
|
38 | + * @param array $params |
|
39 | + */ |
|
40 | + public function twofactorFailed(IUser $user, array $params) { |
|
41 | + $params['uid'] = $user->getUID(); |
|
42 | + $params['displayName'] = $user->getDisplayName(); |
|
43 | 43 | |
44 | - $this->log( |
|
45 | - 'Failed two factor attempt by user %s (%s) with provider %s', |
|
46 | - $params, |
|
47 | - [ |
|
48 | - 'displayName', |
|
49 | - 'uid', |
|
50 | - 'provider', |
|
51 | - ] |
|
52 | - ); |
|
53 | - } |
|
44 | + $this->log( |
|
45 | + 'Failed two factor attempt by user %s (%s) with provider %s', |
|
46 | + $params, |
|
47 | + [ |
|
48 | + 'displayName', |
|
49 | + 'uid', |
|
50 | + 'provider', |
|
51 | + ] |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Logs unsharing of data |
|
57 | - * |
|
58 | - * @param IUser $user |
|
59 | - * @param array $params |
|
60 | - */ |
|
61 | - public function twofactorSuccess(IUser $user, array $params) { |
|
62 | - $params['uid'] = $user->getUID(); |
|
63 | - $params['displayName'] = $user->getDisplayName(); |
|
55 | + /** |
|
56 | + * Logs unsharing of data |
|
57 | + * |
|
58 | + * @param IUser $user |
|
59 | + * @param array $params |
|
60 | + */ |
|
61 | + public function twofactorSuccess(IUser $user, array $params) { |
|
62 | + $params['uid'] = $user->getUID(); |
|
63 | + $params['displayName'] = $user->getDisplayName(); |
|
64 | 64 | |
65 | - $this->log( |
|
66 | - 'Successful two factor attempt by user %s (%s) with provider %s', |
|
67 | - $params, |
|
68 | - [ |
|
69 | - 'displayName', |
|
70 | - 'uid', |
|
71 | - 'provider', |
|
72 | - ] |
|
73 | - ); |
|
74 | - } |
|
65 | + $this->log( |
|
66 | + 'Successful two factor attempt by user %s (%s) with provider %s', |
|
67 | + $params, |
|
68 | + [ |
|
69 | + 'displayName', |
|
70 | + 'uid', |
|
71 | + 'provider', |
|
72 | + ] |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | } |
@@ -36,47 +36,47 @@ |
||
36 | 36 | */ |
37 | 37 | class OwncloudGuestShareType implements IRepairStep { |
38 | 38 | |
39 | - /** @var IDBConnection */ |
|
40 | - private $connection; |
|
39 | + /** @var IDBConnection */ |
|
40 | + private $connection; |
|
41 | 41 | |
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | 44 | |
45 | 45 | |
46 | - public function __construct(IDBConnection $connection, IConfig $config) { |
|
47 | - $this->connection = $connection; |
|
48 | - $this->config = $config; |
|
49 | - } |
|
46 | + public function __construct(IDBConnection $connection, IConfig $config) { |
|
47 | + $this->connection = $connection; |
|
48 | + $this->config = $config; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the step's name |
|
53 | - * |
|
54 | - * @return string |
|
55 | - * @since 9.1.0 |
|
56 | - */ |
|
57 | - public function getName() { |
|
58 | - return 'Fix the share type of guest shares when migrating from ownCloud'; |
|
59 | - } |
|
51 | + /** |
|
52 | + * Returns the step's name |
|
53 | + * |
|
54 | + * @return string |
|
55 | + * @since 9.1.0 |
|
56 | + */ |
|
57 | + public function getName() { |
|
58 | + return 'Fix the share type of guest shares when migrating from ownCloud'; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param IOutput $output |
|
63 | - */ |
|
64 | - public function run(IOutput $output) { |
|
65 | - if (!$this->shouldRun()) { |
|
66 | - return; |
|
67 | - } |
|
61 | + /** |
|
62 | + * @param IOutput $output |
|
63 | + */ |
|
64 | + public function run(IOutput $output) { |
|
65 | + if (!$this->shouldRun()) { |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - $query = $this->connection->getQueryBuilder(); |
|
70 | - $query->update('share') |
|
71 | - ->set('share_type', $query->createNamedParameter(Share::SHARE_TYPE_GUEST)) |
|
72 | - ->where($query->expr()->eq('share_type', $query->createNamedParameter(Share::SHARE_TYPE_EMAIL))); |
|
73 | - $query->execute(); |
|
74 | - } |
|
69 | + $query = $this->connection->getQueryBuilder(); |
|
70 | + $query->update('share') |
|
71 | + ->set('share_type', $query->createNamedParameter(Share::SHARE_TYPE_GUEST)) |
|
72 | + ->where($query->expr()->eq('share_type', $query->createNamedParameter(Share::SHARE_TYPE_EMAIL))); |
|
73 | + $query->execute(); |
|
74 | + } |
|
75 | 75 | |
76 | - protected function shouldRun() { |
|
77 | - $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0'); |
|
78 | - return $appVersion === '0.10.0' || |
|
79 | - $this->config->getAppValue('core', 'vendor', '') === 'owncloud'; |
|
80 | - } |
|
76 | + protected function shouldRun() { |
|
77 | + $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0'); |
|
78 | + return $appVersion === '0.10.0' || |
|
79 | + $this->config->getAppValue('core', 'vendor', '') === 'owncloud'; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
@@ -30,33 +30,33 @@ |
||
30 | 30 | |
31 | 31 | class Base extends \OC\Core\Command\Base { |
32 | 32 | |
33 | - /** @var IUserManager */ |
|
34 | - protected $userManager; |
|
33 | + /** @var IUserManager */ |
|
34 | + protected $userManager; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Return possible values for the named option |
|
38 | - * |
|
39 | - * @param string $optionName |
|
40 | - * @param CompletionContext $context |
|
41 | - * @return string[] |
|
42 | - */ |
|
43 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
44 | - return []; |
|
45 | - } |
|
36 | + /** |
|
37 | + * Return possible values for the named option |
|
38 | + * |
|
39 | + * @param string $optionName |
|
40 | + * @param CompletionContext $context |
|
41 | + * @return string[] |
|
42 | + */ |
|
43 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
44 | + return []; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Return possible values for the named argument |
|
49 | - * |
|
50 | - * @param string $argumentName |
|
51 | - * @param CompletionContext $context |
|
52 | - * @return string[] |
|
53 | - */ |
|
54 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
55 | - if ($argumentName === 'uid') { |
|
56 | - return array_map(function(IUser $user) { |
|
57 | - return $user->getUID(); |
|
58 | - }, $this->userManager->search($context->getCurrentWord(), 100)); |
|
59 | - } |
|
60 | - return []; |
|
61 | - } |
|
47 | + /** |
|
48 | + * Return possible values for the named argument |
|
49 | + * |
|
50 | + * @param string $argumentName |
|
51 | + * @param CompletionContext $context |
|
52 | + * @return string[] |
|
53 | + */ |
|
54 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
55 | + if ($argumentName === 'uid') { |
|
56 | + return array_map(function(IUser $user) { |
|
57 | + return $user->getUID(); |
|
58 | + }, $this->userManager->search($context->getCurrentWord(), 100)); |
|
59 | + } |
|
60 | + return []; |
|
61 | + } |
|
62 | 62 | } |
@@ -23,63 +23,63 @@ |
||
23 | 23 | namespace OC\App\CodeChecker; |
24 | 24 | |
25 | 25 | class PrivateCheck extends AbstractCheck { |
26 | - /** |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - protected function getLocalDescription() { |
|
30 | - return 'private'; |
|
31 | - } |
|
26 | + /** |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + protected function getLocalDescription() { |
|
30 | + return 'private'; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return array |
|
35 | - */ |
|
36 | - public function getLocalClasses() { |
|
37 | - return [ |
|
38 | - // classes replaced by the public api |
|
39 | - 'OC_API' => '6.0.0', |
|
40 | - 'OC_App' => '6.0.0', |
|
41 | - 'OC_AppConfig' => '6.0.0', |
|
42 | - 'OC_Avatar' => '6.0.0', |
|
43 | - 'OC_BackgroundJob' => '6.0.0', |
|
44 | - 'OC_Config' => '6.0.0', |
|
45 | - 'OC_DB' => '6.0.0', |
|
46 | - 'OC_Files' => '6.0.0', |
|
47 | - 'OC_Helper' => '6.0.0', |
|
48 | - 'OC_Hook' => '6.0.0', |
|
49 | - 'OC_Image' => '6.0.0', |
|
50 | - 'OC_JSON' => '6.0.0', |
|
51 | - 'OC_L10N' => '6.0.0', |
|
52 | - 'OC_Log' => '6.0.0', |
|
53 | - 'OC_Mail' => '6.0.0', |
|
54 | - 'OC_Preferences' => '6.0.0', |
|
55 | - 'OC_Search_Provider' => '6.0.0', |
|
56 | - 'OC_Search_Result' => '6.0.0', |
|
57 | - 'OC_Request' => '6.0.0', |
|
58 | - 'OC_Response' => '6.0.0', |
|
59 | - 'OC_Template' => '6.0.0', |
|
60 | - 'OC_User' => '6.0.0', |
|
61 | - 'OC_Util' => '6.0.0', |
|
62 | - ]; |
|
63 | - } |
|
33 | + /** |
|
34 | + * @return array |
|
35 | + */ |
|
36 | + public function getLocalClasses() { |
|
37 | + return [ |
|
38 | + // classes replaced by the public api |
|
39 | + 'OC_API' => '6.0.0', |
|
40 | + 'OC_App' => '6.0.0', |
|
41 | + 'OC_AppConfig' => '6.0.0', |
|
42 | + 'OC_Avatar' => '6.0.0', |
|
43 | + 'OC_BackgroundJob' => '6.0.0', |
|
44 | + 'OC_Config' => '6.0.0', |
|
45 | + 'OC_DB' => '6.0.0', |
|
46 | + 'OC_Files' => '6.0.0', |
|
47 | + 'OC_Helper' => '6.0.0', |
|
48 | + 'OC_Hook' => '6.0.0', |
|
49 | + 'OC_Image' => '6.0.0', |
|
50 | + 'OC_JSON' => '6.0.0', |
|
51 | + 'OC_L10N' => '6.0.0', |
|
52 | + 'OC_Log' => '6.0.0', |
|
53 | + 'OC_Mail' => '6.0.0', |
|
54 | + 'OC_Preferences' => '6.0.0', |
|
55 | + 'OC_Search_Provider' => '6.0.0', |
|
56 | + 'OC_Search_Result' => '6.0.0', |
|
57 | + 'OC_Request' => '6.0.0', |
|
58 | + 'OC_Response' => '6.0.0', |
|
59 | + 'OC_Template' => '6.0.0', |
|
60 | + 'OC_User' => '6.0.0', |
|
61 | + 'OC_Util' => '6.0.0', |
|
62 | + ]; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function getLocalConstants() { |
|
69 | - return []; |
|
70 | - } |
|
65 | + /** |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function getLocalConstants() { |
|
69 | + return []; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function getLocalFunctions() { |
|
76 | - return []; |
|
77 | - } |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function getLocalFunctions() { |
|
76 | + return []; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getLocalMethods() { |
|
83 | - return []; |
|
84 | - } |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getLocalMethods() { |
|
83 | + return []; |
|
84 | + } |
|
85 | 85 | } |
@@ -26,27 +26,27 @@ |
||
26 | 26 | |
27 | 27 | class RequestTime extends Controller { |
28 | 28 | |
29 | - /** |
|
30 | - * @NoAdminRequired |
|
31 | - * |
|
32 | - * @param string $search |
|
33 | - * @return JSONResponse |
|
34 | - */ |
|
35 | - public function getTimezones($search = '') { |
|
36 | - $timezones = \DateTimeZone::listIdentifiers(); |
|
29 | + /** |
|
30 | + * @NoAdminRequired |
|
31 | + * |
|
32 | + * @param string $search |
|
33 | + * @return JSONResponse |
|
34 | + */ |
|
35 | + public function getTimezones($search = '') { |
|
36 | + $timezones = \DateTimeZone::listIdentifiers(); |
|
37 | 37 | |
38 | - if ($search !== '') { |
|
39 | - $timezones = array_filter($timezones, function ($timezone) use ($search) { |
|
40 | - return stripos($timezone, $search) !== false; |
|
41 | - }); |
|
42 | - } |
|
38 | + if ($search !== '') { |
|
39 | + $timezones = array_filter($timezones, function ($timezone) use ($search) { |
|
40 | + return stripos($timezone, $search) !== false; |
|
41 | + }); |
|
42 | + } |
|
43 | 43 | |
44 | - $timezones = array_slice($timezones, 0, 10); |
|
44 | + $timezones = array_slice($timezones, 0, 10); |
|
45 | 45 | |
46 | - $response = []; |
|
47 | - foreach ($timezones as $timezone) { |
|
48 | - $response[$timezone] = $timezone; |
|
49 | - } |
|
50 | - return new JSONResponse($response); |
|
51 | - } |
|
46 | + $response = []; |
|
47 | + foreach ($timezones as $timezone) { |
|
48 | + $response[$timezone] = $timezone; |
|
49 | + } |
|
50 | + return new JSONResponse($response); |
|
51 | + } |
|
52 | 52 | } |
@@ -30,44 +30,44 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | class SearchResultType { |
33 | - /** @var string */ |
|
34 | - protected $label; |
|
33 | + /** @var string */ |
|
34 | + protected $label; |
|
35 | 35 | |
36 | - /** |
|
37 | - * SearchResultType constructor. |
|
38 | - * |
|
39 | - * @param string $label |
|
40 | - * @since 13.0.0 |
|
41 | - */ |
|
42 | - public function __construct($label) { |
|
43 | - $this->label = $this->getValidatedType($label); |
|
44 | - } |
|
36 | + /** |
|
37 | + * SearchResultType constructor. |
|
38 | + * |
|
39 | + * @param string $label |
|
40 | + * @since 13.0.0 |
|
41 | + */ |
|
42 | + public function __construct($label) { |
|
43 | + $this->label = $this->getValidatedType($label); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - * @since 13.0.0 |
|
49 | - */ |
|
50 | - public function getLabel() { |
|
51 | - return $this->label; |
|
52 | - } |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + * @since 13.0.0 |
|
49 | + */ |
|
50 | + public function getLabel() { |
|
51 | + return $this->label; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param $type |
|
56 | - * @return string |
|
57 | - * @throws \InvalidArgumentException |
|
58 | - * @since 13.0.0 |
|
59 | - */ |
|
60 | - protected function getValidatedType($type) { |
|
61 | - $type = trim((string)$type); |
|
54 | + /** |
|
55 | + * @param $type |
|
56 | + * @return string |
|
57 | + * @throws \InvalidArgumentException |
|
58 | + * @since 13.0.0 |
|
59 | + */ |
|
60 | + protected function getValidatedType($type) { |
|
61 | + $type = trim((string)$type); |
|
62 | 62 | |
63 | - if($type === '') { |
|
64 | - throw new \InvalidArgumentException('Type must not be empty'); |
|
65 | - } |
|
63 | + if($type === '') { |
|
64 | + throw new \InvalidArgumentException('Type must not be empty'); |
|
65 | + } |
|
66 | 66 | |
67 | - if($type === 'exact') { |
|
68 | - throw new \InvalidArgumentException('Provided type is a reserved word'); |
|
69 | - } |
|
67 | + if($type === 'exact') { |
|
68 | + throw new \InvalidArgumentException('Provided type is a reserved word'); |
|
69 | + } |
|
70 | 70 | |
71 | - return $type; |
|
72 | - } |
|
71 | + return $type; |
|
72 | + } |
|
73 | 73 | } |
@@ -36,59 +36,59 @@ |
||
36 | 36 | |
37 | 37 | class SystemTagsRelationsCollection extends SimpleCollection { |
38 | 38 | |
39 | - /** |
|
40 | - * SystemTagsRelationsCollection constructor. |
|
41 | - * |
|
42 | - * @param ISystemTagManager $tagManager |
|
43 | - * @param ISystemTagObjectMapper $tagMapper |
|
44 | - * @param IUserSession $userSession |
|
45 | - * @param IGroupManager $groupManager |
|
46 | - * @param EventDispatcherInterface $dispatcher |
|
47 | - */ |
|
48 | - public function __construct( |
|
49 | - ISystemTagManager $tagManager, |
|
50 | - ISystemTagObjectMapper $tagMapper, |
|
51 | - IUserSession $userSession, |
|
52 | - IGroupManager $groupManager, |
|
53 | - EventDispatcherInterface $dispatcher |
|
54 | - ) { |
|
55 | - $children = [ |
|
56 | - new SystemTagsObjectTypeCollection( |
|
57 | - 'files', |
|
58 | - $tagManager, |
|
59 | - $tagMapper, |
|
60 | - $userSession, |
|
61 | - $groupManager, |
|
62 | - function($name) { |
|
63 | - $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
64 | - return !empty($nodes); |
|
65 | - } |
|
66 | - ), |
|
67 | - ]; |
|
39 | + /** |
|
40 | + * SystemTagsRelationsCollection constructor. |
|
41 | + * |
|
42 | + * @param ISystemTagManager $tagManager |
|
43 | + * @param ISystemTagObjectMapper $tagMapper |
|
44 | + * @param IUserSession $userSession |
|
45 | + * @param IGroupManager $groupManager |
|
46 | + * @param EventDispatcherInterface $dispatcher |
|
47 | + */ |
|
48 | + public function __construct( |
|
49 | + ISystemTagManager $tagManager, |
|
50 | + ISystemTagObjectMapper $tagMapper, |
|
51 | + IUserSession $userSession, |
|
52 | + IGroupManager $groupManager, |
|
53 | + EventDispatcherInterface $dispatcher |
|
54 | + ) { |
|
55 | + $children = [ |
|
56 | + new SystemTagsObjectTypeCollection( |
|
57 | + 'files', |
|
58 | + $tagManager, |
|
59 | + $tagMapper, |
|
60 | + $userSession, |
|
61 | + $groupManager, |
|
62 | + function($name) { |
|
63 | + $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
64 | + return !empty($nodes); |
|
65 | + } |
|
66 | + ), |
|
67 | + ]; |
|
68 | 68 | |
69 | - $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); |
|
70 | - $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); |
|
69 | + $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); |
|
70 | + $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); |
|
71 | 71 | |
72 | - foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
73 | - $children[] = new SystemTagsObjectTypeCollection( |
|
74 | - $entity, |
|
75 | - $tagManager, |
|
76 | - $tagMapper, |
|
77 | - $userSession, |
|
78 | - $groupManager, |
|
79 | - $entityExistsFunction |
|
80 | - ); |
|
81 | - } |
|
72 | + foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
73 | + $children[] = new SystemTagsObjectTypeCollection( |
|
74 | + $entity, |
|
75 | + $tagManager, |
|
76 | + $tagMapper, |
|
77 | + $userSession, |
|
78 | + $groupManager, |
|
79 | + $entityExistsFunction |
|
80 | + ); |
|
81 | + } |
|
82 | 82 | |
83 | - parent::__construct('root', $children); |
|
84 | - } |
|
83 | + parent::__construct('root', $children); |
|
84 | + } |
|
85 | 85 | |
86 | - function getName() { |
|
87 | - return 'systemtags-relations'; |
|
88 | - } |
|
86 | + function getName() { |
|
87 | + return 'systemtags-relations'; |
|
88 | + } |
|
89 | 89 | |
90 | - function setName($name) { |
|
91 | - throw new Forbidden('Permission denied to rename this collection'); |
|
92 | - } |
|
90 | + function setName($name) { |
|
91 | + throw new Forbidden('Permission denied to rename this collection'); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | } |
@@ -27,173 +27,173 @@ |
||
27 | 27 | |
28 | 28 | class Expiration { |
29 | 29 | |
30 | - // how long do we keep files a version if no other value is defined in the config file (unit: days) |
|
31 | - const NO_OBLIGATION = -1; |
|
32 | - |
|
33 | - /** @var ITimeFactory */ |
|
34 | - private $timeFactory; |
|
35 | - |
|
36 | - /** @var string */ |
|
37 | - private $retentionObligation; |
|
38 | - |
|
39 | - /** @var int */ |
|
40 | - private $minAge; |
|
41 | - |
|
42 | - /** @var int */ |
|
43 | - private $maxAge; |
|
44 | - |
|
45 | - /** @var bool */ |
|
46 | - private $canPurgeToSaveSpace; |
|
47 | - |
|
48 | - public function __construct(IConfig $config,ITimeFactory $timeFactory){ |
|
49 | - $this->timeFactory = $timeFactory; |
|
50 | - $this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto'); |
|
51 | - |
|
52 | - if ($this->retentionObligation !== 'disabled') { |
|
53 | - $this->parseRetentionObligation(); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Is versions expiration enabled |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function isEnabled(){ |
|
62 | - return $this->retentionObligation !== 'disabled'; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Is default expiration active |
|
67 | - */ |
|
68 | - public function shouldAutoExpire(){ |
|
69 | - return $this->minAge === self::NO_OBLIGATION |
|
70 | - || $this->maxAge === self::NO_OBLIGATION; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Check if given timestamp in expiration range |
|
75 | - * @param int $timestamp |
|
76 | - * @param bool $quotaExceeded |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function isExpired($timestamp, $quotaExceeded = false){ |
|
80 | - // No expiration if disabled |
|
81 | - if (!$this->isEnabled()) { |
|
82 | - return false; |
|
83 | - } |
|
84 | - |
|
85 | - // Purge to save space (if allowed) |
|
86 | - if ($quotaExceeded && $this->canPurgeToSaveSpace) { |
|
87 | - return true; |
|
88 | - } |
|
89 | - |
|
90 | - $time = $this->timeFactory->getTime(); |
|
91 | - // Never expire dates in future e.g. misconfiguration or negative time |
|
92 | - // adjustment |
|
93 | - if ($time<$timestamp) { |
|
94 | - return false; |
|
95 | - } |
|
96 | - |
|
97 | - // Purge as too old |
|
98 | - if ($this->maxAge !== self::NO_OBLIGATION) { |
|
99 | - $maxTimestamp = $time - ($this->maxAge * 86400); |
|
100 | - $isOlderThanMax = $timestamp < $maxTimestamp; |
|
101 | - } else { |
|
102 | - $isOlderThanMax = false; |
|
103 | - } |
|
104 | - |
|
105 | - if ($this->minAge !== self::NO_OBLIGATION) { |
|
106 | - // older than Min obligation and we are running out of quota? |
|
107 | - $minTimestamp = $time - ($this->minAge * 86400); |
|
108 | - $isMinReached = ($timestamp < $minTimestamp) && $quotaExceeded; |
|
109 | - } else { |
|
110 | - $isMinReached = false; |
|
111 | - } |
|
112 | - |
|
113 | - return $isOlderThanMax || $isMinReached; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get maximal retention obligation as a timestamp |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function getMaxAgeAsTimestamp(){ |
|
121 | - $maxAge = false; |
|
122 | - if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) { |
|
123 | - $time = $this->timeFactory->getTime(); |
|
124 | - $maxAge = $time - ($this->maxAge * 86400); |
|
125 | - } |
|
126 | - return $maxAge; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Read versions_retention_obligation, validate it |
|
131 | - * and set private members accordingly |
|
132 | - */ |
|
133 | - private function parseRetentionObligation(){ |
|
134 | - $splitValues = explode(',', $this->retentionObligation); |
|
135 | - if (!isset($splitValues[0])) { |
|
136 | - $minValue = 'auto'; |
|
137 | - } else { |
|
138 | - $minValue = trim($splitValues[0]); |
|
139 | - } |
|
140 | - |
|
141 | - if (!isset($splitValues[1])) { |
|
142 | - $maxValue = 'auto'; |
|
143 | - } else { |
|
144 | - $maxValue = trim($splitValues[1]); |
|
145 | - } |
|
146 | - |
|
147 | - $isValid = true; |
|
148 | - // Validate |
|
149 | - if (!ctype_digit($minValue) && $minValue !== 'auto') { |
|
150 | - $isValid = false; |
|
151 | - \OC::$server->getLogger()->warning( |
|
152 | - $minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', |
|
153 | - ['app'=>'files_versions'] |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - if (!ctype_digit($maxValue) && $maxValue !== 'auto') { |
|
158 | - $isValid = false; |
|
159 | - \OC::$server->getLogger()->warning( |
|
160 | - $maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', |
|
161 | - ['app'=>'files_versions'] |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - if (!$isValid){ |
|
166 | - $minValue = 'auto'; |
|
167 | - $maxValue = 'auto'; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - if ($minValue === 'auto' && $maxValue === 'auto') { |
|
172 | - // Default: Delete anytime if space needed |
|
173 | - $this->minAge = self::NO_OBLIGATION; |
|
174 | - $this->maxAge = self::NO_OBLIGATION; |
|
175 | - $this->canPurgeToSaveSpace = true; |
|
176 | - } elseif ($minValue !== 'auto' && $maxValue === 'auto') { |
|
177 | - // Keep for X days but delete anytime if space needed |
|
178 | - $this->minAge = (int)$minValue; |
|
179 | - $this->maxAge = self::NO_OBLIGATION; |
|
180 | - $this->canPurgeToSaveSpace = true; |
|
181 | - } elseif ($minValue === 'auto' && $maxValue !== 'auto') { |
|
182 | - // Delete anytime if space needed, Delete all older than max automatically |
|
183 | - $this->minAge = self::NO_OBLIGATION; |
|
184 | - $this->maxAge = (int)$maxValue; |
|
185 | - $this->canPurgeToSaveSpace = true; |
|
186 | - } elseif ($minValue !== 'auto' && $maxValue !== 'auto') { |
|
187 | - // Delete all older than max OR older than min if space needed |
|
188 | - |
|
189 | - // Max < Min as per https://github.com/owncloud/core/issues/16301 |
|
190 | - if ($maxValue < $minValue) { |
|
191 | - $maxValue = $minValue; |
|
192 | - } |
|
193 | - |
|
194 | - $this->minAge = (int)$minValue; |
|
195 | - $this->maxAge = (int)$maxValue; |
|
196 | - $this->canPurgeToSaveSpace = false; |
|
197 | - } |
|
198 | - } |
|
30 | + // how long do we keep files a version if no other value is defined in the config file (unit: days) |
|
31 | + const NO_OBLIGATION = -1; |
|
32 | + |
|
33 | + /** @var ITimeFactory */ |
|
34 | + private $timeFactory; |
|
35 | + |
|
36 | + /** @var string */ |
|
37 | + private $retentionObligation; |
|
38 | + |
|
39 | + /** @var int */ |
|
40 | + private $minAge; |
|
41 | + |
|
42 | + /** @var int */ |
|
43 | + private $maxAge; |
|
44 | + |
|
45 | + /** @var bool */ |
|
46 | + private $canPurgeToSaveSpace; |
|
47 | + |
|
48 | + public function __construct(IConfig $config,ITimeFactory $timeFactory){ |
|
49 | + $this->timeFactory = $timeFactory; |
|
50 | + $this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto'); |
|
51 | + |
|
52 | + if ($this->retentionObligation !== 'disabled') { |
|
53 | + $this->parseRetentionObligation(); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Is versions expiration enabled |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function isEnabled(){ |
|
62 | + return $this->retentionObligation !== 'disabled'; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Is default expiration active |
|
67 | + */ |
|
68 | + public function shouldAutoExpire(){ |
|
69 | + return $this->minAge === self::NO_OBLIGATION |
|
70 | + || $this->maxAge === self::NO_OBLIGATION; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Check if given timestamp in expiration range |
|
75 | + * @param int $timestamp |
|
76 | + * @param bool $quotaExceeded |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function isExpired($timestamp, $quotaExceeded = false){ |
|
80 | + // No expiration if disabled |
|
81 | + if (!$this->isEnabled()) { |
|
82 | + return false; |
|
83 | + } |
|
84 | + |
|
85 | + // Purge to save space (if allowed) |
|
86 | + if ($quotaExceeded && $this->canPurgeToSaveSpace) { |
|
87 | + return true; |
|
88 | + } |
|
89 | + |
|
90 | + $time = $this->timeFactory->getTime(); |
|
91 | + // Never expire dates in future e.g. misconfiguration or negative time |
|
92 | + // adjustment |
|
93 | + if ($time<$timestamp) { |
|
94 | + return false; |
|
95 | + } |
|
96 | + |
|
97 | + // Purge as too old |
|
98 | + if ($this->maxAge !== self::NO_OBLIGATION) { |
|
99 | + $maxTimestamp = $time - ($this->maxAge * 86400); |
|
100 | + $isOlderThanMax = $timestamp < $maxTimestamp; |
|
101 | + } else { |
|
102 | + $isOlderThanMax = false; |
|
103 | + } |
|
104 | + |
|
105 | + if ($this->minAge !== self::NO_OBLIGATION) { |
|
106 | + // older than Min obligation and we are running out of quota? |
|
107 | + $minTimestamp = $time - ($this->minAge * 86400); |
|
108 | + $isMinReached = ($timestamp < $minTimestamp) && $quotaExceeded; |
|
109 | + } else { |
|
110 | + $isMinReached = false; |
|
111 | + } |
|
112 | + |
|
113 | + return $isOlderThanMax || $isMinReached; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get maximal retention obligation as a timestamp |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function getMaxAgeAsTimestamp(){ |
|
121 | + $maxAge = false; |
|
122 | + if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) { |
|
123 | + $time = $this->timeFactory->getTime(); |
|
124 | + $maxAge = $time - ($this->maxAge * 86400); |
|
125 | + } |
|
126 | + return $maxAge; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Read versions_retention_obligation, validate it |
|
131 | + * and set private members accordingly |
|
132 | + */ |
|
133 | + private function parseRetentionObligation(){ |
|
134 | + $splitValues = explode(',', $this->retentionObligation); |
|
135 | + if (!isset($splitValues[0])) { |
|
136 | + $minValue = 'auto'; |
|
137 | + } else { |
|
138 | + $minValue = trim($splitValues[0]); |
|
139 | + } |
|
140 | + |
|
141 | + if (!isset($splitValues[1])) { |
|
142 | + $maxValue = 'auto'; |
|
143 | + } else { |
|
144 | + $maxValue = trim($splitValues[1]); |
|
145 | + } |
|
146 | + |
|
147 | + $isValid = true; |
|
148 | + // Validate |
|
149 | + if (!ctype_digit($minValue) && $minValue !== 'auto') { |
|
150 | + $isValid = false; |
|
151 | + \OC::$server->getLogger()->warning( |
|
152 | + $minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', |
|
153 | + ['app'=>'files_versions'] |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + if (!ctype_digit($maxValue) && $maxValue !== 'auto') { |
|
158 | + $isValid = false; |
|
159 | + \OC::$server->getLogger()->warning( |
|
160 | + $maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', |
|
161 | + ['app'=>'files_versions'] |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + if (!$isValid){ |
|
166 | + $minValue = 'auto'; |
|
167 | + $maxValue = 'auto'; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + if ($minValue === 'auto' && $maxValue === 'auto') { |
|
172 | + // Default: Delete anytime if space needed |
|
173 | + $this->minAge = self::NO_OBLIGATION; |
|
174 | + $this->maxAge = self::NO_OBLIGATION; |
|
175 | + $this->canPurgeToSaveSpace = true; |
|
176 | + } elseif ($minValue !== 'auto' && $maxValue === 'auto') { |
|
177 | + // Keep for X days but delete anytime if space needed |
|
178 | + $this->minAge = (int)$minValue; |
|
179 | + $this->maxAge = self::NO_OBLIGATION; |
|
180 | + $this->canPurgeToSaveSpace = true; |
|
181 | + } elseif ($minValue === 'auto' && $maxValue !== 'auto') { |
|
182 | + // Delete anytime if space needed, Delete all older than max automatically |
|
183 | + $this->minAge = self::NO_OBLIGATION; |
|
184 | + $this->maxAge = (int)$maxValue; |
|
185 | + $this->canPurgeToSaveSpace = true; |
|
186 | + } elseif ($minValue !== 'auto' && $maxValue !== 'auto') { |
|
187 | + // Delete all older than max OR older than min if space needed |
|
188 | + |
|
189 | + // Max < Min as per https://github.com/owncloud/core/issues/16301 |
|
190 | + if ($maxValue < $minValue) { |
|
191 | + $maxValue = $minValue; |
|
192 | + } |
|
193 | + |
|
194 | + $this->minAge = (int)$minValue; |
|
195 | + $this->maxAge = (int)$maxValue; |
|
196 | + $this->canPurgeToSaveSpace = false; |
|
197 | + } |
|
198 | + } |
|
199 | 199 | } |
@@ -32,70 +32,70 @@ |
||
32 | 32 | |
33 | 33 | class UUIDFixInsert implements IRepairStep { |
34 | 34 | |
35 | - /** @var IConfig */ |
|
36 | - protected $config; |
|
35 | + /** @var IConfig */ |
|
36 | + protected $config; |
|
37 | 37 | |
38 | - /** @var UserMapping */ |
|
39 | - protected $userMapper; |
|
38 | + /** @var UserMapping */ |
|
39 | + protected $userMapper; |
|
40 | 40 | |
41 | - /** @var GroupMapping */ |
|
42 | - protected $groupMapper; |
|
41 | + /** @var GroupMapping */ |
|
42 | + protected $groupMapper; |
|
43 | 43 | |
44 | - /** @var IJobList */ |
|
45 | - protected $jobList; |
|
44 | + /** @var IJobList */ |
|
45 | + protected $jobList; |
|
46 | 46 | |
47 | - public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) { |
|
48 | - $this->config = $config; |
|
49 | - $this->userMapper = $userMapper; |
|
50 | - $this->groupMapper = $groupMapper; |
|
51 | - $this->jobList = $jobList; |
|
52 | - } |
|
47 | + public function __construct(IConfig $config, UserMapping $userMapper, GroupMapping $groupMapper, IJobList $jobList) { |
|
48 | + $this->config = $config; |
|
49 | + $this->userMapper = $userMapper; |
|
50 | + $this->groupMapper = $groupMapper; |
|
51 | + $this->jobList = $jobList; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns the step's name |
|
56 | - * |
|
57 | - * @return string |
|
58 | - * @since 9.1.0 |
|
59 | - */ |
|
60 | - public function getName() { |
|
61 | - return 'Insert UUIDFix background job for user and group in batches'; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Returns the step's name |
|
56 | + * |
|
57 | + * @return string |
|
58 | + * @since 9.1.0 |
|
59 | + */ |
|
60 | + public function getName() { |
|
61 | + return 'Insert UUIDFix background job for user and group in batches'; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Run repair step. |
|
66 | - * Must throw exception on error. |
|
67 | - * |
|
68 | - * @param IOutput $output |
|
69 | - * @throws \Exception in case of failure |
|
70 | - * @since 9.1.0 |
|
71 | - */ |
|
72 | - public function run(IOutput $output) { |
|
73 | - $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1'); |
|
74 | - if(version_compare($installedVersion, '1.2.1') !== -1) { |
|
75 | - return; |
|
76 | - } |
|
64 | + /** |
|
65 | + * Run repair step. |
|
66 | + * Must throw exception on error. |
|
67 | + * |
|
68 | + * @param IOutput $output |
|
69 | + * @throws \Exception in case of failure |
|
70 | + * @since 9.1.0 |
|
71 | + */ |
|
72 | + public function run(IOutput $output) { |
|
73 | + $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1'); |
|
74 | + if(version_compare($installedVersion, '1.2.1') !== -1) { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - foreach ([$this->userMapper, $this->groupMapper] as $mapper) { |
|
79 | - $offset = 0; |
|
80 | - $batchSize = 50; |
|
81 | - $jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class; |
|
82 | - do { |
|
83 | - $retry = false; |
|
84 | - $records = $mapper->getList($offset, $batchSize); |
|
85 | - if(count($records) === 0){ |
|
86 | - continue; |
|
87 | - } |
|
88 | - try { |
|
89 | - $this->jobList->add($jobClass, ['records' => $records]); |
|
90 | - $offset += $batchSize; |
|
91 | - } catch (\InvalidArgumentException $e) { |
|
92 | - if(strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
93 | - $batchSize = (int)floor(count($records) * 0.8); |
|
94 | - $retry = true; |
|
95 | - } |
|
96 | - } |
|
97 | - } while (count($records) === $batchSize || $retry); |
|
98 | - } |
|
78 | + foreach ([$this->userMapper, $this->groupMapper] as $mapper) { |
|
79 | + $offset = 0; |
|
80 | + $batchSize = 50; |
|
81 | + $jobClass = $mapper instanceof UserMapping ? UUIDFixUser::class : UUIDFixGroup::class; |
|
82 | + do { |
|
83 | + $retry = false; |
|
84 | + $records = $mapper->getList($offset, $batchSize); |
|
85 | + if(count($records) === 0){ |
|
86 | + continue; |
|
87 | + } |
|
88 | + try { |
|
89 | + $this->jobList->add($jobClass, ['records' => $records]); |
|
90 | + $offset += $batchSize; |
|
91 | + } catch (\InvalidArgumentException $e) { |
|
92 | + if(strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
93 | + $batchSize = (int)floor(count($records) * 0.8); |
|
94 | + $retry = true; |
|
95 | + } |
|
96 | + } |
|
97 | + } while (count($records) === $batchSize || $retry); |
|
98 | + } |
|
99 | 99 | |
100 | - } |
|
100 | + } |
|
101 | 101 | } |