@@ -47,42 +47,42 @@ |
||
47 | 47 | * @deprecated 13.0.0 |
48 | 48 | */ |
49 | 49 | class User { |
50 | - /** |
|
51 | - * Get the user id of the user currently logged in. |
|
52 | - * @return string uid or false |
|
53 | - * @deprecated 8.0.0 Use \OC::$server->getUserSession()->getUser()->getUID() |
|
54 | - * @since 5.0.0 |
|
55 | - */ |
|
56 | - public static function getUser() { |
|
57 | - return \OC_User::getUser(); |
|
58 | - } |
|
50 | + /** |
|
51 | + * Get the user id of the user currently logged in. |
|
52 | + * @return string uid or false |
|
53 | + * @deprecated 8.0.0 Use \OC::$server->getUserSession()->getUser()->getUID() |
|
54 | + * @since 5.0.0 |
|
55 | + */ |
|
56 | + public static function getUser() { |
|
57 | + return \OC_User::getUser(); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Check if the user is logged in |
|
62 | - * @return boolean |
|
63 | - * @since 5.0.0 |
|
64 | - * @deprecated 13.0.0 Use annotation based ACLs from the AppFramework instead |
|
65 | - */ |
|
66 | - public static function isLoggedIn() { |
|
67 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
68 | - } |
|
60 | + /** |
|
61 | + * Check if the user is logged in |
|
62 | + * @return boolean |
|
63 | + * @since 5.0.0 |
|
64 | + * @deprecated 13.0.0 Use annotation based ACLs from the AppFramework instead |
|
65 | + */ |
|
66 | + public static function isLoggedIn() { |
|
67 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Check if the user is a admin, redirects to home if not |
|
72 | - * @since 5.0.0 |
|
73 | - * @deprecated 13.0.0 Use annotation based ACLs from the AppFramework instead |
|
74 | - */ |
|
75 | - public static function checkAdminUser() { |
|
76 | - \OC_Util::checkAdminUser(); |
|
77 | - } |
|
70 | + /** |
|
71 | + * Check if the user is a admin, redirects to home if not |
|
72 | + * @since 5.0.0 |
|
73 | + * @deprecated 13.0.0 Use annotation based ACLs from the AppFramework instead |
|
74 | + */ |
|
75 | + public static function checkAdminUser() { |
|
76 | + \OC_Util::checkAdminUser(); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Check if the user is logged in, redirects to home if not. With |
|
81 | - * redirect URL parameter to the request URI. |
|
82 | - * @since 5.0.0 |
|
83 | - * @deprecated 13.0.0 Use annotation based ACLs from the AppFramework instead |
|
84 | - */ |
|
85 | - public static function checkLoggedIn() { |
|
86 | - \OC_Util::checkLoggedIn(); |
|
87 | - } |
|
79 | + /** |
|
80 | + * Check if the user is logged in, redirects to home if not. With |
|
81 | + * redirect URL parameter to the request URI. |
|
82 | + * @since 5.0.0 |
|
83 | + * @deprecated 13.0.0 Use annotation based ACLs from the AppFramework instead |
|
84 | + */ |
|
85 | + public static function checkLoggedIn() { |
|
86 | + \OC_Util::checkLoggedIn(); |
|
87 | + } |
|
88 | 88 | } |
@@ -31,10 +31,10 @@ |
||
31 | 31 | */ |
32 | 32 | interface IProvidesCustomCSP { |
33 | 33 | |
34 | - /** |
|
35 | - * @return ContentSecurityPolicy |
|
36 | - * |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function getCSP(): ContentSecurityPolicy; |
|
34 | + /** |
|
35 | + * @return ContentSecurityPolicy |
|
36 | + * |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function getCSP(): ContentSecurityPolicy; |
|
40 | 40 | } |
@@ -6,35 +6,35 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitProvisioning_API |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'O' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'OCA\\Provisioning_API\\' => 21, |
13 | 13 | ), |
14 | 14 | ); |
15 | 15 | |
16 | - public static $prefixDirsPsr4 = array ( |
|
16 | + public static $prefixDirsPsr4 = array( |
|
17 | 17 | 'OCA\\Provisioning_API\\' => |
18 | - array ( |
|
19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
18 | + array( |
|
19 | + 0 => __DIR__.'/..'.'/../lib', |
|
20 | 20 | ), |
21 | 21 | ); |
22 | 22 | |
23 | - public static $classMap = array ( |
|
24 | - 'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
25 | - 'OCA\\Provisioning_API\\Controller\\AUserData' => __DIR__ . '/..' . '/../lib/Controller/AUserData.php', |
|
26 | - 'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__ . '/..' . '/../lib/Controller/AppConfigController.php', |
|
27 | - 'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php', |
|
28 | - 'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php', |
|
29 | - 'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php', |
|
30 | - 'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__ . '/..' . '/../lib/FederatedFileSharingFactory.php', |
|
31 | - 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
32 | - 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
23 | + public static $classMap = array( |
|
24 | + 'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
25 | + 'OCA\\Provisioning_API\\Controller\\AUserData' => __DIR__.'/..'.'/../lib/Controller/AUserData.php', |
|
26 | + 'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__.'/..'.'/../lib/Controller/AppConfigController.php', |
|
27 | + 'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__.'/..'.'/../lib/Controller/AppsController.php', |
|
28 | + 'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__.'/..'.'/../lib/Controller/GroupsController.php', |
|
29 | + 'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__.'/..'.'/../lib/Controller/UsersController.php', |
|
30 | + 'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__.'/..'.'/../lib/FederatedFileSharingFactory.php', |
|
31 | + 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__.'/..'.'/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
32 | + 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__.'/..'.'/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
33 | 33 | ); |
34 | 34 | |
35 | 35 | public static function getInitializer(ClassLoader $loader) |
36 | 36 | { |
37 | - return \Closure::bind(function () use ($loader) { |
|
37 | + return \Closure::bind(function() use ($loader) { |
|
38 | 38 | $loader->prefixLengthsPsr4 = ComposerStaticInitProvisioning_API::$prefixLengthsPsr4; |
39 | 39 | $loader->prefixDirsPsr4 = ComposerStaticInitProvisioning_API::$prefixDirsPsr4; |
40 | 40 | $loader->classMap = ComposerStaticInitProvisioning_API::$classMap; |
@@ -6,13 +6,13 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
10 | - 'OCA\\Provisioning_API\\Controller\\AUserData' => $baseDir . '/../lib/Controller/AUserData.php', |
|
11 | - 'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir . '/../lib/Controller/AppConfigController.php', |
|
12 | - 'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php', |
|
13 | - 'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php', |
|
14 | - 'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php', |
|
15 | - 'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir . '/../lib/FederatedFileSharingFactory.php', |
|
16 | - 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
17 | - 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir . '/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
9 | + 'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
10 | + 'OCA\\Provisioning_API\\Controller\\AUserData' => $baseDir.'/../lib/Controller/AUserData.php', |
|
11 | + 'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir.'/../lib/Controller/AppConfigController.php', |
|
12 | + 'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir.'/../lib/Controller/AppsController.php', |
|
13 | + 'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir.'/../lib/Controller/GroupsController.php', |
|
14 | + 'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir.'/../lib/Controller/UsersController.php', |
|
15 | + 'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir.'/../lib/FederatedFileSharingFactory.php', |
|
16 | + 'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir.'/../lib/Middleware/Exceptions/NotSubAdminException.php', |
|
17 | + 'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir.'/../lib/Middleware/ProvisioningApiMiddleware.php', |
|
18 | 18 | ); |
@@ -32,77 +32,77 @@ |
||
32 | 32 | */ |
33 | 33 | interface IMountManager { |
34 | 34 | |
35 | - /** |
|
36 | - * Add a new mount |
|
37 | - * |
|
38 | - * @param \OCP\Files\Mount\IMountPoint $mount |
|
39 | - * @since 8.2.0 |
|
40 | - */ |
|
41 | - public function addMount(IMountPoint $mount); |
|
35 | + /** |
|
36 | + * Add a new mount |
|
37 | + * |
|
38 | + * @param \OCP\Files\Mount\IMountPoint $mount |
|
39 | + * @since 8.2.0 |
|
40 | + */ |
|
41 | + public function addMount(IMountPoint $mount); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Remove a mount |
|
45 | - * |
|
46 | - * @param string $mountPoint |
|
47 | - * @since 8.2.0 |
|
48 | - */ |
|
49 | - public function removeMount(string $mountPoint); |
|
43 | + /** |
|
44 | + * Remove a mount |
|
45 | + * |
|
46 | + * @param string $mountPoint |
|
47 | + * @since 8.2.0 |
|
48 | + */ |
|
49 | + public function removeMount(string $mountPoint); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Change the location of a mount |
|
53 | - * |
|
54 | - * @param string $mountPoint |
|
55 | - * @param string $target |
|
56 | - * @since 8.2.0 |
|
57 | - */ |
|
58 | - public function moveMount(string $mountPoint, string $target); |
|
51 | + /** |
|
52 | + * Change the location of a mount |
|
53 | + * |
|
54 | + * @param string $mountPoint |
|
55 | + * @param string $target |
|
56 | + * @since 8.2.0 |
|
57 | + */ |
|
58 | + public function moveMount(string $mountPoint, string $target); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Find the mount for $path |
|
62 | - * |
|
63 | - * @param string $path |
|
64 | - * @return \OCP\Files\Mount\IMountPoint|null |
|
65 | - * @since 8.2.0 |
|
66 | - */ |
|
67 | - public function find(string $path); |
|
60 | + /** |
|
61 | + * Find the mount for $path |
|
62 | + * |
|
63 | + * @param string $path |
|
64 | + * @return \OCP\Files\Mount\IMountPoint|null |
|
65 | + * @since 8.2.0 |
|
66 | + */ |
|
67 | + public function find(string $path); |
|
68 | 68 | |
69 | - /** |
|
70 | - * Find all mounts in $path |
|
71 | - * |
|
72 | - * @param string $path |
|
73 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
74 | - * @since 8.2.0 |
|
75 | - */ |
|
76 | - public function findIn(string $path): array; |
|
69 | + /** |
|
70 | + * Find all mounts in $path |
|
71 | + * |
|
72 | + * @param string $path |
|
73 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
74 | + * @since 8.2.0 |
|
75 | + */ |
|
76 | + public function findIn(string $path): array; |
|
77 | 77 | |
78 | - /** |
|
79 | - * Remove all registered mounts |
|
80 | - * |
|
81 | - * @since 8.2.0 |
|
82 | - */ |
|
83 | - public function clear(); |
|
78 | + /** |
|
79 | + * Remove all registered mounts |
|
80 | + * |
|
81 | + * @since 8.2.0 |
|
82 | + */ |
|
83 | + public function clear(); |
|
84 | 84 | |
85 | - /** |
|
86 | - * Find mounts by storage id |
|
87 | - * |
|
88 | - * @param string $id |
|
89 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
90 | - * @since 8.2.0 |
|
91 | - */ |
|
92 | - public function findByStorageId(string $id): array; |
|
85 | + /** |
|
86 | + * Find mounts by storage id |
|
87 | + * |
|
88 | + * @param string $id |
|
89 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
90 | + * @since 8.2.0 |
|
91 | + */ |
|
92 | + public function findByStorageId(string $id): array; |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
96 | - * @since 8.2.0 |
|
97 | - */ |
|
98 | - public function getAll(): array; |
|
94 | + /** |
|
95 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
96 | + * @since 8.2.0 |
|
97 | + */ |
|
98 | + public function getAll(): array; |
|
99 | 99 | |
100 | - /** |
|
101 | - * Find mounts by numeric storage id |
|
102 | - * |
|
103 | - * @param int $id |
|
104 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
105 | - * @since 8.2.0 |
|
106 | - */ |
|
107 | - public function findByNumericId(int $id): array; |
|
100 | + /** |
|
101 | + * Find mounts by numeric storage id |
|
102 | + * |
|
103 | + * @param int $id |
|
104 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
105 | + * @since 8.2.0 |
|
106 | + */ |
|
107 | + public function findByNumericId(int $id): array; |
|
108 | 108 | } |
@@ -34,33 +34,33 @@ |
||
34 | 34 | */ |
35 | 35 | class LinkMenuAction extends SimpleMenuAction { |
36 | 36 | |
37 | - /** |
|
38 | - * LinkMenuAction constructor. |
|
39 | - * |
|
40 | - * @param string $label |
|
41 | - * @param string $icon |
|
42 | - * @param string $link |
|
43 | - * @since 14.0.0 |
|
44 | - */ |
|
45 | - public function __construct(string $label, string $icon, string $link) { |
|
46 | - parent::__construct('directLink-container', $label, $icon, $link); |
|
47 | - } |
|
37 | + /** |
|
38 | + * LinkMenuAction constructor. |
|
39 | + * |
|
40 | + * @param string $label |
|
41 | + * @param string $icon |
|
42 | + * @param string $link |
|
43 | + * @since 14.0.0 |
|
44 | + */ |
|
45 | + public function __construct(string $label, string $icon, string $link) { |
|
46 | + parent::__construct('directLink-container', $label, $icon, $link); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return string |
|
51 | - * @since 14.0.0 |
|
52 | - */ |
|
53 | - public function render(): string { |
|
54 | - return '<li>' . |
|
55 | - '<a id="directLink-container">' . |
|
56 | - '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' . |
|
57 | - '<label for="directLink">' . Util::sanitizeHTML($this->getLabel()) . '</label>' . |
|
58 | - '</a>' . |
|
59 | - '</li>' . |
|
60 | - '<li>' . |
|
61 | - '<span class="menuitem">' . |
|
62 | - '<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' . |
|
63 | - '</span>' . |
|
64 | - '</li>'; |
|
65 | - } |
|
49 | + /** |
|
50 | + * @return string |
|
51 | + * @since 14.0.0 |
|
52 | + */ |
|
53 | + public function render(): string { |
|
54 | + return '<li>' . |
|
55 | + '<a id="directLink-container">' . |
|
56 | + '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' . |
|
57 | + '<label for="directLink">' . Util::sanitizeHTML($this->getLabel()) . '</label>' . |
|
58 | + '</a>' . |
|
59 | + '</li>' . |
|
60 | + '<li>' . |
|
61 | + '<span class="menuitem">' . |
|
62 | + '<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' . |
|
63 | + '</span>' . |
|
64 | + '</li>'; |
|
65 | + } |
|
66 | 66 | } |
@@ -51,16 +51,16 @@ |
||
51 | 51 | * @since 14.0.0 |
52 | 52 | */ |
53 | 53 | public function render(): string { |
54 | - return '<li>' . |
|
55 | - '<a id="directLink-container">' . |
|
56 | - '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' . |
|
57 | - '<label for="directLink">' . Util::sanitizeHTML($this->getLabel()) . '</label>' . |
|
58 | - '</a>' . |
|
59 | - '</li>' . |
|
60 | - '<li>' . |
|
61 | - '<span class="menuitem">' . |
|
62 | - '<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' . |
|
63 | - '</span>' . |
|
54 | + return '<li>'. |
|
55 | + '<a id="directLink-container">'. |
|
56 | + '<span class="icon '.Util::sanitizeHTML($this->getIcon()).'"></span>'. |
|
57 | + '<label for="directLink">'.Util::sanitizeHTML($this->getLabel()).'</label>'. |
|
58 | + '</a>'. |
|
59 | + '</li>'. |
|
60 | + '<li>'. |
|
61 | + '<span class="menuitem">'. |
|
62 | + '<input id="directLink" type="text" readonly="" value="'.Util::sanitizeHTML($this->getLink()).'">'. |
|
63 | + '</span>'. |
|
64 | 64 | '</li>'; |
65 | 65 | } |
66 | 66 | } |
@@ -105,7 +105,7 @@ |
||
105 | 105 | $defaultLogFile = rtrim($dataDir, '/').'/nextcloud.log'; |
106 | 106 | $output->writeln('Log file: '.$this->config->getSystemValue('logfile', $defaultLogFile)); |
107 | 107 | |
108 | - $rotateSize = $this->config->getSystemValue('log_rotate_size', 100*1024*1024); |
|
108 | + $rotateSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024); |
|
109 | 109 | if ($rotateSize) { |
110 | 110 | $rotateString = \OCP\Util::humanFileSize($rotateSize); |
111 | 111 | } else { |
@@ -38,123 +38,123 @@ |
||
38 | 38 | |
39 | 39 | class File extends Command implements Completion\CompletionAwareInterface { |
40 | 40 | |
41 | - /** @var IConfig */ |
|
42 | - protected $config; |
|
43 | - |
|
44 | - public function __construct(IConfig $config) { |
|
45 | - $this->config = $config; |
|
46 | - parent::__construct(); |
|
47 | - } |
|
48 | - |
|
49 | - protected function configure() { |
|
50 | - $this |
|
51 | - ->setName('log:file') |
|
52 | - ->setDescription('manipulate logging backend') |
|
53 | - ->addOption( |
|
54 | - 'enable', |
|
55 | - null, |
|
56 | - InputOption::VALUE_NONE, |
|
57 | - 'enable this logging backend' |
|
58 | - ) |
|
59 | - ->addOption( |
|
60 | - 'file', |
|
61 | - null, |
|
62 | - InputOption::VALUE_REQUIRED, |
|
63 | - 'set the log file path' |
|
64 | - ) |
|
65 | - ->addOption( |
|
66 | - 'rotate-size', |
|
67 | - null, |
|
68 | - InputOption::VALUE_REQUIRED, |
|
69 | - 'set the file size for log rotation, 0 = disabled' |
|
70 | - ) |
|
71 | - ; |
|
72 | - } |
|
73 | - |
|
74 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
75 | - $toBeSet = []; |
|
76 | - |
|
77 | - if ($input->getOption('enable')) { |
|
78 | - $toBeSet['log_type'] = 'file'; |
|
79 | - } |
|
80 | - |
|
81 | - if ($file = $input->getOption('file')) { |
|
82 | - $toBeSet['logfile'] = $file; |
|
83 | - } |
|
84 | - |
|
85 | - if (($rotateSize = $input->getOption('rotate-size')) !== null) { |
|
86 | - $rotateSize = \OCP\Util::computerFileSize($rotateSize); |
|
87 | - $this->validateRotateSize($rotateSize); |
|
88 | - $toBeSet['log_rotate_size'] = $rotateSize; |
|
89 | - } |
|
90 | - |
|
91 | - // set config |
|
92 | - foreach ($toBeSet as $option => $value) { |
|
93 | - $this->config->setSystemValue($option, $value); |
|
94 | - } |
|
95 | - |
|
96 | - // display config |
|
97 | - // TODO: Drop backwards compatibility for config in the future |
|
98 | - $logType = $this->config->getSystemValue('log_type', 'file'); |
|
99 | - if ($logType === 'file' || $logType === 'owncloud') { |
|
100 | - $enabledText = 'enabled'; |
|
101 | - } else { |
|
102 | - $enabledText = 'disabled'; |
|
103 | - } |
|
104 | - $output->writeln('Log backend file: '.$enabledText); |
|
105 | - |
|
106 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
107 | - $defaultLogFile = rtrim($dataDir, '/').'/nextcloud.log'; |
|
108 | - $output->writeln('Log file: '.$this->config->getSystemValue('logfile', $defaultLogFile)); |
|
109 | - |
|
110 | - $rotateSize = $this->config->getSystemValue('log_rotate_size', 100*1024*1024); |
|
111 | - if ($rotateSize) { |
|
112 | - $rotateString = \OCP\Util::humanFileSize($rotateSize); |
|
113 | - } else { |
|
114 | - $rotateString = 'disabled'; |
|
115 | - } |
|
116 | - $output->writeln('Rotate at: '.$rotateString); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param mixed $rotateSize |
|
121 | - * @throws \InvalidArgumentException |
|
122 | - */ |
|
123 | - protected function validateRotateSize(&$rotateSize) { |
|
124 | - if ($rotateSize === false) { |
|
125 | - throw new \InvalidArgumentException('Error parsing log rotation file size'); |
|
126 | - } |
|
127 | - $rotateSize = (int) $rotateSize; |
|
128 | - if ($rotateSize < 0) { |
|
129 | - throw new \InvalidArgumentException('Log rotation file size must be non-negative'); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $optionName |
|
135 | - * @param CompletionContext $context |
|
136 | - * @return string[] |
|
137 | - */ |
|
138 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
139 | - if ($optionName === 'file') { |
|
140 | - $helper = new ShellPathCompletion( |
|
141 | - $this->getName(), |
|
142 | - 'file', |
|
143 | - Completion::TYPE_OPTION |
|
144 | - ); |
|
145 | - return $helper->run(); |
|
146 | - } elseif ($optionName === 'rotate-size') { |
|
147 | - return [0]; |
|
148 | - } |
|
149 | - return []; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @param string $argumentName |
|
154 | - * @param CompletionContext $context |
|
155 | - * @return string[] |
|
156 | - */ |
|
157 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
158 | - return []; |
|
159 | - } |
|
41 | + /** @var IConfig */ |
|
42 | + protected $config; |
|
43 | + |
|
44 | + public function __construct(IConfig $config) { |
|
45 | + $this->config = $config; |
|
46 | + parent::__construct(); |
|
47 | + } |
|
48 | + |
|
49 | + protected function configure() { |
|
50 | + $this |
|
51 | + ->setName('log:file') |
|
52 | + ->setDescription('manipulate logging backend') |
|
53 | + ->addOption( |
|
54 | + 'enable', |
|
55 | + null, |
|
56 | + InputOption::VALUE_NONE, |
|
57 | + 'enable this logging backend' |
|
58 | + ) |
|
59 | + ->addOption( |
|
60 | + 'file', |
|
61 | + null, |
|
62 | + InputOption::VALUE_REQUIRED, |
|
63 | + 'set the log file path' |
|
64 | + ) |
|
65 | + ->addOption( |
|
66 | + 'rotate-size', |
|
67 | + null, |
|
68 | + InputOption::VALUE_REQUIRED, |
|
69 | + 'set the file size for log rotation, 0 = disabled' |
|
70 | + ) |
|
71 | + ; |
|
72 | + } |
|
73 | + |
|
74 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
75 | + $toBeSet = []; |
|
76 | + |
|
77 | + if ($input->getOption('enable')) { |
|
78 | + $toBeSet['log_type'] = 'file'; |
|
79 | + } |
|
80 | + |
|
81 | + if ($file = $input->getOption('file')) { |
|
82 | + $toBeSet['logfile'] = $file; |
|
83 | + } |
|
84 | + |
|
85 | + if (($rotateSize = $input->getOption('rotate-size')) !== null) { |
|
86 | + $rotateSize = \OCP\Util::computerFileSize($rotateSize); |
|
87 | + $this->validateRotateSize($rotateSize); |
|
88 | + $toBeSet['log_rotate_size'] = $rotateSize; |
|
89 | + } |
|
90 | + |
|
91 | + // set config |
|
92 | + foreach ($toBeSet as $option => $value) { |
|
93 | + $this->config->setSystemValue($option, $value); |
|
94 | + } |
|
95 | + |
|
96 | + // display config |
|
97 | + // TODO: Drop backwards compatibility for config in the future |
|
98 | + $logType = $this->config->getSystemValue('log_type', 'file'); |
|
99 | + if ($logType === 'file' || $logType === 'owncloud') { |
|
100 | + $enabledText = 'enabled'; |
|
101 | + } else { |
|
102 | + $enabledText = 'disabled'; |
|
103 | + } |
|
104 | + $output->writeln('Log backend file: '.$enabledText); |
|
105 | + |
|
106 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
107 | + $defaultLogFile = rtrim($dataDir, '/').'/nextcloud.log'; |
|
108 | + $output->writeln('Log file: '.$this->config->getSystemValue('logfile', $defaultLogFile)); |
|
109 | + |
|
110 | + $rotateSize = $this->config->getSystemValue('log_rotate_size', 100*1024*1024); |
|
111 | + if ($rotateSize) { |
|
112 | + $rotateString = \OCP\Util::humanFileSize($rotateSize); |
|
113 | + } else { |
|
114 | + $rotateString = 'disabled'; |
|
115 | + } |
|
116 | + $output->writeln('Rotate at: '.$rotateString); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param mixed $rotateSize |
|
121 | + * @throws \InvalidArgumentException |
|
122 | + */ |
|
123 | + protected function validateRotateSize(&$rotateSize) { |
|
124 | + if ($rotateSize === false) { |
|
125 | + throw new \InvalidArgumentException('Error parsing log rotation file size'); |
|
126 | + } |
|
127 | + $rotateSize = (int) $rotateSize; |
|
128 | + if ($rotateSize < 0) { |
|
129 | + throw new \InvalidArgumentException('Log rotation file size must be non-negative'); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $optionName |
|
135 | + * @param CompletionContext $context |
|
136 | + * @return string[] |
|
137 | + */ |
|
138 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
139 | + if ($optionName === 'file') { |
|
140 | + $helper = new ShellPathCompletion( |
|
141 | + $this->getName(), |
|
142 | + 'file', |
|
143 | + Completion::TYPE_OPTION |
|
144 | + ); |
|
145 | + return $helper->run(); |
|
146 | + } elseif ($optionName === 'rotate-size') { |
|
147 | + return [0]; |
|
148 | + } |
|
149 | + return []; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @param string $argumentName |
|
154 | + * @param CompletionContext $context |
|
155 | + * @return string[] |
|
156 | + */ |
|
157 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
158 | + return []; |
|
159 | + } |
|
160 | 160 | } |
@@ -35,18 +35,18 @@ |
||
35 | 35 | */ |
36 | 36 | interface IDiscoveryService { |
37 | 37 | |
38 | - /** |
|
39 | - * Discover OCS end-points |
|
40 | - * |
|
41 | - * If no valid discovery data is found the defaults are returned |
|
42 | - * |
|
43 | - * @since 12.0.0 |
|
44 | - * |
|
45 | - * @param string $remote |
|
46 | - * @param string $service the service you want to discover |
|
47 | - * @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 |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function discover(string $remote, string $service, bool $skipCache = false): array; |
|
38 | + /** |
|
39 | + * Discover OCS end-points |
|
40 | + * |
|
41 | + * If no valid discovery data is found the defaults are returned |
|
42 | + * |
|
43 | + * @since 12.0.0 |
|
44 | + * |
|
45 | + * @param string $remote |
|
46 | + * @param string $service the service you want to discover |
|
47 | + * @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 |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function discover(string $remote, string $service, bool $skipCache = false): array; |
|
51 | 51 | |
52 | 52 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | $query = $this->connection->prepare('SELECT `lock` from `*PREFIX*file_locks` WHERE `key` = ?'); |
156 | 156 | $query->execute([$path]); |
157 | - $lockValue = (int)$query->fetchColumn(); |
|
157 | + $lockValue = (int) $query->fetchColumn(); |
|
158 | 158 | if ($type === self::LOCK_SHARED) { |
159 | 159 | if ($this->isLocallyLocked($path)) { |
160 | 160 | // if we have a shared lock we kept open locally but it's released we always have at least 1 shared lock in the db |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | // since we keep shared locks we need to manually clean those |
293 | 293 | $lockedPaths = array_keys($this->sharedLocks); |
294 | - $lockedPaths = array_filter($lockedPaths, function ($path) { |
|
294 | + $lockedPaths = array_filter($lockedPaths, function($path) { |
|
295 | 295 | return $this->sharedLocks[$path]; |
296 | 296 | }); |
297 | 297 |
@@ -40,279 +40,279 @@ |
||
40 | 40 | * Locking provider that stores the locks in the database |
41 | 41 | */ |
42 | 42 | class DBLockingProvider extends AbstractLockingProvider { |
43 | - /** |
|
44 | - * @var \OCP\IDBConnection |
|
45 | - */ |
|
46 | - private $connection; |
|
43 | + /** |
|
44 | + * @var \OCP\IDBConnection |
|
45 | + */ |
|
46 | + private $connection; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var \OCP\ILogger |
|
50 | - */ |
|
51 | - private $logger; |
|
48 | + /** |
|
49 | + * @var \OCP\ILogger |
|
50 | + */ |
|
51 | + private $logger; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var \OCP\AppFramework\Utility\ITimeFactory |
|
55 | - */ |
|
56 | - private $timeFactory; |
|
53 | + /** |
|
54 | + * @var \OCP\AppFramework\Utility\ITimeFactory |
|
55 | + */ |
|
56 | + private $timeFactory; |
|
57 | 57 | |
58 | - private $sharedLocks = []; |
|
58 | + private $sharedLocks = []; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - private $cacheSharedLocks; |
|
60 | + /** |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + private $cacheSharedLocks; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Check if we have an open shared lock for a path |
|
67 | - * |
|
68 | - * @param string $path |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - protected function isLocallyLocked(string $path): bool { |
|
72 | - return isset($this->sharedLocks[$path]) && $this->sharedLocks[$path]; |
|
73 | - } |
|
65 | + /** |
|
66 | + * Check if we have an open shared lock for a path |
|
67 | + * |
|
68 | + * @param string $path |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + protected function isLocallyLocked(string $path): bool { |
|
72 | + return isset($this->sharedLocks[$path]) && $this->sharedLocks[$path]; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Mark a locally acquired lock |
|
77 | - * |
|
78 | - * @param string $path |
|
79 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
80 | - */ |
|
81 | - protected function markAcquire(string $path, int $type) { |
|
82 | - parent::markAcquire($path, $type); |
|
83 | - if ($this->cacheSharedLocks) { |
|
84 | - if ($type === self::LOCK_SHARED) { |
|
85 | - $this->sharedLocks[$path] = true; |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
75 | + /** |
|
76 | + * Mark a locally acquired lock |
|
77 | + * |
|
78 | + * @param string $path |
|
79 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
80 | + */ |
|
81 | + protected function markAcquire(string $path, int $type) { |
|
82 | + parent::markAcquire($path, $type); |
|
83 | + if ($this->cacheSharedLocks) { |
|
84 | + if ($type === self::LOCK_SHARED) { |
|
85 | + $this->sharedLocks[$path] = true; |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Change the type of an existing tracked lock |
|
92 | - * |
|
93 | - * @param string $path |
|
94 | - * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
95 | - */ |
|
96 | - protected function markChange(string $path, int $targetType) { |
|
97 | - parent::markChange($path, $targetType); |
|
98 | - if ($this->cacheSharedLocks) { |
|
99 | - if ($targetType === self::LOCK_SHARED) { |
|
100 | - $this->sharedLocks[$path] = true; |
|
101 | - } elseif ($targetType === self::LOCK_EXCLUSIVE) { |
|
102 | - $this->sharedLocks[$path] = false; |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
90 | + /** |
|
91 | + * Change the type of an existing tracked lock |
|
92 | + * |
|
93 | + * @param string $path |
|
94 | + * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
95 | + */ |
|
96 | + protected function markChange(string $path, int $targetType) { |
|
97 | + parent::markChange($path, $targetType); |
|
98 | + if ($this->cacheSharedLocks) { |
|
99 | + if ($targetType === self::LOCK_SHARED) { |
|
100 | + $this->sharedLocks[$path] = true; |
|
101 | + } elseif ($targetType === self::LOCK_EXCLUSIVE) { |
|
102 | + $this->sharedLocks[$path] = false; |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @param \OCP\IDBConnection $connection |
|
109 | - * @param \OCP\ILogger $logger |
|
110 | - * @param \OCP\AppFramework\Utility\ITimeFactory $timeFactory |
|
111 | - * @param int $ttl |
|
112 | - * @param bool $cacheSharedLocks |
|
113 | - */ |
|
114 | - public function __construct( |
|
115 | - IDBConnection $connection, |
|
116 | - ILogger $logger, |
|
117 | - ITimeFactory $timeFactory, |
|
118 | - int $ttl = 3600, |
|
119 | - $cacheSharedLocks = true |
|
120 | - ) { |
|
121 | - $this->connection = $connection; |
|
122 | - $this->logger = $logger; |
|
123 | - $this->timeFactory = $timeFactory; |
|
124 | - $this->ttl = $ttl; |
|
125 | - $this->cacheSharedLocks = $cacheSharedLocks; |
|
126 | - } |
|
107 | + /** |
|
108 | + * @param \OCP\IDBConnection $connection |
|
109 | + * @param \OCP\ILogger $logger |
|
110 | + * @param \OCP\AppFramework\Utility\ITimeFactory $timeFactory |
|
111 | + * @param int $ttl |
|
112 | + * @param bool $cacheSharedLocks |
|
113 | + */ |
|
114 | + public function __construct( |
|
115 | + IDBConnection $connection, |
|
116 | + ILogger $logger, |
|
117 | + ITimeFactory $timeFactory, |
|
118 | + int $ttl = 3600, |
|
119 | + $cacheSharedLocks = true |
|
120 | + ) { |
|
121 | + $this->connection = $connection; |
|
122 | + $this->logger = $logger; |
|
123 | + $this->timeFactory = $timeFactory; |
|
124 | + $this->ttl = $ttl; |
|
125 | + $this->cacheSharedLocks = $cacheSharedLocks; |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Insert a file locking row if it does not exists. |
|
130 | - * |
|
131 | - * @param string $path |
|
132 | - * @param int $lock |
|
133 | - * @return int number of inserted rows |
|
134 | - */ |
|
135 | - protected function initLockField(string $path, int $lock = 0): int { |
|
136 | - $expire = $this->getExpireTime(); |
|
137 | - return $this->connection->insertIgnoreConflict('file_locks', [ |
|
138 | - 'key' => $path, |
|
139 | - 'lock' => $lock, |
|
140 | - 'ttl' => $expire |
|
141 | - ]); |
|
142 | - } |
|
128 | + /** |
|
129 | + * Insert a file locking row if it does not exists. |
|
130 | + * |
|
131 | + * @param string $path |
|
132 | + * @param int $lock |
|
133 | + * @return int number of inserted rows |
|
134 | + */ |
|
135 | + protected function initLockField(string $path, int $lock = 0): int { |
|
136 | + $expire = $this->getExpireTime(); |
|
137 | + return $this->connection->insertIgnoreConflict('file_locks', [ |
|
138 | + 'key' => $path, |
|
139 | + 'lock' => $lock, |
|
140 | + 'ttl' => $expire |
|
141 | + ]); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @return int |
|
146 | - */ |
|
147 | - protected function getExpireTime(): int { |
|
148 | - return $this->timeFactory->getTime() + $this->ttl; |
|
149 | - } |
|
144 | + /** |
|
145 | + * @return int |
|
146 | + */ |
|
147 | + protected function getExpireTime(): int { |
|
148 | + return $this->timeFactory->getTime() + $this->ttl; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @param string $path |
|
153 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
154 | - * @return bool |
|
155 | - */ |
|
156 | - public function isLocked(string $path, int $type): bool { |
|
157 | - if ($this->hasAcquiredLock($path, $type)) { |
|
158 | - return true; |
|
159 | - } |
|
160 | - $query = $this->connection->prepare('SELECT `lock` from `*PREFIX*file_locks` WHERE `key` = ?'); |
|
161 | - $query->execute([$path]); |
|
162 | - $lockValue = (int)$query->fetchColumn(); |
|
163 | - if ($type === self::LOCK_SHARED) { |
|
164 | - if ($this->isLocallyLocked($path)) { |
|
165 | - // if we have a shared lock we kept open locally but it's released we always have at least 1 shared lock in the db |
|
166 | - return $lockValue > 1; |
|
167 | - } else { |
|
168 | - return $lockValue > 0; |
|
169 | - } |
|
170 | - } elseif ($type === self::LOCK_EXCLUSIVE) { |
|
171 | - return $lockValue === -1; |
|
172 | - } else { |
|
173 | - return false; |
|
174 | - } |
|
175 | - } |
|
151 | + /** |
|
152 | + * @param string $path |
|
153 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
154 | + * @return bool |
|
155 | + */ |
|
156 | + public function isLocked(string $path, int $type): bool { |
|
157 | + if ($this->hasAcquiredLock($path, $type)) { |
|
158 | + return true; |
|
159 | + } |
|
160 | + $query = $this->connection->prepare('SELECT `lock` from `*PREFIX*file_locks` WHERE `key` = ?'); |
|
161 | + $query->execute([$path]); |
|
162 | + $lockValue = (int)$query->fetchColumn(); |
|
163 | + if ($type === self::LOCK_SHARED) { |
|
164 | + if ($this->isLocallyLocked($path)) { |
|
165 | + // if we have a shared lock we kept open locally but it's released we always have at least 1 shared lock in the db |
|
166 | + return $lockValue > 1; |
|
167 | + } else { |
|
168 | + return $lockValue > 0; |
|
169 | + } |
|
170 | + } elseif ($type === self::LOCK_EXCLUSIVE) { |
|
171 | + return $lockValue === -1; |
|
172 | + } else { |
|
173 | + return false; |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @param string $path |
|
179 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
180 | - * @throws \OCP\Lock\LockedException |
|
181 | - */ |
|
182 | - public function acquireLock(string $path, int $type) { |
|
183 | - $expire = $this->getExpireTime(); |
|
184 | - if ($type === self::LOCK_SHARED) { |
|
185 | - if (!$this->isLocallyLocked($path)) { |
|
186 | - $result = $this->initLockField($path, 1); |
|
187 | - if ($result <= 0) { |
|
188 | - $result = $this->connection->executeUpdate( |
|
189 | - 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` + 1, `ttl` = ? WHERE `key` = ? AND `lock` >= 0', |
|
190 | - [$expire, $path] |
|
191 | - ); |
|
192 | - } |
|
193 | - } else { |
|
194 | - $result = 1; |
|
195 | - } |
|
196 | - } else { |
|
197 | - $existing = 0; |
|
198 | - if ($this->hasAcquiredLock($path, ILockingProvider::LOCK_SHARED) === false && $this->isLocallyLocked($path)) { |
|
199 | - $existing = 1; |
|
200 | - } |
|
201 | - $result = $this->initLockField($path, -1); |
|
202 | - if ($result <= 0) { |
|
203 | - $result = $this->connection->executeUpdate( |
|
204 | - 'UPDATE `*PREFIX*file_locks` SET `lock` = -1, `ttl` = ? WHERE `key` = ? AND `lock` = ?', |
|
205 | - [$expire, $path, $existing] |
|
206 | - ); |
|
207 | - } |
|
208 | - } |
|
209 | - if ($result !== 1) { |
|
210 | - throw new LockedException($path); |
|
211 | - } |
|
212 | - $this->markAcquire($path, $type); |
|
213 | - } |
|
177 | + /** |
|
178 | + * @param string $path |
|
179 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
180 | + * @throws \OCP\Lock\LockedException |
|
181 | + */ |
|
182 | + public function acquireLock(string $path, int $type) { |
|
183 | + $expire = $this->getExpireTime(); |
|
184 | + if ($type === self::LOCK_SHARED) { |
|
185 | + if (!$this->isLocallyLocked($path)) { |
|
186 | + $result = $this->initLockField($path, 1); |
|
187 | + if ($result <= 0) { |
|
188 | + $result = $this->connection->executeUpdate( |
|
189 | + 'UPDATE `*PREFIX*file_locks` SET `lock` = `lock` + 1, `ttl` = ? WHERE `key` = ? AND `lock` >= 0', |
|
190 | + [$expire, $path] |
|
191 | + ); |
|
192 | + } |
|
193 | + } else { |
|
194 | + $result = 1; |
|
195 | + } |
|
196 | + } else { |
|
197 | + $existing = 0; |
|
198 | + if ($this->hasAcquiredLock($path, ILockingProvider::LOCK_SHARED) === false && $this->isLocallyLocked($path)) { |
|
199 | + $existing = 1; |
|
200 | + } |
|
201 | + $result = $this->initLockField($path, -1); |
|
202 | + if ($result <= 0) { |
|
203 | + $result = $this->connection->executeUpdate( |
|
204 | + 'UPDATE `*PREFIX*file_locks` SET `lock` = -1, `ttl` = ? WHERE `key` = ? AND `lock` = ?', |
|
205 | + [$expire, $path, $existing] |
|
206 | + ); |
|
207 | + } |
|
208 | + } |
|
209 | + if ($result !== 1) { |
|
210 | + throw new LockedException($path); |
|
211 | + } |
|
212 | + $this->markAcquire($path, $type); |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * @param string $path |
|
217 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
218 | - * |
|
219 | - * @suppress SqlInjectionChecker |
|
220 | - */ |
|
221 | - public function releaseLock(string $path, int $type) { |
|
222 | - $this->markRelease($path, $type); |
|
215 | + /** |
|
216 | + * @param string $path |
|
217 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
218 | + * |
|
219 | + * @suppress SqlInjectionChecker |
|
220 | + */ |
|
221 | + public function releaseLock(string $path, int $type) { |
|
222 | + $this->markRelease($path, $type); |
|
223 | 223 | |
224 | - // we keep shared locks till the end of the request so we can re-use them |
|
225 | - if ($type === self::LOCK_EXCLUSIVE) { |
|
226 | - $this->connection->executeUpdate( |
|
227 | - 'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = -1', |
|
228 | - [$path] |
|
229 | - ); |
|
230 | - } elseif (!$this->cacheSharedLocks) { |
|
231 | - $query = $this->connection->getQueryBuilder(); |
|
232 | - $query->update('file_locks') |
|
233 | - ->set('lock', $query->func()->subtract('lock', $query->createNamedParameter(1))) |
|
234 | - ->where($query->expr()->eq('key', $query->createNamedParameter($path))) |
|
235 | - ->andWhere($query->expr()->gt('lock', $query->createNamedParameter(0))); |
|
236 | - $query->execute(); |
|
237 | - } |
|
238 | - } |
|
224 | + // we keep shared locks till the end of the request so we can re-use them |
|
225 | + if ($type === self::LOCK_EXCLUSIVE) { |
|
226 | + $this->connection->executeUpdate( |
|
227 | + 'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = -1', |
|
228 | + [$path] |
|
229 | + ); |
|
230 | + } elseif (!$this->cacheSharedLocks) { |
|
231 | + $query = $this->connection->getQueryBuilder(); |
|
232 | + $query->update('file_locks') |
|
233 | + ->set('lock', $query->func()->subtract('lock', $query->createNamedParameter(1))) |
|
234 | + ->where($query->expr()->eq('key', $query->createNamedParameter($path))) |
|
235 | + ->andWhere($query->expr()->gt('lock', $query->createNamedParameter(0))); |
|
236 | + $query->execute(); |
|
237 | + } |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * Change the type of an existing lock |
|
242 | - * |
|
243 | - * @param string $path |
|
244 | - * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
245 | - * @throws \OCP\Lock\LockedException |
|
246 | - */ |
|
247 | - public function changeLock(string $path, int $targetType) { |
|
248 | - $expire = $this->getExpireTime(); |
|
249 | - if ($targetType === self::LOCK_SHARED) { |
|
250 | - $result = $this->connection->executeUpdate( |
|
251 | - 'UPDATE `*PREFIX*file_locks` SET `lock` = 1, `ttl` = ? WHERE `key` = ? AND `lock` = -1', |
|
252 | - [$expire, $path] |
|
253 | - ); |
|
254 | - } else { |
|
255 | - // since we only keep one shared lock in the db we need to check if we have more then one shared lock locally manually |
|
256 | - if (isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 1) { |
|
257 | - throw new LockedException($path); |
|
258 | - } |
|
259 | - $result = $this->connection->executeUpdate( |
|
260 | - 'UPDATE `*PREFIX*file_locks` SET `lock` = -1, `ttl` = ? WHERE `key` = ? AND `lock` = 1', |
|
261 | - [$expire, $path] |
|
262 | - ); |
|
263 | - } |
|
264 | - if ($result !== 1) { |
|
265 | - throw new LockedException($path); |
|
266 | - } |
|
267 | - $this->markChange($path, $targetType); |
|
268 | - } |
|
240 | + /** |
|
241 | + * Change the type of an existing lock |
|
242 | + * |
|
243 | + * @param string $path |
|
244 | + * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
245 | + * @throws \OCP\Lock\LockedException |
|
246 | + */ |
|
247 | + public function changeLock(string $path, int $targetType) { |
|
248 | + $expire = $this->getExpireTime(); |
|
249 | + if ($targetType === self::LOCK_SHARED) { |
|
250 | + $result = $this->connection->executeUpdate( |
|
251 | + 'UPDATE `*PREFIX*file_locks` SET `lock` = 1, `ttl` = ? WHERE `key` = ? AND `lock` = -1', |
|
252 | + [$expire, $path] |
|
253 | + ); |
|
254 | + } else { |
|
255 | + // since we only keep one shared lock in the db we need to check if we have more then one shared lock locally manually |
|
256 | + if (isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 1) { |
|
257 | + throw new LockedException($path); |
|
258 | + } |
|
259 | + $result = $this->connection->executeUpdate( |
|
260 | + 'UPDATE `*PREFIX*file_locks` SET `lock` = -1, `ttl` = ? WHERE `key` = ? AND `lock` = 1', |
|
261 | + [$expire, $path] |
|
262 | + ); |
|
263 | + } |
|
264 | + if ($result !== 1) { |
|
265 | + throw new LockedException($path); |
|
266 | + } |
|
267 | + $this->markChange($path, $targetType); |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * cleanup empty locks |
|
272 | - */ |
|
273 | - public function cleanExpiredLocks() { |
|
274 | - $expire = $this->timeFactory->getTime(); |
|
275 | - try { |
|
276 | - $this->connection->executeUpdate( |
|
277 | - 'DELETE FROM `*PREFIX*file_locks` WHERE `ttl` < ?', |
|
278 | - [$expire] |
|
279 | - ); |
|
280 | - } catch (\Exception $e) { |
|
281 | - // If the table is missing, the clean up was successful |
|
282 | - if ($this->connection->tableExists('file_locks')) { |
|
283 | - throw $e; |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
270 | + /** |
|
271 | + * cleanup empty locks |
|
272 | + */ |
|
273 | + public function cleanExpiredLocks() { |
|
274 | + $expire = $this->timeFactory->getTime(); |
|
275 | + try { |
|
276 | + $this->connection->executeUpdate( |
|
277 | + 'DELETE FROM `*PREFIX*file_locks` WHERE `ttl` < ?', |
|
278 | + [$expire] |
|
279 | + ); |
|
280 | + } catch (\Exception $e) { |
|
281 | + // If the table is missing, the clean up was successful |
|
282 | + if ($this->connection->tableExists('file_locks')) { |
|
283 | + throw $e; |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | 287 | |
288 | - /** |
|
289 | - * release all lock acquired by this instance which were marked using the mark* methods |
|
290 | - * |
|
291 | - * @suppress SqlInjectionChecker |
|
292 | - */ |
|
293 | - public function releaseAll() { |
|
294 | - parent::releaseAll(); |
|
288 | + /** |
|
289 | + * release all lock acquired by this instance which were marked using the mark* methods |
|
290 | + * |
|
291 | + * @suppress SqlInjectionChecker |
|
292 | + */ |
|
293 | + public function releaseAll() { |
|
294 | + parent::releaseAll(); |
|
295 | 295 | |
296 | - if (!$this->cacheSharedLocks) { |
|
297 | - return; |
|
298 | - } |
|
299 | - // since we keep shared locks we need to manually clean those |
|
300 | - $lockedPaths = array_keys($this->sharedLocks); |
|
301 | - $lockedPaths = array_filter($lockedPaths, function ($path) { |
|
302 | - return $this->sharedLocks[$path]; |
|
303 | - }); |
|
296 | + if (!$this->cacheSharedLocks) { |
|
297 | + return; |
|
298 | + } |
|
299 | + // since we keep shared locks we need to manually clean those |
|
300 | + $lockedPaths = array_keys($this->sharedLocks); |
|
301 | + $lockedPaths = array_filter($lockedPaths, function ($path) { |
|
302 | + return $this->sharedLocks[$path]; |
|
303 | + }); |
|
304 | 304 | |
305 | - $chunkedPaths = array_chunk($lockedPaths, 100); |
|
305 | + $chunkedPaths = array_chunk($lockedPaths, 100); |
|
306 | 306 | |
307 | - foreach ($chunkedPaths as $chunk) { |
|
308 | - $builder = $this->connection->getQueryBuilder(); |
|
307 | + foreach ($chunkedPaths as $chunk) { |
|
308 | + $builder = $this->connection->getQueryBuilder(); |
|
309 | 309 | |
310 | - $query = $builder->update('file_locks') |
|
311 | - ->set('lock', $builder->func()->subtract('lock', $builder->expr()->literal(1))) |
|
312 | - ->where($builder->expr()->in('key', $builder->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY))) |
|
313 | - ->andWhere($builder->expr()->gt('lock', new Literal(0))); |
|
310 | + $query = $builder->update('file_locks') |
|
311 | + ->set('lock', $builder->func()->subtract('lock', $builder->expr()->literal(1))) |
|
312 | + ->where($builder->expr()->in('key', $builder->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY))) |
|
313 | + ->andWhere($builder->expr()->gt('lock', new Literal(0))); |
|
314 | 314 | |
315 | - $query->execute(); |
|
316 | - } |
|
317 | - } |
|
315 | + $query->execute(); |
|
316 | + } |
|
317 | + } |
|
318 | 318 | } |