Passed
Push — master ( 4e9cd2...bc8d14 )
by Roeland
19:16 queued 09:49
created
lib/private/Files/Storage/Wrapper/PermissionsMask.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -37,122 +37,122 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/private/Diagnostics/QueryLogger.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -29,68 +29,68 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/Command/Db/Migrations/GenerateFromSchemaFileCommand.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -36,170 +36,170 @@
 block discarded – undo
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
-					} else if (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
+                    } else if (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
 }
Please login to merge, or discard this patch.
apps/files/lib/Activity/Settings/FileDeleted.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -27,72 +27,72 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
apps/files/lib/Activity/Settings/FileRestored.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -27,72 +27,72 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
lib/private/DB/QueryBuilder/QueryBuilder.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
 			$params = [];
192 192
 			foreach ($this->getParameters() as $placeholder => $value) {
193 193
 				if (is_array($value)) {
194
-					$params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')';
194
+					$params[] = $placeholder.' => (\''.implode('\', \'', $value).'\')';
195 195
 				} else {
196
-					$params[] = $placeholder . ' => \'' . $value . '\'';
196
+					$params[] = $placeholder.' => \''.$value.'\'';
197 197
 				}
198 198
 			}
199 199
 			if (empty($params)) {
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 	public function selectAlias($select, $alias) {
411 411
 
412 412
 		$this->queryBuilder->addSelect(
413
-			$this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias)
413
+			$this->helper->quoteColumnName($select).' AS '.$this->helper->quoteColumnName($alias)
414 414
 		);
415 415
 
416 416
 		return $this;
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	public function selectDistinct($select) {
433 433
 
434 434
 		$this->queryBuilder->addSelect(
435
-			'DISTINCT ' . $this->helper->quoteColumnName($select)
435
+			'DISTINCT '.$this->helper->quoteColumnName($select)
436 436
 		);
437 437
 
438 438
 		return $this;
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
 	 * @return IParameter
1110 1110
 	 */
1111 1111
 	public function createParameter($name) {
1112
-		return new Parameter(':' . $name);
1112
+		return new Parameter(':'.$name);
1113 1113
 	}
1114 1114
 
1115 1115
 	/**
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
 			return $table;
1177 1177
 		}
1178 1178
 
1179
-		return '*PREFIX*' . $table;
1179
+		return '*PREFIX*'.$table;
1180 1180
 	}
1181 1181
 
1182 1182
 	/**
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 			$tableAlias .= '.';
1192 1192
 		}
1193 1193
 
1194
-		return $this->helper->quoteColumnName($tableAlias . $column);
1194
+		return $this->helper->quoteColumnName($tableAlias.$column);
1195 1195
 	}
1196 1196
 
1197 1197
 	/**
Please login to merge, or discard this patch.
Indentation   +1173 added lines, -1173 removed lines patch added patch discarded remove patch
@@ -48,1177 +48,1177 @@
 block discarded – undo
48 48
 
49 49
 class QueryBuilder implements IQueryBuilder {
50 50
 
51
-	/** @var \OCP\IDBConnection */
52
-	private $connection;
53
-
54
-	/** @var SystemConfig */
55
-	private $systemConfig;
56
-
57
-	/** @var ILogger */
58
-	private $logger;
59
-
60
-	/** @var \Doctrine\DBAL\Query\QueryBuilder */
61
-	private $queryBuilder;
62
-
63
-	/** @var QuoteHelper */
64
-	private $helper;
65
-
66
-	/** @var bool */
67
-	private $automaticTablePrefix = true;
68
-
69
-	/** @var string */
70
-	protected $lastInsertedTable;
71
-
72
-	/**
73
-	 * Initializes a new QueryBuilder.
74
-	 *
75
-	 * @param IDBConnection $connection
76
-	 * @param SystemConfig $systemConfig
77
-	 * @param ILogger $logger
78
-	 */
79
-	public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) {
80
-		$this->connection = $connection;
81
-		$this->systemConfig = $systemConfig;
82
-		$this->logger = $logger;
83
-		$this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection);
84
-		$this->helper = new QuoteHelper();
85
-	}
86
-
87
-	/**
88
-	 * Enable/disable automatic prefixing of table names with the oc_ prefix
89
-	 *
90
-	 * @param bool $enabled If set to true table names will be prefixed with the
91
-	 * owncloud database prefix automatically.
92
-	 * @since 8.2.0
93
-	 */
94
-	public function automaticTablePrefix($enabled) {
95
-		$this->automaticTablePrefix = (bool) $enabled;
96
-	}
97
-
98
-	/**
99
-	 * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
100
-	 * This producer method is intended for convenient inline usage. Example:
101
-	 *
102
-	 * <code>
103
-	 *     $qb = $conn->getQueryBuilder()
104
-	 *         ->select('u')
105
-	 *         ->from('users', 'u')
106
-	 *         ->where($qb->expr()->eq('u.id', 1));
107
-	 * </code>
108
-	 *
109
-	 * For more complex expression construction, consider storing the expression
110
-	 * builder object in a local variable.
111
-	 *
112
-	 * @return \OCP\DB\QueryBuilder\IExpressionBuilder
113
-	 */
114
-	public function expr() {
115
-		if ($this->connection instanceof OracleConnection) {
116
-			return new OCIExpressionBuilder($this->connection, $this);
117
-		} else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
118
-			return new PgSqlExpressionBuilder($this->connection, $this);
119
-		} else if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
120
-			return new MySqlExpressionBuilder($this->connection, $this);
121
-		} else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
122
-			return new SqliteExpressionBuilder($this->connection, $this);
123
-		} else {
124
-			return new ExpressionBuilder($this->connection, $this);
125
-		}
126
-	}
127
-
128
-	/**
129
-	 * Gets an FunctionBuilder used for object-oriented construction of query functions.
130
-	 * This producer method is intended for convenient inline usage. Example:
131
-	 *
132
-	 * <code>
133
-	 *     $qb = $conn->getQueryBuilder()
134
-	 *         ->select('u')
135
-	 *         ->from('users', 'u')
136
-	 *         ->where($qb->fun()->md5('u.id'));
137
-	 * </code>
138
-	 *
139
-	 * For more complex function construction, consider storing the function
140
-	 * builder object in a local variable.
141
-	 *
142
-	 * @return \OCP\DB\QueryBuilder\IFunctionBuilder
143
-	 */
144
-	public function func() {
145
-		if ($this->connection instanceof OracleConnection) {
146
-			return new OCIFunctionBuilder($this->helper);
147
-		} else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
148
-			return new SqliteFunctionBuilder($this->helper);
149
-		} else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
150
-			return new PgSqlFunctionBuilder($this->helper);
151
-		} else {
152
-			return new FunctionBuilder($this->helper);
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Gets the type of the currently built query.
158
-	 *
159
-	 * @return integer
160
-	 */
161
-	public function getType() {
162
-		return $this->queryBuilder->getType();
163
-	}
164
-
165
-	/**
166
-	 * Gets the associated DBAL Connection for this query builder.
167
-	 *
168
-	 * @return \OCP\IDBConnection
169
-	 */
170
-	public function getConnection() {
171
-		return $this->connection;
172
-	}
173
-
174
-	/**
175
-	 * Gets the state of this query builder instance.
176
-	 *
177
-	 * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
178
-	 */
179
-	public function getState() {
180
-		return $this->queryBuilder->getState();
181
-	}
182
-
183
-	/**
184
-	 * Executes this query using the bound parameters and their types.
185
-	 *
186
-	 * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
187
-	 * for insert, update and delete statements.
188
-	 *
189
-	 * @return \Doctrine\DBAL\Driver\Statement|int
190
-	 */
191
-	public function execute() {
192
-		if ($this->systemConfig->getValue('log_query', false)) {
193
-			$params = [];
194
-			foreach ($this->getParameters() as $placeholder => $value) {
195
-				if (is_array($value)) {
196
-					$params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')';
197
-				} else {
198
-					$params[] = $placeholder . ' => \'' . $value . '\'';
199
-				}
200
-			}
201
-			if (empty($params)) {
202
-				$this->logger->debug('DB QueryBuilder: \'{query}\'', [
203
-					'query' => $this->getSQL(),
204
-					'app' => 'core',
205
-				]);
206
-			} else {
207
-				$this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [
208
-					'query' => $this->getSQL(),
209
-					'params' => implode(', ', $params),
210
-					'app' => 'core',
211
-				]);
212
-			}
213
-		}
214
-
215
-		return $this->queryBuilder->execute();
216
-	}
217
-
218
-	/**
219
-	 * Gets the complete SQL string formed by the current specifications of this QueryBuilder.
220
-	 *
221
-	 * <code>
222
-	 *     $qb = $conn->getQueryBuilder()
223
-	 *         ->select('u')
224
-	 *         ->from('User', 'u')
225
-	 *     echo $qb->getSQL(); // SELECT u FROM User u
226
-	 * </code>
227
-	 *
228
-	 * @return string The SQL query string.
229
-	 */
230
-	public function getSQL() {
231
-		return $this->queryBuilder->getSQL();
232
-	}
233
-
234
-	/**
235
-	 * Sets a query parameter for the query being constructed.
236
-	 *
237
-	 * <code>
238
-	 *     $qb = $conn->getQueryBuilder()
239
-	 *         ->select('u')
240
-	 *         ->from('users', 'u')
241
-	 *         ->where('u.id = :user_id')
242
-	 *         ->setParameter(':user_id', 1);
243
-	 * </code>
244
-	 *
245
-	 * @param string|integer $key The parameter position or name.
246
-	 * @param mixed $value The parameter value.
247
-	 * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants.
248
-	 *
249
-	 * @return $this This QueryBuilder instance.
250
-	 */
251
-	public function setParameter($key, $value, $type = null) {
252
-		$this->queryBuilder->setParameter($key, $value, $type);
253
-
254
-		return $this;
255
-	}
256
-
257
-	/**
258
-	 * Sets a collection of query parameters for the query being constructed.
259
-	 *
260
-	 * <code>
261
-	 *     $qb = $conn->getQueryBuilder()
262
-	 *         ->select('u')
263
-	 *         ->from('users', 'u')
264
-	 *         ->where('u.id = :user_id1 OR u.id = :user_id2')
265
-	 *         ->setParameters(array(
266
-	 *             ':user_id1' => 1,
267
-	 *             ':user_id2' => 2
268
-	 *         ));
269
-	 * </code>
270
-	 *
271
-	 * @param array $params The query parameters to set.
272
-	 * @param array $types The query parameters types to set.
273
-	 *
274
-	 * @return $this This QueryBuilder instance.
275
-	 */
276
-	public function setParameters(array $params, array $types = []) {
277
-		$this->queryBuilder->setParameters($params, $types);
278
-
279
-		return $this;
280
-	}
281
-
282
-	/**
283
-	 * Gets all defined query parameters for the query being constructed indexed by parameter index or name.
284
-	 *
285
-	 * @return array The currently defined query parameters indexed by parameter index or name.
286
-	 */
287
-	public function getParameters() {
288
-		return $this->queryBuilder->getParameters();
289
-	}
290
-
291
-	/**
292
-	 * Gets a (previously set) query parameter of the query being constructed.
293
-	 *
294
-	 * @param mixed $key The key (index or name) of the bound parameter.
295
-	 *
296
-	 * @return mixed The value of the bound parameter.
297
-	 */
298
-	public function getParameter($key) {
299
-		return $this->queryBuilder->getParameter($key);
300
-	}
301
-
302
-	/**
303
-	 * Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
304
-	 *
305
-	 * @return array The currently defined query parameter types indexed by parameter index or name.
306
-	 */
307
-	public function getParameterTypes() {
308
-		return $this->queryBuilder->getParameterTypes();
309
-	}
310
-
311
-	/**
312
-	 * Gets a (previously set) query parameter type of the query being constructed.
313
-	 *
314
-	 * @param mixed $key The key (index or name) of the bound parameter type.
315
-	 *
316
-	 * @return mixed The value of the bound parameter type.
317
-	 */
318
-	public function getParameterType($key) {
319
-		return $this->queryBuilder->getParameterType($key);
320
-	}
321
-
322
-	/**
323
-	 * Sets the position of the first result to retrieve (the "offset").
324
-	 *
325
-	 * @param integer $firstResult The first result to return.
326
-	 *
327
-	 * @return $this This QueryBuilder instance.
328
-	 */
329
-	public function setFirstResult($firstResult) {
330
-		$this->queryBuilder->setFirstResult($firstResult);
331
-
332
-		return $this;
333
-	}
334
-
335
-	/**
336
-	 * Gets the position of the first result the query object was set to retrieve (the "offset").
337
-	 * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
338
-	 *
339
-	 * @return integer The position of the first result.
340
-	 */
341
-	public function getFirstResult() {
342
-		return $this->queryBuilder->getFirstResult();
343
-	}
344
-
345
-	/**
346
-	 * Sets the maximum number of results to retrieve (the "limit").
347
-	 *
348
-	 * NOTE: Setting max results to "0" will cause mixed behaviour. While most
349
-	 * of the databases will just return an empty result set, Oracle will return
350
-	 * all entries.
351
-	 *
352
-	 * @param integer $maxResults The maximum number of results to retrieve.
353
-	 *
354
-	 * @return $this This QueryBuilder instance.
355
-	 */
356
-	public function setMaxResults($maxResults) {
357
-		$this->queryBuilder->setMaxResults($maxResults);
358
-
359
-		return $this;
360
-	}
361
-
362
-	/**
363
-	 * Gets the maximum number of results the query object was set to retrieve (the "limit").
364
-	 * Returns NULL if {@link setMaxResults} was not applied to this query builder.
365
-	 *
366
-	 * @return integer The maximum number of results.
367
-	 */
368
-	public function getMaxResults() {
369
-		return $this->queryBuilder->getMaxResults();
370
-	}
371
-
372
-	/**
373
-	 * Specifies an item that is to be returned in the query result.
374
-	 * Replaces any previously specified selections, if any.
375
-	 *
376
-	 * <code>
377
-	 *     $qb = $conn->getQueryBuilder()
378
-	 *         ->select('u.id', 'p.id')
379
-	 *         ->from('users', 'u')
380
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
381
-	 * </code>
382
-	 *
383
-	 * @param mixed ...$selects The selection expressions.
384
-	 *
385
-	 * '@return $this This QueryBuilder instance.
386
-	 */
387
-	public function select(...$selects) {
388
-		if (count($selects) === 1 && is_array($selects[0])) {
389
-			$selects = $selects[0];
390
-		}
391
-
392
-		$this->queryBuilder->select(
393
-			$this->helper->quoteColumnNames($selects)
394
-		);
395
-
396
-		return $this;
397
-	}
398
-
399
-	/**
400
-	 * Specifies an item that is to be returned with a different name in the query result.
401
-	 *
402
-	 * <code>
403
-	 *     $qb = $conn->getQueryBuilder()
404
-	 *         ->selectAlias('u.id', 'user_id')
405
-	 *         ->from('users', 'u')
406
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
407
-	 * </code>
408
-	 *
409
-	 * @param mixed $select The selection expressions.
410
-	 * @param string $alias The column alias used in the constructed query.
411
-	 *
412
-	 * @return $this This QueryBuilder instance.
413
-	 */
414
-	public function selectAlias($select, $alias) {
415
-
416
-		$this->queryBuilder->addSelect(
417
-			$this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias)
418
-		);
419
-
420
-		return $this;
421
-	}
422
-
423
-	/**
424
-	 * Specifies an item that is to be returned uniquely in the query result.
425
-	 *
426
-	 * <code>
427
-	 *     $qb = $conn->getQueryBuilder()
428
-	 *         ->selectDistinct('type')
429
-	 *         ->from('users');
430
-	 * </code>
431
-	 *
432
-	 * @param mixed $select The selection expressions.
433
-	 *
434
-	 * @return $this This QueryBuilder instance.
435
-	 */
436
-	public function selectDistinct($select) {
437
-
438
-		$this->queryBuilder->addSelect(
439
-			'DISTINCT ' . $this->helper->quoteColumnName($select)
440
-		);
441
-
442
-		return $this;
443
-	}
444
-
445
-	/**
446
-	 * Adds an item that is to be returned in the query result.
447
-	 *
448
-	 * <code>
449
-	 *     $qb = $conn->getQueryBuilder()
450
-	 *         ->select('u.id')
451
-	 *         ->addSelect('p.id')
452
-	 *         ->from('users', 'u')
453
-	 *         ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
454
-	 * </code>
455
-	 *
456
-	 * @param mixed ...$selects The selection expression.
457
-	 *
458
-	 * @return $this This QueryBuilder instance.
459
-	 */
460
-	public function addSelect(...$selects) {
461
-		if (count($selects) === 1 && is_array($selects[0])) {
462
-			$selects = $selects[0];
463
-		}
464
-
465
-		$this->queryBuilder->addSelect(
466
-			$this->helper->quoteColumnNames($selects)
467
-		);
468
-
469
-		return $this;
470
-	}
471
-
472
-	/**
473
-	 * Turns the query being built into a bulk delete query that ranges over
474
-	 * a certain table.
475
-	 *
476
-	 * <code>
477
-	 *     $qb = $conn->getQueryBuilder()
478
-	 *         ->delete('users', 'u')
479
-	 *         ->where('u.id = :user_id');
480
-	 *         ->setParameter(':user_id', 1);
481
-	 * </code>
482
-	 *
483
-	 * @param string $delete The table whose rows are subject to the deletion.
484
-	 * @param string $alias The table alias used in the constructed query.
485
-	 *
486
-	 * @return $this This QueryBuilder instance.
487
-	 */
488
-	public function delete($delete = null, $alias = null) {
489
-		$this->queryBuilder->delete(
490
-			$this->getTableName($delete),
491
-			$alias
492
-		);
493
-
494
-		return $this;
495
-	}
496
-
497
-	/**
498
-	 * Turns the query being built into a bulk update query that ranges over
499
-	 * a certain table
500
-	 *
501
-	 * <code>
502
-	 *     $qb = $conn->getQueryBuilder()
503
-	 *         ->update('users', 'u')
504
-	 *         ->set('u.password', md5('password'))
505
-	 *         ->where('u.id = ?');
506
-	 * </code>
507
-	 *
508
-	 * @param string $update The table whose rows are subject to the update.
509
-	 * @param string $alias The table alias used in the constructed query.
510
-	 *
511
-	 * @return $this This QueryBuilder instance.
512
-	 */
513
-	public function update($update = null, $alias = null) {
514
-		$this->queryBuilder->update(
515
-			$this->getTableName($update),
516
-			$alias
517
-		);
518
-
519
-		return $this;
520
-	}
521
-
522
-	/**
523
-	 * Turns the query being built into an insert query that inserts into
524
-	 * a certain table
525
-	 *
526
-	 * <code>
527
-	 *     $qb = $conn->getQueryBuilder()
528
-	 *         ->insert('users')
529
-	 *         ->values(
530
-	 *             array(
531
-	 *                 'name' => '?',
532
-	 *                 'password' => '?'
533
-	 *             )
534
-	 *         );
535
-	 * </code>
536
-	 *
537
-	 * @param string $insert The table into which the rows should be inserted.
538
-	 *
539
-	 * @return $this This QueryBuilder instance.
540
-	 */
541
-	public function insert($insert = null) {
542
-		$this->queryBuilder->insert(
543
-			$this->getTableName($insert)
544
-		);
545
-
546
-		$this->lastInsertedTable = $insert;
547
-
548
-		return $this;
549
-	}
550
-
551
-	/**
552
-	 * Creates and adds a query root corresponding to the table identified by the
553
-	 * given alias, forming a cartesian product with any existing query roots.
554
-	 *
555
-	 * <code>
556
-	 *     $qb = $conn->getQueryBuilder()
557
-	 *         ->select('u.id')
558
-	 *         ->from('users', 'u')
559
-	 * </code>
560
-	 *
561
-	 * @param string $from The table.
562
-	 * @param string|null $alias The alias of the table.
563
-	 *
564
-	 * @return $this This QueryBuilder instance.
565
-	 */
566
-	public function from($from, $alias = null) {
567
-		$this->queryBuilder->from(
568
-			$this->getTableName($from),
569
-			$this->quoteAlias($alias)
570
-		);
571
-
572
-		return $this;
573
-	}
574
-
575
-	/**
576
-	 * Creates and adds a join to the query.
577
-	 *
578
-	 * <code>
579
-	 *     $qb = $conn->getQueryBuilder()
580
-	 *         ->select('u.name')
581
-	 *         ->from('users', 'u')
582
-	 *         ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1');
583
-	 * </code>
584
-	 *
585
-	 * @param string $fromAlias The alias that points to a from clause.
586
-	 * @param string $join The table name to join.
587
-	 * @param string $alias The alias of the join table.
588
-	 * @param string $condition The condition for the join.
589
-	 *
590
-	 * @return $this This QueryBuilder instance.
591
-	 */
592
-	public function join($fromAlias, $join, $alias, $condition = null) {
593
-		$this->queryBuilder->join(
594
-			$this->quoteAlias($fromAlias),
595
-			$this->getTableName($join),
596
-			$this->quoteAlias($alias),
597
-			$condition
598
-		);
599
-
600
-		return $this;
601
-	}
602
-
603
-	/**
604
-	 * Creates and adds a join to the query.
605
-	 *
606
-	 * <code>
607
-	 *     $qb = $conn->getQueryBuilder()
608
-	 *         ->select('u.name')
609
-	 *         ->from('users', 'u')
610
-	 *         ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
611
-	 * </code>
612
-	 *
613
-	 * @param string $fromAlias The alias that points to a from clause.
614
-	 * @param string $join The table name to join.
615
-	 * @param string $alias The alias of the join table.
616
-	 * @param string $condition The condition for the join.
617
-	 *
618
-	 * @return $this This QueryBuilder instance.
619
-	 */
620
-	public function innerJoin($fromAlias, $join, $alias, $condition = null) {
621
-		$this->queryBuilder->innerJoin(
622
-			$this->quoteAlias($fromAlias),
623
-			$this->getTableName($join),
624
-			$this->quoteAlias($alias),
625
-			$condition
626
-		);
627
-
628
-		return $this;
629
-	}
630
-
631
-	/**
632
-	 * Creates and adds a left join to the query.
633
-	 *
634
-	 * <code>
635
-	 *     $qb = $conn->getQueryBuilder()
636
-	 *         ->select('u.name')
637
-	 *         ->from('users', 'u')
638
-	 *         ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
639
-	 * </code>
640
-	 *
641
-	 * @param string $fromAlias The alias that points to a from clause.
642
-	 * @param string $join The table name to join.
643
-	 * @param string $alias The alias of the join table.
644
-	 * @param string $condition The condition for the join.
645
-	 *
646
-	 * @return $this This QueryBuilder instance.
647
-	 */
648
-	public function leftJoin($fromAlias, $join, $alias, $condition = null) {
649
-		$this->queryBuilder->leftJoin(
650
-			$this->quoteAlias($fromAlias),
651
-			$this->getTableName($join),
652
-			$this->quoteAlias($alias),
653
-			$condition
654
-		);
655
-
656
-		return $this;
657
-	}
658
-
659
-	/**
660
-	 * Creates and adds a right join to the query.
661
-	 *
662
-	 * <code>
663
-	 *     $qb = $conn->getQueryBuilder()
664
-	 *         ->select('u.name')
665
-	 *         ->from('users', 'u')
666
-	 *         ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
667
-	 * </code>
668
-	 *
669
-	 * @param string $fromAlias The alias that points to a from clause.
670
-	 * @param string $join The table name to join.
671
-	 * @param string $alias The alias of the join table.
672
-	 * @param string $condition The condition for the join.
673
-	 *
674
-	 * @return $this This QueryBuilder instance.
675
-	 */
676
-	public function rightJoin($fromAlias, $join, $alias, $condition = null) {
677
-		$this->queryBuilder->rightJoin(
678
-			$this->quoteAlias($fromAlias),
679
-			$this->getTableName($join),
680
-			$this->quoteAlias($alias),
681
-			$condition
682
-		);
683
-
684
-		return $this;
685
-	}
686
-
687
-	/**
688
-	 * Sets a new value for a column in a bulk update query.
689
-	 *
690
-	 * <code>
691
-	 *     $qb = $conn->getQueryBuilder()
692
-	 *         ->update('users', 'u')
693
-	 *         ->set('u.password', md5('password'))
694
-	 *         ->where('u.id = ?');
695
-	 * </code>
696
-	 *
697
-	 * @param string $key The column to set.
698
-	 * @param string $value The value, expression, placeholder, etc.
699
-	 *
700
-	 * @return $this This QueryBuilder instance.
701
-	 */
702
-	public function set($key, $value) {
703
-		$this->queryBuilder->set(
704
-			$this->helper->quoteColumnName($key),
705
-			$this->helper->quoteColumnName($value)
706
-		);
707
-
708
-		return $this;
709
-	}
710
-
711
-	/**
712
-	 * Specifies one or more restrictions to the query result.
713
-	 * Replaces any previously specified restrictions, if any.
714
-	 *
715
-	 * <code>
716
-	 *     $qb = $conn->getQueryBuilder()
717
-	 *         ->select('u.name')
718
-	 *         ->from('users', 'u')
719
-	 *         ->where('u.id = ?');
720
-	 *
721
-	 *     // You can optionally programatically build and/or expressions
722
-	 *     $qb = $conn->getQueryBuilder();
723
-	 *
724
-	 *     $or = $qb->expr()->orx();
725
-	 *     $or->add($qb->expr()->eq('u.id', 1));
726
-	 *     $or->add($qb->expr()->eq('u.id', 2));
727
-	 *
728
-	 *     $qb->update('users', 'u')
729
-	 *         ->set('u.password', md5('password'))
730
-	 *         ->where($or);
731
-	 * </code>
732
-	 *
733
-	 * @param mixed ...$predicates The restriction predicates.
734
-	 *
735
-	 * @return $this This QueryBuilder instance.
736
-	 */
737
-	public function where(...$predicates) {
738
-		call_user_func_array(
739
-			[$this->queryBuilder, 'where'],
740
-			$predicates
741
-		);
742
-
743
-		return $this;
744
-	}
745
-
746
-	/**
747
-	 * Adds one or more restrictions to the query results, forming a logical
748
-	 * conjunction with any previously specified restrictions.
749
-	 *
750
-	 * <code>
751
-	 *     $qb = $conn->getQueryBuilder()
752
-	 *         ->select('u')
753
-	 *         ->from('users', 'u')
754
-	 *         ->where('u.username LIKE ?')
755
-	 *         ->andWhere('u.is_active = 1');
756
-	 * </code>
757
-	 *
758
-	 * @param mixed ...$where The query restrictions.
759
-	 *
760
-	 * @return $this This QueryBuilder instance.
761
-	 *
762
-	 * @see where()
763
-	 */
764
-	public function andWhere(...$where) {
765
-		call_user_func_array(
766
-			[$this->queryBuilder, 'andWhere'],
767
-			$where
768
-		);
769
-
770
-		return $this;
771
-	}
772
-
773
-	/**
774
-	 * Adds one or more restrictions to the query results, forming a logical
775
-	 * disjunction with any previously specified restrictions.
776
-	 *
777
-	 * <code>
778
-	 *     $qb = $conn->getQueryBuilder()
779
-	 *         ->select('u.name')
780
-	 *         ->from('users', 'u')
781
-	 *         ->where('u.id = 1')
782
-	 *         ->orWhere('u.id = 2');
783
-	 * </code>
784
-	 *
785
-	 * @param mixed ...$where The WHERE statement.
786
-	 *
787
-	 * @return $this This QueryBuilder instance.
788
-	 *
789
-	 * @see where()
790
-	 */
791
-	public function orWhere(...$where) {
792
-		call_user_func_array(
793
-			[$this->queryBuilder, 'orWhere'],
794
-			$where
795
-		);
796
-
797
-		return $this;
798
-	}
799
-
800
-	/**
801
-	 * Specifies a grouping over the results of the query.
802
-	 * Replaces any previously specified groupings, if any.
803
-	 *
804
-	 * <code>
805
-	 *     $qb = $conn->getQueryBuilder()
806
-	 *         ->select('u.name')
807
-	 *         ->from('users', 'u')
808
-	 *         ->groupBy('u.id');
809
-	 * </code>
810
-	 *
811
-	 * @param mixed ...$groupBys The grouping expression.
812
-	 *
813
-	 * @return $this This QueryBuilder instance.
814
-	 */
815
-	public function groupBy(...$groupBys) {
816
-		if (count($groupBys) === 1 && is_array($groupBys[0])) {
817
-			$groupBys = $groupBys[0];
818
-		}
819
-
820
-		call_user_func_array(
821
-			[$this->queryBuilder, 'groupBy'],
822
-			$this->helper->quoteColumnNames($groupBys)
823
-		);
824
-
825
-		return $this;
826
-	}
827
-
828
-	/**
829
-	 * Adds a grouping expression to the query.
830
-	 *
831
-	 * <code>
832
-	 *     $qb = $conn->getQueryBuilder()
833
-	 *         ->select('u.name')
834
-	 *         ->from('users', 'u')
835
-	 *         ->groupBy('u.lastLogin');
836
-	 *         ->addGroupBy('u.createdAt')
837
-	 * </code>
838
-	 *
839
-	 * @param mixed ...$groupBy The grouping expression.
840
-	 *
841
-	 * @return $this This QueryBuilder instance.
842
-	 */
843
-	public function addGroupBy(...$groupBys) {
844
-		if (count($groupBys) === 1 && is_array($groupBys[0])) {
845
-			$$groupBys = $groupBys[0];
846
-		}
847
-
848
-		call_user_func_array(
849
-			[$this->queryBuilder, 'addGroupBy'],
850
-			$this->helper->quoteColumnNames($groupBys)
851
-		);
852
-
853
-		return $this;
854
-	}
855
-
856
-	/**
857
-	 * Sets a value for a column in an insert query.
858
-	 *
859
-	 * <code>
860
-	 *     $qb = $conn->getQueryBuilder()
861
-	 *         ->insert('users')
862
-	 *         ->values(
863
-	 *             array(
864
-	 *                 'name' => '?'
865
-	 *             )
866
-	 *         )
867
-	 *         ->setValue('password', '?');
868
-	 * </code>
869
-	 *
870
-	 * @param string $column The column into which the value should be inserted.
871
-	 * @param string $value The value that should be inserted into the column.
872
-	 *
873
-	 * @return $this This QueryBuilder instance.
874
-	 */
875
-	public function setValue($column, $value) {
876
-		$this->queryBuilder->setValue(
877
-			$this->helper->quoteColumnName($column),
878
-			$value
879
-		);
880
-
881
-		return $this;
882
-	}
883
-
884
-	/**
885
-	 * Specifies values for an insert query indexed by column names.
886
-	 * Replaces any previous values, if any.
887
-	 *
888
-	 * <code>
889
-	 *     $qb = $conn->getQueryBuilder()
890
-	 *         ->insert('users')
891
-	 *         ->values(
892
-	 *             array(
893
-	 *                 'name' => '?',
894
-	 *                 'password' => '?'
895
-	 *             )
896
-	 *         );
897
-	 * </code>
898
-	 *
899
-	 * @param array $values The values to specify for the insert query indexed by column names.
900
-	 *
901
-	 * @return $this This QueryBuilder instance.
902
-	 */
903
-	public function values(array $values) {
904
-		$quotedValues = [];
905
-		foreach ($values as $key => $value) {
906
-			$quotedValues[$this->helper->quoteColumnName($key)] = $value;
907
-		}
908
-
909
-		$this->queryBuilder->values($quotedValues);
910
-
911
-		return $this;
912
-	}
913
-
914
-	/**
915
-	 * Specifies a restriction over the groups of the query.
916
-	 * Replaces any previous having restrictions, if any.
917
-	 *
918
-	 * @param mixed ...$having The restriction over the groups.
919
-	 *
920
-	 * @return $this This QueryBuilder instance.
921
-	 */
922
-	public function having(...$having) {
923
-		call_user_func_array(
924
-			[$this->queryBuilder, 'having'],
925
-			$having
926
-		);
927
-
928
-		return $this;
929
-	}
930
-
931
-	/**
932
-	 * Adds a restriction over the groups of the query, forming a logical
933
-	 * conjunction with any existing having restrictions.
934
-	 *
935
-	 * @param mixed ...$having The restriction to append.
936
-	 *
937
-	 * @return $this This QueryBuilder instance.
938
-	 */
939
-	public function andHaving(...$having) {
940
-		call_user_func_array(
941
-			[$this->queryBuilder, 'andHaving'],
942
-			$having
943
-		);
944
-
945
-		return $this;
946
-	}
947
-
948
-	/**
949
-	 * Adds a restriction over the groups of the query, forming a logical
950
-	 * disjunction with any existing having restrictions.
951
-	 *
952
-	 * @param mixed ...$having The restriction to add.
953
-	 *
954
-	 * @return $this This QueryBuilder instance.
955
-	 */
956
-	public function orHaving(...$having) {
957
-		call_user_func_array(
958
-			[$this->queryBuilder, 'orHaving'],
959
-			$having
960
-		);
961
-
962
-		return $this;
963
-	}
964
-
965
-	/**
966
-	 * Specifies an ordering for the query results.
967
-	 * Replaces any previously specified orderings, if any.
968
-	 *
969
-	 * @param string $sort The ordering expression.
970
-	 * @param string $order The ordering direction.
971
-	 *
972
-	 * @return $this This QueryBuilder instance.
973
-	 */
974
-	public function orderBy($sort, $order = null) {
975
-		$this->queryBuilder->orderBy(
976
-			$this->helper->quoteColumnName($sort),
977
-			$order
978
-		);
979
-
980
-		return $this;
981
-	}
982
-
983
-	/**
984
-	 * Adds an ordering to the query results.
985
-	 *
986
-	 * @param string $sort The ordering expression.
987
-	 * @param string $order The ordering direction.
988
-	 *
989
-	 * @return $this This QueryBuilder instance.
990
-	 */
991
-	public function addOrderBy($sort, $order = null) {
992
-		$this->queryBuilder->addOrderBy(
993
-			$this->helper->quoteColumnName($sort),
994
-			$order
995
-		);
996
-
997
-		return $this;
998
-	}
999
-
1000
-	/**
1001
-	 * Gets a query part by its name.
1002
-	 *
1003
-	 * @param string $queryPartName
1004
-	 *
1005
-	 * @return mixed
1006
-	 */
1007
-	public function getQueryPart($queryPartName) {
1008
-		return $this->queryBuilder->getQueryPart($queryPartName);
1009
-	}
1010
-
1011
-	/**
1012
-	 * Gets all query parts.
1013
-	 *
1014
-	 * @return array
1015
-	 */
1016
-	public function getQueryParts() {
1017
-		return $this->queryBuilder->getQueryParts();
1018
-	}
1019
-
1020
-	/**
1021
-	 * Resets SQL parts.
1022
-	 *
1023
-	 * @param array|null $queryPartNames
1024
-	 *
1025
-	 * @return $this This QueryBuilder instance.
1026
-	 */
1027
-	public function resetQueryParts($queryPartNames = null) {
1028
-		$this->queryBuilder->resetQueryParts($queryPartNames);
1029
-
1030
-		return $this;
1031
-	}
1032
-
1033
-	/**
1034
-	 * Resets a single SQL part.
1035
-	 *
1036
-	 * @param string $queryPartName
1037
-	 *
1038
-	 * @return $this This QueryBuilder instance.
1039
-	 */
1040
-	public function resetQueryPart($queryPartName) {
1041
-		$this->queryBuilder->resetQueryPart($queryPartName);
1042
-
1043
-		return $this;
1044
-	}
1045
-
1046
-	/**
1047
-	 * Creates a new named parameter and bind the value $value to it.
1048
-	 *
1049
-	 * This method provides a shortcut for PDOStatement::bindValue
1050
-	 * when using prepared statements.
1051
-	 *
1052
-	 * The parameter $value specifies the value that you want to bind. If
1053
-	 * $placeholder is not provided bindValue() will automatically create a
1054
-	 * placeholder for you. An automatic placeholder will be of the name
1055
-	 * ':dcValue1', ':dcValue2' etc.
1056
-	 *
1057
-	 * For more information see {@link http://php.net/pdostatement-bindparam}
1058
-	 *
1059
-	 * Example:
1060
-	 * <code>
1061
-	 * $value = 2;
1062
-	 * $q->eq( 'id', $q->bindValue( $value ) );
1063
-	 * $stmt = $q->executeQuery(); // executed with 'id = 2'
1064
-	 * </code>
1065
-	 *
1066
-	 * @license New BSD License
1067
-	 * @link http://www.zetacomponents.org
1068
-	 *
1069
-	 * @param mixed $value
1070
-	 * @param mixed $type
1071
-	 * @param string $placeHolder The name to bind with. The string must start with a colon ':'.
1072
-	 *
1073
-	 * @return IParameter the placeholder name used.
1074
-	 */
1075
-	public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) {
1076
-		return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder));
1077
-	}
1078
-
1079
-	/**
1080
-	 * Creates a new positional parameter and bind the given value to it.
1081
-	 *
1082
-	 * Attention: If you are using positional parameters with the query builder you have
1083
-	 * to be very careful to bind all parameters in the order they appear in the SQL
1084
-	 * statement , otherwise they get bound in the wrong order which can lead to serious
1085
-	 * bugs in your code.
1086
-	 *
1087
-	 * Example:
1088
-	 * <code>
1089
-	 *  $qb = $conn->getQueryBuilder();
1090
-	 *  $qb->select('u.*')
1091
-	 *     ->from('users', 'u')
1092
-	 *     ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR))
1093
-	 *     ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR))
1094
-	 * </code>
1095
-	 *
1096
-	 * @param mixed $value
1097
-	 * @param integer $type
1098
-	 *
1099
-	 * @return IParameter
1100
-	 */
1101
-	public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) {
1102
-		return new Parameter($this->queryBuilder->createPositionalParameter($value, $type));
1103
-	}
1104
-
1105
-	/**
1106
-	 * Creates a new parameter
1107
-	 *
1108
-	 * Example:
1109
-	 * <code>
1110
-	 *  $qb = $conn->getQueryBuilder();
1111
-	 *  $qb->select('u.*')
1112
-	 *     ->from('users', 'u')
1113
-	 *     ->where('u.username = ' . $qb->createParameter('name'))
1114
-	 *     ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR))
1115
-	 * </code>
1116
-	 *
1117
-	 * @param string $name
1118
-	 *
1119
-	 * @return IParameter
1120
-	 */
1121
-	public function createParameter($name) {
1122
-		return new Parameter(':' . $name);
1123
-	}
1124
-
1125
-	/**
1126
-	 * Creates a new function
1127
-	 *
1128
-	 * Attention: Column names inside the call have to be quoted before hand
1129
-	 *
1130
-	 * Example:
1131
-	 * <code>
1132
-	 *  $qb = $conn->getQueryBuilder();
1133
-	 *  $qb->select($qb->createFunction('COUNT(*)'))
1134
-	 *     ->from('users', 'u')
1135
-	 *  echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
1136
-	 * </code>
1137
-	 * <code>
1138
-	 *  $qb = $conn->getQueryBuilder();
1139
-	 *  $qb->select($qb->createFunction('COUNT(`column`)'))
1140
-	 *     ->from('users', 'u')
1141
-	 *  echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
1142
-	 * </code>
1143
-	 *
1144
-	 * @param string $call
1145
-	 *
1146
-	 * @return IQueryFunction
1147
-	 */
1148
-	public function createFunction($call) {
1149
-		return new QueryFunction($call);
1150
-	}
1151
-
1152
-	/**
1153
-	 * Used to get the id of the last inserted element
1154
-	 * @return int
1155
-	 * @throws \BadMethodCallException When being called before an insert query has been run.
1156
-	 */
1157
-	public function getLastInsertId() {
1158
-		if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) {
1159
-			// lastInsertId() needs the prefix but no quotes
1160
-			$table = $this->prefixTableName($this->lastInsertedTable);
1161
-			return (int) $this->connection->lastInsertId($table);
1162
-		}
1163
-
1164
-		throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.');
1165
-	}
1166
-
1167
-	/**
1168
-	 * Returns the table name quoted and with database prefix as needed by the implementation
1169
-	 *
1170
-	 * @param string $table
1171
-	 * @return string
1172
-	 */
1173
-	public function getTableName($table) {
1174
-		if ($table instanceof IQueryFunction) {
1175
-			return (string) $table;
1176
-		}
1177
-
1178
-		$table = $this->prefixTableName($table);
1179
-		return $this->helper->quoteColumnName($table);
1180
-	}
1181
-
1182
-	/**
1183
-	 * Returns the table name with database prefix as needed by the implementation
1184
-	 *
1185
-	 * @param string $table
1186
-	 * @return string
1187
-	 */
1188
-	protected function prefixTableName($table) {
1189
-		if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) {
1190
-			return $table;
1191
-		}
1192
-
1193
-		return '*PREFIX*' . $table;
1194
-	}
1195
-
1196
-	/**
1197
-	 * Returns the column name quoted and with table alias prefix as needed by the implementation
1198
-	 *
1199
-	 * @param string $column
1200
-	 * @param string $tableAlias
1201
-	 * @return string
1202
-	 */
1203
-	public function getColumnName($column, $tableAlias = '') {
1204
-		if ($tableAlias !== '') {
1205
-			$tableAlias .= '.';
1206
-		}
1207
-
1208
-		return $this->helper->quoteColumnName($tableAlias . $column);
1209
-	}
1210
-
1211
-	/**
1212
-	 * Returns the column name quoted and with table alias prefix as needed by the implementation
1213
-	 *
1214
-	 * @param string $alias
1215
-	 * @return string
1216
-	 */
1217
-	public function quoteAlias($alias) {
1218
-		if ($alias === '' || $alias === null) {
1219
-			return $alias;
1220
-		}
1221
-
1222
-		return $this->helper->quoteColumnName($alias);
1223
-	}
51
+    /** @var \OCP\IDBConnection */
52
+    private $connection;
53
+
54
+    /** @var SystemConfig */
55
+    private $systemConfig;
56
+
57
+    /** @var ILogger */
58
+    private $logger;
59
+
60
+    /** @var \Doctrine\DBAL\Query\QueryBuilder */
61
+    private $queryBuilder;
62
+
63
+    /** @var QuoteHelper */
64
+    private $helper;
65
+
66
+    /** @var bool */
67
+    private $automaticTablePrefix = true;
68
+
69
+    /** @var string */
70
+    protected $lastInsertedTable;
71
+
72
+    /**
73
+     * Initializes a new QueryBuilder.
74
+     *
75
+     * @param IDBConnection $connection
76
+     * @param SystemConfig $systemConfig
77
+     * @param ILogger $logger
78
+     */
79
+    public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) {
80
+        $this->connection = $connection;
81
+        $this->systemConfig = $systemConfig;
82
+        $this->logger = $logger;
83
+        $this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection);
84
+        $this->helper = new QuoteHelper();
85
+    }
86
+
87
+    /**
88
+     * Enable/disable automatic prefixing of table names with the oc_ prefix
89
+     *
90
+     * @param bool $enabled If set to true table names will be prefixed with the
91
+     * owncloud database prefix automatically.
92
+     * @since 8.2.0
93
+     */
94
+    public function automaticTablePrefix($enabled) {
95
+        $this->automaticTablePrefix = (bool) $enabled;
96
+    }
97
+
98
+    /**
99
+     * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
100
+     * This producer method is intended for convenient inline usage. Example:
101
+     *
102
+     * <code>
103
+     *     $qb = $conn->getQueryBuilder()
104
+     *         ->select('u')
105
+     *         ->from('users', 'u')
106
+     *         ->where($qb->expr()->eq('u.id', 1));
107
+     * </code>
108
+     *
109
+     * For more complex expression construction, consider storing the expression
110
+     * builder object in a local variable.
111
+     *
112
+     * @return \OCP\DB\QueryBuilder\IExpressionBuilder
113
+     */
114
+    public function expr() {
115
+        if ($this->connection instanceof OracleConnection) {
116
+            return new OCIExpressionBuilder($this->connection, $this);
117
+        } else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
118
+            return new PgSqlExpressionBuilder($this->connection, $this);
119
+        } else if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
120
+            return new MySqlExpressionBuilder($this->connection, $this);
121
+        } else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
122
+            return new SqliteExpressionBuilder($this->connection, $this);
123
+        } else {
124
+            return new ExpressionBuilder($this->connection, $this);
125
+        }
126
+    }
127
+
128
+    /**
129
+     * Gets an FunctionBuilder used for object-oriented construction of query functions.
130
+     * This producer method is intended for convenient inline usage. Example:
131
+     *
132
+     * <code>
133
+     *     $qb = $conn->getQueryBuilder()
134
+     *         ->select('u')
135
+     *         ->from('users', 'u')
136
+     *         ->where($qb->fun()->md5('u.id'));
137
+     * </code>
138
+     *
139
+     * For more complex function construction, consider storing the function
140
+     * builder object in a local variable.
141
+     *
142
+     * @return \OCP\DB\QueryBuilder\IFunctionBuilder
143
+     */
144
+    public function func() {
145
+        if ($this->connection instanceof OracleConnection) {
146
+            return new OCIFunctionBuilder($this->helper);
147
+        } else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
148
+            return new SqliteFunctionBuilder($this->helper);
149
+        } else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
150
+            return new PgSqlFunctionBuilder($this->helper);
151
+        } else {
152
+            return new FunctionBuilder($this->helper);
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Gets the type of the currently built query.
158
+     *
159
+     * @return integer
160
+     */
161
+    public function getType() {
162
+        return $this->queryBuilder->getType();
163
+    }
164
+
165
+    /**
166
+     * Gets the associated DBAL Connection for this query builder.
167
+     *
168
+     * @return \OCP\IDBConnection
169
+     */
170
+    public function getConnection() {
171
+        return $this->connection;
172
+    }
173
+
174
+    /**
175
+     * Gets the state of this query builder instance.
176
+     *
177
+     * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.
178
+     */
179
+    public function getState() {
180
+        return $this->queryBuilder->getState();
181
+    }
182
+
183
+    /**
184
+     * Executes this query using the bound parameters and their types.
185
+     *
186
+     * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
187
+     * for insert, update and delete statements.
188
+     *
189
+     * @return \Doctrine\DBAL\Driver\Statement|int
190
+     */
191
+    public function execute() {
192
+        if ($this->systemConfig->getValue('log_query', false)) {
193
+            $params = [];
194
+            foreach ($this->getParameters() as $placeholder => $value) {
195
+                if (is_array($value)) {
196
+                    $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')';
197
+                } else {
198
+                    $params[] = $placeholder . ' => \'' . $value . '\'';
199
+                }
200
+            }
201
+            if (empty($params)) {
202
+                $this->logger->debug('DB QueryBuilder: \'{query}\'', [
203
+                    'query' => $this->getSQL(),
204
+                    'app' => 'core',
205
+                ]);
206
+            } else {
207
+                $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [
208
+                    'query' => $this->getSQL(),
209
+                    'params' => implode(', ', $params),
210
+                    'app' => 'core',
211
+                ]);
212
+            }
213
+        }
214
+
215
+        return $this->queryBuilder->execute();
216
+    }
217
+
218
+    /**
219
+     * Gets the complete SQL string formed by the current specifications of this QueryBuilder.
220
+     *
221
+     * <code>
222
+     *     $qb = $conn->getQueryBuilder()
223
+     *         ->select('u')
224
+     *         ->from('User', 'u')
225
+     *     echo $qb->getSQL(); // SELECT u FROM User u
226
+     * </code>
227
+     *
228
+     * @return string The SQL query string.
229
+     */
230
+    public function getSQL() {
231
+        return $this->queryBuilder->getSQL();
232
+    }
233
+
234
+    /**
235
+     * Sets a query parameter for the query being constructed.
236
+     *
237
+     * <code>
238
+     *     $qb = $conn->getQueryBuilder()
239
+     *         ->select('u')
240
+     *         ->from('users', 'u')
241
+     *         ->where('u.id = :user_id')
242
+     *         ->setParameter(':user_id', 1);
243
+     * </code>
244
+     *
245
+     * @param string|integer $key The parameter position or name.
246
+     * @param mixed $value The parameter value.
247
+     * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants.
248
+     *
249
+     * @return $this This QueryBuilder instance.
250
+     */
251
+    public function setParameter($key, $value, $type = null) {
252
+        $this->queryBuilder->setParameter($key, $value, $type);
253
+
254
+        return $this;
255
+    }
256
+
257
+    /**
258
+     * Sets a collection of query parameters for the query being constructed.
259
+     *
260
+     * <code>
261
+     *     $qb = $conn->getQueryBuilder()
262
+     *         ->select('u')
263
+     *         ->from('users', 'u')
264
+     *         ->where('u.id = :user_id1 OR u.id = :user_id2')
265
+     *         ->setParameters(array(
266
+     *             ':user_id1' => 1,
267
+     *             ':user_id2' => 2
268
+     *         ));
269
+     * </code>
270
+     *
271
+     * @param array $params The query parameters to set.
272
+     * @param array $types The query parameters types to set.
273
+     *
274
+     * @return $this This QueryBuilder instance.
275
+     */
276
+    public function setParameters(array $params, array $types = []) {
277
+        $this->queryBuilder->setParameters($params, $types);
278
+
279
+        return $this;
280
+    }
281
+
282
+    /**
283
+     * Gets all defined query parameters for the query being constructed indexed by parameter index or name.
284
+     *
285
+     * @return array The currently defined query parameters indexed by parameter index or name.
286
+     */
287
+    public function getParameters() {
288
+        return $this->queryBuilder->getParameters();
289
+    }
290
+
291
+    /**
292
+     * Gets a (previously set) query parameter of the query being constructed.
293
+     *
294
+     * @param mixed $key The key (index or name) of the bound parameter.
295
+     *
296
+     * @return mixed The value of the bound parameter.
297
+     */
298
+    public function getParameter($key) {
299
+        return $this->queryBuilder->getParameter($key);
300
+    }
301
+
302
+    /**
303
+     * Gets all defined query parameter types for the query being constructed indexed by parameter index or name.
304
+     *
305
+     * @return array The currently defined query parameter types indexed by parameter index or name.
306
+     */
307
+    public function getParameterTypes() {
308
+        return $this->queryBuilder->getParameterTypes();
309
+    }
310
+
311
+    /**
312
+     * Gets a (previously set) query parameter type of the query being constructed.
313
+     *
314
+     * @param mixed $key The key (index or name) of the bound parameter type.
315
+     *
316
+     * @return mixed The value of the bound parameter type.
317
+     */
318
+    public function getParameterType($key) {
319
+        return $this->queryBuilder->getParameterType($key);
320
+    }
321
+
322
+    /**
323
+     * Sets the position of the first result to retrieve (the "offset").
324
+     *
325
+     * @param integer $firstResult The first result to return.
326
+     *
327
+     * @return $this This QueryBuilder instance.
328
+     */
329
+    public function setFirstResult($firstResult) {
330
+        $this->queryBuilder->setFirstResult($firstResult);
331
+
332
+        return $this;
333
+    }
334
+
335
+    /**
336
+     * Gets the position of the first result the query object was set to retrieve (the "offset").
337
+     * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
338
+     *
339
+     * @return integer The position of the first result.
340
+     */
341
+    public function getFirstResult() {
342
+        return $this->queryBuilder->getFirstResult();
343
+    }
344
+
345
+    /**
346
+     * Sets the maximum number of results to retrieve (the "limit").
347
+     *
348
+     * NOTE: Setting max results to "0" will cause mixed behaviour. While most
349
+     * of the databases will just return an empty result set, Oracle will return
350
+     * all entries.
351
+     *
352
+     * @param integer $maxResults The maximum number of results to retrieve.
353
+     *
354
+     * @return $this This QueryBuilder instance.
355
+     */
356
+    public function setMaxResults($maxResults) {
357
+        $this->queryBuilder->setMaxResults($maxResults);
358
+
359
+        return $this;
360
+    }
361
+
362
+    /**
363
+     * Gets the maximum number of results the query object was set to retrieve (the "limit").
364
+     * Returns NULL if {@link setMaxResults} was not applied to this query builder.
365
+     *
366
+     * @return integer The maximum number of results.
367
+     */
368
+    public function getMaxResults() {
369
+        return $this->queryBuilder->getMaxResults();
370
+    }
371
+
372
+    /**
373
+     * Specifies an item that is to be returned in the query result.
374
+     * Replaces any previously specified selections, if any.
375
+     *
376
+     * <code>
377
+     *     $qb = $conn->getQueryBuilder()
378
+     *         ->select('u.id', 'p.id')
379
+     *         ->from('users', 'u')
380
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
381
+     * </code>
382
+     *
383
+     * @param mixed ...$selects The selection expressions.
384
+     *
385
+     * '@return $this This QueryBuilder instance.
386
+     */
387
+    public function select(...$selects) {
388
+        if (count($selects) === 1 && is_array($selects[0])) {
389
+            $selects = $selects[0];
390
+        }
391
+
392
+        $this->queryBuilder->select(
393
+            $this->helper->quoteColumnNames($selects)
394
+        );
395
+
396
+        return $this;
397
+    }
398
+
399
+    /**
400
+     * Specifies an item that is to be returned with a different name in the query result.
401
+     *
402
+     * <code>
403
+     *     $qb = $conn->getQueryBuilder()
404
+     *         ->selectAlias('u.id', 'user_id')
405
+     *         ->from('users', 'u')
406
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
407
+     * </code>
408
+     *
409
+     * @param mixed $select The selection expressions.
410
+     * @param string $alias The column alias used in the constructed query.
411
+     *
412
+     * @return $this This QueryBuilder instance.
413
+     */
414
+    public function selectAlias($select, $alias) {
415
+
416
+        $this->queryBuilder->addSelect(
417
+            $this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias)
418
+        );
419
+
420
+        return $this;
421
+    }
422
+
423
+    /**
424
+     * Specifies an item that is to be returned uniquely in the query result.
425
+     *
426
+     * <code>
427
+     *     $qb = $conn->getQueryBuilder()
428
+     *         ->selectDistinct('type')
429
+     *         ->from('users');
430
+     * </code>
431
+     *
432
+     * @param mixed $select The selection expressions.
433
+     *
434
+     * @return $this This QueryBuilder instance.
435
+     */
436
+    public function selectDistinct($select) {
437
+
438
+        $this->queryBuilder->addSelect(
439
+            'DISTINCT ' . $this->helper->quoteColumnName($select)
440
+        );
441
+
442
+        return $this;
443
+    }
444
+
445
+    /**
446
+     * Adds an item that is to be returned in the query result.
447
+     *
448
+     * <code>
449
+     *     $qb = $conn->getQueryBuilder()
450
+     *         ->select('u.id')
451
+     *         ->addSelect('p.id')
452
+     *         ->from('users', 'u')
453
+     *         ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
454
+     * </code>
455
+     *
456
+     * @param mixed ...$selects The selection expression.
457
+     *
458
+     * @return $this This QueryBuilder instance.
459
+     */
460
+    public function addSelect(...$selects) {
461
+        if (count($selects) === 1 && is_array($selects[0])) {
462
+            $selects = $selects[0];
463
+        }
464
+
465
+        $this->queryBuilder->addSelect(
466
+            $this->helper->quoteColumnNames($selects)
467
+        );
468
+
469
+        return $this;
470
+    }
471
+
472
+    /**
473
+     * Turns the query being built into a bulk delete query that ranges over
474
+     * a certain table.
475
+     *
476
+     * <code>
477
+     *     $qb = $conn->getQueryBuilder()
478
+     *         ->delete('users', 'u')
479
+     *         ->where('u.id = :user_id');
480
+     *         ->setParameter(':user_id', 1);
481
+     * </code>
482
+     *
483
+     * @param string $delete The table whose rows are subject to the deletion.
484
+     * @param string $alias The table alias used in the constructed query.
485
+     *
486
+     * @return $this This QueryBuilder instance.
487
+     */
488
+    public function delete($delete = null, $alias = null) {
489
+        $this->queryBuilder->delete(
490
+            $this->getTableName($delete),
491
+            $alias
492
+        );
493
+
494
+        return $this;
495
+    }
496
+
497
+    /**
498
+     * Turns the query being built into a bulk update query that ranges over
499
+     * a certain table
500
+     *
501
+     * <code>
502
+     *     $qb = $conn->getQueryBuilder()
503
+     *         ->update('users', 'u')
504
+     *         ->set('u.password', md5('password'))
505
+     *         ->where('u.id = ?');
506
+     * </code>
507
+     *
508
+     * @param string $update The table whose rows are subject to the update.
509
+     * @param string $alias The table alias used in the constructed query.
510
+     *
511
+     * @return $this This QueryBuilder instance.
512
+     */
513
+    public function update($update = null, $alias = null) {
514
+        $this->queryBuilder->update(
515
+            $this->getTableName($update),
516
+            $alias
517
+        );
518
+
519
+        return $this;
520
+    }
521
+
522
+    /**
523
+     * Turns the query being built into an insert query that inserts into
524
+     * a certain table
525
+     *
526
+     * <code>
527
+     *     $qb = $conn->getQueryBuilder()
528
+     *         ->insert('users')
529
+     *         ->values(
530
+     *             array(
531
+     *                 'name' => '?',
532
+     *                 'password' => '?'
533
+     *             )
534
+     *         );
535
+     * </code>
536
+     *
537
+     * @param string $insert The table into which the rows should be inserted.
538
+     *
539
+     * @return $this This QueryBuilder instance.
540
+     */
541
+    public function insert($insert = null) {
542
+        $this->queryBuilder->insert(
543
+            $this->getTableName($insert)
544
+        );
545
+
546
+        $this->lastInsertedTable = $insert;
547
+
548
+        return $this;
549
+    }
550
+
551
+    /**
552
+     * Creates and adds a query root corresponding to the table identified by the
553
+     * given alias, forming a cartesian product with any existing query roots.
554
+     *
555
+     * <code>
556
+     *     $qb = $conn->getQueryBuilder()
557
+     *         ->select('u.id')
558
+     *         ->from('users', 'u')
559
+     * </code>
560
+     *
561
+     * @param string $from The table.
562
+     * @param string|null $alias The alias of the table.
563
+     *
564
+     * @return $this This QueryBuilder instance.
565
+     */
566
+    public function from($from, $alias = null) {
567
+        $this->queryBuilder->from(
568
+            $this->getTableName($from),
569
+            $this->quoteAlias($alias)
570
+        );
571
+
572
+        return $this;
573
+    }
574
+
575
+    /**
576
+     * Creates and adds a join to the query.
577
+     *
578
+     * <code>
579
+     *     $qb = $conn->getQueryBuilder()
580
+     *         ->select('u.name')
581
+     *         ->from('users', 'u')
582
+     *         ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1');
583
+     * </code>
584
+     *
585
+     * @param string $fromAlias The alias that points to a from clause.
586
+     * @param string $join The table name to join.
587
+     * @param string $alias The alias of the join table.
588
+     * @param string $condition The condition for the join.
589
+     *
590
+     * @return $this This QueryBuilder instance.
591
+     */
592
+    public function join($fromAlias, $join, $alias, $condition = null) {
593
+        $this->queryBuilder->join(
594
+            $this->quoteAlias($fromAlias),
595
+            $this->getTableName($join),
596
+            $this->quoteAlias($alias),
597
+            $condition
598
+        );
599
+
600
+        return $this;
601
+    }
602
+
603
+    /**
604
+     * Creates and adds a join to the query.
605
+     *
606
+     * <code>
607
+     *     $qb = $conn->getQueryBuilder()
608
+     *         ->select('u.name')
609
+     *         ->from('users', 'u')
610
+     *         ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
611
+     * </code>
612
+     *
613
+     * @param string $fromAlias The alias that points to a from clause.
614
+     * @param string $join The table name to join.
615
+     * @param string $alias The alias of the join table.
616
+     * @param string $condition The condition for the join.
617
+     *
618
+     * @return $this This QueryBuilder instance.
619
+     */
620
+    public function innerJoin($fromAlias, $join, $alias, $condition = null) {
621
+        $this->queryBuilder->innerJoin(
622
+            $this->quoteAlias($fromAlias),
623
+            $this->getTableName($join),
624
+            $this->quoteAlias($alias),
625
+            $condition
626
+        );
627
+
628
+        return $this;
629
+    }
630
+
631
+    /**
632
+     * Creates and adds a left join to the query.
633
+     *
634
+     * <code>
635
+     *     $qb = $conn->getQueryBuilder()
636
+     *         ->select('u.name')
637
+     *         ->from('users', 'u')
638
+     *         ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
639
+     * </code>
640
+     *
641
+     * @param string $fromAlias The alias that points to a from clause.
642
+     * @param string $join The table name to join.
643
+     * @param string $alias The alias of the join table.
644
+     * @param string $condition The condition for the join.
645
+     *
646
+     * @return $this This QueryBuilder instance.
647
+     */
648
+    public function leftJoin($fromAlias, $join, $alias, $condition = null) {
649
+        $this->queryBuilder->leftJoin(
650
+            $this->quoteAlias($fromAlias),
651
+            $this->getTableName($join),
652
+            $this->quoteAlias($alias),
653
+            $condition
654
+        );
655
+
656
+        return $this;
657
+    }
658
+
659
+    /**
660
+     * Creates and adds a right join to the query.
661
+     *
662
+     * <code>
663
+     *     $qb = $conn->getQueryBuilder()
664
+     *         ->select('u.name')
665
+     *         ->from('users', 'u')
666
+     *         ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
667
+     * </code>
668
+     *
669
+     * @param string $fromAlias The alias that points to a from clause.
670
+     * @param string $join The table name to join.
671
+     * @param string $alias The alias of the join table.
672
+     * @param string $condition The condition for the join.
673
+     *
674
+     * @return $this This QueryBuilder instance.
675
+     */
676
+    public function rightJoin($fromAlias, $join, $alias, $condition = null) {
677
+        $this->queryBuilder->rightJoin(
678
+            $this->quoteAlias($fromAlias),
679
+            $this->getTableName($join),
680
+            $this->quoteAlias($alias),
681
+            $condition
682
+        );
683
+
684
+        return $this;
685
+    }
686
+
687
+    /**
688
+     * Sets a new value for a column in a bulk update query.
689
+     *
690
+     * <code>
691
+     *     $qb = $conn->getQueryBuilder()
692
+     *         ->update('users', 'u')
693
+     *         ->set('u.password', md5('password'))
694
+     *         ->where('u.id = ?');
695
+     * </code>
696
+     *
697
+     * @param string $key The column to set.
698
+     * @param string $value The value, expression, placeholder, etc.
699
+     *
700
+     * @return $this This QueryBuilder instance.
701
+     */
702
+    public function set($key, $value) {
703
+        $this->queryBuilder->set(
704
+            $this->helper->quoteColumnName($key),
705
+            $this->helper->quoteColumnName($value)
706
+        );
707
+
708
+        return $this;
709
+    }
710
+
711
+    /**
712
+     * Specifies one or more restrictions to the query result.
713
+     * Replaces any previously specified restrictions, if any.
714
+     *
715
+     * <code>
716
+     *     $qb = $conn->getQueryBuilder()
717
+     *         ->select('u.name')
718
+     *         ->from('users', 'u')
719
+     *         ->where('u.id = ?');
720
+     *
721
+     *     // You can optionally programatically build and/or expressions
722
+     *     $qb = $conn->getQueryBuilder();
723
+     *
724
+     *     $or = $qb->expr()->orx();
725
+     *     $or->add($qb->expr()->eq('u.id', 1));
726
+     *     $or->add($qb->expr()->eq('u.id', 2));
727
+     *
728
+     *     $qb->update('users', 'u')
729
+     *         ->set('u.password', md5('password'))
730
+     *         ->where($or);
731
+     * </code>
732
+     *
733
+     * @param mixed ...$predicates The restriction predicates.
734
+     *
735
+     * @return $this This QueryBuilder instance.
736
+     */
737
+    public function where(...$predicates) {
738
+        call_user_func_array(
739
+            [$this->queryBuilder, 'where'],
740
+            $predicates
741
+        );
742
+
743
+        return $this;
744
+    }
745
+
746
+    /**
747
+     * Adds one or more restrictions to the query results, forming a logical
748
+     * conjunction with any previously specified restrictions.
749
+     *
750
+     * <code>
751
+     *     $qb = $conn->getQueryBuilder()
752
+     *         ->select('u')
753
+     *         ->from('users', 'u')
754
+     *         ->where('u.username LIKE ?')
755
+     *         ->andWhere('u.is_active = 1');
756
+     * </code>
757
+     *
758
+     * @param mixed ...$where The query restrictions.
759
+     *
760
+     * @return $this This QueryBuilder instance.
761
+     *
762
+     * @see where()
763
+     */
764
+    public function andWhere(...$where) {
765
+        call_user_func_array(
766
+            [$this->queryBuilder, 'andWhere'],
767
+            $where
768
+        );
769
+
770
+        return $this;
771
+    }
772
+
773
+    /**
774
+     * Adds one or more restrictions to the query results, forming a logical
775
+     * disjunction with any previously specified restrictions.
776
+     *
777
+     * <code>
778
+     *     $qb = $conn->getQueryBuilder()
779
+     *         ->select('u.name')
780
+     *         ->from('users', 'u')
781
+     *         ->where('u.id = 1')
782
+     *         ->orWhere('u.id = 2');
783
+     * </code>
784
+     *
785
+     * @param mixed ...$where The WHERE statement.
786
+     *
787
+     * @return $this This QueryBuilder instance.
788
+     *
789
+     * @see where()
790
+     */
791
+    public function orWhere(...$where) {
792
+        call_user_func_array(
793
+            [$this->queryBuilder, 'orWhere'],
794
+            $where
795
+        );
796
+
797
+        return $this;
798
+    }
799
+
800
+    /**
801
+     * Specifies a grouping over the results of the query.
802
+     * Replaces any previously specified groupings, if any.
803
+     *
804
+     * <code>
805
+     *     $qb = $conn->getQueryBuilder()
806
+     *         ->select('u.name')
807
+     *         ->from('users', 'u')
808
+     *         ->groupBy('u.id');
809
+     * </code>
810
+     *
811
+     * @param mixed ...$groupBys The grouping expression.
812
+     *
813
+     * @return $this This QueryBuilder instance.
814
+     */
815
+    public function groupBy(...$groupBys) {
816
+        if (count($groupBys) === 1 && is_array($groupBys[0])) {
817
+            $groupBys = $groupBys[0];
818
+        }
819
+
820
+        call_user_func_array(
821
+            [$this->queryBuilder, 'groupBy'],
822
+            $this->helper->quoteColumnNames($groupBys)
823
+        );
824
+
825
+        return $this;
826
+    }
827
+
828
+    /**
829
+     * Adds a grouping expression to the query.
830
+     *
831
+     * <code>
832
+     *     $qb = $conn->getQueryBuilder()
833
+     *         ->select('u.name')
834
+     *         ->from('users', 'u')
835
+     *         ->groupBy('u.lastLogin');
836
+     *         ->addGroupBy('u.createdAt')
837
+     * </code>
838
+     *
839
+     * @param mixed ...$groupBy The grouping expression.
840
+     *
841
+     * @return $this This QueryBuilder instance.
842
+     */
843
+    public function addGroupBy(...$groupBys) {
844
+        if (count($groupBys) === 1 && is_array($groupBys[0])) {
845
+            $$groupBys = $groupBys[0];
846
+        }
847
+
848
+        call_user_func_array(
849
+            [$this->queryBuilder, 'addGroupBy'],
850
+            $this->helper->quoteColumnNames($groupBys)
851
+        );
852
+
853
+        return $this;
854
+    }
855
+
856
+    /**
857
+     * Sets a value for a column in an insert query.
858
+     *
859
+     * <code>
860
+     *     $qb = $conn->getQueryBuilder()
861
+     *         ->insert('users')
862
+     *         ->values(
863
+     *             array(
864
+     *                 'name' => '?'
865
+     *             )
866
+     *         )
867
+     *         ->setValue('password', '?');
868
+     * </code>
869
+     *
870
+     * @param string $column The column into which the value should be inserted.
871
+     * @param string $value The value that should be inserted into the column.
872
+     *
873
+     * @return $this This QueryBuilder instance.
874
+     */
875
+    public function setValue($column, $value) {
876
+        $this->queryBuilder->setValue(
877
+            $this->helper->quoteColumnName($column),
878
+            $value
879
+        );
880
+
881
+        return $this;
882
+    }
883
+
884
+    /**
885
+     * Specifies values for an insert query indexed by column names.
886
+     * Replaces any previous values, if any.
887
+     *
888
+     * <code>
889
+     *     $qb = $conn->getQueryBuilder()
890
+     *         ->insert('users')
891
+     *         ->values(
892
+     *             array(
893
+     *                 'name' => '?',
894
+     *                 'password' => '?'
895
+     *             )
896
+     *         );
897
+     * </code>
898
+     *
899
+     * @param array $values The values to specify for the insert query indexed by column names.
900
+     *
901
+     * @return $this This QueryBuilder instance.
902
+     */
903
+    public function values(array $values) {
904
+        $quotedValues = [];
905
+        foreach ($values as $key => $value) {
906
+            $quotedValues[$this->helper->quoteColumnName($key)] = $value;
907
+        }
908
+
909
+        $this->queryBuilder->values($quotedValues);
910
+
911
+        return $this;
912
+    }
913
+
914
+    /**
915
+     * Specifies a restriction over the groups of the query.
916
+     * Replaces any previous having restrictions, if any.
917
+     *
918
+     * @param mixed ...$having The restriction over the groups.
919
+     *
920
+     * @return $this This QueryBuilder instance.
921
+     */
922
+    public function having(...$having) {
923
+        call_user_func_array(
924
+            [$this->queryBuilder, 'having'],
925
+            $having
926
+        );
927
+
928
+        return $this;
929
+    }
930
+
931
+    /**
932
+     * Adds a restriction over the groups of the query, forming a logical
933
+     * conjunction with any existing having restrictions.
934
+     *
935
+     * @param mixed ...$having The restriction to append.
936
+     *
937
+     * @return $this This QueryBuilder instance.
938
+     */
939
+    public function andHaving(...$having) {
940
+        call_user_func_array(
941
+            [$this->queryBuilder, 'andHaving'],
942
+            $having
943
+        );
944
+
945
+        return $this;
946
+    }
947
+
948
+    /**
949
+     * Adds a restriction over the groups of the query, forming a logical
950
+     * disjunction with any existing having restrictions.
951
+     *
952
+     * @param mixed ...$having The restriction to add.
953
+     *
954
+     * @return $this This QueryBuilder instance.
955
+     */
956
+    public function orHaving(...$having) {
957
+        call_user_func_array(
958
+            [$this->queryBuilder, 'orHaving'],
959
+            $having
960
+        );
961
+
962
+        return $this;
963
+    }
964
+
965
+    /**
966
+     * Specifies an ordering for the query results.
967
+     * Replaces any previously specified orderings, if any.
968
+     *
969
+     * @param string $sort The ordering expression.
970
+     * @param string $order The ordering direction.
971
+     *
972
+     * @return $this This QueryBuilder instance.
973
+     */
974
+    public function orderBy($sort, $order = null) {
975
+        $this->queryBuilder->orderBy(
976
+            $this->helper->quoteColumnName($sort),
977
+            $order
978
+        );
979
+
980
+        return $this;
981
+    }
982
+
983
+    /**
984
+     * Adds an ordering to the query results.
985
+     *
986
+     * @param string $sort The ordering expression.
987
+     * @param string $order The ordering direction.
988
+     *
989
+     * @return $this This QueryBuilder instance.
990
+     */
991
+    public function addOrderBy($sort, $order = null) {
992
+        $this->queryBuilder->addOrderBy(
993
+            $this->helper->quoteColumnName($sort),
994
+            $order
995
+        );
996
+
997
+        return $this;
998
+    }
999
+
1000
+    /**
1001
+     * Gets a query part by its name.
1002
+     *
1003
+     * @param string $queryPartName
1004
+     *
1005
+     * @return mixed
1006
+     */
1007
+    public function getQueryPart($queryPartName) {
1008
+        return $this->queryBuilder->getQueryPart($queryPartName);
1009
+    }
1010
+
1011
+    /**
1012
+     * Gets all query parts.
1013
+     *
1014
+     * @return array
1015
+     */
1016
+    public function getQueryParts() {
1017
+        return $this->queryBuilder->getQueryParts();
1018
+    }
1019
+
1020
+    /**
1021
+     * Resets SQL parts.
1022
+     *
1023
+     * @param array|null $queryPartNames
1024
+     *
1025
+     * @return $this This QueryBuilder instance.
1026
+     */
1027
+    public function resetQueryParts($queryPartNames = null) {
1028
+        $this->queryBuilder->resetQueryParts($queryPartNames);
1029
+
1030
+        return $this;
1031
+    }
1032
+
1033
+    /**
1034
+     * Resets a single SQL part.
1035
+     *
1036
+     * @param string $queryPartName
1037
+     *
1038
+     * @return $this This QueryBuilder instance.
1039
+     */
1040
+    public function resetQueryPart($queryPartName) {
1041
+        $this->queryBuilder->resetQueryPart($queryPartName);
1042
+
1043
+        return $this;
1044
+    }
1045
+
1046
+    /**
1047
+     * Creates a new named parameter and bind the value $value to it.
1048
+     *
1049
+     * This method provides a shortcut for PDOStatement::bindValue
1050
+     * when using prepared statements.
1051
+     *
1052
+     * The parameter $value specifies the value that you want to bind. If
1053
+     * $placeholder is not provided bindValue() will automatically create a
1054
+     * placeholder for you. An automatic placeholder will be of the name
1055
+     * ':dcValue1', ':dcValue2' etc.
1056
+     *
1057
+     * For more information see {@link http://php.net/pdostatement-bindparam}
1058
+     *
1059
+     * Example:
1060
+     * <code>
1061
+     * $value = 2;
1062
+     * $q->eq( 'id', $q->bindValue( $value ) );
1063
+     * $stmt = $q->executeQuery(); // executed with 'id = 2'
1064
+     * </code>
1065
+     *
1066
+     * @license New BSD License
1067
+     * @link http://www.zetacomponents.org
1068
+     *
1069
+     * @param mixed $value
1070
+     * @param mixed $type
1071
+     * @param string $placeHolder The name to bind with. The string must start with a colon ':'.
1072
+     *
1073
+     * @return IParameter the placeholder name used.
1074
+     */
1075
+    public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) {
1076
+        return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder));
1077
+    }
1078
+
1079
+    /**
1080
+     * Creates a new positional parameter and bind the given value to it.
1081
+     *
1082
+     * Attention: If you are using positional parameters with the query builder you have
1083
+     * to be very careful to bind all parameters in the order they appear in the SQL
1084
+     * statement , otherwise they get bound in the wrong order which can lead to serious
1085
+     * bugs in your code.
1086
+     *
1087
+     * Example:
1088
+     * <code>
1089
+     *  $qb = $conn->getQueryBuilder();
1090
+     *  $qb->select('u.*')
1091
+     *     ->from('users', 'u')
1092
+     *     ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR))
1093
+     *     ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR))
1094
+     * </code>
1095
+     *
1096
+     * @param mixed $value
1097
+     * @param integer $type
1098
+     *
1099
+     * @return IParameter
1100
+     */
1101
+    public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) {
1102
+        return new Parameter($this->queryBuilder->createPositionalParameter($value, $type));
1103
+    }
1104
+
1105
+    /**
1106
+     * Creates a new parameter
1107
+     *
1108
+     * Example:
1109
+     * <code>
1110
+     *  $qb = $conn->getQueryBuilder();
1111
+     *  $qb->select('u.*')
1112
+     *     ->from('users', 'u')
1113
+     *     ->where('u.username = ' . $qb->createParameter('name'))
1114
+     *     ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR))
1115
+     * </code>
1116
+     *
1117
+     * @param string $name
1118
+     *
1119
+     * @return IParameter
1120
+     */
1121
+    public function createParameter($name) {
1122
+        return new Parameter(':' . $name);
1123
+    }
1124
+
1125
+    /**
1126
+     * Creates a new function
1127
+     *
1128
+     * Attention: Column names inside the call have to be quoted before hand
1129
+     *
1130
+     * Example:
1131
+     * <code>
1132
+     *  $qb = $conn->getQueryBuilder();
1133
+     *  $qb->select($qb->createFunction('COUNT(*)'))
1134
+     *     ->from('users', 'u')
1135
+     *  echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u
1136
+     * </code>
1137
+     * <code>
1138
+     *  $qb = $conn->getQueryBuilder();
1139
+     *  $qb->select($qb->createFunction('COUNT(`column`)'))
1140
+     *     ->from('users', 'u')
1141
+     *  echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u
1142
+     * </code>
1143
+     *
1144
+     * @param string $call
1145
+     *
1146
+     * @return IQueryFunction
1147
+     */
1148
+    public function createFunction($call) {
1149
+        return new QueryFunction($call);
1150
+    }
1151
+
1152
+    /**
1153
+     * Used to get the id of the last inserted element
1154
+     * @return int
1155
+     * @throws \BadMethodCallException When being called before an insert query has been run.
1156
+     */
1157
+    public function getLastInsertId() {
1158
+        if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) {
1159
+            // lastInsertId() needs the prefix but no quotes
1160
+            $table = $this->prefixTableName($this->lastInsertedTable);
1161
+            return (int) $this->connection->lastInsertId($table);
1162
+        }
1163
+
1164
+        throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.');
1165
+    }
1166
+
1167
+    /**
1168
+     * Returns the table name quoted and with database prefix as needed by the implementation
1169
+     *
1170
+     * @param string $table
1171
+     * @return string
1172
+     */
1173
+    public function getTableName($table) {
1174
+        if ($table instanceof IQueryFunction) {
1175
+            return (string) $table;
1176
+        }
1177
+
1178
+        $table = $this->prefixTableName($table);
1179
+        return $this->helper->quoteColumnName($table);
1180
+    }
1181
+
1182
+    /**
1183
+     * Returns the table name with database prefix as needed by the implementation
1184
+     *
1185
+     * @param string $table
1186
+     * @return string
1187
+     */
1188
+    protected function prefixTableName($table) {
1189
+        if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) {
1190
+            return $table;
1191
+        }
1192
+
1193
+        return '*PREFIX*' . $table;
1194
+    }
1195
+
1196
+    /**
1197
+     * Returns the column name quoted and with table alias prefix as needed by the implementation
1198
+     *
1199
+     * @param string $column
1200
+     * @param string $tableAlias
1201
+     * @return string
1202
+     */
1203
+    public function getColumnName($column, $tableAlias = '') {
1204
+        if ($tableAlias !== '') {
1205
+            $tableAlias .= '.';
1206
+        }
1207
+
1208
+        return $this->helper->quoteColumnName($tableAlias . $column);
1209
+    }
1210
+
1211
+    /**
1212
+     * Returns the column name quoted and with table alias prefix as needed by the implementation
1213
+     *
1214
+     * @param string $alias
1215
+     * @return string
1216
+     */
1217
+    public function quoteAlias($alias) {
1218
+        if ($alias === '' || $alias === null) {
1219
+            return $alias;
1220
+        }
1221
+
1222
+        return $this->helper->quoteColumnName($alias);
1223
+    }
1224 1224
 }
