Completed
Pull Request — master (#8094)
by Joas
40:52 queued 21:12
created
lib/private/Tagging/Tag.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -37,54 +37,54 @@
 block discarded – undo
37 37
  */
38 38
 class Tag extends Entity {
39 39
 
40
-	protected $owner;
41
-	protected $type;
42
-	protected $name;
40
+    protected $owner;
41
+    protected $type;
42
+    protected $name;
43 43
 
44
-	/**
45
-	* Constructor.
46
-	*
47
-	* @param string $owner The tag's owner
48
-	* @param string $type The type of item this tag is used for
49
-	* @param string $name The tag's name
50
-	*/
51
-	public function __construct($owner = null, $type = null, $name = null) {
52
-		$this->setOwner($owner);
53
-		$this->setType($type);
54
-		$this->setName($name);
55
-	}
44
+    /**
45
+     * Constructor.
46
+     *
47
+     * @param string $owner The tag's owner
48
+     * @param string $type The type of item this tag is used for
49
+     * @param string $name The tag's name
50
+     */
51
+    public function __construct($owner = null, $type = null, $name = null) {
52
+        $this->setOwner($owner);
53
+        $this->setType($type);
54
+        $this->setName($name);
55
+    }
56 56
 
57
-	/**
58
-	 * Transform a database columnname to a property
59
-	 *
60
-	 * @param string $columnName the name of the column
61
-	 * @return string the property name
62
-	 * @todo migrate existing database columns to the correct names
63
-	 * to be able to drop this direct mapping
64
-	 */
65
-	public function columnToProperty($columnName){
66
-		if ($columnName === 'category') {
67
-		    return 'name';
68
-		} elseif ($columnName === 'uid') {
69
-		    return 'owner';
70
-		} else {
71
-		    return parent::columnToProperty($columnName);
72
-		}
73
-	}
57
+    /**
58
+     * Transform a database columnname to a property
59
+     *
60
+     * @param string $columnName the name of the column
61
+     * @return string the property name
62
+     * @todo migrate existing database columns to the correct names
63
+     * to be able to drop this direct mapping
64
+     */
65
+    public function columnToProperty($columnName){
66
+        if ($columnName === 'category') {
67
+            return 'name';
68
+        } elseif ($columnName === 'uid') {
69
+            return 'owner';
70
+        } else {
71
+            return parent::columnToProperty($columnName);
72
+        }
73
+    }
74 74
 
75
-	/**
76
-	 * Transform a property to a database column name
77
-	 *
78
-	 * @param string $property the name of the property
79
-	 * @return string the column name
80
-	 */
81
-	public function propertyToColumn($property){
82
-		if ($property === 'name') {
83
-		    return 'category';
84
-		} elseif ($property === 'owner') {
85
-		    return 'uid';
86
-		} else {
87
-		    return parent::propertyToColumn($property);
88
-		}
89
-	}
75
+    /**
76
+     * Transform a property to a database column name
77
+     *
78
+     * @param string $property the name of the property
79
+     * @return string the column name
80
+     */
81
+    public function propertyToColumn($property){
82
+        if ($property === 'name') {
83
+            return 'category';
84
+        } elseif ($property === 'owner') {
85
+            return 'uid';
86
+        } else {
87
+            return parent::propertyToColumn($property);
88
+        }
89
+    }
90 90
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @todo migrate existing database columns to the correct names
63 63
 	 * to be able to drop this direct mapping
64 64
 	 */
65
-	public function columnToProperty($columnName){
65
+	public function columnToProperty($columnName) {
66 66
 		if ($columnName === 'category') {
67 67
 		    return 'name';
68 68
 		} elseif ($columnName === 'uid') {
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 * @param string $property the name of the property
79 79
 	 * @return string the column name
80 80
 	 */
81
-	public function propertyToColumn($property){
81
+	public function propertyToColumn($property) {
82 82
 		if ($property === 'name') {
83 83
 		    return 'category';
84 84
 		} elseif ($property === 'owner') {
Please login to merge, or discard this patch.
lib/private/TagManager.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -40,53 +40,53 @@
 block discarded – undo
40 40
 
41 41
 class TagManager implements \OCP\ITagManager {
42 42
 
43
-	/**
44
-	 * User session
45
-	 *
46
-	 * @var \OCP\IUserSession
47
-	 */
48
-	private $userSession;
43
+    /**
44
+     * User session
45
+     *
46
+     * @var \OCP\IUserSession
47
+     */
48
+    private $userSession;
49 49
 
50
-	/**
51
-	 * TagMapper
52
-	 *
53
-	 * @var TagMapper
54
-	 */
55
-	private $mapper;
50
+    /**
51
+     * TagMapper
52
+     *
53
+     * @var TagMapper
54
+     */
55
+    private $mapper;
56 56
 
57
-	/**
58
-	* Constructor.
59
-	*
60
-	* @param TagMapper $mapper Instance of the TagMapper abstraction layer.
61
-	* @param \OCP\IUserSession $userSession the user session
62
-	*/
63
-	public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) {
64
-		$this->mapper = $mapper;
65
-		$this->userSession = $userSession;
57
+    /**
58
+     * Constructor.
59
+     *
60
+     * @param TagMapper $mapper Instance of the TagMapper abstraction layer.
61
+     * @param \OCP\IUserSession $userSession the user session
62
+     */
63
+    public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) {
64
+        $this->mapper = $mapper;
65
+        $this->userSession = $userSession;
66 66
 
67
-	}
67
+    }
68 68
 
69
-	/**
70
-	* Create a new \OCP\ITags instance and load tags from db.
71
-	*
72
-	* @see \OCP\ITags
73
-	* @param string $type The type identifier e.g. 'contact' or 'event'.
74
-	* @param array $defaultTags An array of default tags to be used if none are stored.
75
-	* @param boolean $includeShared Whether to include tags for items shared with this user by others.
76
-	* @param string $userId user for which to retrieve the tags, defaults to the currently
77
-	* logged in user
78
-	* @return \OCP\ITags
79
-	*/
80
-	public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
81
-		if (is_null($userId)) {
82
-			$user = $this->userSession->getUser();
83
-			if ($user === null) {
84
-				// nothing we can do without a user
85
-				return null;
86
-			}
87
-			$userId = $this->userSession->getUser()->getUId();
88
-		}
89
-		return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
90
-	}
69
+    /**
70
+     * Create a new \OCP\ITags instance and load tags from db.
71
+     *
72
+     * @see \OCP\ITags
73
+     * @param string $type The type identifier e.g. 'contact' or 'event'.
74
+     * @param array $defaultTags An array of default tags to be used if none are stored.
75
+     * @param boolean $includeShared Whether to include tags for items shared with this user by others.
76
+     * @param string $userId user for which to retrieve the tags, defaults to the currently
77
+     * logged in user
78
+     * @return \OCP\ITags
79
+     */
80
+    public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
81
+        if (is_null($userId)) {
82
+            $user = $this->userSession->getUser();
83
+            if ($user === null) {
84
+                // nothing we can do without a user
85
+                return null;
86
+            }
87
+            $userId = $this->userSession->getUser()->getUId();
88
+        }
89
+        return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
90
+    }
91 91
 
92 92
 }
Please login to merge, or discard this patch.
lib/private/ContactsManager.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -27,164 +27,164 @@
 block discarded – undo
27 27
 
28 28
 namespace OC {
29 29
 
30
-	class ContactsManager implements \OCP\Contacts\IManager {
31
-
32
-		/**
33
-		 * This function is used to search and find contacts within the users address books.
34
-		 * In case $pattern is empty all contacts will be returned.
35
-		 *
36
-		 * @param string $pattern which should match within the $searchProperties
37
-		 * @param array $searchProperties defines the properties within the query pattern should match
38
-		 * @param array $options - for future use. One should always have options!
39
-		 * @return array an array of contacts which are arrays of key-value-pairs
40
-		 */
41
-		public function search($pattern, $searchProperties = array(), $options = array()) {
42
-			$this->loadAddressBooks();
43
-			$result = array();
44
-			foreach($this->addressBooks as $addressBook) {
45
-				$r = $addressBook->search($pattern, $searchProperties, $options);
46
-				$contacts = array();
47
-				foreach($r as $c){
48
-					$c['addressbook-key'] = $addressBook->getKey();
49
-					$contacts[] = $c;
50
-				}
51
-				$result = array_merge($result, $contacts);
52
-			}
53
-
54
-			return $result;
55
-		}
56
-
57
-		/**
58
-		 * This function can be used to delete the contact identified by the given id
59
-		 *
60
-		 * @param object $id the unique identifier to a contact
61
-		 * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
62
-		 * @return bool successful or not
63
-		 */
64
-		public function delete($id, $addressBookKey) {
65
-			$addressBook = $this->getAddressBook($addressBookKey);
66
-			if (!$addressBook) {
67
-				return null;
68
-			}
69
-
70
-			if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
71
-				return $addressBook->delete($id);
72
-			}
73
-
74
-			return null;
75
-		}
76
-
77
-		/**
78
-		 * This function is used to create a new contact if 'id' is not given or not present.
79
-		 * Otherwise the contact will be updated by replacing the entire data set.
80
-		 *
81
-		 * @param array $properties this array if key-value-pairs defines a contact
82
-		 * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
83
-		 * @return array representing the contact just created or updated
84
-		 */
85
-		public function createOrUpdate($properties, $addressBookKey) {
86
-			$addressBook = $this->getAddressBook($addressBookKey);
87
-			if (!$addressBook) {
88
-				return null;
89
-			}
90
-
91
-			if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
92
-				return $addressBook->createOrUpdate($properties);
93
-			}
94
-
95
-			return null;
96
-		}
97
-
98
-		/**
99
-		 * Check if contacts are available (e.g. contacts app enabled)
100
-		 *
101
-		 * @return bool true if enabled, false if not
102
-		 */
103
-		public function isEnabled() {
104
-			return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
105
-		}
106
-
107
-		/**
108
-		 * @param \OCP\IAddressBook $addressBook
109
-		 */
110
-		public function registerAddressBook(\OCP\IAddressBook $addressBook) {
111
-			$this->addressBooks[$addressBook->getKey()] = $addressBook;
112
-		}
113
-
114
-		/**
115
-		 * @param \OCP\IAddressBook $addressBook
116
-		 */
117
-		public function unregisterAddressBook(\OCP\IAddressBook $addressBook) {
118
-			unset($this->addressBooks[$addressBook->getKey()]);
119
-		}
120
-
121
-		/**
122
-		 * @return array
123
-		 */
124
-		public function getAddressBooks() {
125
-			$this->loadAddressBooks();
126
-			$result = array();
127
-			foreach($this->addressBooks as $addressBook) {
128
-				$result[$addressBook->getKey()] = $addressBook->getDisplayName();
129
-			}
130
-
131
-			return $result;
132
-		}
133
-
134
-		/**
135
-		 * removes all registered address book instances
136
-		 */
137
-		public function clear() {
138
-			$this->addressBooks = array();
139
-			$this->addressBookLoaders = array();
140
-		}
141
-
142
-		/**
143
-		 * @var \OCP\IAddressBook[] which holds all registered address books
144
-		 */
145
-		private $addressBooks = array();
146
-
147
-		/**
148
-		 * @var \Closure[] to call to load/register address books
149
-		 */
150
-		private $addressBookLoaders = array();
151
-
152
-		/**
153
-		 * In order to improve lazy loading a closure can be registered which will be called in case
154
-		 * address books are actually requested
155
-		 *
156
-		 * @param \Closure $callable
157
-		 */
158
-		public function register(\Closure $callable)
159
-		{
160
-			$this->addressBookLoaders[] = $callable;
161
-		}
162
-
163
-		/**
164
-		 * Get (and load when needed) the address book for $key
165
-		 *
166
-		 * @param string $addressBookKey
167
-		 * @return \OCP\IAddressBook
168
-		 */
169
-		protected function getAddressBook($addressBookKey)
170
-		{
171
-			$this->loadAddressBooks();
172
-			if (!array_key_exists($addressBookKey, $this->addressBooks)) {
173
-				return null;
174
-			}
175
-
176
-			return $this->addressBooks[$addressBookKey];
177
-		}
178
-
179
-		/**
180
-		 * Load all address books registered with 'register'
181
-		 */
182
-		protected function loadAddressBooks()
183
-		{
184
-			foreach($this->addressBookLoaders as $callable) {
185
-				$callable($this);
186
-			}
187
-			$this->addressBookLoaders = array();
188
-		}
189
-	}
30
+    class ContactsManager implements \OCP\Contacts\IManager {
31
+
32
+        /**
33
+         * This function is used to search and find contacts within the users address books.
34
+         * In case $pattern is empty all contacts will be returned.
35
+         *
36
+         * @param string $pattern which should match within the $searchProperties
37
+         * @param array $searchProperties defines the properties within the query pattern should match
38
+         * @param array $options - for future use. One should always have options!
39
+         * @return array an array of contacts which are arrays of key-value-pairs
40
+         */
41
+        public function search($pattern, $searchProperties = array(), $options = array()) {
42
+            $this->loadAddressBooks();
43
+            $result = array();
44
+            foreach($this->addressBooks as $addressBook) {
45
+                $r = $addressBook->search($pattern, $searchProperties, $options);
46
+                $contacts = array();
47
+                foreach($r as $c){
48
+                    $c['addressbook-key'] = $addressBook->getKey();
49
+                    $contacts[] = $c;
50
+                }
51
+                $result = array_merge($result, $contacts);
52
+            }
53
+
54
+            return $result;
55
+        }
56
+
57
+        /**
58
+         * This function can be used to delete the contact identified by the given id
59
+         *
60
+         * @param object $id the unique identifier to a contact
61
+         * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
62
+         * @return bool successful or not
63
+         */
64
+        public function delete($id, $addressBookKey) {
65
+            $addressBook = $this->getAddressBook($addressBookKey);
66
+            if (!$addressBook) {
67
+                return null;
68
+            }
69
+
70
+            if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
71
+                return $addressBook->delete($id);
72
+            }
73
+
74
+            return null;
75
+        }
76
+
77
+        /**
78
+         * This function is used to create a new contact if 'id' is not given or not present.
79
+         * Otherwise the contact will be updated by replacing the entire data set.
80
+         *
81
+         * @param array $properties this array if key-value-pairs defines a contact
82
+         * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
83
+         * @return array representing the contact just created or updated
84
+         */
85
+        public function createOrUpdate($properties, $addressBookKey) {
86
+            $addressBook = $this->getAddressBook($addressBookKey);
87
+            if (!$addressBook) {
88
+                return null;
89
+            }
90
+
91
+            if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
92
+                return $addressBook->createOrUpdate($properties);
93
+            }
94
+
95
+            return null;
96
+        }
97
+
98
+        /**
99
+         * Check if contacts are available (e.g. contacts app enabled)
100
+         *
101
+         * @return bool true if enabled, false if not
102
+         */
103
+        public function isEnabled() {
104
+            return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
105
+        }
106
+
107
+        /**
108
+         * @param \OCP\IAddressBook $addressBook
109
+         */
110
+        public function registerAddressBook(\OCP\IAddressBook $addressBook) {
111
+            $this->addressBooks[$addressBook->getKey()] = $addressBook;
112
+        }
113
+
114
+        /**
115
+         * @param \OCP\IAddressBook $addressBook
116
+         */
117
+        public function unregisterAddressBook(\OCP\IAddressBook $addressBook) {
118
+            unset($this->addressBooks[$addressBook->getKey()]);
119
+        }
120
+
121
+        /**
122
+         * @return array
123
+         */
124
+        public function getAddressBooks() {
125
+            $this->loadAddressBooks();
126
+            $result = array();
127
+            foreach($this->addressBooks as $addressBook) {
128
+                $result[$addressBook->getKey()] = $addressBook->getDisplayName();
129
+            }
130
+
131
+            return $result;
132
+        }
133
+
134
+        /**
135
+         * removes all registered address book instances
136
+         */
137
+        public function clear() {
138
+            $this->addressBooks = array();
139
+            $this->addressBookLoaders = array();
140
+        }
141
+
142
+        /**
143
+         * @var \OCP\IAddressBook[] which holds all registered address books
144
+         */
145
+        private $addressBooks = array();
146
+
147
+        /**
148
+         * @var \Closure[] to call to load/register address books
149
+         */
150
+        private $addressBookLoaders = array();
151
+
152
+        /**
153
+         * In order to improve lazy loading a closure can be registered which will be called in case
154
+         * address books are actually requested
155
+         *
156
+         * @param \Closure $callable
157
+         */
158
+        public function register(\Closure $callable)
159
+        {
160
+            $this->addressBookLoaders[] = $callable;
161
+        }
162
+
163
+        /**
164
+         * Get (and load when needed) the address book for $key
165
+         *
166
+         * @param string $addressBookKey
167
+         * @return \OCP\IAddressBook
168
+         */
169
+        protected function getAddressBook($addressBookKey)
170
+        {
171
+            $this->loadAddressBooks();
172
+            if (!array_key_exists($addressBookKey, $this->addressBooks)) {
173
+                return null;
174
+            }
175
+
176
+            return $this->addressBooks[$addressBookKey];
177
+        }
178
+
179
+        /**
180
+         * Load all address books registered with 'register'
181
+         */
182
+        protected function loadAddressBooks()
183
+        {
184
+            foreach($this->addressBookLoaders as $callable) {
185
+                $callable($this);
186
+            }
187
+            $this->addressBookLoaders = array();
188
+        }
189
+    }
190 190
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
 		public function search($pattern, $searchProperties = array(), $options = array()) {
42 42
 			$this->loadAddressBooks();
43 43
 			$result = array();
44
-			foreach($this->addressBooks as $addressBook) {
44
+			foreach ($this->addressBooks as $addressBook) {
45 45
 				$r = $addressBook->search($pattern, $searchProperties, $options);
46 46
 				$contacts = array();
47
-				foreach($r as $c){
47
+				foreach ($r as $c) {
48 48
 					$c['addressbook-key'] = $addressBook->getKey();
49 49
 					$contacts[] = $c;
50 50
 				}
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		public function getAddressBooks() {
125 125
 			$this->loadAddressBooks();
126 126
 			$result = array();
127
-			foreach($this->addressBooks as $addressBook) {
127
+			foreach ($this->addressBooks as $addressBook) {
128 128
 				$result[$addressBook->getKey()] = $addressBook->getDisplayName();
129 129
 			}
130 130
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		 */
182 182
 		protected function loadAddressBooks()
183 183
 		{
184
-			foreach($this->addressBookLoaders as $callable) {
184
+			foreach ($this->addressBookLoaders as $callable) {
185 185
 				$callable($this);
186 186
 			}
187 187
 			$this->addressBookLoaders = array();
Please login to merge, or discard this patch.
lib/private/Installer.php 5 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -412,7 +412,7 @@
 block discarded – undo
412 412
 			$appDir = OC_App::getInstallPath() . '/' . $appId;
413 413
 			OC_Helper::rmdirr($appDir);
414 414
 			return true;
415
-		}else{
415
+		} else{
416 416
 			\OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR);
417 417
 
418 418
 			return false;
Please login to merge, or discard this patch.
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -36,17 +36,12 @@
 block discarded – undo
36 36
 namespace OC;
37 37
 
38 38
 use Doctrine\DBAL\Exception\TableExistsException;
39
-use OC\App\AppManager;
40 39
 use OC\App\AppStore\Bundles\Bundle;
41 40
 use OC\App\AppStore\Fetcher\AppFetcher;
42
-use OC\App\CodeChecker\CodeChecker;
43
-use OC\App\CodeChecker\EmptyCheck;
44
-use OC\App\CodeChecker\PrivateCheck;
45 41
 use OC\Archive\TAR;
46 42
 use OC_App;
47 43
 use OC_DB;
48 44
 use OC_Helper;
49
-use OCP\App\IAppManager;
50 45
 use OCP\Http\Client\IClientService;
51 46
 use OCP\IConfig;
52 47
 use OCP\ILogger;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -420,7 +420,7 @@
 block discarded – undo
420 420
 
421 421
 	/**
422 422
 	 * Check if app has been installed from git
423
-	 * @param string $name name of the application to remove
423
+	 * @param string $appId
424 424
 	 * @return boolean
425 425
 	 *
426 426
 	 * The function will check if the path contains a .git folder
Please login to merge, or discard this patch.
Indentation   +565 added lines, -565 removed lines patch added patch discarded remove patch
@@ -57,569 +57,569 @@
 block discarded – undo
57 57
  * This class provides the functionality needed to install, update and remove apps
58 58
  */
59 59
 class Installer {
60
-	/** @var AppFetcher */
61
-	private $appFetcher;
62
-	/** @var IClientService */
63
-	private $clientService;
64
-	/** @var ITempManager */
65
-	private $tempManager;
66
-	/** @var ILogger */
67
-	private $logger;
68
-	/** @var IConfig */
69
-	private $config;
70
-	/** @var array - for caching the result of app fetcher */
71
-	private $apps = null;
72
-	/** @var bool|null - for caching the result of the ready status */
73
-	private $isInstanceReadyForUpdates = null;
74
-
75
-	/**
76
-	 * @param AppFetcher $appFetcher
77
-	 * @param IClientService $clientService
78
-	 * @param ITempManager $tempManager
79
-	 * @param ILogger $logger
80
-	 * @param IConfig $config
81
-	 */
82
-	public function __construct(AppFetcher $appFetcher,
83
-								IClientService $clientService,
84
-								ITempManager $tempManager,
85
-								ILogger $logger,
86
-								IConfig $config) {
87
-		$this->appFetcher = $appFetcher;
88
-		$this->clientService = $clientService;
89
-		$this->tempManager = $tempManager;
90
-		$this->logger = $logger;
91
-		$this->config = $config;
92
-	}
93
-
94
-	/**
95
-	 * Installs an app that is located in one of the app folders already
96
-	 *
97
-	 * @param string $appId App to install
98
-	 * @throws \Exception
99
-	 * @return string app ID
100
-	 */
101
-	public function installApp($appId) {
102
-		$app = \OC_App::findAppInDirectories($appId);
103
-		if($app === false) {
104
-			throw new \Exception('App not found in any app directory');
105
-		}
106
-
107
-		$basedir = $app['path'].'/'.$appId;
108
-		$info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true);
109
-
110
-		$l = \OC::$server->getL10N('core');
111
-
112
-		if(!is_array($info)) {
113
-			throw new \Exception(
114
-				$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
115
-					[$info['name']]
116
-				)
117
-			);
118
-		}
119
-
120
-		$version = \OCP\Util::getVersion();
121
-		if (!\OC_App::isAppCompatible($version, $info)) {
122
-			throw new \Exception(
123
-				// TODO $l
124
-				$l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
125
-					[$info['name']]
126
-				)
127
-			);
128
-		}
129
-
130
-		// check for required dependencies
131
-		\OC_App::checkAppDependencies($this->config, $l, $info);
132
-		\OC_App::registerAutoloading($appId, $basedir);
133
-
134
-		//install the database
135
-		if(is_file($basedir.'/appinfo/database.xml')) {
136
-			if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) {
137
-				OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml');
138
-			} else {
139
-				OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml');
140
-			}
141
-		} else {
142
-			$ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection());
143
-			$ms->migrate();
144
-		}
145
-
146
-		\OC_App::setupBackgroundJobs($info['background-jobs']);
147
-		if(isset($info['settings']) && is_array($info['settings'])) {
148
-			\OC::$server->getSettingsManager()->setupSettings($info['settings']);
149
-		}
150
-
151
-		//run appinfo/install.php
152
-		if(!isset($data['noinstall']) or $data['noinstall']==false) {
153
-			self::includeAppScript($basedir . '/appinfo/install.php');
154
-		}
155
-
156
-		$appData = OC_App::getAppInfo($appId);
157
-		OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']);
158
-
159
-		//set the installed version
160
-		\OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false));
161
-		\OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no');
162
-
163
-		//set remote/public handlers
164
-		foreach($info['remote'] as $name=>$path) {
165
-			\OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path);
166
-		}
167
-		foreach($info['public'] as $name=>$path) {
168
-			\OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path);
169
-		}
170
-
171
-		OC_App::setAppTypes($info['id']);
172
-
173
-		return $info['id'];
174
-	}
175
-
176
-	/**
177
-	 * @brief checks whether or not an app is installed
178
-	 * @param string $app app
179
-	 * @returns bool
180
-	 *
181
-	 * Checks whether or not an app is installed, i.e. registered in apps table.
182
-	 */
183
-	public static function isInstalled( $app ) {
184
-		return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null);
185
-	}
186
-
187
-	/**
188
-	 * Updates the specified app from the appstore
189
-	 *
190
-	 * @param string $appId
191
-	 * @return bool
192
-	 */
193
-	public function updateAppstoreApp($appId) {
194
-		if($this->isUpdateAvailable($appId)) {
195
-			try {
196
-				$this->downloadApp($appId);
197
-			} catch (\Exception $e) {
198
-				$this->logger->logException($e, [
199
-					'level' => \OCP\Util::ERROR,
200
-					'app' => 'core',
201
-				]);
202
-				return false;
203
-			}
204
-			return OC_App::updateApp($appId);
205
-		}
206
-
207
-		return false;
208
-	}
209
-
210
-	/**
211
-	 * Downloads an app and puts it into the app directory
212
-	 *
213
-	 * @param string $appId
214
-	 *
215
-	 * @throws \Exception If the installation was not successful
216
-	 */
217
-	public function downloadApp($appId) {
218
-		$appId = strtolower($appId);
219
-
220
-		$apps = $this->appFetcher->get();
221
-		foreach($apps as $app) {
222
-			if($app['id'] === $appId) {
223
-				// Load the certificate
224
-				$certificate = new X509();
225
-				$certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
226
-				$loadedCertificate = $certificate->loadX509($app['certificate']);
227
-
228
-				// Verify if the certificate has been revoked
229
-				$crl = new X509();
230
-				$crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
231
-				$crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl'));
232
-				if($crl->validateSignature() !== true) {
233
-					throw new \Exception('Could not validate CRL signature');
234
-				}
235
-				$csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString();
236
-				$revoked = $crl->getRevoked($csn);
237
-				if ($revoked !== false) {
238
-					throw new \Exception(
239
-						sprintf(
240
-							'Certificate "%s" has been revoked',
241
-							$csn
242
-						)
243
-					);
244
-				}
245
-
246
-				// Verify if the certificate has been issued by the Nextcloud Code Authority CA
247
-				if($certificate->validateSignature() !== true) {
248
-					throw new \Exception(
249
-						sprintf(
250
-							'App with id %s has a certificate not issued by a trusted Code Signing Authority',
251
-							$appId
252
-						)
253
-					);
254
-				}
255
-
256
-				// Verify if the certificate is issued for the requested app id
257
-				$certInfo = openssl_x509_parse($app['certificate']);
258
-				if(!isset($certInfo['subject']['CN'])) {
259
-					throw new \Exception(
260
-						sprintf(
261
-							'App with id %s has a cert with no CN',
262
-							$appId
263
-						)
264
-					);
265
-				}
266
-				if($certInfo['subject']['CN'] !== $appId) {
267
-					throw new \Exception(
268
-						sprintf(
269
-							'App with id %s has a cert issued to %s',
270
-							$appId,
271
-							$certInfo['subject']['CN']
272
-						)
273
-					);
274
-				}
275
-
276
-				// Download the release
277
-				$tempFile = $this->tempManager->getTemporaryFile('.tar.gz');
278
-				$client = $this->clientService->newClient();
279
-				$client->get($app['releases'][0]['download'], ['save_to' => $tempFile]);
280
-
281
-				// Check if the signature actually matches the downloaded content
282
-				$certificate = openssl_get_publickey($app['certificate']);
283
-				$verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512);
284
-				openssl_free_key($certificate);
285
-
286
-				if($verified === true) {
287
-					// Seems to match, let's proceed
288
-					$extractDir = $this->tempManager->getTemporaryFolder();
289
-					$archive = new TAR($tempFile);
290
-
291
-					if($archive) {
292
-						if (!$archive->extract($extractDir)) {
293
-							throw new \Exception(
294
-								sprintf(
295
-									'Could not extract app %s',
296
-									$appId
297
-								)
298
-							);
299
-						}
300
-						$allFiles = scandir($extractDir);
301
-						$folders = array_diff($allFiles, ['.', '..']);
302
-						$folders = array_values($folders);
303
-
304
-						if(count($folders) > 1) {
305
-							throw new \Exception(
306
-								sprintf(
307
-									'Extracted app %s has more than 1 folder',
308
-									$appId
309
-								)
310
-							);
311
-						}
312
-
313
-						// Check if appinfo/info.xml has the same app ID as well
314
-						$loadEntities = libxml_disable_entity_loader(false);
315
-						$xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml');
316
-						libxml_disable_entity_loader($loadEntities);
317
-						if((string)$xml->id !== $appId) {
318
-							throw new \Exception(
319
-								sprintf(
320
-									'App for id %s has a wrong app ID in info.xml: %s',
321
-									$appId,
322
-									(string)$xml->id
323
-								)
324
-							);
325
-						}
326
-
327
-						// Check if the version is lower than before
328
-						$currentVersion = OC_App::getAppVersion($appId);
329
-						$newVersion = (string)$xml->version;
330
-						if(version_compare($currentVersion, $newVersion) === 1) {
331
-							throw new \Exception(
332
-								sprintf(
333
-									'App for id %s has version %s and tried to update to lower version %s',
334
-									$appId,
335
-									$currentVersion,
336
-									$newVersion
337
-								)
338
-							);
339
-						}
340
-
341
-						$baseDir = OC_App::getInstallPath() . '/' . $appId;
342
-						// Remove old app with the ID if existent
343
-						OC_Helper::rmdirr($baseDir);
344
-						// Move to app folder
345
-						if(@mkdir($baseDir)) {
346
-							$extractDir .= '/' . $folders[0];
347
-							OC_Helper::copyr($extractDir, $baseDir);
348
-						}
349
-						OC_Helper::copyr($extractDir, $baseDir);
350
-						OC_Helper::rmdirr($extractDir);
351
-						return;
352
-					} else {
353
-						throw new \Exception(
354
-							sprintf(
355
-								'Could not extract app with ID %s to %s',
356
-								$appId,
357
-								$extractDir
358
-							)
359
-						);
360
-					}
361
-				} else {
362
-					// Signature does not match
363
-					throw new \Exception(
364
-						sprintf(
365
-							'App with id %s has invalid signature',
366
-							$appId
367
-						)
368
-					);
369
-				}
370
-			}
371
-		}
372
-
373
-		throw new \Exception(
374
-			sprintf(
375
-				'Could not download app %s',
376
-				$appId
377
-			)
378
-		);
379
-	}
380
-
381
-	/**
382
-	 * Check if an update for the app is available
383
-	 *
384
-	 * @param string $appId
385
-	 * @return string|false false or the version number of the update
386
-	 */
387
-	public function isUpdateAvailable($appId) {
388
-		if ($this->isInstanceReadyForUpdates === null) {
389
-			$installPath = OC_App::getInstallPath();
390
-			if ($installPath === false || $installPath === null) {
391
-				$this->isInstanceReadyForUpdates = false;
392
-			} else {
393
-				$this->isInstanceReadyForUpdates = true;
394
-			}
395
-		}
396
-
397
-		if ($this->isInstanceReadyForUpdates === false) {
398
-			return false;
399
-		}
400
-
401
-		if ($this->isInstalledFromGit($appId) === true) {
402
-			return false;
403
-		}
404
-
405
-		if ($this->apps === null) {
406
-			$this->apps = $this->appFetcher->get();
407
-		}
408
-
409
-		foreach($this->apps as $app) {
410
-			if($app['id'] === $appId) {
411
-				$currentVersion = OC_App::getAppVersion($appId);
412
-				$newestVersion = $app['releases'][0]['version'];
413
-				if (version_compare($newestVersion, $currentVersion, '>')) {
414
-					return $newestVersion;
415
-				} else {
416
-					return false;
417
-				}
418
-			}
419
-		}
420
-
421
-		return false;
422
-	}
423
-
424
-	/**
425
-	 * Check if app has been installed from git
426
-	 * @param string $name name of the application to remove
427
-	 * @return boolean
428
-	 *
429
-	 * The function will check if the path contains a .git folder
430
-	 */
431
-	private function isInstalledFromGit($appId) {
432
-		$app = \OC_App::findAppInDirectories($appId);
433
-		if($app === false) {
434
-			return false;
435
-		}
436
-		$basedir = $app['path'].'/'.$appId;
437
-		return file_exists($basedir.'/.git/');
438
-	}
439
-
440
-	/**
441
-	 * Check if app is already downloaded
442
-	 * @param string $name name of the application to remove
443
-	 * @return boolean
444
-	 *
445
-	 * The function will check if the app is already downloaded in the apps repository
446
-	 */
447
-	public function isDownloaded($name) {
448
-		foreach(\OC::$APPSROOTS as $dir) {
449
-			$dirToTest  = $dir['path'];
450
-			$dirToTest .= '/';
451
-			$dirToTest .= $name;
452
-			$dirToTest .= '/';
453
-
454
-			if (is_dir($dirToTest)) {
455
-				return true;
456
-			}
457
-		}
458
-
459
-		return false;
460
-	}
461
-
462
-	/**
463
-	 * Removes an app
464
-	 * @param string $appId ID of the application to remove
465
-	 * @return boolean
466
-	 *
467
-	 *
468
-	 * This function works as follows
469
-	 *   -# call uninstall repair steps
470
-	 *   -# removing the files
471
-	 *
472
-	 * The function will not delete preferences, tables and the configuration,
473
-	 * this has to be done by the function oc_app_uninstall().
474
-	 */
475
-	public function removeApp($appId) {
476
-		if($this->isDownloaded( $appId )) {
477
-			$appDir = OC_App::getInstallPath() . '/' . $appId;
478
-			OC_Helper::rmdirr($appDir);
479
-			return true;
480
-		}else{
481
-			\OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR);
482
-
483
-			return false;
484
-		}
485
-
486
-	}
487
-
488
-	/**
489
-	 * Installs the app within the bundle and marks the bundle as installed
490
-	 *
491
-	 * @param Bundle $bundle
492
-	 * @throws \Exception If app could not get installed
493
-	 */
494
-	public function installAppBundle(Bundle $bundle) {
495
-		$appIds = $bundle->getAppIdentifiers();
496
-		foreach($appIds as $appId) {
497
-			if(!$this->isDownloaded($appId)) {
498
-				$this->downloadApp($appId);
499
-			}
500
-			$this->installApp($appId);
501
-			$app = new OC_App();
502
-			$app->enable($appId);
503
-		}
504
-		$bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true);
505
-		$bundles[] = $bundle->getIdentifier();
506
-		$this->config->setAppValue('core', 'installed.bundles', json_encode($bundles));
507
-	}
508
-
509
-	/**
510
-	 * Installs shipped apps
511
-	 *
512
-	 * This function installs all apps found in the 'apps' directory that should be enabled by default;
513
-	 * @param bool $softErrors When updating we ignore errors and simply log them, better to have a
514
-	 *                         working ownCloud at the end instead of an aborted update.
515
-	 * @return array Array of error messages (appid => Exception)
516
-	 */
517
-	public static function installShippedApps($softErrors = false) {
518
-		$errors = [];
519
-		foreach(\OC::$APPSROOTS as $app_dir) {
520
-			if($dir = opendir( $app_dir['path'] )) {
521
-				while( false !== ( $filename = readdir( $dir ))) {
522
-					if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) {
523
-						if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
524
-							if(!Installer::isInstalled($filename)) {
525
-								$info=OC_App::getAppInfo($filename);
526
-								$enabled = isset($info['default_enable']);
527
-								if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps()))
528
-									  && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
529
-									if ($softErrors) {
530
-										try {
531
-											Installer::installShippedApp($filename);
532
-										} catch (HintException $e) {
533
-											if ($e->getPrevious() instanceof TableExistsException) {
534
-												$errors[$filename] = $e;
535
-												continue;
536
-											}
537
-											throw $e;
538
-										}
539
-									} else {
540
-										Installer::installShippedApp($filename);
541
-									}
542
-									\OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes');
543
-								}
544
-							}
545
-						}
546
-					}
547
-				}
548
-				closedir( $dir );
549
-			}
550
-		}
551
-
552
-		return $errors;
553
-	}
554
-
555
-	/**
556
-	 * install an app already placed in the app folder
557
-	 * @param string $app id of the app to install
558
-	 * @return integer
559
-	 */
560
-	public static function installShippedApp($app) {
561
-		//install the database
562
-		$appPath = OC_App::getAppPath($app);
563
-		\OC_App::registerAutoloading($app, $appPath);
564
-
565
-		if(is_file("$appPath/appinfo/database.xml")) {
566
-			try {
567
-				OC_DB::createDbFromStructure("$appPath/appinfo/database.xml");
568
-			} catch (TableExistsException $e) {
569
-				throw new HintException(
570
-					'Failed to enable app ' . $app,
571
-					'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.',
572
-					0, $e
573
-				);
574
-			}
575
-		} else {
576
-			$ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection());
577
-			$ms->migrate();
578
-		}
579
-
580
-		//run appinfo/install.php
581
-		self::includeAppScript("$appPath/appinfo/install.php");
582
-
583
-		$info = OC_App::getAppInfo($app);
584
-		if (is_null($info)) {
585
-			return false;
586
-		}
587
-		\OC_App::setupBackgroundJobs($info['background-jobs']);
588
-
589
-		OC_App::executeRepairSteps($app, $info['repair-steps']['install']);
590
-
591
-		$config = \OC::$server->getConfig();
592
-
593
-		$config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app));
594
-		if (array_key_exists('ocsid', $info)) {
595
-			$config->setAppValue($app, 'ocsid', $info['ocsid']);
596
-		}
597
-
598
-		//set remote/public handlers
599
-		foreach($info['remote'] as $name=>$path) {
600
-			$config->setAppValue('core', 'remote_'.$name, $app.'/'.$path);
601
-		}
602
-		foreach($info['public'] as $name=>$path) {
603
-			$config->setAppValue('core', 'public_'.$name, $app.'/'.$path);
604
-		}
605
-
606
-		OC_App::setAppTypes($info['id']);
607
-
608
-		if(isset($info['settings']) && is_array($info['settings'])) {
609
-			// requires that autoloading was registered for the app,
610
-			// as happens before running the install.php some lines above
611
-			\OC::$server->getSettingsManager()->setupSettings($info['settings']);
612
-		}
613
-
614
-		return $info['id'];
615
-	}
616
-
617
-	/**
618
-	 * @param string $script
619
-	 */
620
-	private static function includeAppScript($script) {
621
-		if ( file_exists($script) ){
622
-			include $script;
623
-		}
624
-	}
60
+    /** @var AppFetcher */
61
+    private $appFetcher;
62
+    /** @var IClientService */
63
+    private $clientService;
64
+    /** @var ITempManager */
65
+    private $tempManager;
66
+    /** @var ILogger */
67
+    private $logger;
68
+    /** @var IConfig */
69
+    private $config;
70
+    /** @var array - for caching the result of app fetcher */
71
+    private $apps = null;
72
+    /** @var bool|null - for caching the result of the ready status */
73
+    private $isInstanceReadyForUpdates = null;
74
+
75
+    /**
76
+     * @param AppFetcher $appFetcher
77
+     * @param IClientService $clientService
78
+     * @param ITempManager $tempManager
79
+     * @param ILogger $logger
80
+     * @param IConfig $config
81
+     */
82
+    public function __construct(AppFetcher $appFetcher,
83
+                                IClientService $clientService,
84
+                                ITempManager $tempManager,
85
+                                ILogger $logger,
86
+                                IConfig $config) {
87
+        $this->appFetcher = $appFetcher;
88
+        $this->clientService = $clientService;
89
+        $this->tempManager = $tempManager;
90
+        $this->logger = $logger;
91
+        $this->config = $config;
92
+    }
93
+
94
+    /**
95
+     * Installs an app that is located in one of the app folders already
96
+     *
97
+     * @param string $appId App to install
98
+     * @throws \Exception
99
+     * @return string app ID
100
+     */
101
+    public function installApp($appId) {
102
+        $app = \OC_App::findAppInDirectories($appId);
103
+        if($app === false) {
104
+            throw new \Exception('App not found in any app directory');
105
+        }
106
+
107
+        $basedir = $app['path'].'/'.$appId;
108
+        $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true);
109
+
110
+        $l = \OC::$server->getL10N('core');
111
+
112
+        if(!is_array($info)) {
113
+            throw new \Exception(
114
+                $l->t('App "%s" cannot be installed because appinfo file cannot be read.',
115
+                    [$info['name']]
116
+                )
117
+            );
118
+        }
119
+
120
+        $version = \OCP\Util::getVersion();
121
+        if (!\OC_App::isAppCompatible($version, $info)) {
122
+            throw new \Exception(
123
+                // TODO $l
124
+                $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.',
125
+                    [$info['name']]
126
+                )
127
+            );
128
+        }
129
+
130
+        // check for required dependencies
131
+        \OC_App::checkAppDependencies($this->config, $l, $info);
132
+        \OC_App::registerAutoloading($appId, $basedir);
133
+
134
+        //install the database
135
+        if(is_file($basedir.'/appinfo/database.xml')) {
136
+            if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) {
137
+                OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml');
138
+            } else {
139
+                OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml');
140
+            }
141
+        } else {
142
+            $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection());
143
+            $ms->migrate();
144
+        }
145
+
146
+        \OC_App::setupBackgroundJobs($info['background-jobs']);
147
+        if(isset($info['settings']) && is_array($info['settings'])) {
148
+            \OC::$server->getSettingsManager()->setupSettings($info['settings']);
149
+        }
150
+
151
+        //run appinfo/install.php
152
+        if(!isset($data['noinstall']) or $data['noinstall']==false) {
153
+            self::includeAppScript($basedir . '/appinfo/install.php');
154
+        }
155
+
156
+        $appData = OC_App::getAppInfo($appId);
157
+        OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']);
158
+
159
+        //set the installed version
160
+        \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false));
161
+        \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no');
162
+
163
+        //set remote/public handlers
164
+        foreach($info['remote'] as $name=>$path) {
165
+            \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path);
166
+        }
167
+        foreach($info['public'] as $name=>$path) {
168
+            \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path);
169
+        }
170
+
171
+        OC_App::setAppTypes($info['id']);
172
+
173
+        return $info['id'];
174
+    }
175
+
176
+    /**
177
+     * @brief checks whether or not an app is installed
178
+     * @param string $app app
179
+     * @returns bool
180
+     *
181
+     * Checks whether or not an app is installed, i.e. registered in apps table.
182
+     */
183
+    public static function isInstalled( $app ) {
184
+        return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null);
185
+    }
186
+
187
+    /**
188
+     * Updates the specified app from the appstore
189
+     *
190
+     * @param string $appId
191
+     * @return bool
192
+     */
193
+    public function updateAppstoreApp($appId) {
194
+        if($this->isUpdateAvailable($appId)) {
195
+            try {
196
+                $this->downloadApp($appId);
197
+            } catch (\Exception $e) {
198
+                $this->logger->logException($e, [
199
+                    'level' => \OCP\Util::ERROR,
200
+                    'app' => 'core',
201
+                ]);
202
+                return false;
203
+            }
204
+            return OC_App::updateApp($appId);
205
+        }
206
+
207
+        return false;
208
+    }
209
+
210
+    /**
211
+     * Downloads an app and puts it into the app directory
212
+     *
213
+     * @param string $appId
214
+     *
215
+     * @throws \Exception If the installation was not successful
216
+     */
217
+    public function downloadApp($appId) {
218
+        $appId = strtolower($appId);
219
+
220
+        $apps = $this->appFetcher->get();
221
+        foreach($apps as $app) {
222
+            if($app['id'] === $appId) {
223
+                // Load the certificate
224
+                $certificate = new X509();
225
+                $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
226
+                $loadedCertificate = $certificate->loadX509($app['certificate']);
227
+
228
+                // Verify if the certificate has been revoked
229
+                $crl = new X509();
230
+                $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
231
+                $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl'));
232
+                if($crl->validateSignature() !== true) {
233
+                    throw new \Exception('Could not validate CRL signature');
234
+                }
235
+                $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString();
236
+                $revoked = $crl->getRevoked($csn);
237
+                if ($revoked !== false) {
238
+                    throw new \Exception(
239
+                        sprintf(
240
+                            'Certificate "%s" has been revoked',
241
+                            $csn
242
+                        )
243
+                    );
244
+                }
245
+
246
+                // Verify if the certificate has been issued by the Nextcloud Code Authority CA
247
+                if($certificate->validateSignature() !== true) {
248
+                    throw new \Exception(
249
+                        sprintf(
250
+                            'App with id %s has a certificate not issued by a trusted Code Signing Authority',
251
+                            $appId
252
+                        )
253
+                    );
254
+                }
255
+
256
+                // Verify if the certificate is issued for the requested app id
257
+                $certInfo = openssl_x509_parse($app['certificate']);
258
+                if(!isset($certInfo['subject']['CN'])) {
259
+                    throw new \Exception(
260
+                        sprintf(
261
+                            'App with id %s has a cert with no CN',
262
+                            $appId
263
+                        )
264
+                    );
265
+                }
266
+                if($certInfo['subject']['CN'] !== $appId) {
267
+                    throw new \Exception(
268
+                        sprintf(
269
+                            'App with id %s has a cert issued to %s',
270
+                            $appId,
271
+                            $certInfo['subject']['CN']
272
+                        )
273
+                    );
274
+                }
275
+
276
+                // Download the release
277
+                $tempFile = $this->tempManager->getTemporaryFile('.tar.gz');
278
+                $client = $this->clientService->newClient();
279
+                $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]);
280
+
281
+                // Check if the signature actually matches the downloaded content
282
+                $certificate = openssl_get_publickey($app['certificate']);
283
+                $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512);
284
+                openssl_free_key($certificate);
285
+
286
+                if($verified === true) {
287
+                    // Seems to match, let's proceed
288
+                    $extractDir = $this->tempManager->getTemporaryFolder();
289
+                    $archive = new TAR($tempFile);
290
+
291
+                    if($archive) {
292
+                        if (!$archive->extract($extractDir)) {
293
+                            throw new \Exception(
294
+                                sprintf(
295
+                                    'Could not extract app %s',
296
+                                    $appId
297
+                                )
298
+                            );
299
+                        }
300
+                        $allFiles = scandir($extractDir);
301
+                        $folders = array_diff($allFiles, ['.', '..']);
302
+                        $folders = array_values($folders);
303
+
304
+                        if(count($folders) > 1) {
305
+                            throw new \Exception(
306
+                                sprintf(
307
+                                    'Extracted app %s has more than 1 folder',
308
+                                    $appId
309
+                                )
310
+                            );
311
+                        }
312
+
313
+                        // Check if appinfo/info.xml has the same app ID as well
314
+                        $loadEntities = libxml_disable_entity_loader(false);
315
+                        $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml');
316
+                        libxml_disable_entity_loader($loadEntities);
317
+                        if((string)$xml->id !== $appId) {
318
+                            throw new \Exception(
319
+                                sprintf(
320
+                                    'App for id %s has a wrong app ID in info.xml: %s',
321
+                                    $appId,
322
+                                    (string)$xml->id
323
+                                )
324
+                            );
325
+                        }
326
+
327
+                        // Check if the version is lower than before
328
+                        $currentVersion = OC_App::getAppVersion($appId);
329
+                        $newVersion = (string)$xml->version;
330
+                        if(version_compare($currentVersion, $newVersion) === 1) {
331
+                            throw new \Exception(
332
+                                sprintf(
333
+                                    'App for id %s has version %s and tried to update to lower version %s',
334
+                                    $appId,
335
+                                    $currentVersion,
336
+                                    $newVersion
337
+                                )
338
+                            );
339
+                        }
340
+
341
+                        $baseDir = OC_App::getInstallPath() . '/' . $appId;
342
+                        // Remove old app with the ID if existent
343
+                        OC_Helper::rmdirr($baseDir);
344
+                        // Move to app folder
345
+                        if(@mkdir($baseDir)) {
346
+                            $extractDir .= '/' . $folders[0];
347
+                            OC_Helper::copyr($extractDir, $baseDir);
348
+                        }
349
+                        OC_Helper::copyr($extractDir, $baseDir);
350
+                        OC_Helper::rmdirr($extractDir);
351
+                        return;
352
+                    } else {
353
+                        throw new \Exception(
354
+                            sprintf(
355
+                                'Could not extract app with ID %s to %s',
356
+                                $appId,
357
+                                $extractDir
358
+                            )
359
+                        );
360
+                    }
361
+                } else {
362
+                    // Signature does not match
363
+                    throw new \Exception(
364
+                        sprintf(
365
+                            'App with id %s has invalid signature',
366
+                            $appId
367
+                        )
368
+                    );
369
+                }
370
+            }
371
+        }
372
+
373
+        throw new \Exception(
374
+            sprintf(
375
+                'Could not download app %s',
376
+                $appId
377
+            )
378
+        );
379
+    }
380
+
381
+    /**
382
+     * Check if an update for the app is available
383
+     *
384
+     * @param string $appId
385
+     * @return string|false false or the version number of the update
386
+     */
387
+    public function isUpdateAvailable($appId) {
388
+        if ($this->isInstanceReadyForUpdates === null) {
389
+            $installPath = OC_App::getInstallPath();
390
+            if ($installPath === false || $installPath === null) {
391
+                $this->isInstanceReadyForUpdates = false;
392
+            } else {
393
+                $this->isInstanceReadyForUpdates = true;
394
+            }
395
+        }
396
+
397
+        if ($this->isInstanceReadyForUpdates === false) {
398
+            return false;
399
+        }
400
+
401
+        if ($this->isInstalledFromGit($appId) === true) {
402
+            return false;
403
+        }
404
+
405
+        if ($this->apps === null) {
406
+            $this->apps = $this->appFetcher->get();
407
+        }
408
+
409
+        foreach($this->apps as $app) {
410
+            if($app['id'] === $appId) {
411
+                $currentVersion = OC_App::getAppVersion($appId);
412
+                $newestVersion = $app['releases'][0]['version'];
413
+                if (version_compare($newestVersion, $currentVersion, '>')) {
414
+                    return $newestVersion;
415
+                } else {
416
+                    return false;
417
+                }
418
+            }
419
+        }
420
+
421
+        return false;
422
+    }
423
+
424
+    /**
425
+     * Check if app has been installed from git
426
+     * @param string $name name of the application to remove
427
+     * @return boolean
428
+     *
429
+     * The function will check if the path contains a .git folder
430
+     */
431
+    private function isInstalledFromGit($appId) {
432
+        $app = \OC_App::findAppInDirectories($appId);
433
+        if($app === false) {
434
+            return false;
435
+        }
436
+        $basedir = $app['path'].'/'.$appId;
437
+        return file_exists($basedir.'/.git/');
438
+    }
439
+
440
+    /**
441
+     * Check if app is already downloaded
442
+     * @param string $name name of the application to remove
443
+     * @return boolean
444
+     *
445
+     * The function will check if the app is already downloaded in the apps repository
446
+     */
447
+    public function isDownloaded($name) {
448
+        foreach(\OC::$APPSROOTS as $dir) {
449
+            $dirToTest  = $dir['path'];
450
+            $dirToTest .= '/';
451
+            $dirToTest .= $name;
452
+            $dirToTest .= '/';
453
+
454
+            if (is_dir($dirToTest)) {
455
+                return true;
456
+            }
457
+        }
458
+
459
+        return false;
460
+    }
461
+
462
+    /**
463
+     * Removes an app
464
+     * @param string $appId ID of the application to remove
465
+     * @return boolean
466
+     *
467
+     *
468
+     * This function works as follows
469
+     *   -# call uninstall repair steps
470
+     *   -# removing the files
471
+     *
472
+     * The function will not delete preferences, tables and the configuration,
473
+     * this has to be done by the function oc_app_uninstall().
474
+     */
475
+    public function removeApp($appId) {
476
+        if($this->isDownloaded( $appId )) {
477
+            $appDir = OC_App::getInstallPath() . '/' . $appId;
478
+            OC_Helper::rmdirr($appDir);
479
+            return true;
480
+        }else{
481
+            \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR);
482
+
483
+            return false;
484
+        }
485
+
486
+    }
487
+
488
+    /**
489
+     * Installs the app within the bundle and marks the bundle as installed
490
+     *
491
+     * @param Bundle $bundle
492
+     * @throws \Exception If app could not get installed
493
+     */
494
+    public function installAppBundle(Bundle $bundle) {
495
+        $appIds = $bundle->getAppIdentifiers();
496
+        foreach($appIds as $appId) {
497
+            if(!$this->isDownloaded($appId)) {
498
+                $this->downloadApp($appId);
499
+            }
500
+            $this->installApp($appId);
501
+            $app = new OC_App();
502
+            $app->enable($appId);
503
+        }
504
+        $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true);
505
+        $bundles[] = $bundle->getIdentifier();
506
+        $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles));
507
+    }
508
+
509
+    /**
510
+     * Installs shipped apps
511
+     *
512
+     * This function installs all apps found in the 'apps' directory that should be enabled by default;
513
+     * @param bool $softErrors When updating we ignore errors and simply log them, better to have a
514
+     *                         working ownCloud at the end instead of an aborted update.
515
+     * @return array Array of error messages (appid => Exception)
516
+     */
517
+    public static function installShippedApps($softErrors = false) {
518
+        $errors = [];
519
+        foreach(\OC::$APPSROOTS as $app_dir) {
520
+            if($dir = opendir( $app_dir['path'] )) {
521
+                while( false !== ( $filename = readdir( $dir ))) {
522
+                    if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) {
523
+                        if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
524
+                            if(!Installer::isInstalled($filename)) {
525
+                                $info=OC_App::getAppInfo($filename);
526
+                                $enabled = isset($info['default_enable']);
527
+                                if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps()))
528
+                                      && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
529
+                                    if ($softErrors) {
530
+                                        try {
531
+                                            Installer::installShippedApp($filename);
532
+                                        } catch (HintException $e) {
533
+                                            if ($e->getPrevious() instanceof TableExistsException) {
534
+                                                $errors[$filename] = $e;
535
+                                                continue;
536
+                                            }
537
+                                            throw $e;
538
+                                        }
539
+                                    } else {
540
+                                        Installer::installShippedApp($filename);
541
+                                    }
542
+                                    \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes');
543
+                                }
544
+                            }
545
+                        }
546
+                    }
547
+                }
548
+                closedir( $dir );
549
+            }
550
+        }
551
+
552
+        return $errors;
553
+    }
554
+
555
+    /**
556
+     * install an app already placed in the app folder
557
+     * @param string $app id of the app to install
558
+     * @return integer
559
+     */
560
+    public static function installShippedApp($app) {
561
+        //install the database
562
+        $appPath = OC_App::getAppPath($app);
563
+        \OC_App::registerAutoloading($app, $appPath);
564
+
565
+        if(is_file("$appPath/appinfo/database.xml")) {
566
+            try {
567
+                OC_DB::createDbFromStructure("$appPath/appinfo/database.xml");
568
+            } catch (TableExistsException $e) {
569
+                throw new HintException(
570
+                    'Failed to enable app ' . $app,
571
+                    'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.',
572
+                    0, $e
573
+                );
574
+            }
575
+        } else {
576
+            $ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection());
577
+            $ms->migrate();
578
+        }
579
+
580
+        //run appinfo/install.php
581
+        self::includeAppScript("$appPath/appinfo/install.php");
582
+
583
+        $info = OC_App::getAppInfo($app);
584
+        if (is_null($info)) {
585
+            return false;
586
+        }
587
+        \OC_App::setupBackgroundJobs($info['background-jobs']);
588
+
589
+        OC_App::executeRepairSteps($app, $info['repair-steps']['install']);
590
+
591
+        $config = \OC::$server->getConfig();
592
+
593
+        $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app));
594
+        if (array_key_exists('ocsid', $info)) {
595
+            $config->setAppValue($app, 'ocsid', $info['ocsid']);
596
+        }
597
+
598
+        //set remote/public handlers
599
+        foreach($info['remote'] as $name=>$path) {
600
+            $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path);
601
+        }
602
+        foreach($info['public'] as $name=>$path) {
603
+            $config->setAppValue('core', 'public_'.$name, $app.'/'.$path);
604
+        }
605
+
606
+        OC_App::setAppTypes($info['id']);
607
+
608
+        if(isset($info['settings']) && is_array($info['settings'])) {
609
+            // requires that autoloading was registered for the app,
610
+            // as happens before running the install.php some lines above
611
+            \OC::$server->getSettingsManager()->setupSettings($info['settings']);
612
+        }
613
+
614
+        return $info['id'];
615
+    }
616
+
617
+    /**
618
+     * @param string $script
619
+     */
620
+    private static function includeAppScript($script) {
621
+        if ( file_exists($script) ){
622
+            include $script;
623
+        }
624
+    }
625 625
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 */
101 101
 	public function installApp($appId) {
102 102
 		$app = \OC_App::findAppInDirectories($appId);
103
-		if($app === false) {
103
+		if ($app === false) {
104 104
 			throw new \Exception('App not found in any app directory');
105 105
 		}
106 106
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
 		$l = \OC::$server->getL10N('core');
111 111
 
112
-		if(!is_array($info)) {
112
+		if (!is_array($info)) {
113 113
 			throw new \Exception(
114 114
 				$l->t('App "%s" cannot be installed because appinfo file cannot be read.',
115 115
 					[$info['name']]
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		\OC_App::registerAutoloading($appId, $basedir);
133 133
 
134 134
 		//install the database
135
-		if(is_file($basedir.'/appinfo/database.xml')) {
135
+		if (is_file($basedir.'/appinfo/database.xml')) {
136 136
 			if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) {
137 137
 				OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml');
138 138
 			} else {
@@ -144,13 +144,13 @@  discard block
 block discarded – undo
144 144
 		}
145 145
 
146 146
 		\OC_App::setupBackgroundJobs($info['background-jobs']);
147
-		if(isset($info['settings']) && is_array($info['settings'])) {
147
+		if (isset($info['settings']) && is_array($info['settings'])) {
148 148
 			\OC::$server->getSettingsManager()->setupSettings($info['settings']);
149 149
 		}
150 150
 
151 151
 		//run appinfo/install.php
152
-		if(!isset($data['noinstall']) or $data['noinstall']==false) {
153
-			self::includeAppScript($basedir . '/appinfo/install.php');
152
+		if (!isset($data['noinstall']) or $data['noinstall'] == false) {
153
+			self::includeAppScript($basedir.'/appinfo/install.php');
154 154
 		}
155 155
 
156 156
 		$appData = OC_App::getAppInfo($appId);
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 		\OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no');
162 162
 
163 163
 		//set remote/public handlers
164
-		foreach($info['remote'] as $name=>$path) {
164
+		foreach ($info['remote'] as $name=>$path) {
165 165
 			\OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path);
166 166
 		}
167
-		foreach($info['public'] as $name=>$path) {
167
+		foreach ($info['public'] as $name=>$path) {
168 168
 			\OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path);
169 169
 		}
170 170
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * Checks whether or not an app is installed, i.e. registered in apps table.
182 182
 	 */
183
-	public static function isInstalled( $app ) {
183
+	public static function isInstalled($app) {
184 184
 		return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null);
185 185
 	}
186 186
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 * @return bool
192 192
 	 */
193 193
 	public function updateAppstoreApp($appId) {
194
-		if($this->isUpdateAvailable($appId)) {
194
+		if ($this->isUpdateAvailable($appId)) {
195 195
 			try {
196 196
 				$this->downloadApp($appId);
197 197
 			} catch (\Exception $e) {
@@ -218,18 +218,18 @@  discard block
 block discarded – undo
218 218
 		$appId = strtolower($appId);
219 219
 
220 220
 		$apps = $this->appFetcher->get();
221
-		foreach($apps as $app) {
222
-			if($app['id'] === $appId) {
221
+		foreach ($apps as $app) {
222
+			if ($app['id'] === $appId) {
223 223
 				// Load the certificate
224 224
 				$certificate = new X509();
225
-				$certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
225
+				$certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt'));
226 226
 				$loadedCertificate = $certificate->loadX509($app['certificate']);
227 227
 
228 228
 				// Verify if the certificate has been revoked
229 229
 				$crl = new X509();
230
-				$crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
231
-				$crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl'));
232
-				if($crl->validateSignature() !== true) {
230
+				$crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt'));
231
+				$crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl'));
232
+				if ($crl->validateSignature() !== true) {
233 233
 					throw new \Exception('Could not validate CRL signature');
234 234
 				}
235 235
 				$csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString();
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 				}
245 245
 
246 246
 				// Verify if the certificate has been issued by the Nextcloud Code Authority CA
247
-				if($certificate->validateSignature() !== true) {
247
+				if ($certificate->validateSignature() !== true) {
248 248
 					throw new \Exception(
249 249
 						sprintf(
250 250
 							'App with id %s has a certificate not issued by a trusted Code Signing Authority',
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 
256 256
 				// Verify if the certificate is issued for the requested app id
257 257
 				$certInfo = openssl_x509_parse($app['certificate']);
258
-				if(!isset($certInfo['subject']['CN'])) {
258
+				if (!isset($certInfo['subject']['CN'])) {
259 259
 					throw new \Exception(
260 260
 						sprintf(
261 261
 							'App with id %s has a cert with no CN',
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 						)
264 264
 					);
265 265
 				}
266
-				if($certInfo['subject']['CN'] !== $appId) {
266
+				if ($certInfo['subject']['CN'] !== $appId) {
267 267
 					throw new \Exception(
268 268
 						sprintf(
269 269
 							'App with id %s has a cert issued to %s',
@@ -280,15 +280,15 @@  discard block
 block discarded – undo
280 280
 
281 281
 				// Check if the signature actually matches the downloaded content
282 282
 				$certificate = openssl_get_publickey($app['certificate']);
283
-				$verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512);
283
+				$verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512);
284 284
 				openssl_free_key($certificate);
285 285
 
286
-				if($verified === true) {
286
+				if ($verified === true) {
287 287
 					// Seems to match, let's proceed
288 288
 					$extractDir = $this->tempManager->getTemporaryFolder();
289 289
 					$archive = new TAR($tempFile);
290 290
 
291
-					if($archive) {
291
+					if ($archive) {
292 292
 						if (!$archive->extract($extractDir)) {
293 293
 							throw new \Exception(
294 294
 								sprintf(
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 						$folders = array_diff($allFiles, ['.', '..']);
302 302
 						$folders = array_values($folders);
303 303
 
304
-						if(count($folders) > 1) {
304
+						if (count($folders) > 1) {
305 305
 							throw new \Exception(
306 306
 								sprintf(
307 307
 									'Extracted app %s has more than 1 folder',
@@ -312,22 +312,22 @@  discard block
 block discarded – undo
312 312
 
313 313
 						// Check if appinfo/info.xml has the same app ID as well
314 314
 						$loadEntities = libxml_disable_entity_loader(false);
315
-						$xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml');
315
+						$xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml');
316 316
 						libxml_disable_entity_loader($loadEntities);
317
-						if((string)$xml->id !== $appId) {
317
+						if ((string) $xml->id !== $appId) {
318 318
 							throw new \Exception(
319 319
 								sprintf(
320 320
 									'App for id %s has a wrong app ID in info.xml: %s',
321 321
 									$appId,
322
-									(string)$xml->id
322
+									(string) $xml->id
323 323
 								)
324 324
 							);
325 325
 						}
326 326
 
327 327
 						// Check if the version is lower than before
328 328
 						$currentVersion = OC_App::getAppVersion($appId);
329
-						$newVersion = (string)$xml->version;
330
-						if(version_compare($currentVersion, $newVersion) === 1) {
329
+						$newVersion = (string) $xml->version;
330
+						if (version_compare($currentVersion, $newVersion) === 1) {
331 331
 							throw new \Exception(
332 332
 								sprintf(
333 333
 									'App for id %s has version %s and tried to update to lower version %s',
@@ -338,12 +338,12 @@  discard block
 block discarded – undo
338 338
 							);
339 339
 						}
340 340
 
341
-						$baseDir = OC_App::getInstallPath() . '/' . $appId;
341
+						$baseDir = OC_App::getInstallPath().'/'.$appId;
342 342
 						// Remove old app with the ID if existent
343 343
 						OC_Helper::rmdirr($baseDir);
344 344
 						// Move to app folder
345
-						if(@mkdir($baseDir)) {
346
-							$extractDir .= '/' . $folders[0];
345
+						if (@mkdir($baseDir)) {
346
+							$extractDir .= '/'.$folders[0];
347 347
 							OC_Helper::copyr($extractDir, $baseDir);
348 348
 						}
349 349
 						OC_Helper::copyr($extractDir, $baseDir);
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
 			$this->apps = $this->appFetcher->get();
407 407
 		}
408 408
 
409
-		foreach($this->apps as $app) {
410
-			if($app['id'] === $appId) {
409
+		foreach ($this->apps as $app) {
410
+			if ($app['id'] === $appId) {
411 411
 				$currentVersion = OC_App::getAppVersion($appId);
412 412
 				$newestVersion = $app['releases'][0]['version'];
413 413
 				if (version_compare($newestVersion, $currentVersion, '>')) {
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 	 */
431 431
 	private function isInstalledFromGit($appId) {
432 432
 		$app = \OC_App::findAppInDirectories($appId);
433
-		if($app === false) {
433
+		if ($app === false) {
434 434
 			return false;
435 435
 		}
436 436
 		$basedir = $app['path'].'/'.$appId;
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 	 * The function will check if the app is already downloaded in the apps repository
446 446
 	 */
447 447
 	public function isDownloaded($name) {
448
-		foreach(\OC::$APPSROOTS as $dir) {
448
+		foreach (\OC::$APPSROOTS as $dir) {
449 449
 			$dirToTest  = $dir['path'];
450 450
 			$dirToTest .= '/';
451 451
 			$dirToTest .= $name;
@@ -473,11 +473,11 @@  discard block
 block discarded – undo
473 473
 	 * this has to be done by the function oc_app_uninstall().
474 474
 	 */
475 475
 	public function removeApp($appId) {
476
-		if($this->isDownloaded( $appId )) {
477
-			$appDir = OC_App::getInstallPath() . '/' . $appId;
476
+		if ($this->isDownloaded($appId)) {
477
+			$appDir = OC_App::getInstallPath().'/'.$appId;
478 478
 			OC_Helper::rmdirr($appDir);
479 479
 			return true;
480
-		}else{
480
+		} else {
481 481
 			\OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR);
482 482
 
483 483
 			return false;
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	 */
494 494
 	public function installAppBundle(Bundle $bundle) {
495 495
 		$appIds = $bundle->getAppIdentifiers();
496
-		foreach($appIds as $appId) {
497
-			if(!$this->isDownloaded($appId)) {
496
+		foreach ($appIds as $appId) {
497
+			if (!$this->isDownloaded($appId)) {
498 498
 				$this->downloadApp($appId);
499 499
 			}
500 500
 			$this->installApp($appId);
@@ -516,13 +516,13 @@  discard block
 block discarded – undo
516 516
 	 */
517 517
 	public static function installShippedApps($softErrors = false) {
518 518
 		$errors = [];
519
-		foreach(\OC::$APPSROOTS as $app_dir) {
520
-			if($dir = opendir( $app_dir['path'] )) {
521
-				while( false !== ( $filename = readdir( $dir ))) {
522
-					if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) {
523
-						if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
524
-							if(!Installer::isInstalled($filename)) {
525
-								$info=OC_App::getAppInfo($filename);
519
+		foreach (\OC::$APPSROOTS as $app_dir) {
520
+			if ($dir = opendir($app_dir['path'])) {
521
+				while (false !== ($filename = readdir($dir))) {
522
+					if ($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) {
523
+						if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) {
524
+							if (!Installer::isInstalled($filename)) {
525
+								$info = OC_App::getAppInfo($filename);
526 526
 								$enabled = isset($info['default_enable']);
527 527
 								if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps()))
528 528
 									  && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 						}
546 546
 					}
547 547
 				}
548
-				closedir( $dir );
548
+				closedir($dir);
549 549
 			}
550 550
 		}
551 551
 
@@ -562,12 +562,12 @@  discard block
 block discarded – undo
562 562
 		$appPath = OC_App::getAppPath($app);
563 563
 		\OC_App::registerAutoloading($app, $appPath);
564 564
 
565
-		if(is_file("$appPath/appinfo/database.xml")) {
565
+		if (is_file("$appPath/appinfo/database.xml")) {
566 566
 			try {
567 567
 				OC_DB::createDbFromStructure("$appPath/appinfo/database.xml");
568 568
 			} catch (TableExistsException $e) {
569 569
 				throw new HintException(
570
-					'Failed to enable app ' . $app,
570
+					'Failed to enable app '.$app,
571 571
 					'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.',
572 572
 					0, $e
573 573
 				);
@@ -596,16 +596,16 @@  discard block
 block discarded – undo
596 596
 		}
597 597
 
598 598
 		//set remote/public handlers
599
-		foreach($info['remote'] as $name=>$path) {
599
+		foreach ($info['remote'] as $name=>$path) {
600 600
 			$config->setAppValue('core', 'remote_'.$name, $app.'/'.$path);
601 601
 		}
602
-		foreach($info['public'] as $name=>$path) {
602
+		foreach ($info['public'] as $name=>$path) {
603 603
 			$config->setAppValue('core', 'public_'.$name, $app.'/'.$path);
604 604
 		}
605 605
 
606 606
 		OC_App::setAppTypes($info['id']);
607 607
 
608
-		if(isset($info['settings']) && is_array($info['settings'])) {
608
+		if (isset($info['settings']) && is_array($info['settings'])) {
609 609
 			// requires that autoloading was registered for the app,
610 610
 			// as happens before running the install.php some lines above
611 611
 			\OC::$server->getSettingsManager()->setupSettings($info['settings']);
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 	 * @param string $script
619 619
 	 */
620 620
 	private static function includeAppScript($script) {
621
-		if ( file_exists($script) ){
621
+		if (file_exists($script)) {
622 622
 			include $script;
623 623
 		}
624 624
 	}
Please login to merge, or discard this patch.
lib/private/Archive/Archive.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@
 block discarded – undo
134 134
 				}
135 135
 				if(is_dir($source.'/'.$file)) {
136 136
 					$this->addRecursive($path.'/'.$file, $source.'/'.$file);
137
-				}else{
137
+				} else{
138 138
 					$this->addFile($path.'/'.$file, $source.'/'.$file);
139 139
 				}
140 140
 			}
Please login to merge, or discard this patch.
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -33,111 +33,111 @@
 block discarded – undo
33 33
 namespace OC\Archive;
34 34
 
35 35
 abstract class Archive {
36
-	/**
37
-	 * @param $source
38
-	 */
39
-	public abstract function __construct($source);
40
-	/**
41
-	 * add an empty folder to the archive
42
-	 * @param string $path
43
-	 * @return bool
44
-	 */
45
-	public abstract function addFolder($path);
46
-	/**
47
-	 * add a file to the archive
48
-	 * @param string $path
49
-	 * @param string $source either a local file or string data
50
-	 * @return bool
51
-	 */
52
-	public abstract function addFile($path, $source='');
53
-	/**
54
-	 * rename a file or folder in the archive
55
-	 * @param string $source
56
-	 * @param string $dest
57
-	 * @return bool
58
-	 */
59
-	public abstract function rename($source, $dest);
60
-	/**
61
-	 * get the uncompressed size of a file in the archive
62
-	 * @param string $path
63
-	 * @return int
64
-	 */
65
-	public abstract function filesize($path);
66
-	/**
67
-	 * get the last modified time of a file in the archive
68
-	 * @param string $path
69
-	 * @return int
70
-	 */
71
-	public abstract function mtime($path);
72
-	/**
73
-	 * get the files in a folder
74
-	 * @param string $path
75
-	 * @return array
76
-	 */
77
-	public abstract function getFolder($path);
78
-	/**
79
-	 * get all files in the archive
80
-	 * @return array
81
-	 */
82
-	public abstract function getFiles();
83
-	/**
84
-	 * get the content of a file
85
-	 * @param string $path
86
-	 * @return string
87
-	 */
88
-	public abstract function getFile($path);
89
-	/**
90
-	 * extract a single file from the archive
91
-	 * @param string $path
92
-	 * @param string $dest
93
-	 * @return bool
94
-	 */
95
-	public abstract function extractFile($path, $dest);
96
-	/**
97
-	 * extract the archive
98
-	 * @param string $dest
99
-	 * @return bool
100
-	 */
101
-	public abstract function extract($dest);
102
-	/**
103
-	 * check if a file or folder exists in the archive
104
-	 * @param string $path
105
-	 * @return bool
106
-	 */
107
-	public abstract function fileExists($path);
108
-	/**
109
-	 * remove a file or folder from the archive
110
-	 * @param string $path
111
-	 * @return bool
112
-	 */
113
-	public abstract function remove($path);
114
-	/**
115
-	 * get a file handler
116
-	 * @param string $path
117
-	 * @param string $mode
118
-	 * @return resource
119
-	 */
120
-	public abstract function getStream($path, $mode);
121
-	/**
122
-	 * add a folder and all its content
123
-	 * @param string $path
124
-	 * @param string $source
125
-	 * @return boolean|null
126
-	 */
127
-	public function addRecursive($path, $source) {
128
-		$dh = opendir($source);
129
-		if(is_resource($dh)) {
130
-			$this->addFolder($path);
131
-			while (($file = readdir($dh)) !== false) {
132
-				if($file === '.' || $file === '..') {
133
-					continue;
134
-				}
135
-				if(is_dir($source.'/'.$file)) {
136
-					$this->addRecursive($path.'/'.$file, $source.'/'.$file);
137
-				}else{
138
-					$this->addFile($path.'/'.$file, $source.'/'.$file);
139
-				}
140
-			}
141
-		}
142
-	}
36
+    /**
37
+     * @param $source
38
+     */
39
+    public abstract function __construct($source);
40
+    /**
41
+     * add an empty folder to the archive
42
+     * @param string $path
43
+     * @return bool
44
+     */
45
+    public abstract function addFolder($path);
46
+    /**
47
+     * add a file to the archive
48
+     * @param string $path
49
+     * @param string $source either a local file or string data
50
+     * @return bool
51
+     */
52
+    public abstract function addFile($path, $source='');
53
+    /**
54
+     * rename a file or folder in the archive
55
+     * @param string $source
56
+     * @param string $dest
57
+     * @return bool
58
+     */
59
+    public abstract function rename($source, $dest);
60
+    /**
61
+     * get the uncompressed size of a file in the archive
62
+     * @param string $path
63
+     * @return int
64
+     */
65
+    public abstract function filesize($path);
66
+    /**
67
+     * get the last modified time of a file in the archive
68
+     * @param string $path
69
+     * @return int
70
+     */
71
+    public abstract function mtime($path);
72
+    /**
73
+     * get the files in a folder
74
+     * @param string $path
75
+     * @return array
76
+     */
77
+    public abstract function getFolder($path);
78
+    /**
79
+     * get all files in the archive
80
+     * @return array
81
+     */
82
+    public abstract function getFiles();
83
+    /**
84
+     * get the content of a file
85
+     * @param string $path
86
+     * @return string
87
+     */
88
+    public abstract function getFile($path);
89
+    /**
90
+     * extract a single file from the archive
91
+     * @param string $path
92
+     * @param string $dest
93
+     * @return bool
94
+     */
95
+    public abstract function extractFile($path, $dest);
96
+    /**
97
+     * extract the archive
98
+     * @param string $dest
99
+     * @return bool
100
+     */
101
+    public abstract function extract($dest);
102
+    /**
103
+     * check if a file or folder exists in the archive
104
+     * @param string $path
105
+     * @return bool
106
+     */
107
+    public abstract function fileExists($path);
108
+    /**
109
+     * remove a file or folder from the archive
110
+     * @param string $path
111
+     * @return bool
112
+     */
113
+    public abstract function remove($path);
114
+    /**
115
+     * get a file handler
116
+     * @param string $path
117
+     * @param string $mode
118
+     * @return resource
119
+     */
120
+    public abstract function getStream($path, $mode);
121
+    /**
122
+     * add a folder and all its content
123
+     * @param string $path
124
+     * @param string $source
125
+     * @return boolean|null
126
+     */
127
+    public function addRecursive($path, $source) {
128
+        $dh = opendir($source);
129
+        if(is_resource($dh)) {
130
+            $this->addFolder($path);
131
+            while (($file = readdir($dh)) !== false) {
132
+                if($file === '.' || $file === '..') {
133
+                    continue;
134
+                }
135
+                if(is_dir($source.'/'.$file)) {
136
+                    $this->addRecursive($path.'/'.$file, $source.'/'.$file);
137
+                }else{
138
+                    $this->addFile($path.'/'.$file, $source.'/'.$file);
139
+                }
140
+            }
141
+        }
142
+    }
143 143
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 * @param string $source either a local file or string data
50 50
 	 * @return bool
51 51
 	 */
52
-	public abstract function addFile($path, $source='');
52
+	public abstract function addFile($path, $source = '');
53 53
 	/**
54 54
 	 * rename a file or folder in the archive
55 55
 	 * @param string $source
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
 	 */
127 127
 	public function addRecursive($path, $source) {
128 128
 		$dh = opendir($source);
129
-		if(is_resource($dh)) {
129
+		if (is_resource($dh)) {
130 130
 			$this->addFolder($path);
131 131
 			while (($file = readdir($dh)) !== false) {
132
-				if($file === '.' || $file === '..') {
132
+				if ($file === '.' || $file === '..') {
133 133
 					continue;
134 134
 				}
135
-				if(is_dir($source.'/'.$file)) {
135
+				if (is_dir($source.'/'.$file)) {
136 136
 					$this->addRecursive($path.'/'.$file, $source.'/'.$file);
137
-				}else{
137
+				} else {
138 138
 					$this->addFile($path.'/'.$file, $source.'/'.$file);
139 139
 				}
140 140
 			}
Please login to merge, or discard this patch.
lib/private/NaturalSort_DefaultCollator.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -25,14 +25,14 @@
 block discarded – undo
25 25
 namespace OC;
26 26
 
27 27
 class NaturalSort_DefaultCollator {
28
-	public function compare($a, $b) {
29
-		$result = strcasecmp($a, $b);
30
-		if ($result === 0) {
31
-			if ($a === $b) {
32
-				return 0;
33
-			}
34
-			return ($a > $b) ? -1 : 1;
35
-		}
36
-		return ($result < 0) ? -1 : 1;
37
-	}
28
+    public function compare($a, $b) {
29
+        $result = strcasecmp($a, $b);
30
+        if ($result === 0) {
31
+            if ($a === $b) {
32
+                return 0;
33
+            }
34
+            return ($a > $b) ? -1 : 1;
35
+        }
36
+        return ($result < 0) ? -1 : 1;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
lib/private/TemplateLayout.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
 			parent::__construct( 'core', 'layout.user' );
62 62
 			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
63 63
 				$this->assign('bodyid', 'body-settings');
64
-			}else{
64
+			} else{
65 65
 				$this->assign('bodyid', 'body-user');
66 66
 			}
67 67
 
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -56,44 +56,44 @@  discard block
 block discarded – undo
56 56
 	 * @param string $renderAs
57 57
 	 * @param string $appId application id
58 58
 	 */
59
-	public function __construct( $renderAs, $appId = '' ) {
59
+	public function __construct($renderAs, $appId = '') {
60 60
 
61 61
 		// yes - should be injected ....
62 62
 		$this->config = \OC::$server->getConfig();
63 63
 
64 64
 
65 65
 		// Decide which page we show
66
-		if($renderAs == 'user') {
67
-			parent::__construct( 'core', 'layout.user' );
68
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
66
+		if ($renderAs == 'user') {
67
+			parent::__construct('core', 'layout.user');
68
+			if (in_array(\OC_App::getCurrentApp(), ['settings', 'admin', 'help']) !== false) {
69 69
 				$this->assign('bodyid', 'body-settings');
70
-			}else{
70
+			} else {
71 71
 				$this->assign('bodyid', 'body-user');
72 72
 			}
73 73
 
74 74
 			// Code integrity notification
75 75
 			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
76
+			if (\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77 77
 				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
78 78
 			}
79 79
 
80 80
 			// Add navigation entry
81
-			$this->assign( 'application', '');
82
-			$this->assign( 'appid', $appId );
81
+			$this->assign('application', '');
82
+			$this->assign('appid', $appId);
83 83
 			$navigation = \OC_App::getNavigation();
84
-			$this->assign( 'navigation', $navigation);
84
+			$this->assign('navigation', $navigation);
85 85
 			$settingsNavigation = \OC_App::getSettingsNavigation();
86
-			$this->assign( 'settingsnavigation', $settingsNavigation);
87
-			foreach($navigation as $entry) {
86
+			$this->assign('settingsnavigation', $settingsNavigation);
87
+			foreach ($navigation as $entry) {
88 88
 				if ($entry['active']) {
89
-					$this->assign( 'application', $entry['name'] );
89
+					$this->assign('application', $entry['name']);
90 90
 					break;
91 91
 				}
92 92
 			}
93 93
 
94
-			foreach($settingsNavigation as $entry) {
94
+			foreach ($settingsNavigation as $entry) {
95 95
 				if ($entry['active']) {
96
-					$this->assign( 'application', $entry['name'] );
96
+					$this->assign('application', $entry['name']);
97 97
 					break;
98 98
 				}
99 99
 			}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		// Send the language to our layouts
122 122
 		$this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
123 123
 
124
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
124
+		if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
125 125
 			if (empty(self::$versionHash)) {
126 126
 				$v = \OC_App::getAppVersions();
127 127
 				$v['core'] = implode('.', \OCP\Util::getVersion());
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
153 153
 			}
154 154
 		}
155
-		foreach($jsFiles as $info) {
155
+		foreach ($jsFiles as $info) {
156 156
 			$web = $info[1];
157 157
 			$file = $info[2];
158
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
158
+			$this->append('jsfiles', $web.'/'.$file.$this->getVersionHashSuffix());
159 159
 		}
160 160
 
161 161
 		try {
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
 		// Do not initialise scss appdata until we have a fully installed instance
168 168
 		// Do not load scss for update, errors, installation or login page
169
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
169
+		if (\OC::$server->getSystemConfig()->getValue('installed', false)
170 170
 			&& !\OCP\Util::needUpgrade()
171 171
 			&& $pathInfo !== ''
172 172
 			&& !preg_match('/^\/login/', $pathInfo)) {
@@ -181,14 +181,14 @@  discard block
 block discarded – undo
181 181
 		$this->assign('cssfiles', array());
182 182
 		$this->assign('printcssfiles', []);
183 183
 		$this->assign('versionHash', self::$versionHash);
184
-		foreach($cssFiles as $info) {
184
+		foreach ($cssFiles as $info) {
185 185
 			$web = $info[1];
186 186
 			$file = $info[2];
187 187
 
188 188
 			if (substr($file, -strlen('print.css')) === 'print.css') {
189
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
189
+				$this->append('printcssfiles', $web.'/'.$file.$this->getVersionHashSuffix());
190 190
 			} else {
191
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
191
+				$this->append('cssfiles', $web.'/'.$file.$this->getVersionHashSuffix($web, $file));
192 192
 			}
193 193
 		}
194 194
 	}
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 
209 209
 		if ($this->config->getSystemValue('installed', false)) {
210 210
 			if (\OC::$server->getAppManager()->isInstalled('theming')) {
211
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
211
+				$themingSuffix = '-'.$this->config->getAppValue('theming', 'cachebuster', '0');
212 212
 			}
213 213
 			$v = \OC_App::getAppVersions();
214 214
 		}
@@ -216,21 +216,21 @@  discard block
 block discarded – undo
216 216
 		// Try the webroot path for a match
217 217
 		if ($path !== false && $path !== '') {
218 218
 			$appName = $this->getAppNamefromPath($path);
219
-			if(array_key_exists($appName, $v)) {
219
+			if (array_key_exists($appName, $v)) {
220 220
 				$appVersion = $v[$appName];
221
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
221
+				return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix;
222 222
 			}
223 223
 		}
224 224
 		// fallback to the file path instead
225 225
 		if ($file !== false && $file !== '') {
226 226
 			$appName = $this->getAppNamefromPath($file);
227
-			if(array_key_exists($appName, $v)) {
227
+			if (array_key_exists($appName, $v)) {
228 228
 				$appVersion = $v[$appName];
229
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
229
+				return '?v='.substr(md5($appVersion), 0, 8).$themingSuffix;
230 230
 			}
231 231
 		}
232 232
 
233
-		return '?v=' . self::$versionHash . $themingSuffix;
233
+		return '?v='.self::$versionHash.$themingSuffix;
234 234
 	}
235 235
 
236 236
 	/**
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		// Read the selected theme from the config file
242 242
 		$theme = \OC_Util::getTheme();
243 243
 
244
-		if($compileScss) {
244
+		if ($compileScss) {
245 245
 			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
246 246
 		} else {
247 247
 			$SCSSCacher = null;
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 		$locator = new \OC\Template\CSSResourceLocator(
251 251
 			\OC::$server->getLogger(),
252 252
 			$theme,
253
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
254
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
253
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
254
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
255 255
 			$SCSSCacher
256 256
 		);
257 257
 		$locator->find($styles);
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 		$locator = new \OC\Template\JSResourceLocator(
287 287
 			\OC::$server->getLogger(),
288 288
 			$theme,
289
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
290
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
289
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
290
+			array(\OC::$SERVERROOT => \OC::$WEBROOT),
291 291
 			new JSCombiner(
292 292
 				\OC::$server->getAppDataDir('js'),
293 293
 				\OC::$server->getURLGenerator(),
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	 */
309 309
 	public static function convertToRelativePath($filePath) {
310 310
 		$relativePath = explode(\OC::$SERVERROOT, $filePath);
311
-		if(count($relativePath) !== 2) {
311
+		if (count($relativePath) !== 2) {
312 312
 			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
313 313
 		}
314 314
 
Please login to merge, or discard this patch.
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -45,282 +45,282 @@
 block discarded – undo
45 45
 
46 46
 class TemplateLayout extends \OC_Template {
47 47
 
48
-	private static $versionHash = '';
49
-
50
-	/**
51
-	 * @var \OCP\IConfig
52
-	 */
53
-	private $config;
54
-
55
-	/**
56
-	 * @param string $renderAs
57
-	 * @param string $appId application id
58
-	 */
59
-	public function __construct( $renderAs, $appId = '' ) {
60
-
61
-		// yes - should be injected ....
62
-		$this->config = \OC::$server->getConfig();
63
-
64
-
65
-		// Decide which page we show
66
-		if($renderAs == 'user') {
67
-			parent::__construct( 'core', 'layout.user' );
68
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
69
-				$this->assign('bodyid', 'body-settings');
70
-			}else{
71
-				$this->assign('bodyid', 'body-user');
72
-			}
73
-
74
-			// Code integrity notification
75
-			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77
-				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
78
-			}
79
-
80
-			// Add navigation entry
81
-			$this->assign( 'application', '');
82
-			$this->assign( 'appid', $appId );
83
-			$navigation = \OC_App::getNavigation();
84
-			$this->assign( 'navigation', $navigation);
85
-			$settingsNavigation = \OC_App::getSettingsNavigation();
86
-			$this->assign( 'settingsnavigation', $settingsNavigation);
87
-			foreach($navigation as $entry) {
88
-				if ($entry['active']) {
89
-					$this->assign( 'application', $entry['name'] );
90
-					break;
91
-				}
92
-			}
93
-
94
-			foreach($settingsNavigation as $entry) {
95
-				if ($entry['active']) {
96
-					$this->assign( 'application', $entry['name'] );
97
-					break;
98
-				}
99
-			}
100
-			$userDisplayName = \OC_User::getDisplayName();
101
-			$this->assign('user_displayname', $userDisplayName);
102
-			$this->assign('user_uid', \OC_User::getUser());
103
-
104
-			if (\OC_User::getUser() === false) {
105
-				$this->assign('userAvatarSet', false);
106
-			} else {
107
-				$this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
108
-				$this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
109
-			}
110
-
111
-			// check if app menu icons should be inverted
112
-			try {
113
-				/** @var \OCA\Theming\Util $util */
114
-				$util = \OC::$server->query(\OCA\Theming\Util::class);
115
-				$this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
116
-			} catch (\OCP\AppFramework\QueryException $e) {
117
-				$this->assign('themingInvertMenu', false);
118
-			}
119
-
120
-		} else if ($renderAs == 'error') {
121
-			parent::__construct('core', 'layout.guest', '', false);
122
-			$this->assign('bodyid', 'body-login');
123
-		} else if ($renderAs == 'guest') {
124
-			parent::__construct('core', 'layout.guest');
125
-			$this->assign('bodyid', 'body-login');
126
-		} else {
127
-			parent::__construct('core', 'layout.base');
128
-
129
-		}
130
-		// Send the language to our layouts
131
-		$this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
132
-
133
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
134
-			if (empty(self::$versionHash)) {
135
-				$v = \OC_App::getAppVersions();
136
-				$v['core'] = implode('.', \OCP\Util::getVersion());
137
-				self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
138
-			}
139
-		} else {
140
-			self::$versionHash = md5('not installed');
141
-		}
142
-
143
-		// Add the js files
144
-		$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
145
-		$this->assign('jsfiles', array());
146
-		if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
147
-			if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
148
-				$jsConfigHelper = new JSConfigHelper(
149
-					\OC::$server->getL10N('lib'),
150
-					\OC::$server->query(Defaults::class),
151
-					\OC::$server->getAppManager(),
152
-					\OC::$server->getSession(),
153
-					\OC::$server->getUserSession()->getUser(),
154
-					$this->config,
155
-					\OC::$server->getGroupManager(),
156
-					\OC::$server->getIniWrapper(),
157
-					\OC::$server->getURLGenerator()
158
-				);
159
-				$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
160
-			} else {
161
-				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
162
-			}
163
-		}
164
-		foreach($jsFiles as $info) {
165
-			$web = $info[1];
166
-			$file = $info[2];
167
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
168
-		}
169
-
170
-		try {
171
-			$pathInfo = \OC::$server->getRequest()->getPathInfo();
172
-		} catch (\Exception $e) {
173
-			$pathInfo = '';
174
-		}
175
-
176
-		// Do not initialise scss appdata until we have a fully installed instance
177
-		// Do not load scss for update, errors, installation or login page
178
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
179
-			&& !\OCP\Util::needUpgrade()
180
-			&& $pathInfo !== ''
181
-			&& !preg_match('/^\/login/', $pathInfo)) {
182
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
183
-		} else {
184
-			// If we ignore the scss compiler,
185
-			// we need to load the guest css fallback
186
-			\OC_Util::addStyle('guest');
187
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
188
-		}
189
-
190
-		$this->assign('cssfiles', array());
191
-		$this->assign('printcssfiles', []);
192
-		$this->assign('versionHash', self::$versionHash);
193
-		foreach($cssFiles as $info) {
194
-			$web = $info[1];
195
-			$file = $info[2];
196
-
197
-			if (substr($file, -strlen('print.css')) === 'print.css') {
198
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
199
-			} else {
200
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
201
-			}
202
-		}
203
-	}
204
-
205
-	/**
206
-	 * @param string $path
207
- 	 * @param string $file
208
-	 * @return string
209
-	 */
210
-	protected function getVersionHashSuffix($path = false, $file = false) {
211
-		if ($this->config->getSystemValue('debug', false)) {
212
-			// allows chrome workspace mapping in debug mode
213
-			return "";
214
-		}
215
-		$themingSuffix = '';
216
-		$v = [];
217
-
218
-		if ($this->config->getSystemValue('installed', false)) {
219
-			if (\OC::$server->getAppManager()->isInstalled('theming')) {
220
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
221
-			}
222
-			$v = \OC_App::getAppVersions();
223
-		}
224
-
225
-		// Try the webroot path for a match
226
-		if ($path !== false && $path !== '') {
227
-			$appName = $this->getAppNamefromPath($path);
228
-			if(array_key_exists($appName, $v)) {
229
-				$appVersion = $v[$appName];
230
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
231
-			}
232
-		}
233
-		// fallback to the file path instead
234
-		if ($file !== false && $file !== '') {
235
-			$appName = $this->getAppNamefromPath($file);
236
-			if(array_key_exists($appName, $v)) {
237
-				$appVersion = $v[$appName];
238
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
239
-			}
240
-		}
241
-
242
-		return '?v=' . self::$versionHash . $themingSuffix;
243
-	}
244
-
245
-	/**
246
-	 * @param array $styles
247
-	 * @return array
248
-	 */
249
-	static public function findStylesheetFiles($styles, $compileScss = true) {
250
-		// Read the selected theme from the config file
251
-		$theme = \OC_Util::getTheme();
252
-
253
-		if($compileScss) {
254
-			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
255
-		} else {
256
-			$SCSSCacher = null;
257
-		}
258
-
259
-		$locator = new \OC\Template\CSSResourceLocator(
260
-			\OC::$server->getLogger(),
261
-			$theme,
262
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
263
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
264
-			$SCSSCacher
265
-		);
266
-		$locator->find($styles);
267
-		return $locator->getResources();
268
-	}
269
-
270
-	/**
271
-	 * @param string $path
272
-	 * @return string|boolean
273
-	 */
274
-	public function getAppNamefromPath($path) {
275
-		if ($path !== '' && is_string($path)) {
276
-			$pathParts = explode('/', $path);
277
-			if ($pathParts[0] === 'css') {
278
-				// This is a scss request
279
-				return $pathParts[1];
280
-			}
281
-			return end($pathParts);
282
-		}
283
-		return false;
284
-
285
-	}
286
-
287
-	/**
288
-	 * @param array $scripts
289
-	 * @return array
290
-	 */
291
-	static public function findJavascriptFiles($scripts) {
292
-		// Read the selected theme from the config file
293
-		$theme = \OC_Util::getTheme();
294
-
295
-		$locator = new \OC\Template\JSResourceLocator(
296
-			\OC::$server->getLogger(),
297
-			$theme,
298
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
299
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
300
-			new JSCombiner(
301
-				\OC::$server->getAppDataDir('js'),
302
-				\OC::$server->getURLGenerator(),
303
-				\OC::$server->getMemCacheFactory()->createDistributed('JS'),
304
-				\OC::$server->getSystemConfig(),
305
-				\OC::$server->getLogger()
306
-			)
307
-			);
308
-		$locator->find($scripts);
309
-		return $locator->getResources();
310
-	}
311
-
312
-	/**
313
-	 * Converts the absolute file path to a relative path from \OC::$SERVERROOT
314
-	 * @param string $filePath Absolute path
315
-	 * @return string Relative path
316
-	 * @throws \Exception If $filePath is not under \OC::$SERVERROOT
317
-	 */
318
-	public static function convertToRelativePath($filePath) {
319
-		$relativePath = explode(\OC::$SERVERROOT, $filePath);
320
-		if(count($relativePath) !== 2) {
321
-			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
322
-		}
323
-
324
-		return $relativePath[1];
325
-	}
48
+    private static $versionHash = '';
49
+
50
+    /**
51
+     * @var \OCP\IConfig
52
+     */
53
+    private $config;
54
+
55
+    /**
56
+     * @param string $renderAs
57
+     * @param string $appId application id
58
+     */
59
+    public function __construct( $renderAs, $appId = '' ) {
60
+
61
+        // yes - should be injected ....
62
+        $this->config = \OC::$server->getConfig();
63
+
64
+
65
+        // Decide which page we show
66
+        if($renderAs == 'user') {
67
+            parent::__construct( 'core', 'layout.user' );
68
+            if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
69
+                $this->assign('bodyid', 'body-settings');
70
+            }else{
71
+                $this->assign('bodyid', 'body-user');
72
+            }
73
+
74
+            // Code integrity notification
75
+            $integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
+            if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77
+                \OCP\Util::addScript('core', 'integritycheck-failed-notification');
78
+            }
79
+
80
+            // Add navigation entry
81
+            $this->assign( 'application', '');
82
+            $this->assign( 'appid', $appId );
83
+            $navigation = \OC_App::getNavigation();
84
+            $this->assign( 'navigation', $navigation);
85
+            $settingsNavigation = \OC_App::getSettingsNavigation();
86
+            $this->assign( 'settingsnavigation', $settingsNavigation);
87
+            foreach($navigation as $entry) {
88
+                if ($entry['active']) {
89
+                    $this->assign( 'application', $entry['name'] );
90
+                    break;
91
+                }
92
+            }
93
+
94
+            foreach($settingsNavigation as $entry) {
95
+                if ($entry['active']) {
96
+                    $this->assign( 'application', $entry['name'] );
97
+                    break;
98
+                }
99
+            }
100
+            $userDisplayName = \OC_User::getDisplayName();
101
+            $this->assign('user_displayname', $userDisplayName);
102
+            $this->assign('user_uid', \OC_User::getUser());
103
+
104
+            if (\OC_User::getUser() === false) {
105
+                $this->assign('userAvatarSet', false);
106
+            } else {
107
+                $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
108
+                $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
109
+            }
110
+
111
+            // check if app menu icons should be inverted
112
+            try {
113
+                /** @var \OCA\Theming\Util $util */
114
+                $util = \OC::$server->query(\OCA\Theming\Util::class);
115
+                $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
116
+            } catch (\OCP\AppFramework\QueryException $e) {
117
+                $this->assign('themingInvertMenu', false);
118
+            }
119
+
120
+        } else if ($renderAs == 'error') {
121
+            parent::__construct('core', 'layout.guest', '', false);
122
+            $this->assign('bodyid', 'body-login');
123
+        } else if ($renderAs == 'guest') {
124
+            parent::__construct('core', 'layout.guest');
125
+            $this->assign('bodyid', 'body-login');
126
+        } else {
127
+            parent::__construct('core', 'layout.base');
128
+
129
+        }
130
+        // Send the language to our layouts
131
+        $this->assign('language', \OC::$server->getL10NFactory()->findLanguage());
132
+
133
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
134
+            if (empty(self::$versionHash)) {
135
+                $v = \OC_App::getAppVersions();
136
+                $v['core'] = implode('.', \OCP\Util::getVersion());
137
+                self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
138
+            }
139
+        } else {
140
+            self::$versionHash = md5('not installed');
141
+        }
142
+
143
+        // Add the js files
144
+        $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
145
+        $this->assign('jsfiles', array());
146
+        if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
147
+            if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
148
+                $jsConfigHelper = new JSConfigHelper(
149
+                    \OC::$server->getL10N('lib'),
150
+                    \OC::$server->query(Defaults::class),
151
+                    \OC::$server->getAppManager(),
152
+                    \OC::$server->getSession(),
153
+                    \OC::$server->getUserSession()->getUser(),
154
+                    $this->config,
155
+                    \OC::$server->getGroupManager(),
156
+                    \OC::$server->getIniWrapper(),
157
+                    \OC::$server->getURLGenerator()
158
+                );
159
+                $this->assign('inline_ocjs', $jsConfigHelper->getConfig());
160
+            } else {
161
+                $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
162
+            }
163
+        }
164
+        foreach($jsFiles as $info) {
165
+            $web = $info[1];
166
+            $file = $info[2];
167
+            $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
168
+        }
169
+
170
+        try {
171
+            $pathInfo = \OC::$server->getRequest()->getPathInfo();
172
+        } catch (\Exception $e) {
173
+            $pathInfo = '';
174
+        }
175
+
176
+        // Do not initialise scss appdata until we have a fully installed instance
177
+        // Do not load scss for update, errors, installation or login page
178
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)
179
+            && !\OCP\Util::needUpgrade()
180
+            && $pathInfo !== ''
181
+            && !preg_match('/^\/login/', $pathInfo)) {
182
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
183
+        } else {
184
+            // If we ignore the scss compiler,
185
+            // we need to load the guest css fallback
186
+            \OC_Util::addStyle('guest');
187
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
188
+        }
189
+
190
+        $this->assign('cssfiles', array());
191
+        $this->assign('printcssfiles', []);
192
+        $this->assign('versionHash', self::$versionHash);
193
+        foreach($cssFiles as $info) {
194
+            $web = $info[1];
195
+            $file = $info[2];
196
+
197
+            if (substr($file, -strlen('print.css')) === 'print.css') {
198
+                $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
199
+            } else {
200
+                $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
201
+            }
202
+        }
203
+    }
204
+
205
+    /**
206
+     * @param string $path
207
+     * @param string $file
208
+     * @return string
209
+     */
210
+    protected function getVersionHashSuffix($path = false, $file = false) {
211
+        if ($this->config->getSystemValue('debug', false)) {
212
+            // allows chrome workspace mapping in debug mode
213
+            return "";
214
+        }
215
+        $themingSuffix = '';
216
+        $v = [];
217
+
218
+        if ($this->config->getSystemValue('installed', false)) {
219
+            if (\OC::$server->getAppManager()->isInstalled('theming')) {
220
+                $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
221
+            }
222
+            $v = \OC_App::getAppVersions();
223
+        }
224
+
225
+        // Try the webroot path for a match
226
+        if ($path !== false && $path !== '') {
227
+            $appName = $this->getAppNamefromPath($path);
228
+            if(array_key_exists($appName, $v)) {
229
+                $appVersion = $v[$appName];
230
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
231
+            }
232
+        }
233
+        // fallback to the file path instead
234
+        if ($file !== false && $file !== '') {
235
+            $appName = $this->getAppNamefromPath($file);
236
+            if(array_key_exists($appName, $v)) {
237
+                $appVersion = $v[$appName];
238
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
239
+            }
240
+        }
241
+
242
+        return '?v=' . self::$versionHash . $themingSuffix;
243
+    }
244
+
245
+    /**
246
+     * @param array $styles
247
+     * @return array
248
+     */
249
+    static public function findStylesheetFiles($styles, $compileScss = true) {
250
+        // Read the selected theme from the config file
251
+        $theme = \OC_Util::getTheme();
252
+
253
+        if($compileScss) {
254
+            $SCSSCacher = \OC::$server->query(SCSSCacher::class);
255
+        } else {
256
+            $SCSSCacher = null;
257
+        }
258
+
259
+        $locator = new \OC\Template\CSSResourceLocator(
260
+            \OC::$server->getLogger(),
261
+            $theme,
262
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
263
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
264
+            $SCSSCacher
265
+        );
266
+        $locator->find($styles);
267
+        return $locator->getResources();
268
+    }
269
+
270
+    /**
271
+     * @param string $path
272
+     * @return string|boolean
273
+     */
274
+    public function getAppNamefromPath($path) {
275
+        if ($path !== '' && is_string($path)) {
276
+            $pathParts = explode('/', $path);
277
+            if ($pathParts[0] === 'css') {
278
+                // This is a scss request
279
+                return $pathParts[1];
280
+            }
281
+            return end($pathParts);
282
+        }
283
+        return false;
284
+
285
+    }
286
+
287
+    /**
288
+     * @param array $scripts
289
+     * @return array
290
+     */
291
+    static public function findJavascriptFiles($scripts) {
292
+        // Read the selected theme from the config file
293
+        $theme = \OC_Util::getTheme();
294
+
295
+        $locator = new \OC\Template\JSResourceLocator(
296
+            \OC::$server->getLogger(),
297
+            $theme,
298
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
299
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
300
+            new JSCombiner(
301
+                \OC::$server->getAppDataDir('js'),
302
+                \OC::$server->getURLGenerator(),
303
+                \OC::$server->getMemCacheFactory()->createDistributed('JS'),
304
+                \OC::$server->getSystemConfig(),
305
+                \OC::$server->getLogger()
306
+            )
307
+            );
308
+        $locator->find($scripts);
309
+        return $locator->getResources();
310
+    }
311
+
312
+    /**
313
+     * Converts the absolute file path to a relative path from \OC::$SERVERROOT
314
+     * @param string $filePath Absolute path
315
+     * @return string Relative path
316
+     * @throws \Exception If $filePath is not under \OC::$SERVERROOT
317
+     */
318
+    public static function convertToRelativePath($filePath) {
319
+        $relativePath = explode(\OC::$SERVERROOT, $filePath);
320
+        if(count($relativePath) !== 2) {
321
+            throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
322
+        }
323
+
324
+        return $relativePath[1];
325
+    }
326 326
 }
Please login to merge, or discard this patch.
lib/private/Migration/BackgroundRepair.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function execute($jobList, ILogger $logger = null) {
59 59
 		// add an interval of 15 mins
60
-		$this->setInterval(15*60);
60
+		$this->setInterval(15 * 60);
61 61
 
62 62
 		$this->jobList = $jobList;
63 63
 		$this->logger = $logger;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		try {
91 91
 			$repair->addStep($step);
92 92
 		} catch (\Exception $ex) {
93
-			$this->logger->logException($ex,[
93
+			$this->logger->logException($ex, [
94 94
 				'app' => 'migration'
95 95
 			]);
96 96
 
Please login to merge, or discard this patch.
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -37,81 +37,81 @@
 block discarded – undo
37 37
  */
38 38
 class BackgroundRepair extends TimedJob {
39 39
 
40
-	/** @var IJobList */
41
-	private $jobList;
40
+    /** @var IJobList */
41
+    private $jobList;
42 42
 
43
-	/** @var ILogger */
44
-	private $logger;
43
+    /** @var ILogger */
44
+    private $logger;
45 45
 
46
-	/** @var EventDispatcher */
47
-	private $dispatcher;
46
+    /** @var EventDispatcher */
47
+    private $dispatcher;
48 48
 
49
-	public function setDispatcher(EventDispatcher $dispatcher) {
50
-		$this->dispatcher = $dispatcher;
51
-	}
52
-	/**
53
-	 * run the job, then remove it from the job list
54
-	 *
55
-	 * @param JobList $jobList
56
-	 * @param ILogger|null $logger
57
-	 */
58
-	public function execute($jobList, ILogger $logger = null) {
59
-		// add an interval of 15 mins
60
-		$this->setInterval(15*60);
49
+    public function setDispatcher(EventDispatcher $dispatcher) {
50
+        $this->dispatcher = $dispatcher;
51
+    }
52
+    /**
53
+     * run the job, then remove it from the job list
54
+     *
55
+     * @param JobList $jobList
56
+     * @param ILogger|null $logger
57
+     */
58
+    public function execute($jobList, ILogger $logger = null) {
59
+        // add an interval of 15 mins
60
+        $this->setInterval(15*60);
61 61
 
62
-		$this->jobList = $jobList;
63
-		$this->logger = $logger;
64
-		parent::execute($jobList, $logger);
65
-	}
62
+        $this->jobList = $jobList;
63
+        $this->logger = $logger;
64
+        parent::execute($jobList, $logger);
65
+    }
66 66
 
67
-	/**
68
-	 * @param array $argument
69
-	 * @throws \Exception
70
-	 * @throws \OC\NeedsUpdateException
71
-	 */
72
-	protected function run($argument) {
73
-		if (!isset($argument['app']) || !isset($argument['step'])) {
74
-			// remove the job - we can never execute it
75
-			$this->jobList->remove($this, $this->argument);
76
-			return;
77
-		}
78
-		$app = $argument['app'];
67
+    /**
68
+     * @param array $argument
69
+     * @throws \Exception
70
+     * @throws \OC\NeedsUpdateException
71
+     */
72
+    protected function run($argument) {
73
+        if (!isset($argument['app']) || !isset($argument['step'])) {
74
+            // remove the job - we can never execute it
75
+            $this->jobList->remove($this, $this->argument);
76
+            return;
77
+        }
78
+        $app = $argument['app'];
79 79
 
80
-		try {
81
-			$this->loadApp($app);
82
-		} catch (NeedsUpdateException $ex) {
83
-			// as long as the app is not yet done with it's offline migration
84
-			// we better not start with the live migration
85
-			return;
86
-		}
80
+        try {
81
+            $this->loadApp($app);
82
+        } catch (NeedsUpdateException $ex) {
83
+            // as long as the app is not yet done with it's offline migration
84
+            // we better not start with the live migration
85
+            return;
86
+        }
87 87
 
88
-		$step = $argument['step'];
89
-		$repair = new Repair([], $this->dispatcher);
90
-		try {
91
-			$repair->addStep($step);
92
-		} catch (\Exception $ex) {
93
-			$this->logger->logException($ex,[
94
-				'app' => 'migration'
95
-			]);
88
+        $step = $argument['step'];
89
+        $repair = new Repair([], $this->dispatcher);
90
+        try {
91
+            $repair->addStep($step);
92
+        } catch (\Exception $ex) {
93
+            $this->logger->logException($ex,[
94
+                'app' => 'migration'
95
+            ]);
96 96
 
97
-			// remove the job - we can never execute it
98
-			$this->jobList->remove($this, $this->argument);
99
-			return;
100
-		}
97
+            // remove the job - we can never execute it
98
+            $this->jobList->remove($this, $this->argument);
99
+            return;
100
+        }
101 101
 
102
-		// execute the repair step
103
-		$repair->run();
102
+        // execute the repair step
103
+        $repair->run();
104 104
 
105
-		// remove the job once executed successfully
106
-		$this->jobList->remove($this, $this->argument);
107
-	}
105
+        // remove the job once executed successfully
106
+        $this->jobList->remove($this, $this->argument);
107
+    }
108 108
 
109
-	/**
110
-	 * @codeCoverageIgnore
111
-	 * @param $app
112
-	 * @throws NeedsUpdateException
113
-	 */
114
-	protected function loadApp($app) {
115
-		OC_App::loadApp($app);
116
-	}
109
+    /**
110
+     * @codeCoverageIgnore
111
+     * @param $app
112
+     * @throws NeedsUpdateException
113
+     */
114
+    protected function loadApp($app) {
115
+        OC_App::loadApp($app);
116
+    }
117 117
 }
Please login to merge, or discard this patch.
lib/private/Command/QueueBus.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
 		if ($command instanceof ICommand) {
56 56
 			// ensure the command can be serialized
57 57
 			$serialized = serialize($command);
58
-			if(strlen($serialized) > 4000) {
58
+			if (strlen($serialized) > 4000) {
59 59
 				throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
60 60
 			}
61 61
 			$unserialized = unserialize($serialized);
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -26,48 +26,48 @@
 block discarded – undo
26 26
 use OCP\Command\ICommand;
27 27
 
28 28
 class QueueBus implements IBus {
29
-	/**
30
-	 * @var ICommand[]|callable[]
31
-	 */
32
-	private $queue = [];
29
+    /**
30
+     * @var ICommand[]|callable[]
31
+     */
32
+    private $queue = [];
33 33
 
34
-	/**
35
-	 * Schedule a command to be fired
36
-	 *
37
-	 * @param \OCP\Command\ICommand | callable $command
38
-	 */
39
-	public function push($command) {
40
-		$this->queue[] = $command;
41
-	}
34
+    /**
35
+     * Schedule a command to be fired
36
+     *
37
+     * @param \OCP\Command\ICommand | callable $command
38
+     */
39
+    public function push($command) {
40
+        $this->queue[] = $command;
41
+    }
42 42
 
43
-	/**
44
-	 * Require all commands using a trait to be run synchronous
45
-	 *
46
-	 * @param string $trait
47
-	 */
48
-	public function requireSync($trait) {
49
-	}
43
+    /**
44
+     * Require all commands using a trait to be run synchronous
45
+     *
46
+     * @param string $trait
47
+     */
48
+    public function requireSync($trait) {
49
+    }
50 50
 
51
-	/**
52
-	 * @param \OCP\Command\ICommand | callable $command
53
-	 */
54
-	private function runCommand($command) {
55
-		if ($command instanceof ICommand) {
56
-			// ensure the command can be serialized
57
-			$serialized = serialize($command);
58
-			if(strlen($serialized) > 4000) {
59
-				throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
60
-			}
61
-			$unserialized = unserialize($serialized);
62
-			$unserialized->handle();
63
-		} else {
64
-			$command();
65
-		}
66
-	}
51
+    /**
52
+     * @param \OCP\Command\ICommand | callable $command
53
+     */
54
+    private function runCommand($command) {
55
+        if ($command instanceof ICommand) {
56
+            // ensure the command can be serialized
57
+            $serialized = serialize($command);
58
+            if(strlen($serialized) > 4000) {
59
+                throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)');
60
+            }
61
+            $unserialized = unserialize($serialized);
62
+            $unserialized->handle();
63
+        } else {
64
+            $command();
65
+        }
66
+    }
67 67
 
68
-	public function run() {
69
-		while ($command = array_shift($this->queue)) {
70
-			$this->runCommand($command);
71
-		}
72
-	}
68
+    public function run() {
69
+        while ($command = array_shift($this->queue)) {
70
+            $this->runCommand($command);
71
+        }
72
+    }
73 73
 }
Please login to merge, or discard this patch.