Passed
Push — master ( 61a02b...010b07 )
by Roeland
19:08 queued 08:59
created
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/public/AppFramework/Controller.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -44,116 +44,116 @@
 block discarded – undo
44 44
  */
45 45
 abstract class Controller {
46 46
 
47
-	/**
48
-	 * app name
49
-	 * @var string
50
-	 * @since 7.0.0
51
-	 */
52
-	protected $appName;
53
-
54
-	/**
55
-	 * current request
56
-	 * @var \OCP\IRequest
57
-	 * @since 6.0.0
58
-	 */
59
-	protected $request;
60
-
61
-	/**
62
-	 * @var array
63
-	 * @since 7.0.0
64
-	 */
65
-	private $responders;
66
-
67
-	/**
68
-	 * constructor of the controller
69
-	 * @param string $appName the name of the app
70
-	 * @param IRequest $request an instance of the request
71
-	 * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
72
-	 */
73
-	public function __construct($appName,
74
-	                            IRequest $request) {
75
-		$this->appName = $appName;
76
-		$this->request = $request;
77
-
78
-		// default responders
79
-		$this->responders = array(
80
-			'json' => function ($data) {
81
-				if ($data instanceof DataResponse) {
82
-					$response = new JSONResponse(
83
-						$data->getData(),
84
-						$data->getStatus()
85
-					);
86
-					$dataHeaders = $data->getHeaders();
87
-					$headers = $response->getHeaders();
88
-					// do not overwrite Content-Type if it already exists
89
-					if (isset($dataHeaders['Content-Type'])) {
90
-						unset($headers['Content-Type']);
91
-					}
92
-					$response->setHeaders(array_merge($dataHeaders, $headers));
93
-					return $response;
94
-				}
95
-				return new JSONResponse($data);
96
-			}
97
-		);
98
-	}
99
-
100
-
101
-	/**
102
-	 * Parses an HTTP accept header and returns the supported responder type
103
-	 * @param string $acceptHeader
104
-	 * @param string $default
105
-	 * @return string the responder type
106
-	 * @since 7.0.0
107
-	 * @since 9.1.0 Added default parameter
108
-	 */
109
-	public function getResponderByHTTPHeader($acceptHeader, $default='json') {
110
-		$headers = explode(',', $acceptHeader);
111
-
112
-		// return the first matching responder
113
-		foreach ($headers as $header) {
114
-			$header = strtolower(trim($header));
115
-
116
-			$responder = str_replace('application/', '', $header);
117
-
118
-			if (array_key_exists($responder, $this->responders)) {
119
-				return $responder;
120
-			}
121
-		}
122
-
123
-		// no matching header return default
124
-		return $default;
125
-	}
126
-
127
-
128
-	/**
129
-	 * Registers a formatter for a type
130
-	 * @param string $format
131
-	 * @param \Closure $responder
132
-	 * @since 7.0.0
133
-	 */
134
-	protected function registerResponder($format, \Closure $responder) {
135
-		$this->responders[$format] = $responder;
136
-	}
137
-
138
-
139
-	/**
140
-	 * Serializes and formats a response
141
-	 * @param mixed $response the value that was returned from a controller and
142
-	 * is not a Response instance
143
-	 * @param string $format the format for which a formatter has been registered
144
-	 * @throws \DomainException if format does not match a registered formatter
145
-	 * @return Response
146
-	 * @since 7.0.0
147
-	 */
148
-	public function buildResponse($response, $format='json') {
149
-		if(array_key_exists($format, $this->responders)) {
150
-
151
-			$responder = $this->responders[$format];
152
-
153
-			return $responder($response);
154
-
155
-		}
156
-		throw new \DomainException('No responder registered for format '.
157
-			$format . '!');
158
-	}
47
+    /**
48
+     * app name
49
+     * @var string
50
+     * @since 7.0.0
51
+     */
52
+    protected $appName;
53
+
54
+    /**
55
+     * current request
56
+     * @var \OCP\IRequest
57
+     * @since 6.0.0
58
+     */
59
+    protected $request;
60
+
61
+    /**
62
+     * @var array
63
+     * @since 7.0.0
64
+     */
65
+    private $responders;
66
+
67
+    /**
68
+     * constructor of the controller
69
+     * @param string $appName the name of the app
70
+     * @param IRequest $request an instance of the request
71
+     * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
72
+     */
73
+    public function __construct($appName,
74
+                                IRequest $request) {
75
+        $this->appName = $appName;
76
+        $this->request = $request;
77
+
78
+        // default responders
79
+        $this->responders = array(
80
+            'json' => function ($data) {
81
+                if ($data instanceof DataResponse) {
82
+                    $response = new JSONResponse(
83
+                        $data->getData(),
84
+                        $data->getStatus()
85
+                    );
86
+                    $dataHeaders = $data->getHeaders();
87
+                    $headers = $response->getHeaders();
88
+                    // do not overwrite Content-Type if it already exists
89
+                    if (isset($dataHeaders['Content-Type'])) {
90
+                        unset($headers['Content-Type']);
91
+                    }
92
+                    $response->setHeaders(array_merge($dataHeaders, $headers));
93
+                    return $response;
94
+                }
95
+                return new JSONResponse($data);
96
+            }
97
+        );
98
+    }
99
+
100
+
101
+    /**
102
+     * Parses an HTTP accept header and returns the supported responder type
103
+     * @param string $acceptHeader
104
+     * @param string $default
105
+     * @return string the responder type
106
+     * @since 7.0.0
107
+     * @since 9.1.0 Added default parameter
108
+     */
109
+    public function getResponderByHTTPHeader($acceptHeader, $default='json') {
110
+        $headers = explode(',', $acceptHeader);
111
+
112
+        // return the first matching responder
113
+        foreach ($headers as $header) {
114
+            $header = strtolower(trim($header));
115
+
116
+            $responder = str_replace('application/', '', $header);
117
+
118
+            if (array_key_exists($responder, $this->responders)) {
119
+                return $responder;
120
+            }
121
+        }
122
+
123
+        // no matching header return default
124
+        return $default;
125
+    }
126
+
127
+
128
+    /**
129
+     * Registers a formatter for a type
130
+     * @param string $format
131
+     * @param \Closure $responder
132
+     * @since 7.0.0
133
+     */
134
+    protected function registerResponder($format, \Closure $responder) {
135
+        $this->responders[$format] = $responder;
136
+    }
137
+
138
+
139
+    /**
140
+     * Serializes and formats a response
141
+     * @param mixed $response the value that was returned from a controller and
142
+     * is not a Response instance
143
+     * @param string $format the format for which a formatter has been registered
144
+     * @throws \DomainException if format does not match a registered formatter
145
+     * @return Response
146
+     * @since 7.0.0
147
+     */
148
+    public function buildResponse($response, $format='json') {
149
+        if(array_key_exists($format, $this->responders)) {
150
+
151
+            $responder = $this->responders[$format];
152
+
153
+            return $responder($response);
154
+
155
+        }
156
+        throw new \DomainException('No responder registered for format '.
157
+            $format . '!');
158
+    }
159 159
 }
