@@ -37,122 +37,122 @@ |
||
37 | 37 | * Note that the read permissions can't be masked |
38 | 38 | */ |
39 | 39 | class PermissionsMask extends Wrapper { |
40 | - /** |
|
41 | - * @var int the permissions bits we want to keep |
|
42 | - */ |
|
43 | - private $mask; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array $arguments ['storage' => $storage, 'mask' => $mask] |
|
47 | - * |
|
48 | - * $storage: The storage the permissions mask should be applied on |
|
49 | - * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants |
|
50 | - */ |
|
51 | - public function __construct($arguments) { |
|
52 | - parent::__construct($arguments); |
|
53 | - $this->mask = $arguments['mask']; |
|
54 | - } |
|
55 | - |
|
56 | - private function checkMask($permissions) { |
|
57 | - return ($this->mask & $permissions) === $permissions; |
|
58 | - } |
|
59 | - |
|
60 | - public function isUpdatable($path) { |
|
61 | - return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); |
|
62 | - } |
|
63 | - |
|
64 | - public function isCreatable($path) { |
|
65 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); |
|
66 | - } |
|
67 | - |
|
68 | - public function isDeletable($path) { |
|
69 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); |
|
70 | - } |
|
71 | - |
|
72 | - public function isSharable($path) { |
|
73 | - return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); |
|
74 | - } |
|
75 | - |
|
76 | - public function getPermissions($path) { |
|
77 | - return $this->storage->getPermissions($path) & $this->mask; |
|
78 | - } |
|
79 | - |
|
80 | - public function rename($path1, $path2) { |
|
81 | - $p = strpos($path1, $path2); |
|
82 | - if ($p === 0) { |
|
83 | - $part = substr($path1, strlen($path2)); |
|
84 | - //This is a rename of the transfer file to the original file |
|
85 | - if (strpos($part, '.ocTransferId') === 0) { |
|
86 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2); |
|
87 | - } |
|
88 | - } |
|
89 | - return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2); |
|
90 | - } |
|
91 | - |
|
92 | - public function copy($path1, $path2) { |
|
93 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2); |
|
94 | - } |
|
95 | - |
|
96 | - public function touch($path, $mtime = null) { |
|
97 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
98 | - return $this->checkMask($permissions) and parent::touch($path, $mtime); |
|
99 | - } |
|
100 | - |
|
101 | - public function mkdir($path) { |
|
102 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); |
|
103 | - } |
|
104 | - |
|
105 | - public function rmdir($path) { |
|
106 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); |
|
107 | - } |
|
108 | - |
|
109 | - public function unlink($path) { |
|
110 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); |
|
111 | - } |
|
112 | - |
|
113 | - public function file_put_contents($path, $data) { |
|
114 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
115 | - return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; |
|
116 | - } |
|
117 | - |
|
118 | - public function fopen($path, $mode) { |
|
119 | - if ($mode === 'r' or $mode === 'rb') { |
|
120 | - return parent::fopen($path, $mode); |
|
121 | - } else { |
|
122 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
123 | - return $this->checkMask($permissions) ? parent::fopen($path, $mode) : false; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * get a cache instance for the storage |
|
129 | - * |
|
130 | - * @param string $path |
|
131 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
132 | - * @return \OC\Files\Cache\Cache |
|
133 | - */ |
|
134 | - public function getCache($path = '', $storage = null) { |
|
135 | - if (!$storage) { |
|
136 | - $storage = $this; |
|
137 | - } |
|
138 | - $sourceCache = parent::getCache($path, $storage); |
|
139 | - return new CachePermissionsMask($sourceCache, $this->mask); |
|
140 | - } |
|
141 | - |
|
142 | - public function getMetaData($path) { |
|
143 | - $data = parent::getMetaData($path); |
|
144 | - |
|
145 | - if ($data && isset($data['permissions'])) { |
|
146 | - $data['scan_permissions'] = isset($data['scan_permissions']) ? $data['scan_permissions'] : $data['permissions']; |
|
147 | - $data['permissions'] &= $this->mask; |
|
148 | - } |
|
149 | - return $data; |
|
150 | - } |
|
151 | - |
|
152 | - public function getScanner($path = '', $storage = null) { |
|
153 | - if (!$storage) { |
|
154 | - $storage = $this->storage; |
|
155 | - } |
|
156 | - return parent::getScanner($path, $storage); |
|
157 | - } |
|
40 | + /** |
|
41 | + * @var int the permissions bits we want to keep |
|
42 | + */ |
|
43 | + private $mask; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array $arguments ['storage' => $storage, 'mask' => $mask] |
|
47 | + * |
|
48 | + * $storage: The storage the permissions mask should be applied on |
|
49 | + * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants |
|
50 | + */ |
|
51 | + public function __construct($arguments) { |
|
52 | + parent::__construct($arguments); |
|
53 | + $this->mask = $arguments['mask']; |
|
54 | + } |
|
55 | + |
|
56 | + private function checkMask($permissions) { |
|
57 | + return ($this->mask & $permissions) === $permissions; |
|
58 | + } |
|
59 | + |
|
60 | + public function isUpdatable($path) { |
|
61 | + return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); |
|
62 | + } |
|
63 | + |
|
64 | + public function isCreatable($path) { |
|
65 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); |
|
66 | + } |
|
67 | + |
|
68 | + public function isDeletable($path) { |
|
69 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); |
|
70 | + } |
|
71 | + |
|
72 | + public function isSharable($path) { |
|
73 | + return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); |
|
74 | + } |
|
75 | + |
|
76 | + public function getPermissions($path) { |
|
77 | + return $this->storage->getPermissions($path) & $this->mask; |
|
78 | + } |
|
79 | + |
|
80 | + public function rename($path1, $path2) { |
|
81 | + $p = strpos($path1, $path2); |
|
82 | + if ($p === 0) { |
|
83 | + $part = substr($path1, strlen($path2)); |
|
84 | + //This is a rename of the transfer file to the original file |
|
85 | + if (strpos($part, '.ocTransferId') === 0) { |
|
86 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2); |
|
87 | + } |
|
88 | + } |
|
89 | + return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2); |
|
90 | + } |
|
91 | + |
|
92 | + public function copy($path1, $path2) { |
|
93 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2); |
|
94 | + } |
|
95 | + |
|
96 | + public function touch($path, $mtime = null) { |
|
97 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
98 | + return $this->checkMask($permissions) and parent::touch($path, $mtime); |
|
99 | + } |
|
100 | + |
|
101 | + public function mkdir($path) { |
|
102 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); |
|
103 | + } |
|
104 | + |
|
105 | + public function rmdir($path) { |
|
106 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); |
|
107 | + } |
|
108 | + |
|
109 | + public function unlink($path) { |
|
110 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); |
|
111 | + } |
|
112 | + |
|
113 | + public function file_put_contents($path, $data) { |
|
114 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
115 | + return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; |
|
116 | + } |
|
117 | + |
|
118 | + public function fopen($path, $mode) { |
|
119 | + if ($mode === 'r' or $mode === 'rb') { |
|
120 | + return parent::fopen($path, $mode); |
|
121 | + } else { |
|
122 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
123 | + return $this->checkMask($permissions) ? parent::fopen($path, $mode) : false; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * get a cache instance for the storage |
|
129 | + * |
|
130 | + * @param string $path |
|
131 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
132 | + * @return \OC\Files\Cache\Cache |
|
133 | + */ |
|
134 | + public function getCache($path = '', $storage = null) { |
|
135 | + if (!$storage) { |
|
136 | + $storage = $this; |
|
137 | + } |
|
138 | + $sourceCache = parent::getCache($path, $storage); |
|
139 | + return new CachePermissionsMask($sourceCache, $this->mask); |
|
140 | + } |
|
141 | + |
|
142 | + public function getMetaData($path) { |
|
143 | + $data = parent::getMetaData($path); |
|
144 | + |
|
145 | + if ($data && isset($data['permissions'])) { |
|
146 | + $data['scan_permissions'] = isset($data['scan_permissions']) ? $data['scan_permissions'] : $data['permissions']; |
|
147 | + $data['permissions'] &= $this->mask; |
|
148 | + } |
|
149 | + return $data; |
|
150 | + } |
|
151 | + |
|
152 | + public function getScanner($path = '', $storage = null) { |
|
153 | + if (!$storage) { |
|
154 | + $storage = $this->storage; |
|
155 | + } |
|
156 | + return parent::getScanner($path, $storage); |
|
157 | + } |
|
158 | 158 | } |
@@ -29,68 +29,68 @@ |
||
29 | 29 | use OCP\Diagnostics\IQueryLogger; |
30 | 30 | |
31 | 31 | class QueryLogger implements IQueryLogger { |
32 | - /** |
|
33 | - * @var \OC\Diagnostics\Query |
|
34 | - */ |
|
35 | - protected $activeQuery; |
|
32 | + /** |
|
33 | + * @var \OC\Diagnostics\Query |
|
34 | + */ |
|
35 | + protected $activeQuery; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var CappedMemoryCache |
|
39 | - */ |
|
40 | - protected $queries; |
|
37 | + /** |
|
38 | + * @var CappedMemoryCache |
|
39 | + */ |
|
40 | + protected $queries; |
|
41 | 41 | |
42 | - /** |
|
43 | - * QueryLogger constructor. |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - $this->queries = new CappedMemoryCache(1024); |
|
47 | - } |
|
42 | + /** |
|
43 | + * QueryLogger constructor. |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + $this->queries = new CappedMemoryCache(1024); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @var bool - Module needs to be activated by some app |
|
52 | - */ |
|
53 | - private $activated = false; |
|
50 | + /** |
|
51 | + * @var bool - Module needs to be activated by some app |
|
52 | + */ |
|
53 | + private $activated = false; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @inheritdoc |
|
57 | - */ |
|
58 | - public function startQuery($sql, array $params = null, array $types = null) { |
|
59 | - if ($this->activated) { |
|
60 | - $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack()); |
|
61 | - } |
|
62 | - } |
|
55 | + /** |
|
56 | + * @inheritdoc |
|
57 | + */ |
|
58 | + public function startQuery($sql, array $params = null, array $types = null) { |
|
59 | + if ($this->activated) { |
|
60 | + $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack()); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - private function getStack() { |
|
65 | - $stack = debug_backtrace(); |
|
66 | - array_shift($stack); |
|
67 | - array_shift($stack); |
|
68 | - array_shift($stack); |
|
69 | - return $stack; |
|
70 | - } |
|
64 | + private function getStack() { |
|
65 | + $stack = debug_backtrace(); |
|
66 | + array_shift($stack); |
|
67 | + array_shift($stack); |
|
68 | + array_shift($stack); |
|
69 | + return $stack; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @inheritdoc |
|
74 | - */ |
|
75 | - public function stopQuery() { |
|
76 | - if ($this->activated && $this->activeQuery) { |
|
77 | - $this->activeQuery->end(microtime(true)); |
|
78 | - $this->queries[] = $this->activeQuery; |
|
79 | - $this->activeQuery = null; |
|
80 | - } |
|
81 | - } |
|
72 | + /** |
|
73 | + * @inheritdoc |
|
74 | + */ |
|
75 | + public function stopQuery() { |
|
76 | + if ($this->activated && $this->activeQuery) { |
|
77 | + $this->activeQuery->end(microtime(true)); |
|
78 | + $this->queries[] = $this->activeQuery; |
|
79 | + $this->activeQuery = null; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @inheritdoc |
|
85 | - */ |
|
86 | - public function getQueries() { |
|
87 | - return $this->queries->getData(); |
|
88 | - } |
|
83 | + /** |
|
84 | + * @inheritdoc |
|
85 | + */ |
|
86 | + public function getQueries() { |
|
87 | + return $this->queries->getData(); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @inheritdoc |
|
92 | - */ |
|
93 | - public function activate() { |
|
94 | - $this->activated = true; |
|
95 | - } |
|
90 | + /** |
|
91 | + * @inheritdoc |
|
92 | + */ |
|
93 | + public function activate() { |
|
94 | + $this->activated = true; |
|
95 | + } |
|
96 | 96 | } |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | $appName = $input->getArgument('app'); |
61 | 61 | $version = $input->getArgument('version'); |
62 | 62 | |
63 | - if (!preg_match('/^\d{1,16}$/',$version)) { |
|
63 | + if (!preg_match('/^\d{1,16}$/', $version)) { |
|
64 | 64 | $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); |
65 | 65 | return 1; |
66 | 66 | } |
67 | 67 | |
68 | - $schemaFile = $this->appManager->getAppPath($appName) . '/appinfo/database.xml'; |
|
68 | + $schemaFile = $this->appManager->getAppPath($appName).'/appinfo/database.xml'; |
|
69 | 69 | if (!file_exists($schemaFile)) { |
70 | - $output->writeln('<error>App ' . $appName . ' does not have a database.xml file</error>'); |
|
70 | + $output->writeln('<error>App '.$appName.' does not have a database.xml file</error>'); |
|
71 | 71 | return 2; |
72 | 72 | } |
73 | 73 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
81 | 81 | |
82 | 82 | $date = date('YmdHis'); |
83 | - $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date, $schemaBody); |
|
83 | + $path = $this->generateMigration($ms, 'Version'.$version.'Date'.$date, $schemaBody); |
|
84 | 84 | |
85 | 85 | $output->writeln("New migration class has been generated to <info>$path</info>"); |
86 | 86 | return 0; |
@@ -36,170 +36,170 @@ |
||
36 | 36 | |
37 | 37 | class GenerateFromSchemaFileCommand extends GenerateCommand { |
38 | 38 | |
39 | - /** @var IConfig */ |
|
40 | - protected $config; |
|
39 | + /** @var IConfig */ |
|
40 | + protected $config; |
|
41 | 41 | |
42 | - public function __construct(IConfig $config, IAppManager $appManager, IDBConnection $connection) { |
|
43 | - parent::__construct($connection, $appManager); |
|
44 | - $this->config = $config; |
|
45 | - } |
|
42 | + public function __construct(IConfig $config, IAppManager $appManager, IDBConnection $connection) { |
|
43 | + parent::__construct($connection, $appManager); |
|
44 | + $this->config = $config; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - protected function configure() { |
|
49 | - parent::configure(); |
|
48 | + protected function configure() { |
|
49 | + parent::configure(); |
|
50 | 50 | |
51 | - $this->setName('migrations:generate-from-schema'); |
|
52 | - } |
|
51 | + $this->setName('migrations:generate-from-schema'); |
|
52 | + } |
|
53 | 53 | |
54 | - public function execute(InputInterface $input, OutputInterface $output) { |
|
55 | - $appName = $input->getArgument('app'); |
|
56 | - $version = $input->getArgument('version'); |
|
54 | + public function execute(InputInterface $input, OutputInterface $output) { |
|
55 | + $appName = $input->getArgument('app'); |
|
56 | + $version = $input->getArgument('version'); |
|
57 | 57 | |
58 | - if (!preg_match('/^\d{1,16}$/',$version)) { |
|
59 | - $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); |
|
60 | - return 1; |
|
61 | - } |
|
58 | + if (!preg_match('/^\d{1,16}$/',$version)) { |
|
59 | + $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); |
|
60 | + return 1; |
|
61 | + } |
|
62 | 62 | |
63 | - $schemaFile = $this->appManager->getAppPath($appName) . '/appinfo/database.xml'; |
|
64 | - if (!file_exists($schemaFile)) { |
|
65 | - $output->writeln('<error>App ' . $appName . ' does not have a database.xml file</error>'); |
|
66 | - return 2; |
|
67 | - } |
|
63 | + $schemaFile = $this->appManager->getAppPath($appName) . '/appinfo/database.xml'; |
|
64 | + if (!file_exists($schemaFile)) { |
|
65 | + $output->writeln('<error>App ' . $appName . ' does not have a database.xml file</error>'); |
|
66 | + return 2; |
|
67 | + } |
|
68 | 68 | |
69 | - $reader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform()); |
|
70 | - $schema = new Schema(); |
|
71 | - $reader->loadSchemaFromFile($schemaFile, $schema); |
|
69 | + $reader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform()); |
|
70 | + $schema = new Schema(); |
|
71 | + $reader->loadSchemaFromFile($schemaFile, $schema); |
|
72 | 72 | |
73 | - $schemaBody = $this->schemaToMigration($schema); |
|
73 | + $schemaBody = $this->schemaToMigration($schema); |
|
74 | 74 | |
75 | - $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
75 | + $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
76 | 76 | |
77 | - $date = date('YmdHis'); |
|
78 | - $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date, $schemaBody); |
|
77 | + $date = date('YmdHis'); |
|
78 | + $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date, $schemaBody); |
|
79 | 79 | |
80 | - $output->writeln("New migration class has been generated to <info>$path</info>"); |
|
81 | - return 0; |
|
82 | - } |
|
80 | + $output->writeln("New migration class has been generated to <info>$path</info>"); |
|
81 | + return 0; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @param Schema $schema |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - protected function schemaToMigration(Schema $schema) { |
|
89 | - $content = <<<'EOT' |
|
84 | + /** |
|
85 | + * @param Schema $schema |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + protected function schemaToMigration(Schema $schema) { |
|
89 | + $content = <<<'EOT' |
|
90 | 90 | /** @var ISchemaWrapper $schema */ |
91 | 91 | $schema = $schemaClosure(); |
92 | 92 | |
93 | 93 | EOT; |
94 | 94 | |
95 | - foreach ($schema->getTables() as $table) { |
|
96 | - $content .= str_replace('{{table-name}}', substr($table->getName(), 3), <<<'EOT' |
|
95 | + foreach ($schema->getTables() as $table) { |
|
96 | + $content .= str_replace('{{table-name}}', substr($table->getName(), 3), <<<'EOT' |
|
97 | 97 | |
98 | 98 | if (!$schema->hasTable('{{table-name}}')) { |
99 | 99 | $table = $schema->createTable('{{table-name}}'); |
100 | 100 | |
101 | 101 | EOT |
102 | - ); |
|
102 | + ); |
|
103 | 103 | |
104 | - foreach ($table->getColumns() as $column) { |
|
105 | - $content .= str_replace(['{{name}}', '{{type}}'], [$column->getName(), $column->getType()->getName()], <<<'EOT' |
|
104 | + foreach ($table->getColumns() as $column) { |
|
105 | + $content .= str_replace(['{{name}}', '{{type}}'], [$column->getName(), $column->getType()->getName()], <<<'EOT' |
|
106 | 106 | $table->addColumn('{{name}}', '{{type}}', [ |
107 | 107 | |
108 | 108 | EOT |
109 | - ); |
|
110 | - if ($column->getAutoincrement()) { |
|
111 | - $content .= <<<'EOT' |
|
109 | + ); |
|
110 | + if ($column->getAutoincrement()) { |
|
111 | + $content .= <<<'EOT' |
|
112 | 112 | 'autoincrement' => true, |
113 | 113 | |
114 | 114 | EOT; |
115 | - } |
|
116 | - $content .= str_replace('{{notnull}}', $column->getNotnull() ? 'true' : 'false', <<<'EOT' |
|
115 | + } |
|
116 | + $content .= str_replace('{{notnull}}', $column->getNotnull() ? 'true' : 'false', <<<'EOT' |
|
117 | 117 | 'notnull' => {{notnull}}, |
118 | 118 | |
119 | 119 | EOT |
120 | - ); |
|
121 | - if ($column->getLength() !== null) { |
|
122 | - $content .= str_replace('{{length}}', $column->getLength(), <<<'EOT' |
|
120 | + ); |
|
121 | + if ($column->getLength() !== null) { |
|
122 | + $content .= str_replace('{{length}}', $column->getLength(), <<<'EOT' |
|
123 | 123 | 'length' => {{length}}, |
124 | 124 | |
125 | 125 | EOT |
126 | - ); |
|
127 | - } |
|
128 | - $default = $column->getDefault(); |
|
129 | - if ($default !== null) { |
|
130 | - if (is_string($default)) { |
|
131 | - $default = "'$default'"; |
|
132 | - } elseif (is_bool($default)) { |
|
133 | - $default = ($default === true) ? 'true' : 'false'; |
|
134 | - } |
|
135 | - $content .= str_replace('{{default}}', $default, <<<'EOT' |
|
126 | + ); |
|
127 | + } |
|
128 | + $default = $column->getDefault(); |
|
129 | + if ($default !== null) { |
|
130 | + if (is_string($default)) { |
|
131 | + $default = "'$default'"; |
|
132 | + } elseif (is_bool($default)) { |
|
133 | + $default = ($default === true) ? 'true' : 'false'; |
|
134 | + } |
|
135 | + $content .= str_replace('{{default}}', $default, <<<'EOT' |
|
136 | 136 | 'default' => {{default}}, |
137 | 137 | |
138 | 138 | EOT |
139 | - ); |
|
140 | - } |
|
141 | - if ($column->getUnsigned()) { |
|
142 | - $content .= <<<'EOT' |
|
139 | + ); |
|
140 | + } |
|
141 | + if ($column->getUnsigned()) { |
|
142 | + $content .= <<<'EOT' |
|
143 | 143 | 'unsigned' => true, |
144 | 144 | |
145 | 145 | EOT; |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - $content .= <<<'EOT' |
|
148 | + $content .= <<<'EOT' |
|
149 | 149 | ]); |
150 | 150 | |
151 | 151 | EOT; |
152 | - } |
|
152 | + } |
|
153 | 153 | |
154 | - $content .= <<<'EOT' |
|
154 | + $content .= <<<'EOT' |
|
155 | 155 | |
156 | 156 | EOT; |
157 | 157 | |
158 | - $primaryKey = $table->getPrimaryKey(); |
|
159 | - if ($primaryKey !== null) { |
|
160 | - $content .= str_replace('{{columns}}', implode('\', \'', $primaryKey->getUnquotedColumns()), <<<'EOT' |
|
158 | + $primaryKey = $table->getPrimaryKey(); |
|
159 | + if ($primaryKey !== null) { |
|
160 | + $content .= str_replace('{{columns}}', implode('\', \'', $primaryKey->getUnquotedColumns()), <<<'EOT' |
|
161 | 161 | $table->setPrimaryKey(['{{columns}}']); |
162 | 162 | |
163 | 163 | EOT |
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - foreach ($table->getIndexes() as $index) { |
|
168 | - if ($index->isPrimary()) { |
|
169 | - continue; |
|
170 | - } |
|
171 | - |
|
172 | - if ($index->isUnique()) { |
|
173 | - $content .= str_replace( |
|
174 | - ['{{columns}}', '{{name}}'], |
|
175 | - [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], |
|
176 | - <<<'EOT' |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + foreach ($table->getIndexes() as $index) { |
|
168 | + if ($index->isPrimary()) { |
|
169 | + continue; |
|
170 | + } |
|
171 | + |
|
172 | + if ($index->isUnique()) { |
|
173 | + $content .= str_replace( |
|
174 | + ['{{columns}}', '{{name}}'], |
|
175 | + [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], |
|
176 | + <<<'EOT' |
|
177 | 177 | $table->addUniqueIndex(['{{columns}}'], '{{name}}'); |
178 | 178 | |
179 | 179 | EOT |
180 | - ); |
|
181 | - } else { |
|
182 | - $content .= str_replace( |
|
183 | - ['{{columns}}', '{{name}}'], |
|
184 | - [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], |
|
185 | - <<<'EOT' |
|
180 | + ); |
|
181 | + } else { |
|
182 | + $content .= str_replace( |
|
183 | + ['{{columns}}', '{{name}}'], |
|
184 | + [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], |
|
185 | + <<<'EOT' |
|
186 | 186 | $table->addIndex(['{{columns}}'], '{{name}}'); |
187 | 187 | |
188 | 188 | EOT |
189 | - ); |
|
190 | - } |
|
191 | - } |
|
189 | + ); |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - $content .= <<<'EOT' |
|
193 | + $content .= <<<'EOT' |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | EOT; |
197 | - } |
|
197 | + } |
|
198 | 198 | |
199 | - $content .= <<<'EOT' |
|
199 | + $content .= <<<'EOT' |
|
200 | 200 | return $schema; |
201 | 201 | EOT; |
202 | 202 | |
203 | - return $content; |
|
204 | - } |
|
203 | + return $content; |
|
204 | + } |
|
205 | 205 | } |
@@ -27,72 +27,72 @@ |
||
27 | 27 | |
28 | 28 | class FileDeleted implements ISetting { |
29 | 29 | |
30 | - /** @var IL10N */ |
|
31 | - protected $l; |
|
30 | + /** @var IL10N */ |
|
31 | + protected $l; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param IL10N $l |
|
35 | - */ |
|
36 | - public function __construct(IL10N $l) { |
|
37 | - $this->l = $l; |
|
38 | - } |
|
33 | + /** |
|
34 | + * @param IL10N $l |
|
35 | + */ |
|
36 | + public function __construct(IL10N $l) { |
|
37 | + $this->l = $l; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string Lowercase a-z and underscore only identifier |
|
42 | - * @since 11.0.0 |
|
43 | - */ |
|
44 | - public function getIdentifier() { |
|
45 | - return 'file_deleted'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return string Lowercase a-z and underscore only identifier |
|
42 | + * @since 11.0.0 |
|
43 | + */ |
|
44 | + public function getIdentifier() { |
|
45 | + return 'file_deleted'; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return string A translated string |
|
50 | - * @since 11.0.0 |
|
51 | - */ |
|
52 | - public function getName() { |
|
53 | - return $this->l->t('A file or folder has been <strong>deleted</strong>'); |
|
54 | - } |
|
48 | + /** |
|
49 | + * @return string A translated string |
|
50 | + * @since 11.0.0 |
|
51 | + */ |
|
52 | + public function getName() { |
|
53 | + return $this->l->t('A file or folder has been <strong>deleted</strong>'); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return int whether the filter should be rather on the top or bottom of |
|
58 | - * the admin section. The filters are arranged in ascending order of the |
|
59 | - * priority values. It is required to return a value between 0 and 100. |
|
60 | - * @since 11.0.0 |
|
61 | - */ |
|
62 | - public function getPriority() { |
|
63 | - return 3; |
|
64 | - } |
|
56 | + /** |
|
57 | + * @return int whether the filter should be rather on the top or bottom of |
|
58 | + * the admin section. The filters are arranged in ascending order of the |
|
59 | + * priority values. It is required to return a value between 0 and 100. |
|
60 | + * @since 11.0.0 |
|
61 | + */ |
|
62 | + public function getPriority() { |
|
63 | + return 3; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return bool True when the option can be changed for the stream |
|
68 | - * @since 11.0.0 |
|
69 | - */ |
|
70 | - public function canChangeStream() { |
|
71 | - return true; |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return bool True when the option can be changed for the stream |
|
68 | + * @since 11.0.0 |
|
69 | + */ |
|
70 | + public function canChangeStream() { |
|
71 | + return true; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return bool True when the option can be changed for the stream |
|
76 | - * @since 11.0.0 |
|
77 | - */ |
|
78 | - public function isDefaultEnabledStream() { |
|
79 | - return true; |
|
80 | - } |
|
74 | + /** |
|
75 | + * @return bool True when the option can be changed for the stream |
|
76 | + * @since 11.0.0 |
|
77 | + */ |
|
78 | + public function isDefaultEnabledStream() { |
|
79 | + return true; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return bool True when the option can be changed for the mail |
|
84 | - * @since 11.0.0 |
|
85 | - */ |
|
86 | - public function canChangeMail() { |
|
87 | - return true; |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return bool True when the option can be changed for the mail |
|
84 | + * @since 11.0.0 |
|
85 | + */ |
|
86 | + public function canChangeMail() { |
|
87 | + return true; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @return bool True when the option can be changed for the stream |
|
92 | - * @since 11.0.0 |
|
93 | - */ |
|
94 | - public function isDefaultEnabledMail() { |
|
95 | - return false; |
|
96 | - } |
|
90 | + /** |
|
91 | + * @return bool True when the option can be changed for the stream |
|
92 | + * @since 11.0.0 |
|
93 | + */ |
|
94 | + public function isDefaultEnabledMail() { |
|
95 | + return false; |
|
96 | + } |
|
97 | 97 | } |
98 | 98 |
@@ -27,72 +27,72 @@ |
||
27 | 27 | |
28 | 28 | class FileRestored implements ISetting { |
29 | 29 | |
30 | - /** @var IL10N */ |
|
31 | - protected $l; |
|
30 | + /** @var IL10N */ |
|
31 | + protected $l; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param IL10N $l |
|
35 | - */ |
|
36 | - public function __construct(IL10N $l) { |
|
37 | - $this->l = $l; |
|
38 | - } |
|
33 | + /** |
|
34 | + * @param IL10N $l |
|
35 | + */ |
|
36 | + public function __construct(IL10N $l) { |
|
37 | + $this->l = $l; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string Lowercase a-z and underscore only identifier |
|
42 | - * @since 11.0.0 |
|
43 | - */ |
|
44 | - public function getIdentifier() { |
|
45 | - return 'file_restored'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return string Lowercase a-z and underscore only identifier |
|
42 | + * @since 11.0.0 |
|
43 | + */ |
|
44 | + public function getIdentifier() { |
|
45 | + return 'file_restored'; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return string A translated string |
|
50 | - * @since 11.0.0 |
|
51 | - */ |
|
52 | - public function getName() { |
|
53 | - return $this->l->t('A file or folder has been <strong>restored</strong>'); |
|
54 | - } |
|
48 | + /** |
|
49 | + * @return string A translated string |
|
50 | + * @since 11.0.0 |
|
51 | + */ |
|
52 | + public function getName() { |
|
53 | + return $this->l->t('A file or folder has been <strong>restored</strong>'); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return int whether the filter should be rather on the top or bottom of |
|
58 | - * the admin section. The filters are arranged in ascending order of the |
|
59 | - * priority values. It is required to return a value between 0 and 100. |
|
60 | - * @since 11.0.0 |
|
61 | - */ |
|
62 | - public function getPriority() { |
|
63 | - return 4; |
|
64 | - } |
|
56 | + /** |
|
57 | + * @return int whether the filter should be rather on the top or bottom of |
|
58 | + * the admin section. The filters are arranged in ascending order of the |
|
59 | + * priority values. It is required to return a value between 0 and 100. |
|
60 | + * @since 11.0.0 |
|
61 | + */ |
|
62 | + public function getPriority() { |
|
63 | + return 4; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return bool True when the option can be changed for the stream |
|
68 | - * @since 11.0.0 |
|
69 | - */ |
|
70 | - public function canChangeStream() { |
|
71 | - return true; |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return bool True when the option can be changed for the stream |
|
68 | + * @since 11.0.0 |
|
69 | + */ |
|
70 | + public function canChangeStream() { |
|
71 | + return true; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return bool True when the option can be changed for the stream |
|
76 | - * @since 11.0.0 |
|
77 | - */ |
|
78 | - public function isDefaultEnabledStream() { |
|
79 | - return true; |
|
80 | - } |
|
74 | + /** |
|
75 | + * @return bool True when the option can be changed for the stream |
|
76 | + * @since 11.0.0 |
|
77 | + */ |
|
78 | + public function isDefaultEnabledStream() { |
|
79 | + return true; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return bool True when the option can be changed for the mail |
|
84 | - * @since 11.0.0 |
|
85 | - */ |
|
86 | - public function canChangeMail() { |
|
87 | - return true; |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return bool True when the option can be changed for the mail |
|
84 | + * @since 11.0.0 |
|
85 | + */ |
|
86 | + public function canChangeMail() { |
|
87 | + return true; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @return bool True when the option can be changed for the stream |
|
92 | - * @since 11.0.0 |
|
93 | - */ |
|
94 | - public function isDefaultEnabledMail() { |
|
95 | - return false; |
|
96 | - } |
|
90 | + /** |
|
91 | + * @return bool True when the option can be changed for the stream |
|
92 | + * @since 11.0.0 |
|
93 | + */ |
|
94 | + public function isDefaultEnabledMail() { |
|
95 | + return false; |
|
96 | + } |
|
97 | 97 | } |
98 | 98 |
@@ -27,55 +27,55 @@ |
||
27 | 27 | use OCP\DB\QueryBuilder\IQueryFunction; |
28 | 28 | |
29 | 29 | class QuoteHelper { |
30 | - /** |
|
31 | - * @param array|string|ILiteral|IParameter|IQueryFunction $strings string, Literal or Parameter |
|
32 | - * @return array|string |
|
33 | - */ |
|
34 | - public function quoteColumnNames($strings) { |
|
35 | - if (!is_array($strings)) { |
|
36 | - return $this->quoteColumnName($strings); |
|
37 | - } |
|
30 | + /** |
|
31 | + * @param array|string|ILiteral|IParameter|IQueryFunction $strings string, Literal or Parameter |
|
32 | + * @return array|string |
|
33 | + */ |
|
34 | + public function quoteColumnNames($strings) { |
|
35 | + if (!is_array($strings)) { |
|
36 | + return $this->quoteColumnName($strings); |
|
37 | + } |
|
38 | 38 | |
39 | - $return = []; |
|
40 | - foreach ($strings as $string) { |
|
41 | - $return[] = $this->quoteColumnName($string); |
|
42 | - } |
|
39 | + $return = []; |
|
40 | + foreach ($strings as $string) { |
|
41 | + $return[] = $this->quoteColumnName($string); |
|
42 | + } |
|
43 | 43 | |
44 | - return $return; |
|
45 | - } |
|
44 | + return $return; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string|ILiteral|IParameter|IQueryFunction $string string, Literal or Parameter |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function quoteColumnName($string) { |
|
52 | - if ($string instanceof IParameter || $string instanceof ILiteral || $string instanceof IQueryFunction) { |
|
53 | - return (string) $string; |
|
54 | - } |
|
47 | + /** |
|
48 | + * @param string|ILiteral|IParameter|IQueryFunction $string string, Literal or Parameter |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function quoteColumnName($string) { |
|
52 | + if ($string instanceof IParameter || $string instanceof ILiteral || $string instanceof IQueryFunction) { |
|
53 | + return (string) $string; |
|
54 | + } |
|
55 | 55 | |
56 | - if ($string === null || $string === 'null' || $string === '*') { |
|
57 | - return $string; |
|
58 | - } |
|
56 | + if ($string === null || $string === 'null' || $string === '*') { |
|
57 | + return $string; |
|
58 | + } |
|
59 | 59 | |
60 | - if (!is_string($string)) { |
|
61 | - throw new \InvalidArgumentException('Only strings, Literals and Parameters are allowed'); |
|
62 | - } |
|
60 | + if (!is_string($string)) { |
|
61 | + throw new \InvalidArgumentException('Only strings, Literals and Parameters are allowed'); |
|
62 | + } |
|
63 | 63 | |
64 | - $string = str_replace(' AS ', ' as ', $string); |
|
65 | - if (substr_count($string, ' as ')) { |
|
66 | - return implode(' as ', array_map([$this, 'quoteColumnName'], explode(' as ', $string, 2))); |
|
67 | - } |
|
64 | + $string = str_replace(' AS ', ' as ', $string); |
|
65 | + if (substr_count($string, ' as ')) { |
|
66 | + return implode(' as ', array_map([$this, 'quoteColumnName'], explode(' as ', $string, 2))); |
|
67 | + } |
|
68 | 68 | |
69 | - if (substr_count($string, '.')) { |
|
70 | - list($alias, $columnName) = explode('.', $string, 2); |
|
69 | + if (substr_count($string, '.')) { |
|
70 | + list($alias, $columnName) = explode('.', $string, 2); |
|
71 | 71 | |
72 | - if ($columnName === '*') { |
|
73 | - return '`' . $alias . '`.*'; |
|
74 | - } |
|
72 | + if ($columnName === '*') { |
|
73 | + return '`' . $alias . '`.*'; |
|
74 | + } |
|
75 | 75 | |
76 | - return '`' . $alias . '`.`' . $columnName . '`'; |
|
77 | - } |
|
76 | + return '`' . $alias . '`.`' . $columnName . '`'; |
|
77 | + } |
|
78 | 78 | |
79 | - return '`' . $string . '`'; |
|
80 | - } |
|
79 | + return '`' . $string . '`'; |
|
80 | + } |
|
81 | 81 | } |
@@ -70,12 +70,12 @@ |
||
70 | 70 | list($alias, $columnName) = explode('.', $string, 2); |
71 | 71 | |
72 | 72 | if ($columnName === '*') { |
73 | - return '`' . $alias . '`.*'; |
|
73 | + return '`'.$alias.'`.*'; |
|
74 | 74 | } |
75 | 75 | |
76 | - return '`' . $alias . '`.`' . $columnName . '`'; |
|
76 | + return '`'.$alias.'`.`'.$columnName.'`'; |
|
77 | 77 | } |
78 | 78 | |
79 | - return '`' . $string . '`'; |
|
79 | + return '`'.$string.'`'; |
|
80 | 80 | } |
81 | 81 | } |
@@ -29,39 +29,39 @@ |
||
29 | 29 | |
30 | 30 | class ConfigController extends OCSController { |
31 | 31 | |
32 | - /** @var IConfig */ |
|
33 | - private $config; |
|
32 | + /** @var IConfig */ |
|
33 | + private $config; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $appName |
|
37 | - * @param IRequest $request |
|
38 | - * @param IConfig $config |
|
39 | - */ |
|
40 | - public function __construct($appName, |
|
41 | - IRequest $request, |
|
42 | - IConfig $config) { |
|
43 | - parent::__construct($appName, $request); |
|
44 | - $this->config = $config; |
|
45 | - } |
|
35 | + /** |
|
36 | + * @param string $appName |
|
37 | + * @param IRequest $request |
|
38 | + * @param IConfig $config |
|
39 | + */ |
|
40 | + public function __construct($appName, |
|
41 | + IRequest $request, |
|
42 | + IConfig $config) { |
|
43 | + parent::__construct($appName, $request); |
|
44 | + $this->config = $config; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $appid |
|
49 | - * @param string $configkey |
|
50 | - * @param string $value |
|
51 | - * @return DataResponse |
|
52 | - */ |
|
53 | - public function setAppValue($appid, $configkey, $value) { |
|
54 | - $this->config->setAppValue($appid, $configkey, $value); |
|
55 | - return new DataResponse(); |
|
56 | - } |
|
47 | + /** |
|
48 | + * @param string $appid |
|
49 | + * @param string $configkey |
|
50 | + * @param string $value |
|
51 | + * @return DataResponse |
|
52 | + */ |
|
53 | + public function setAppValue($appid, $configkey, $value) { |
|
54 | + $this->config->setAppValue($appid, $configkey, $value); |
|
55 | + return new DataResponse(); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $appid |
|
60 | - * @param string $configkey |
|
61 | - * @return DataResponse |
|
62 | - */ |
|
63 | - public function deleteAppValue($appid, $configkey) { |
|
64 | - $this->config->deleteAppValue($appid, $configkey); |
|
65 | - return new DataResponse(); |
|
66 | - } |
|
58 | + /** |
|
59 | + * @param string $appid |
|
60 | + * @param string $configkey |
|
61 | + * @return DataResponse |
|
62 | + */ |
|
63 | + public function deleteAppValue($appid, $configkey) { |
|
64 | + $this->config->deleteAppValue($appid, $configkey); |
|
65 | + return new DataResponse(); |
|
66 | + } |
|
67 | 67 | } |
@@ -33,12 +33,12 @@ |
||
33 | 33 | */ |
34 | 34 | interface ICallbackResponse { |
35 | 35 | |
36 | - /** |
|
37 | - * Outputs the content that should be printed |
|
38 | - * |
|
39 | - * @param IOutput $output a small wrapper that handles output |
|
40 | - * @since 8.1.0 |
|
41 | - */ |
|
42 | - public function callback(IOutput $output); |
|
36 | + /** |
|
37 | + * Outputs the content that should be printed |
|
38 | + * |
|
39 | + * @param IOutput $output a small wrapper that handles output |
|
40 | + * @since 8.1.0 |
|
41 | + */ |
|
42 | + public function callback(IOutput $output); |
|
43 | 43 | |
44 | 44 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | public function get($key) { |
100 | - $result = self::$cache->get($this->getNameSpace() . $key); |
|
100 | + $result = self::$cache->get($this->getNameSpace().$key); |
|
101 | 101 | if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
102 | 102 | return null; |
103 | 103 | } else { |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | |
108 | 108 | public function set($key, $value, $ttl = 0) { |
109 | 109 | if ($ttl > 0) { |
110 | - $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
110 | + $result = self::$cache->set($this->getNameSpace().$key, $value, $ttl); |
|
111 | 111 | } else { |
112 | - $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
112 | + $result = self::$cache->set($this->getNameSpace().$key, $value); |
|
113 | 113 | } |
114 | 114 | if ($result !== true) { |
115 | 115 | $this->verifyReturnCode(); |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | public function hasKey($key) { |
121 | - self::$cache->get($this->getNameSpace() . $key); |
|
121 | + self::$cache->get($this->getNameSpace().$key); |
|
122 | 122 | return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
123 | 123 | } |
124 | 124 | |
125 | 125 | public function remove($key) { |
126 | - $result= self::$cache->delete($this->getNameSpace() . $key); |
|
126 | + $result = self::$cache->delete($this->getNameSpace().$key); |
|
127 | 127 | if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
128 | 128 | $this->verifyReturnCode(); |
129 | 129 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | public function clear($prefix = '') { |
134 | - $prefix = $this->getNameSpace() . $prefix; |
|
134 | + $prefix = $this->getNameSpace().$prefix; |
|
135 | 135 | $allKeys = self::$cache->getAllKeys(); |
136 | 136 | if ($allKeys === false) { |
137 | 137 | // newer Memcached doesn't like getAllKeys(), flush everything |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @throws \Exception |
166 | 166 | */ |
167 | 167 | public function add($key, $value, $ttl = 0) { |
168 | - $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
168 | + $result = self::$cache->add($this->getPrefix().$key, $value, $ttl); |
|
169 | 169 | if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
170 | 170 | $this->verifyReturnCode(); |
171 | 171 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function inc($key, $step = 1) { |
183 | 183 | $this->add($key, 0); |
184 | - $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
184 | + $result = self::$cache->increment($this->getPrefix().$key, $step); |
|
185 | 185 | |
186 | 186 | if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
187 | 187 | return false; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return int | bool |
199 | 199 | */ |
200 | 200 | public function dec($key, $step = 1) { |
201 | - $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
201 | + $result = self::$cache->decrement($this->getPrefix().$key, $step); |
|
202 | 202 | |
203 | 203 | if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
204 | 204 | return false; |
@@ -36,193 +36,193 @@ |
||
36 | 36 | use OCP\IMemcache; |
37 | 37 | |
38 | 38 | class Memcached extends Cache implements IMemcache { |
39 | - use CASTrait; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var \Memcached $cache |
|
43 | - */ |
|
44 | - private static $cache = null; |
|
45 | - |
|
46 | - use CADTrait; |
|
47 | - |
|
48 | - public function __construct($prefix = '') { |
|
49 | - parent::__construct($prefix); |
|
50 | - if (is_null(self::$cache)) { |
|
51 | - self::$cache = new \Memcached(); |
|
52 | - |
|
53 | - $defaultOptions = [ |
|
54 | - \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
55 | - \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
56 | - \Memcached::OPT_SEND_TIMEOUT => 50, |
|
57 | - \Memcached::OPT_RECV_TIMEOUT => 50, |
|
58 | - \Memcached::OPT_POLL_TIMEOUT => 50, |
|
59 | - |
|
60 | - // Enable compression |
|
61 | - \Memcached::OPT_COMPRESSION => true, |
|
62 | - |
|
63 | - // Turn on consistent hashing |
|
64 | - \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
65 | - |
|
66 | - // Enable Binary Protocol |
|
67 | - //\Memcached::OPT_BINARY_PROTOCOL => true, |
|
68 | - ]; |
|
69 | - // by default enable igbinary serializer if available |
|
70 | - if (\Memcached::HAVE_IGBINARY) { |
|
71 | - $defaultOptions[\Memcached::OPT_SERIALIZER] = |
|
72 | - \Memcached::SERIALIZER_IGBINARY; |
|
73 | - } |
|
74 | - $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); |
|
75 | - if (is_array($options)) { |
|
76 | - $options = $options + $defaultOptions; |
|
77 | - self::$cache->setOptions($options); |
|
78 | - } else { |
|
79 | - throw new HintException("Expected 'memcached_options' config to be an array, got $options"); |
|
80 | - } |
|
81 | - |
|
82 | - $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers'); |
|
83 | - if (!$servers) { |
|
84 | - $server = \OC::$server->getSystemConfig()->getValue('memcached_server'); |
|
85 | - if ($server) { |
|
86 | - $servers = [$server]; |
|
87 | - } else { |
|
88 | - $servers = [['localhost', 11211]]; |
|
89 | - } |
|
90 | - } |
|
91 | - self::$cache->addServers($servers); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * entries in XCache gets namespaced to prevent collisions between owncloud instances and users |
|
97 | - */ |
|
98 | - protected function getNameSpace() { |
|
99 | - return $this->prefix; |
|
100 | - } |
|
101 | - |
|
102 | - public function get($key) { |
|
103 | - $result = self::$cache->get($this->getNameSpace() . $key); |
|
104 | - if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
|
105 | - return null; |
|
106 | - } else { |
|
107 | - return $result; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - public function set($key, $value, $ttl = 0) { |
|
112 | - if ($ttl > 0) { |
|
113 | - $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
114 | - } else { |
|
115 | - $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
116 | - } |
|
117 | - if ($result !== true) { |
|
118 | - $this->verifyReturnCode(); |
|
119 | - } |
|
120 | - return $result; |
|
121 | - } |
|
122 | - |
|
123 | - public function hasKey($key) { |
|
124 | - self::$cache->get($this->getNameSpace() . $key); |
|
125 | - return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
|
126 | - } |
|
127 | - |
|
128 | - public function remove($key) { |
|
129 | - $result= self::$cache->delete($this->getNameSpace() . $key); |
|
130 | - if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
|
131 | - $this->verifyReturnCode(); |
|
132 | - } |
|
133 | - return $result; |
|
134 | - } |
|
135 | - |
|
136 | - public function clear($prefix = '') { |
|
137 | - $prefix = $this->getNameSpace() . $prefix; |
|
138 | - $allKeys = self::$cache->getAllKeys(); |
|
139 | - if ($allKeys === false) { |
|
140 | - // newer Memcached doesn't like getAllKeys(), flush everything |
|
141 | - self::$cache->flush(); |
|
142 | - return true; |
|
143 | - } |
|
144 | - $keys = []; |
|
145 | - $prefixLength = strlen($prefix); |
|
146 | - foreach ($allKeys as $key) { |
|
147 | - if (substr($key, 0, $prefixLength) === $prefix) { |
|
148 | - $keys[] = $key; |
|
149 | - } |
|
150 | - } |
|
151 | - if (method_exists(self::$cache, 'deleteMulti')) { |
|
152 | - self::$cache->deleteMulti($keys); |
|
153 | - } else { |
|
154 | - foreach ($keys as $key) { |
|
155 | - self::$cache->delete($key); |
|
156 | - } |
|
157 | - } |
|
158 | - return true; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Set a value in the cache if it's not already stored |
|
163 | - * |
|
164 | - * @param string $key |
|
165 | - * @param mixed $value |
|
166 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
167 | - * @return bool |
|
168 | - * @throws \Exception |
|
169 | - */ |
|
170 | - public function add($key, $value, $ttl = 0) { |
|
171 | - $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
172 | - if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
|
173 | - $this->verifyReturnCode(); |
|
174 | - } |
|
175 | - return $result; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Increase a stored number |
|
180 | - * |
|
181 | - * @param string $key |
|
182 | - * @param int $step |
|
183 | - * @return int | bool |
|
184 | - */ |
|
185 | - public function inc($key, $step = 1) { |
|
186 | - $this->add($key, 0); |
|
187 | - $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
188 | - |
|
189 | - if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
190 | - return false; |
|
191 | - } |
|
192 | - |
|
193 | - return $result; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Decrease a stored number |
|
198 | - * |
|
199 | - * @param string $key |
|
200 | - * @param int $step |
|
201 | - * @return int | bool |
|
202 | - */ |
|
203 | - public function dec($key, $step = 1) { |
|
204 | - $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
205 | - |
|
206 | - if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - return $result; |
|
211 | - } |
|
212 | - |
|
213 | - public static function isAvailable() { |
|
214 | - return extension_loaded('memcached'); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @throws \Exception |
|
219 | - */ |
|
220 | - private function verifyReturnCode() { |
|
221 | - $code = self::$cache->getResultCode(); |
|
222 | - if ($code === \Memcached::RES_SUCCESS) { |
|
223 | - return; |
|
224 | - } |
|
225 | - $message = self::$cache->getResultMessage(); |
|
226 | - throw new \Exception("Error $code interacting with memcached : $message"); |
|
227 | - } |
|
39 | + use CASTrait; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var \Memcached $cache |
|
43 | + */ |
|
44 | + private static $cache = null; |
|
45 | + |
|
46 | + use CADTrait; |
|
47 | + |
|
48 | + public function __construct($prefix = '') { |
|
49 | + parent::__construct($prefix); |
|
50 | + if (is_null(self::$cache)) { |
|
51 | + self::$cache = new \Memcached(); |
|
52 | + |
|
53 | + $defaultOptions = [ |
|
54 | + \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
55 | + \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
56 | + \Memcached::OPT_SEND_TIMEOUT => 50, |
|
57 | + \Memcached::OPT_RECV_TIMEOUT => 50, |
|
58 | + \Memcached::OPT_POLL_TIMEOUT => 50, |
|
59 | + |
|
60 | + // Enable compression |
|
61 | + \Memcached::OPT_COMPRESSION => true, |
|
62 | + |
|
63 | + // Turn on consistent hashing |
|
64 | + \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
65 | + |
|
66 | + // Enable Binary Protocol |
|
67 | + //\Memcached::OPT_BINARY_PROTOCOL => true, |
|
68 | + ]; |
|
69 | + // by default enable igbinary serializer if available |
|
70 | + if (\Memcached::HAVE_IGBINARY) { |
|
71 | + $defaultOptions[\Memcached::OPT_SERIALIZER] = |
|
72 | + \Memcached::SERIALIZER_IGBINARY; |
|
73 | + } |
|
74 | + $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); |
|
75 | + if (is_array($options)) { |
|
76 | + $options = $options + $defaultOptions; |
|
77 | + self::$cache->setOptions($options); |
|
78 | + } else { |
|
79 | + throw new HintException("Expected 'memcached_options' config to be an array, got $options"); |
|
80 | + } |
|
81 | + |
|
82 | + $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers'); |
|
83 | + if (!$servers) { |
|
84 | + $server = \OC::$server->getSystemConfig()->getValue('memcached_server'); |
|
85 | + if ($server) { |
|
86 | + $servers = [$server]; |
|
87 | + } else { |
|
88 | + $servers = [['localhost', 11211]]; |
|
89 | + } |
|
90 | + } |
|
91 | + self::$cache->addServers($servers); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * entries in XCache gets namespaced to prevent collisions between owncloud instances and users |
|
97 | + */ |
|
98 | + protected function getNameSpace() { |
|
99 | + return $this->prefix; |
|
100 | + } |
|
101 | + |
|
102 | + public function get($key) { |
|
103 | + $result = self::$cache->get($this->getNameSpace() . $key); |
|
104 | + if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
|
105 | + return null; |
|
106 | + } else { |
|
107 | + return $result; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + public function set($key, $value, $ttl = 0) { |
|
112 | + if ($ttl > 0) { |
|
113 | + $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
114 | + } else { |
|
115 | + $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
116 | + } |
|
117 | + if ($result !== true) { |
|
118 | + $this->verifyReturnCode(); |
|
119 | + } |
|
120 | + return $result; |
|
121 | + } |
|
122 | + |
|
123 | + public function hasKey($key) { |
|
124 | + self::$cache->get($this->getNameSpace() . $key); |
|
125 | + return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
|
126 | + } |
|
127 | + |
|
128 | + public function remove($key) { |
|
129 | + $result= self::$cache->delete($this->getNameSpace() . $key); |
|
130 | + if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
|
131 | + $this->verifyReturnCode(); |
|
132 | + } |
|
133 | + return $result; |
|
134 | + } |
|
135 | + |
|
136 | + public function clear($prefix = '') { |
|
137 | + $prefix = $this->getNameSpace() . $prefix; |
|
138 | + $allKeys = self::$cache->getAllKeys(); |
|
139 | + if ($allKeys === false) { |
|
140 | + // newer Memcached doesn't like getAllKeys(), flush everything |
|
141 | + self::$cache->flush(); |
|
142 | + return true; |
|
143 | + } |
|
144 | + $keys = []; |
|
145 | + $prefixLength = strlen($prefix); |
|
146 | + foreach ($allKeys as $key) { |
|
147 | + if (substr($key, 0, $prefixLength) === $prefix) { |
|
148 | + $keys[] = $key; |
|
149 | + } |
|
150 | + } |
|
151 | + if (method_exists(self::$cache, 'deleteMulti')) { |
|
152 | + self::$cache->deleteMulti($keys); |
|
153 | + } else { |
|
154 | + foreach ($keys as $key) { |
|
155 | + self::$cache->delete($key); |
|
156 | + } |
|
157 | + } |
|
158 | + return true; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Set a value in the cache if it's not already stored |
|
163 | + * |
|
164 | + * @param string $key |
|
165 | + * @param mixed $value |
|
166 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
167 | + * @return bool |
|
168 | + * @throws \Exception |
|
169 | + */ |
|
170 | + public function add($key, $value, $ttl = 0) { |
|
171 | + $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
172 | + if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
|
173 | + $this->verifyReturnCode(); |
|
174 | + } |
|
175 | + return $result; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Increase a stored number |
|
180 | + * |
|
181 | + * @param string $key |
|
182 | + * @param int $step |
|
183 | + * @return int | bool |
|
184 | + */ |
|
185 | + public function inc($key, $step = 1) { |
|
186 | + $this->add($key, 0); |
|
187 | + $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
188 | + |
|
189 | + if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
190 | + return false; |
|
191 | + } |
|
192 | + |
|
193 | + return $result; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Decrease a stored number |
|
198 | + * |
|
199 | + * @param string $key |
|
200 | + * @param int $step |
|
201 | + * @return int | bool |
|
202 | + */ |
|
203 | + public function dec($key, $step = 1) { |
|
204 | + $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
205 | + |
|
206 | + if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + return $result; |
|
211 | + } |
|
212 | + |
|
213 | + public static function isAvailable() { |
|
214 | + return extension_loaded('memcached'); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @throws \Exception |
|
219 | + */ |
|
220 | + private function verifyReturnCode() { |
|
221 | + $code = self::$cache->getResultCode(); |
|
222 | + if ($code === \Memcached::RES_SUCCESS) { |
|
223 | + return; |
|
224 | + } |
|
225 | + $message = self::$cache->getResultMessage(); |
|
226 | + throw new \Exception("Error $code interacting with memcached : $message"); |
|
227 | + } |
|
228 | 228 | } |