Please login to merge, or discard this patch.
lib/private/DB/QueryBuilder/QuoteHelper.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -27,55 +27,55 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -70,12 +70,12 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
apps/testing/lib/Controller/ConfigController.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,39 +29,39 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
apps/testing/lib/Controller/LockingController.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -39,208 +39,208 @@
 block discarded – undo
39 39
 
40 40
 class LockingController extends OCSController {
41 41
 
42
-	/** @var ILockingProvider */
43
-	protected $lockingProvider;
44
-
45
-	/** @var FakeDBLockingProvider */
46
-	protected $fakeDBLockingProvider;
47
-
48
-	/** @var IDBConnection */
49
-	protected $connection;
50
-
51
-	/** @var IConfig */
52
-	protected $config;
53
-
54
-	/** @var IRootFolder */
55
-	protected $rootFolder;
56
-
57
-	/**
58
-	 * @param string $appName
59
-	 * @param IRequest $request
60
-	 * @param ILockingProvider $lockingProvider
61
-	 * @param FakeDBLockingProvider $fakeDBLockingProvider
62
-	 * @param IDBConnection $connection
63
-	 * @param IConfig $config
64
-	 * @param IRootFolder $rootFolder
65
-	 */
66
-	public function __construct($appName,
67
-								IRequest $request,
68
-								ILockingProvider $lockingProvider,
69
-								FakeDBLockingProvider $fakeDBLockingProvider,
70
-								IDBConnection $connection,
71
-								IConfig $config,
72
-								IRootFolder $rootFolder) {
73
-		parent::__construct($appName, $request);
74
-
75
-		$this->lockingProvider = $lockingProvider;
76
-		$this->fakeDBLockingProvider = $fakeDBLockingProvider;
77
-		$this->connection = $connection;
78
-		$this->config = $config;
79
-		$this->rootFolder = $rootFolder;
80
-	}
81
-
82
-	/**
83
-	 * @return ILockingProvider
84
-	 * @throws \RuntimeException
85
-	 */
86
-	protected function getLockingProvider() {
87
-		if ($this->lockingProvider instanceof DBLockingProvider) {
88
-			return $this->fakeDBLockingProvider;
89
-		}
90
-		throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
91
-	}
92
-
93
-	/**
94
-	 * @param string $user
95
-	 * @param string $path
96
-	 * @return string
97
-	 * @throws NotFoundException
98
-	 */
99
-	protected function getPath($user, $path) {
100
-		$node = $this->rootFolder->getUserFolder($user)->get($path);
101
-		return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
102
-	}
103
-
104
-	/**
105
-	 * @return DataResponse
106
-	 * @throws OCSException
107
-	 */
108
-	public function isLockingEnabled() {
109
-		try {
110
-			$this->getLockingProvider();
111
-			return new DataResponse();
112
-		} catch (\RuntimeException $e) {
113
-			throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e);
114
-		}
115
-	}
116
-
117
-	/**
118
-	 * @param int $type
119
-	 * @param string $user
120
-	 * @param string $path
121
-	 * @return DataResponse
122
-	 * @throws OCSException
123
-	 */
124
-	public function acquireLock($type, $user, $path) {
125
-		try {
126
-			$path = $this->getPath($user, $path);
127
-		} catch (NoUserException $e) {
128
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
129
-		} catch (NotFoundException $e) {
130
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
131
-		}
132
-
133
-		$lockingProvider = $this->getLockingProvider();
134
-
135
-		try {
136
-			$lockingProvider->acquireLock($path, $type);
137
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
138
-			return new DataResponse();
139
-		} catch (LockedException $e) {
140
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
141
-		}
142
-	}
143
-
144
-	/**
145
-	 * @param int $type
146
-	 * @param string $user
147
-	 * @param string $path
148
-	 * @return DataResponse
149
-	 * @throws OCSException
150
-	 */
151
-	public function changeLock($type, $user, $path) {
152
-		try {
153
-			$path = $this->getPath($user, $path);
154
-		} catch (NoUserException $e) {
155
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
156
-		} catch (NotFoundException $e) {
157
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
158
-		}
159
-
160
-		$lockingProvider = $this->getLockingProvider();
161
-
162
-		try {
163
-			$lockingProvider->changeLock($path, $type);
164
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
165
-			return new DataResponse();
166
-		} catch (LockedException $e) {
167
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
168
-		}
169
-	}
170
-
171
-	/**
172
-	 * @param int $type
173
-	 * @param string $user
174
-	 * @param string $path
175
-	 * @return DataResponse
176
-	 * @throws OCSException
177
-	 */
178
-	public function releaseLock($type, $user, $path) {
179
-		try {
180
-			$path = $this->getPath($user, $path);
181
-		} catch (NoUserException $e) {
182
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
183
-		} catch (NotFoundException $e) {
184
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
185
-		}
186
-
187
-		$lockingProvider = $this->getLockingProvider();
188
-
189
-		try {
190
-			$lockingProvider->releaseLock($path, $type);
191
-			$this->config->deleteAppValue('testing', 'locking_' . $path);
192
-			return new DataResponse();
193
-		} catch (LockedException $e) {
194
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
195
-		}
196
-	}
197
-
198
-	/**
199
-	 * @param int $type
200
-	 * @param string $user
201
-	 * @param string $path
202
-	 * @return DataResponse
203
-	 * @throws OCSException
204
-	 */
205
-	public function isLocked($type, $user, $path) {
206
-		try {
207
-			$path = $this->getPath($user, $path);
208
-		} catch (NoUserException $e) {
209
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
210
-		} catch (NotFoundException $e) {
211
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
212
-		}
213
-
214
-		$lockingProvider = $this->getLockingProvider();
215
-
216
-		if ($lockingProvider->isLocked($path, $type)) {
217
-			return new DataResponse();
218
-		}
219
-
220
-		throw new OCSException('', Http::STATUS_LOCKED);
221
-	}
222
-
223
-	/**
224
-	 * @param int $type
225
-	 * @return DataResponse
226
-	 */
227
-	public function releaseAll($type = null) {
228
-		$lockingProvider = $this->getLockingProvider();
229
-
230
-		foreach ($this->config->getAppKeys('testing') as $lock) {
231
-			if (strpos($lock, 'locking_') === 0) {
232
-				$path = substr($lock, strlen('locking_'));
233
-
234
-				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
-				} else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238
-				} else {
239
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
240
-				}
241
-			}
242
-		}
243
-
244
-		return new DataResponse();
245
-	}
42
+    /** @var ILockingProvider */
43
+    protected $lockingProvider;
44
+
45
+    /** @var FakeDBLockingProvider */
46
+    protected $fakeDBLockingProvider;
47
+
48
+    /** @var IDBConnection */
49
+    protected $connection;
50
+
51
+    /** @var IConfig */
52
+    protected $config;
53
+
54
+    /** @var IRootFolder */
55
+    protected $rootFolder;
56
+
57
+    /**
58
+     * @param string $appName
59
+     * @param IRequest $request
60
+     * @param ILockingProvider $lockingProvider
61
+     * @param FakeDBLockingProvider $fakeDBLockingProvider
62
+     * @param IDBConnection $connection
63
+     * @param IConfig $config
64
+     * @param IRootFolder $rootFolder
65
+     */
66
+    public function __construct($appName,
67
+                                IRequest $request,
68
+                                ILockingProvider $lockingProvider,
69
+                                FakeDBLockingProvider $fakeDBLockingProvider,
70
+                                IDBConnection $connection,
71
+                                IConfig $config,
72
+                                IRootFolder $rootFolder) {
73
+        parent::__construct($appName, $request);
74
+
75
+        $this->lockingProvider = $lockingProvider;
76
+        $this->fakeDBLockingProvider = $fakeDBLockingProvider;
77
+        $this->connection = $connection;
78
+        $this->config = $config;
79
+        $this->rootFolder = $rootFolder;
80
+    }
81
+
82
+    /**
83
+     * @return ILockingProvider
84
+     * @throws \RuntimeException
85
+     */
86
+    protected function getLockingProvider() {
87
+        if ($this->lockingProvider instanceof DBLockingProvider) {
88
+            return $this->fakeDBLockingProvider;
89
+        }
90
+        throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
91
+    }
92
+
93
+    /**
94
+     * @param string $user
95
+     * @param string $path
96
+     * @return string
97
+     * @throws NotFoundException
98
+     */
99
+    protected function getPath($user, $path) {
100
+        $node = $this->rootFolder->getUserFolder($user)->get($path);
101
+        return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
102
+    }
103
+
104
+    /**
105
+     * @return DataResponse
106
+     * @throws OCSException
107
+     */
108
+    public function isLockingEnabled() {
109
+        try {
110
+            $this->getLockingProvider();
111
+            return new DataResponse();
112
+        } catch (\RuntimeException $e) {
113
+            throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e);
114
+        }
115
+    }
116
+
117
+    /**
118
+     * @param int $type
119
+     * @param string $user
120
+     * @param string $path
121
+     * @return DataResponse
122
+     * @throws OCSException
123
+     */
124
+    public function acquireLock($type, $user, $path) {
125
+        try {
126
+            $path = $this->getPath($user, $path);
127
+        } catch (NoUserException $e) {
128
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
129
+        } catch (NotFoundException $e) {
130
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
131
+        }
132
+
133
+        $lockingProvider = $this->getLockingProvider();
134
+
135
+        try {
136
+            $lockingProvider->acquireLock($path, $type);
137
+            $this->config->setAppValue('testing', 'locking_' . $path, $type);
138
+            return new DataResponse();
139
+        } catch (LockedException $e) {
140
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
141
+        }
142
+    }
143
+
144
+    /**
145
+     * @param int $type
146
+     * @param string $user
147
+     * @param string $path
148
+     * @return DataResponse
149
+     * @throws OCSException
150
+     */
151
+    public function changeLock($type, $user, $path) {
152
+        try {
153
+            $path = $this->getPath($user, $path);
154
+        } catch (NoUserException $e) {
155
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
156
+        } catch (NotFoundException $e) {
157
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
158
+        }
159
+
160
+        $lockingProvider = $this->getLockingProvider();
161
+
162
+        try {
163
+            $lockingProvider->changeLock($path, $type);
164
+            $this->config->setAppValue('testing', 'locking_' . $path, $type);
165
+            return new DataResponse();
166
+        } catch (LockedException $e) {
167
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
168
+        }
169
+    }
170
+
171
+    /**
172
+     * @param int $type
173
+     * @param string $user
174
+     * @param string $path
175
+     * @return DataResponse
176
+     * @throws OCSException
177
+     */
178
+    public function releaseLock($type, $user, $path) {
179
+        try {
180
+            $path = $this->getPath($user, $path);
181
+        } catch (NoUserException $e) {
182
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
183
+        } catch (NotFoundException $e) {
184
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
185
+        }
186
+
187
+        $lockingProvider = $this->getLockingProvider();
188
+
189
+        try {
190
+            $lockingProvider->releaseLock($path, $type);
191
+            $this->config->deleteAppValue('testing', 'locking_' . $path);
192
+            return new DataResponse();
193
+        } catch (LockedException $e) {
194
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
195
+        }
196
+    }
197
+
198
+    /**
199
+     * @param int $type
200
+     * @param string $user
201
+     * @param string $path
202
+     * @return DataResponse
203
+     * @throws OCSException
204
+     */
205
+    public function isLocked($type, $user, $path) {
206
+        try {
207
+            $path = $this->getPath($user, $path);
208
+        } catch (NoUserException $e) {
209
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
210
+        } catch (NotFoundException $e) {
211
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
212
+        }
213
+
214
+        $lockingProvider = $this->getLockingProvider();
215
+
216
+        if ($lockingProvider->isLocked($path, $type)) {
217
+            return new DataResponse();
218
+        }
219
+
220
+        throw new OCSException('', Http::STATUS_LOCKED);
221
+    }
222
+
223
+    /**
224
+     * @param int $type
225
+     * @return DataResponse
226
+     */
227
+    public function releaseAll($type = null) {
228
+        $lockingProvider = $this->getLockingProvider();
229
+
230
+        foreach ($this->config->getAppKeys('testing') as $lock) {
231
+            if (strpos($lock, 'locking_') === 0) {
232
+                $path = substr($lock, strlen('locking_'));
233
+
234
+                if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
+                } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238
+                } else {
239
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
240
+                }
241
+            }
242
+        }
243
+
244
+        return new DataResponse();
245
+    }
246 246
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	protected function getPath($user, $path) {
100 100
 		$node = $this->rootFolder->getUserFolder($user)->get($path);
101
-		return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
101
+		return 'files/'.md5($node->getStorage()->getId().'::'.trim($node->getInternalPath(), '/'));
102 102
 	}