Please login to merge, or discard this patch.
lib/private/DB/QueryBuilder/QuoteHelper.php 1 patch
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.
lib/private/Repair/OldGroupMembershipShares.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -31,89 +31,89 @@
 block discarded – undo
31 31
 
32 32
 class OldGroupMembershipShares implements IRepairStep {
33 33
 
34
-	/** @var \OCP\IDBConnection */
35
-	protected $connection;
36
-
37
-	/** @var \OCP\IGroupManager */
38
-	protected $groupManager;
39
-
40
-	/**
41
-	 * @var array [gid => [uid => (bool)]]
42
-	 */
43
-	protected $memberships;
44
-
45
-	/**
46
-	 * @param IDBConnection $connection
47
-	 * @param IGroupManager $groupManager
48
-	 */
49
-	public function __construct(IDBConnection $connection, IGroupManager $groupManager) {
50
-		$this->connection = $connection;
51
-		$this->groupManager = $groupManager;
52
-	}
53
-
54
-	/**
55
-	 * Returns the step's name
56
-	 *
57
-	 * @return string
58
-	 */
59
-	public function getName() {
60
-		return 'Remove shares of old group memberships';
61
-	}
62
-
63
-	/**
64
-	 * Run repair step.
65
-	 * Must throw exception on error.
66
-	 *
67
-	 * @throws \Exception in case of failure
68
-	 * @suppress SqlInjectionChecker
69
-	 */
70
-	public function run(IOutput $output) {
71
-		$deletedEntries = 0;
72
-
73
-		$query = $this->connection->getQueryBuilder();
74
-		$query->select('s1.id')->selectAlias('s1.share_with', 'user')->selectAlias('s2.share_with', 'group')
75
-			->from('share', 's1')
76
-			->where($query->expr()->isNotNull('s1.parent'))
77
-				// \OC\Share\Constant::$shareTypeGroupUserUnique === 2
78
-				->andWhere($query->expr()->eq('s1.share_type', $query->expr()->literal(2)))
79
-				->andWhere($query->expr()->isNotNull('s2.id'))
80
-				->andWhere($query->expr()->eq('s2.share_type', $query->expr()->literal(Share::SHARE_TYPE_GROUP)))
81
-			->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'));
82
-
83
-		$deleteQuery = $this->connection->getQueryBuilder();
84
-		$deleteQuery->delete('share')
85
-			->where($query->expr()->eq('id', $deleteQuery->createParameter('share')));
86
-
87
-		$result = $query->execute();
88
-		while ($row = $result->fetch()) {
89
-			if (!$this->isMember($row['group'], $row['user'])) {
90
-				$deletedEntries += $deleteQuery->setParameter('share', (int) $row['id'])
91
-					->execute();
92
-			}
93
-		}
94
-		$result->closeCursor();
95
-
96
-		if ($deletedEntries) {
97
-			$output->info('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore');
98
-		}
99
-	}
100
-
101
-	/**
102
-	 * @param string $gid
103
-	 * @param string $uid
104
-	 * @return bool
105
-	 */
106
-	protected function isMember($gid, $uid) {
107
-		if (isset($this->memberships[$gid][$uid])) {
108
-			return $this->memberships[$gid][$uid];
109
-		}
110
-
111
-		$isMember = $this->groupManager->isInGroup($uid, $gid);
112
-		if (!isset($this->memberships[$gid])) {
113
-			$this->memberships[$gid] = [];
114
-		}
115
-		$this->memberships[$gid][$uid] = $isMember;
116
-
117
-		return $isMember;
118
-	}
34
+    /** @var \OCP\IDBConnection */
35
+    protected $connection;
36
+
37
+    /** @var \OCP\IGroupManager */
38
+    protected $groupManager;
39
+
40
+    /**
41
+     * @var array [gid => [uid => (bool)]]
42
+     */
43
+    protected $memberships;
44
+
45
+    /**
46
+     * @param IDBConnection $connection
47
+     * @param IGroupManager $groupManager
48
+     */
49
+    public function __construct(IDBConnection $connection, IGroupManager $groupManager) {
50
+        $this->connection = $connection;
51
+        $this->groupManager = $groupManager;
52
+    }
53
+
54
+    /**
55
+     * Returns the step's name
56
+     *
57
+     * @return string
58
+     */
59
+    public function getName() {
60
+        return 'Remove shares of old group memberships';
61
+    }
62
+
63
+    /**
64
+     * Run repair step.
65
+     * Must throw exception on error.
66
+     *
67
+     * @throws \Exception in case of failure
68
+     * @suppress SqlInjectionChecker
69
+     */
70
+    public function run(IOutput $output) {
71
+        $deletedEntries = 0;
72
+
73
+        $query = $this->connection->getQueryBuilder();
74
+        $query->select('s1.id')->selectAlias('s1.share_with', 'user')->selectAlias('s2.share_with', 'group')
75
+            ->from('share', 's1')
76
+            ->where($query->expr()->isNotNull('s1.parent'))
77
+                // \OC\Share\Constant::$shareTypeGroupUserUnique === 2
78
+                ->andWhere($query->expr()->eq('s1.share_type', $query->expr()->literal(2)))
79
+                ->andWhere($query->expr()->isNotNull('s2.id'))
80
+                ->andWhere($query->expr()->eq('s2.share_type', $query->expr()->literal(Share::SHARE_TYPE_GROUP)))
81
+            ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'));
82
+
83
+        $deleteQuery = $this->connection->getQueryBuilder();
84
+        $deleteQuery->delete('share')
85
+            ->where($query->expr()->eq('id', $deleteQuery->createParameter('share')));
86
+
87
+        $result = $query->execute();
88
+        while ($row = $result->fetch()) {
89
+            if (!$this->isMember($row['group'], $row['user'])) {
90
+                $deletedEntries += $deleteQuery->setParameter('share', (int) $row['id'])
91
+                    ->execute();
92
+            }
93
+        }
94
+        $result->closeCursor();
95
+
96
+        if ($deletedEntries) {
97
+            $output->info('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore');
98
+        }
99
+    }
100
+
101
+    /**
102
+     * @param string $gid
103
+     * @param string $uid
104
+     * @return bool
105
+     */
106
+    protected function isMember($gid, $uid) {
107
+        if (isset($this->memberships[$gid][$uid])) {
108
+            return $this->memberships[$gid][$uid];
109
+        }
110
+
111
+        $isMember = $this->groupManager->isInGroup($uid, $gid);
112
+        if (!isset($this->memberships[$gid])) {
113
+            $this->memberships[$gid] = [];
114
+        }
115
+        $this->memberships[$gid][$uid] = $isMember;
116
+
117
+        return $isMember;
118
+    }
119 119
 }
