@@ -33,37 +33,37 @@ |
||
33 | 33 | * Map a user to a bucket. |
34 | 34 | */ |
35 | 35 | class Mapper { |
36 | - /** @var IUser */ |
|
37 | - private $user; |
|
36 | + /** @var IUser */ |
|
37 | + private $user; |
|
38 | 38 | |
39 | - /** @var IConfig */ |
|
40 | - private $config; |
|
39 | + /** @var IConfig */ |
|
40 | + private $config; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Mapper constructor. |
|
44 | - * |
|
45 | - * @param IUser $user |
|
46 | - * @param IConfig $config |
|
47 | - */ |
|
48 | - public function __construct(IUser $user, IConfig $config) { |
|
49 | - $this->user = $user; |
|
50 | - $this->config = $config; |
|
51 | - } |
|
42 | + /** |
|
43 | + * Mapper constructor. |
|
44 | + * |
|
45 | + * @param IUser $user |
|
46 | + * @param IConfig $config |
|
47 | + */ |
|
48 | + public function __construct(IUser $user, IConfig $config) { |
|
49 | + $this->user = $user; |
|
50 | + $this->config = $config; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param int $numBuckets |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function getBucket($numBuckets = 64) { |
|
58 | - // Get the bucket config and shift if provided. |
|
59 | - // Allow us to prevent writing in old filled buckets |
|
60 | - $config = $this->config->getSystemValue('objectstore_multibucket'); |
|
61 | - $minBucket = is_array($config) && isset($config['arguments']['min_bucket']) |
|
62 | - ? (int)$config['arguments']['min_bucket'] |
|
63 | - : 0; |
|
53 | + /** |
|
54 | + * @param int $numBuckets |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function getBucket($numBuckets = 64) { |
|
58 | + // Get the bucket config and shift if provided. |
|
59 | + // Allow us to prevent writing in old filled buckets |
|
60 | + $config = $this->config->getSystemValue('objectstore_multibucket'); |
|
61 | + $minBucket = is_array($config) && isset($config['arguments']['min_bucket']) |
|
62 | + ? (int)$config['arguments']['min_bucket'] |
|
63 | + : 0; |
|
64 | 64 | |
65 | - $hash = md5($this->user->getUID()); |
|
66 | - $num = hexdec(substr($hash, 0, 4)); |
|
67 | - return (string)(($num % ($numBuckets - $minBucket)) + $minBucket); |
|
68 | - } |
|
65 | + $hash = md5($this->user->getUID()); |
|
66 | + $num = hexdec(substr($hash, 0, 4)); |
|
67 | + return (string)(($num % ($numBuckets - $minBucket)) + $minBucket); |
|
68 | + } |
|
69 | 69 | } |
@@ -33,60 +33,60 @@ |
||
33 | 33 | use OCP\Files\SimpleFS\ISimpleFolder; |
34 | 34 | |
35 | 35 | class Root extends AppData { |
36 | - private $isMultibucketPreviewDistributionEnabled = false; |
|
37 | - public function __construct(IRootFolder $rootFolder, SystemConfig $systemConfig) { |
|
38 | - parent::__construct($rootFolder, $systemConfig, 'preview'); |
|
36 | + private $isMultibucketPreviewDistributionEnabled = false; |
|
37 | + public function __construct(IRootFolder $rootFolder, SystemConfig $systemConfig) { |
|
38 | + parent::__construct($rootFolder, $systemConfig, 'preview'); |
|
39 | 39 | |
40 | - $this->isMultibucketPreviewDistributionEnabled = $systemConfig->getValue('objectstore.multibucket.preview-distribution', false) === true; |
|
41 | - } |
|
40 | + $this->isMultibucketPreviewDistributionEnabled = $systemConfig->getValue('objectstore.multibucket.preview-distribution', false) === true; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - public function getFolder(string $name): ISimpleFolder { |
|
45 | - $internalFolder = self::getInternalFolder($name); |
|
44 | + public function getFolder(string $name): ISimpleFolder { |
|
45 | + $internalFolder = self::getInternalFolder($name); |
|
46 | 46 | |
47 | - try { |
|
48 | - return parent::getFolder($internalFolder); |
|
49 | - } catch (NotFoundException $e) { |
|
50 | - /* |
|
47 | + try { |
|
48 | + return parent::getFolder($internalFolder); |
|
49 | + } catch (NotFoundException $e) { |
|
50 | + /* |
|
51 | 51 | * The new folder structure is not found. |
52 | 52 | * Lets try the old one |
53 | 53 | */ |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - try { |
|
57 | - return parent::getFolder($name); |
|
58 | - } catch (NotFoundException $e) { |
|
59 | - /* |
|
56 | + try { |
|
57 | + return parent::getFolder($name); |
|
58 | + } catch (NotFoundException $e) { |
|
59 | + /* |
|
60 | 60 | * The old folder structure is not found. |
61 | 61 | * Lets try the multibucket fallback if available |
62 | 62 | */ |
63 | - if ($this->isMultibucketPreviewDistributionEnabled) { |
|
64 | - return parent::getFolder('old-multibucket/' . $internalFolder); |
|
65 | - } |
|
63 | + if ($this->isMultibucketPreviewDistributionEnabled) { |
|
64 | + return parent::getFolder('old-multibucket/' . $internalFolder); |
|
65 | + } |
|
66 | 66 | |
67 | - // when there is no further fallback just throw the exception |
|
68 | - throw $e; |
|
69 | - } |
|
70 | - } |
|
67 | + // when there is no further fallback just throw the exception |
|
68 | + throw $e; |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - public function newFolder(string $name): ISimpleFolder { |
|
73 | - $internalFolder = self::getInternalFolder($name); |
|
74 | - return parent::newFolder($internalFolder); |
|
75 | - } |
|
72 | + public function newFolder(string $name): ISimpleFolder { |
|
73 | + $internalFolder = self::getInternalFolder($name); |
|
74 | + return parent::newFolder($internalFolder); |
|
75 | + } |
|
76 | 76 | |
77 | - /* |
|
77 | + /* |
|
78 | 78 | * Do not allow directory listing on this special root |
79 | 79 | * since it gets to big and time consuming |
80 | 80 | */ |
81 | - public function getDirectoryListing(): array { |
|
82 | - return []; |
|
83 | - } |
|
81 | + public function getDirectoryListing(): array { |
|
82 | + return []; |
|
83 | + } |
|
84 | 84 | |
85 | - public static function getInternalFolder(string $name): string { |
|
86 | - return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name; |
|
87 | - } |
|
85 | + public static function getInternalFolder(string $name): string { |
|
86 | + return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name; |
|
87 | + } |
|
88 | 88 | |
89 | - public function getStorageId(): int { |
|
90 | - return $this->getAppDataRootFolder()->getStorage()->getCache()->getNumericStorageId(); |
|
91 | - } |
|
89 | + public function getStorageId(): int { |
|
90 | + return $this->getAppDataRootFolder()->getStorage()->getCache()->getNumericStorageId(); |
|
91 | + } |
|
92 | 92 | } |
@@ -32,23 +32,23 @@ |
||
32 | 32 | use OCP\Migration\SimpleMigrationStep; |
33 | 33 | |
34 | 34 | class Version23000Date20211203110726 extends SimpleMigrationStep { |
35 | - private const TABLE_NAME = 'profile_config'; |
|
35 | + private const TABLE_NAME = 'profile_config'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IOutput $output |
|
39 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
40 | - * @param array $options |
|
41 | - * @return null|ISchemaWrapper |
|
42 | - */ |
|
43 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
44 | - /** @var ISchemaWrapper $schema */ |
|
45 | - $schema = $schemaClosure(); |
|
37 | + /** |
|
38 | + * @param IOutput $output |
|
39 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
40 | + * @param array $options |
|
41 | + * @return null|ISchemaWrapper |
|
42 | + */ |
|
43 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
44 | + /** @var ISchemaWrapper $schema */ |
|
45 | + $schema = $schemaClosure(); |
|
46 | 46 | |
47 | - $table = $schema->getTable(self::TABLE_NAME); |
|
48 | - if ($table->hasIndex('user_id')) { |
|
49 | - $table->renameIndex('user_id', self::TABLE_NAME . '_user_id_idx'); |
|
50 | - return $schema; |
|
51 | - } |
|
52 | - return null; |
|
53 | - } |
|
47 | + $table = $schema->getTable(self::TABLE_NAME); |
|
48 | + if ($table->hasIndex('user_id')) { |
|
49 | + $table->renameIndex('user_id', self::TABLE_NAME . '_user_id_idx'); |
|
50 | + return $schema; |
|
51 | + } |
|
52 | + return null; |
|
53 | + } |
|
54 | 54 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | * Defines the public facing principal option |
32 | 32 | */ |
33 | 33 | class PublicPrincipalPlugin extends Plugin { |
34 | - public function getCurrentPrincipal(): ?string { |
|
35 | - return 'principals/system/public'; |
|
36 | - } |
|
34 | + public function getCurrentPrincipal(): ?string { |
|
35 | + return 'principals/system/public'; |
|
36 | + } |
|
37 | 37 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * Set a custom principal uri to allow public requests to its calendar |
33 | 33 | */ |
34 | 34 | class CustomPrincipalPlugin extends Plugin { |
35 | - public function setCurrentPrincipal(?string $currentPrincipal): void { |
|
36 | - $this->currentPrincipal = $currentPrincipal; |
|
37 | - } |
|
35 | + public function setCurrentPrincipal(?string $currentPrincipal): void { |
|
36 | + $this->currentPrincipal = $currentPrincipal; |
|
37 | + } |
|
38 | 38 | } |
@@ -27,18 +27,18 @@ |
||
27 | 27 | namespace OCA\User_LDAP\PagedResults; |
28 | 28 | |
29 | 29 | trait TLinkId { |
30 | - public function getLinkId($link) { |
|
31 | - if (is_object($link)) { |
|
32 | - return spl_object_id($link); |
|
33 | - } elseif (is_resource($link)) { |
|
34 | - return (int)$link; |
|
35 | - } elseif (is_array($link) && isset($link[0])) { |
|
36 | - if (is_object($link[0])) { |
|
37 | - return spl_object_id($link[0]); |
|
38 | - } elseif (is_resource($link[0])) { |
|
39 | - return (int)$link[0]; |
|
40 | - } |
|
41 | - } |
|
42 | - throw new \RuntimeException('No resource provided'); |
|
43 | - } |
|
30 | + public function getLinkId($link) { |
|
31 | + if (is_object($link)) { |
|
32 | + return spl_object_id($link); |
|
33 | + } elseif (is_resource($link)) { |
|
34 | + return (int)$link; |
|
35 | + } elseif (is_array($link) && isset($link[0])) { |
|
36 | + if (is_object($link[0])) { |
|
37 | + return spl_object_id($link[0]); |
|
38 | + } elseif (is_resource($link[0])) { |
|
39 | + return (int)$link[0]; |
|
40 | + } |
|
41 | + } |
|
42 | + throw new \RuntimeException('No resource provided'); |
|
43 | + } |
|
44 | 44 | } |
@@ -39,117 +39,117 @@ |
||
39 | 39 | |
40 | 40 | class Version2000Date20190808074233 extends SimpleMigrationStep { |
41 | 41 | |
42 | - /** |
|
43 | - * @param IOutput $output |
|
44 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
45 | - * @param array $options |
|
46 | - * @return null|ISchemaWrapper |
|
47 | - */ |
|
48 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
49 | - /** @var ISchemaWrapper $schema */ |
|
50 | - $schema = $schemaClosure(); |
|
42 | + /** |
|
43 | + * @param IOutput $output |
|
44 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
45 | + * @param array $options |
|
46 | + * @return null|ISchemaWrapper |
|
47 | + */ |
|
48 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
49 | + /** @var ISchemaWrapper $schema */ |
|
50 | + $schema = $schemaClosure(); |
|
51 | 51 | |
52 | - if (!$schema->hasTable('flow_checks')) { |
|
53 | - $table = $schema->createTable('flow_checks'); |
|
54 | - $table->addColumn('id', Types::INTEGER, [ |
|
55 | - 'autoincrement' => true, |
|
56 | - 'notnull' => true, |
|
57 | - 'length' => 4, |
|
58 | - ]); |
|
59 | - $table->addColumn('class', Types::STRING, [ |
|
60 | - 'notnull' => true, |
|
61 | - 'length' => 256, |
|
62 | - 'default' => '', |
|
63 | - ]); |
|
64 | - $table->addColumn('operator', Types::STRING, [ |
|
65 | - 'notnull' => true, |
|
66 | - 'length' => 16, |
|
67 | - 'default' => '', |
|
68 | - ]); |
|
69 | - $table->addColumn('value', Types::TEXT, [ |
|
70 | - 'notnull' => false, |
|
71 | - ]); |
|
72 | - $table->addColumn('hash', Types::STRING, [ |
|
73 | - 'notnull' => true, |
|
74 | - 'length' => 32, |
|
75 | - 'default' => '', |
|
76 | - ]); |
|
77 | - $table->setPrimaryKey(['id']); |
|
78 | - $table->addUniqueIndex(['hash'], 'flow_unique_hash'); |
|
79 | - } |
|
52 | + if (!$schema->hasTable('flow_checks')) { |
|
53 | + $table = $schema->createTable('flow_checks'); |
|
54 | + $table->addColumn('id', Types::INTEGER, [ |
|
55 | + 'autoincrement' => true, |
|
56 | + 'notnull' => true, |
|
57 | + 'length' => 4, |
|
58 | + ]); |
|
59 | + $table->addColumn('class', Types::STRING, [ |
|
60 | + 'notnull' => true, |
|
61 | + 'length' => 256, |
|
62 | + 'default' => '', |
|
63 | + ]); |
|
64 | + $table->addColumn('operator', Types::STRING, [ |
|
65 | + 'notnull' => true, |
|
66 | + 'length' => 16, |
|
67 | + 'default' => '', |
|
68 | + ]); |
|
69 | + $table->addColumn('value', Types::TEXT, [ |
|
70 | + 'notnull' => false, |
|
71 | + ]); |
|
72 | + $table->addColumn('hash', Types::STRING, [ |
|
73 | + 'notnull' => true, |
|
74 | + 'length' => 32, |
|
75 | + 'default' => '', |
|
76 | + ]); |
|
77 | + $table->setPrimaryKey(['id']); |
|
78 | + $table->addUniqueIndex(['hash'], 'flow_unique_hash'); |
|
79 | + } |
|
80 | 80 | |
81 | - if (!$schema->hasTable('flow_operations')) { |
|
82 | - $table = $schema->createTable('flow_operations'); |
|
83 | - $table->addColumn('id', Types::INTEGER, [ |
|
84 | - 'autoincrement' => true, |
|
85 | - 'notnull' => true, |
|
86 | - 'length' => 4, |
|
87 | - ]); |
|
88 | - $table->addColumn('class', Types::STRING, [ |
|
89 | - 'notnull' => true, |
|
90 | - 'length' => 256, |
|
91 | - 'default' => '', |
|
92 | - ]); |
|
93 | - $table->addColumn('name', Types::STRING, [ |
|
94 | - 'notnull' => false, |
|
95 | - 'length' => 256, |
|
96 | - 'default' => '', |
|
97 | - ]); |
|
98 | - $table->addColumn('checks', Types::TEXT, [ |
|
99 | - 'notnull' => false, |
|
100 | - ]); |
|
101 | - $table->addColumn('operation', Types::TEXT, [ |
|
102 | - 'notnull' => false, |
|
103 | - ]); |
|
104 | - $this->ensureEntityColumns($table); |
|
105 | - $table->setPrimaryKey(['id']); |
|
106 | - } else { |
|
107 | - $table = $schema->getTable('flow_operations'); |
|
108 | - $this->ensureEntityColumns($table); |
|
109 | - } |
|
81 | + if (!$schema->hasTable('flow_operations')) { |
|
82 | + $table = $schema->createTable('flow_operations'); |
|
83 | + $table->addColumn('id', Types::INTEGER, [ |
|
84 | + 'autoincrement' => true, |
|
85 | + 'notnull' => true, |
|
86 | + 'length' => 4, |
|
87 | + ]); |
|
88 | + $table->addColumn('class', Types::STRING, [ |
|
89 | + 'notnull' => true, |
|
90 | + 'length' => 256, |
|
91 | + 'default' => '', |
|
92 | + ]); |
|
93 | + $table->addColumn('name', Types::STRING, [ |
|
94 | + 'notnull' => false, |
|
95 | + 'length' => 256, |
|
96 | + 'default' => '', |
|
97 | + ]); |
|
98 | + $table->addColumn('checks', Types::TEXT, [ |
|
99 | + 'notnull' => false, |
|
100 | + ]); |
|
101 | + $table->addColumn('operation', Types::TEXT, [ |
|
102 | + 'notnull' => false, |
|
103 | + ]); |
|
104 | + $this->ensureEntityColumns($table); |
|
105 | + $table->setPrimaryKey(['id']); |
|
106 | + } else { |
|
107 | + $table = $schema->getTable('flow_operations'); |
|
108 | + $this->ensureEntityColumns($table); |
|
109 | + } |
|
110 | 110 | |
111 | - if (!$schema->hasTable('flow_operations_scope')) { |
|
112 | - $table = $schema->createTable('flow_operations_scope'); |
|
113 | - $table->addColumn('id', Types::BIGINT, [ |
|
114 | - 'autoincrement' => true, |
|
115 | - 'notnull' => true, |
|
116 | - 'length' => 4, |
|
117 | - ]); |
|
118 | - $table->addColumn('operation_id', Types::INTEGER, [ |
|
119 | - 'notnull' => true, |
|
120 | - 'length' => 4, |
|
121 | - 'default' => 0, |
|
122 | - ]); |
|
123 | - $table->addColumn('type', Types::INTEGER, [ |
|
124 | - 'notnull' => true, |
|
125 | - 'length' => 4, |
|
126 | - 'default' => 0, |
|
127 | - ]); |
|
128 | - $table->addColumn('value', Types::STRING, [ |
|
129 | - 'notnull' => false, |
|
130 | - 'length' => 64, |
|
131 | - 'default' => '', |
|
132 | - ]); |
|
133 | - $table->setPrimaryKey(['id']); |
|
134 | - $table->addUniqueIndex(['operation_id', 'type', 'value'], 'flow_unique_scope'); |
|
135 | - } |
|
111 | + if (!$schema->hasTable('flow_operations_scope')) { |
|
112 | + $table = $schema->createTable('flow_operations_scope'); |
|
113 | + $table->addColumn('id', Types::BIGINT, [ |
|
114 | + 'autoincrement' => true, |
|
115 | + 'notnull' => true, |
|
116 | + 'length' => 4, |
|
117 | + ]); |
|
118 | + $table->addColumn('operation_id', Types::INTEGER, [ |
|
119 | + 'notnull' => true, |
|
120 | + 'length' => 4, |
|
121 | + 'default' => 0, |
|
122 | + ]); |
|
123 | + $table->addColumn('type', Types::INTEGER, [ |
|
124 | + 'notnull' => true, |
|
125 | + 'length' => 4, |
|
126 | + 'default' => 0, |
|
127 | + ]); |
|
128 | + $table->addColumn('value', Types::STRING, [ |
|
129 | + 'notnull' => false, |
|
130 | + 'length' => 64, |
|
131 | + 'default' => '', |
|
132 | + ]); |
|
133 | + $table->setPrimaryKey(['id']); |
|
134 | + $table->addUniqueIndex(['operation_id', 'type', 'value'], 'flow_unique_scope'); |
|
135 | + } |
|
136 | 136 | |
137 | - return $schema; |
|
138 | - } |
|
137 | + return $schema; |
|
138 | + } |
|
139 | 139 | |
140 | - protected function ensureEntityColumns(Table $table) { |
|
141 | - if (!$table->hasColumn('entity')) { |
|
142 | - $table->addColumn('entity', Types::STRING, [ |
|
143 | - 'notnull' => true, |
|
144 | - 'length' => 256, |
|
145 | - 'default' => File::class, |
|
146 | - ]); |
|
147 | - } |
|
148 | - if (!$table->hasColumn('events')) { |
|
149 | - $table->addColumn('events', Types::TEXT, [ |
|
150 | - 'notnull' => true, |
|
151 | - 'default' => '[]', |
|
152 | - ]); |
|
153 | - } |
|
154 | - } |
|
140 | + protected function ensureEntityColumns(Table $table) { |
|
141 | + if (!$table->hasColumn('entity')) { |
|
142 | + $table->addColumn('entity', Types::STRING, [ |
|
143 | + 'notnull' => true, |
|
144 | + 'length' => 256, |
|
145 | + 'default' => File::class, |
|
146 | + ]); |
|
147 | + } |
|
148 | + if (!$table->hasColumn('events')) { |
|
149 | + $table->addColumn('events', Types::TEXT, [ |
|
150 | + 'notnull' => true, |
|
151 | + 'default' => '[]', |
|
152 | + ]); |
|
153 | + } |
|
154 | + } |
|
155 | 155 | } |
@@ -32,23 +32,23 @@ |
||
32 | 32 | |
33 | 33 | class Version2200Date20210805101925 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | 44 | |
45 | - if ($schema->hasTable('flow_operations')) { |
|
46 | - $table = $schema->getTable('flow_operations'); |
|
47 | - $table->changeColumn('name', [ |
|
48 | - 'notnull' => false, |
|
49 | - ]); |
|
50 | - } |
|
45 | + if ($schema->hasTable('flow_operations')) { |
|
46 | + $table = $schema->getTable('flow_operations'); |
|
47 | + $table->changeColumn('name', [ |
|
48 | + 'notnull' => false, |
|
49 | + ]); |
|
50 | + } |
|
51 | 51 | |
52 | - return $schema; |
|
53 | - } |
|
52 | + return $schema; |
|
53 | + } |
|
54 | 54 | } |
@@ -23,20 +23,20 @@ |
||
23 | 23 | namespace OCA\DAV\Connector\Sabre; |
24 | 24 | |
25 | 25 | class MtimeSanitizer { |
26 | - public static function sanitizeMtime(string $mtimeFromRequest): int { |
|
27 | - // In PHP 5.X "is_numeric" returns true for strings in hexadecimal |
|
28 | - // notation. This is no longer the case in PHP 7.X, so this check |
|
29 | - // ensures that strings with hexadecimal notations fail too in PHP 5.X. |
|
30 | - $isHexadecimal = preg_match('/^\s*0[xX]/', $mtimeFromRequest); |
|
31 | - if ($isHexadecimal || !is_numeric($mtimeFromRequest)) { |
|
32 | - throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).'); |
|
33 | - } |
|
26 | + public static function sanitizeMtime(string $mtimeFromRequest): int { |
|
27 | + // In PHP 5.X "is_numeric" returns true for strings in hexadecimal |
|
28 | + // notation. This is no longer the case in PHP 7.X, so this check |
|
29 | + // ensures that strings with hexadecimal notations fail too in PHP 5.X. |
|
30 | + $isHexadecimal = preg_match('/^\s*0[xX]/', $mtimeFromRequest); |
|
31 | + if ($isHexadecimal || !is_numeric($mtimeFromRequest)) { |
|
32 | + throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).'); |
|
33 | + } |
|
34 | 34 | |
35 | - // Prevent writing invalid mtime (timezone-proof) |
|
36 | - if ((int)$mtimeFromRequest <= 24 * 60 * 60) { |
|
37 | - throw new \InvalidArgumentException('X-OC-MTime header must be a valid positive integer'); |
|
38 | - } |
|
35 | + // Prevent writing invalid mtime (timezone-proof) |
|
36 | + if ((int)$mtimeFromRequest <= 24 * 60 * 60) { |
|
37 | + throw new \InvalidArgumentException('X-OC-MTime header must be a valid positive integer'); |
|
38 | + } |
|
39 | 39 | |
40 | - return (int)$mtimeFromRequest; |
|
41 | - } |
|
40 | + return (int)$mtimeFromRequest; |
|
41 | + } |
|
42 | 42 | } |