103 103
 
104 104
 	/**
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 		try {
136 136
 			$lockingProvider->acquireLock($path, $type);
137
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
137
+			$this->config->setAppValue('testing', 'locking_'.$path, $type);
138 138
 			return new DataResponse();
139 139
 		} catch (LockedException $e) {
140 140
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 
162 162
 		try {
163 163
 			$lockingProvider->changeLock($path, $type);
164
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
164
+			$this->config->setAppValue('testing', 'locking_'.$path, $type);
165 165
 			return new DataResponse();
166 166
 		} catch (LockedException $e) {
167 167
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 		try {
190 190
 			$lockingProvider->releaseLock($path, $type);
191
-			$this->config->deleteAppValue('testing', 'locking_' . $path);
191
+			$this->config->deleteAppValue('testing', 'locking_'.$path);
192 192
 			return new DataResponse();
193 193
 		} catch (LockedException $e) {
194 194
 			throw new OCSException('', Http::STATUS_LOCKED, $e);
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 			if (strpos($lock, 'locking_') === 0) {
232 232
 				$path = substr($lock, strlen('locking_'));
233 233
 
234
-				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
234
+				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235 235
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
-				} else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
236
+				} else if ($type === ILockingProvider::LOCK_SHARED && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237 237
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238 238
 				} else {
239 239
 					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
Please login to merge, or discard this patch.