Please login to merge, or discard this patch.
lib/private/Repair/RepairInvalidShares.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -33,90 +33,90 @@
 block discarded – undo
33 33
  */
34 34
 class RepairInvalidShares implements IRepairStep {
35 35
 
36
-	const CHUNK_SIZE = 200;
37
-
38
-	/** @var \OCP\IConfig */
39
-	protected $config;
40
-
41
-	/** @var \OCP\IDBConnection */
42
-	protected $connection;
43
-
44
-	/**
45
-	 * @param \OCP\IConfig $config
46
-	 * @param \OCP\IDBConnection $connection
47
-	 */
48
-	public function __construct($config, $connection) {
49
-		$this->connection = $connection;
50
-		$this->config = $config;
51
-	}
52
-
53
-	public function getName() {
54
-		return 'Repair invalid shares';
55
-	}
56
-
57
-	/**
58
-	 * Adjust file share permissions
59
-	 * @suppress SqlInjectionChecker
60
-	 */
61
-	private function adjustFileSharePermissions(IOutput $out) {
62
-		$mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE;
63
-		$builder = $this->connection->getQueryBuilder();
64
-
65
-		$permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask);
66
-		$builder
67
-			->update('share')
68
-			->set('permissions', $permsFunc)
69
-			->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
70
-			->andWhere($builder->expr()->neq('permissions', $permsFunc));
71
-
72
-		$updatedEntries = $builder->execute();
73
-		if ($updatedEntries > 0) {
74
-			$out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
75
-		}
76
-	}
77
-
78
-	/**
79
-	 * Remove shares where the parent share does not exist anymore
80
-	 */
81
-	private function removeSharesNonExistingParent(IOutput $out) {
82
-		$deletedEntries = 0;
83
-
84
-		$query = $this->connection->getQueryBuilder();
85
-		$query->select('s1.parent')
86
-			->from('share', 's1')
87
-			->where($query->expr()->isNotNull('s1.parent'))
88
-				->andWhere($query->expr()->isNull('s2.id'))
89
-			->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))
90
-			->groupBy('s1.parent')
91
-			->setMaxResults(self::CHUNK_SIZE);
92
-
93
-		$deleteQuery = $this->connection->getQueryBuilder();
94
-		$deleteQuery->delete('share')
95
-			->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
96
-
97
-		$deletedInLastChunk = self::CHUNK_SIZE;
98
-		while ($deletedInLastChunk === self::CHUNK_SIZE) {
99
-			$deletedInLastChunk = 0;
100
-			$result = $query->execute();
101
-			while ($row = $result->fetch()) {
102
-				$deletedInLastChunk++;
103
-				$deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])
104
-					->execute();
105
-			}
106
-			$result->closeCursor();
107
-		}
108
-
109
-		if ($deletedEntries) {
110
-			$out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
111
-		}
112
-	}
113
-
114
-	public function run(IOutput $out) {
115
-		$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
116
-		if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
117
-			$this->adjustFileSharePermissions($out);
118
-		}
119
-
120
-		$this->removeSharesNonExistingParent($out);
121
-	}
36
+    const CHUNK_SIZE = 200;
37
+
38
+    /** @var \OCP\IConfig */
39
+    protected $config;
40
+
41
+    /** @var \OCP\IDBConnection */
42
+    protected $connection;
43
+
44
+    /**
45
+     * @param \OCP\IConfig $config
46
+     * @param \OCP\IDBConnection $connection
47
+     */
48
+    public function __construct($config, $connection) {
49
+        $this->connection = $connection;
50
+        $this->config = $config;
51
+    }
52
+
53
+    public function getName() {
54
+        return 'Repair invalid shares';
55
+    }
56
+
57
+    /**
58
+     * Adjust file share permissions
59
+     * @suppress SqlInjectionChecker
60
+     */
61
+    private function adjustFileSharePermissions(IOutput $out) {
62
+        $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE;
63
+        $builder = $this->connection->getQueryBuilder();
64
+
65
+        $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask);
66
+        $builder
67
+            ->update('share')
68
+            ->set('permissions', $permsFunc)
69
+            ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
70
+            ->andWhere($builder->expr()->neq('permissions', $permsFunc));
71
+
72
+        $updatedEntries = $builder->execute();
73
+        if ($updatedEntries > 0) {
74
+            $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
75
+        }
76
+    }
77
+
78
+    /**
79
+     * Remove shares where the parent share does not exist anymore
80
+     */
81
+    private function removeSharesNonExistingParent(IOutput $out) {
82
+        $deletedEntries = 0;
83
+
84
+        $query = $this->connection->getQueryBuilder();
85
+        $query->select('s1.parent')
86
+            ->from('share', 's1')
87
+            ->where($query->expr()->isNotNull('s1.parent'))
88
+                ->andWhere($query->expr()->isNull('s2.id'))
89
+            ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))
90
+            ->groupBy('s1.parent')
91
+            ->setMaxResults(self::CHUNK_SIZE);
92
+
93
+        $deleteQuery = $this->connection->getQueryBuilder();
94
+        $deleteQuery->delete('share')
95
+            ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
96
+
97
+        $deletedInLastChunk = self::CHUNK_SIZE;
98
+        while ($deletedInLastChunk === self::CHUNK_SIZE) {
99
+            $deletedInLastChunk = 0;
100
+            $result = $query->execute();
101
+            while ($row = $result->fetch()) {
102
+                $deletedInLastChunk++;
103
+                $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])
104
+                    ->execute();
105
+            }
106
+            $result->closeCursor();
107
+        }
108
+
109
+        if ($deletedEntries) {
110
+            $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
111
+        }
112
+    }
113
+
114
+    public function run(IOutput $out) {
115
+        $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
116
+        if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
117
+            $this->adjustFileSharePermissions($out);
118
+        }
119
+
120
+        $this->removeSharesNonExistingParent($out);
121
+    }
122 122
 }
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 1 patch
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.
lib/public/AppFramework/Http/ICallbackResponse.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@
 block discarded – undo
33 33
  */
34 34
 interface ICallbackResponse {
35 35
 
36
-	/**
37
-	 * Outputs the content that should be printed
38
-	 *
39
-	 * @param IOutput $output a small wrapper that handles output
40
-	 * @since 8.1.0
41
-	 */
42
-	public function callback(IOutput $output);
36
+    /**
37
+     * Outputs the content that should be printed
38
+     *
39
+     * @param IOutput $output a small wrapper that handles output
40
+     * @since 8.1.0
41
+     */
42
+    public function callback(IOutput $output);
43 43
 
44 44
 }
Please login to merge, or discard this patch.
lib/private/Search/Provider/File.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,45 +32,45 @@
 block discarded – undo
32 32
  */
33 33
 class File extends \OCP\Search\Provider {
34 34
 
35
-	/**
36
-	 * Search for files and folders matching the given query
37
-	 * @param string $query
38
-	 * @return \OCP\Search\Result
39
-	 */
40
-	public function search($query) {
41
-		$files = Filesystem::search($query);
42
-		$results = array();
43
-		// edit results
44
-		foreach ($files as $fileData) {
45
-			// skip versions
46
-			if (strpos($fileData['path'], '_versions') === 0) {
47
-				continue;
48
-			}
49
-			// skip top-level folder
50
-			if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
51
-				continue;
52
-			}
53
-			// create audio result
54
-			if($fileData['mimepart'] === 'audio'){
55
-				$result = new \OC\Search\Result\Audio($fileData);
56
-			}
57
-			// create image result
58
-			elseif($fileData['mimepart'] === 'image'){
59
-				$result = new \OC\Search\Result\Image($fileData);
60
-			}
61
-			// create folder result
62
-			elseif($fileData['mimetype'] === 'httpd/unix-directory'){
63
-				$result = new \OC\Search\Result\Folder($fileData);
64
-			}
65
-			// or create file result
66
-			else{
67
-				$result = new \OC\Search\Result\File($fileData);
68
-			}
69
-			// add to results
70
-			$results[] = $result;
71
-		}
72
-		// return
73
-		return $results;
74
-	}
35
+    /**
36
+     * Search for files and folders matching the given query
37
+     * @param string $query
38
+     * @return \OCP\Search\Result
39
+     */
40
+    public function search($query) {
41
+        $files = Filesystem::search($query);
42
+        $results = array();
43
+        // edit results
44
+        foreach ($files as $fileData) {
45
+            // skip versions
46
+            if (strpos($fileData['path'], '_versions') === 0) {
47
+                continue;
48
+            }
49
+            // skip top-level folder
50
+            if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
51
+                continue;
52
+            }
53
+            // create audio result
54
+            if($fileData['mimepart'] === 'audio'){
55
+                $result = new \OC\Search\Result\Audio($fileData);
56
+            }
57
+            // create image result
58
+            elseif($fileData['mimepart'] === 'image'){
59
+                $result = new \OC\Search\Result\Image($fileData);
60
+            }
61
+            // create folder result
62
+            elseif($fileData['mimetype'] === 'httpd/unix-directory'){
63
+                $result = new \OC\Search\Result\Folder($fileData);
64
+            }
65
+            // or create file result
66
+            else{
67
+                $result = new \OC\Search\Result\File($fileData);
68
+            }
69
+            // add to results
70
+            $results[] = $result;
71
+        }
72
+        // return
73
+        return $results;
74
+    }
75 75
 	
76 76
 }
Please login to merge, or discard this patch.