@@ -36,85 +36,85 @@ |
||
| 36 | 36 | * Provide an interface to all search providers |
| 37 | 37 | */ |
| 38 | 38 | class Search implements ISearch { |
| 39 | - /** @var Provider[] */ |
|
| 40 | - private $providers = []; |
|
| 41 | - private $registeredProviders = []; |
|
| 39 | + /** @var Provider[] */ |
|
| 40 | + private $providers = []; |
|
| 41 | + private $registeredProviders = []; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Search all providers for $query |
|
| 45 | - * @param string $query |
|
| 46 | - * @param string[] $inApps optionally limit results to the given apps |
|
| 47 | - * @param int $page pages start at page 1 |
|
| 48 | - * @param int $size, 0 = all |
|
| 49 | - * @return array An array of OC\Search\Result's |
|
| 50 | - */ |
|
| 51 | - public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) { |
|
| 52 | - $this->initProviders(); |
|
| 53 | - $results = []; |
|
| 54 | - foreach ($this->providers as $provider) { |
|
| 55 | - if (! $provider->providesResultsFor($inApps)) { |
|
| 56 | - continue; |
|
| 57 | - } |
|
| 58 | - if ($provider instanceof PagedProvider) { |
|
| 59 | - $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
| 60 | - } elseif ($provider instanceof Provider) { |
|
| 61 | - $providerResults = $provider->search($query); |
|
| 62 | - if ($size > 0) { |
|
| 63 | - $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
| 64 | - $results = array_merge($results, $slicedResults); |
|
| 65 | - } else { |
|
| 66 | - $results = array_merge($results, $providerResults); |
|
| 67 | - } |
|
| 68 | - } else { |
|
| 69 | - \OC::$server->getLogger()->warning('Ignoring Unknown search provider', ['provider' => $provider]); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - return $results; |
|
| 73 | - } |
|
| 43 | + /** |
|
| 44 | + * Search all providers for $query |
|
| 45 | + * @param string $query |
|
| 46 | + * @param string[] $inApps optionally limit results to the given apps |
|
| 47 | + * @param int $page pages start at page 1 |
|
| 48 | + * @param int $size, 0 = all |
|
| 49 | + * @return array An array of OC\Search\Result's |
|
| 50 | + */ |
|
| 51 | + public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) { |
|
| 52 | + $this->initProviders(); |
|
| 53 | + $results = []; |
|
| 54 | + foreach ($this->providers as $provider) { |
|
| 55 | + if (! $provider->providesResultsFor($inApps)) { |
|
| 56 | + continue; |
|
| 57 | + } |
|
| 58 | + if ($provider instanceof PagedProvider) { |
|
| 59 | + $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
| 60 | + } elseif ($provider instanceof Provider) { |
|
| 61 | + $providerResults = $provider->search($query); |
|
| 62 | + if ($size > 0) { |
|
| 63 | + $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
| 64 | + $results = array_merge($results, $slicedResults); |
|
| 65 | + } else { |
|
| 66 | + $results = array_merge($results, $providerResults); |
|
| 67 | + } |
|
| 68 | + } else { |
|
| 69 | + \OC::$server->getLogger()->warning('Ignoring Unknown search provider', ['provider' => $provider]); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + return $results; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Remove all registered search providers |
|
| 77 | - */ |
|
| 78 | - public function clearProviders() { |
|
| 79 | - $this->providers = []; |
|
| 80 | - $this->registeredProviders = []; |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * Remove all registered search providers |
|
| 77 | + */ |
|
| 78 | + public function clearProviders() { |
|
| 79 | + $this->providers = []; |
|
| 80 | + $this->registeredProviders = []; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Remove one existing search provider |
|
| 85 | - * @param string $provider class name of a OC\Search\Provider |
|
| 86 | - */ |
|
| 87 | - public function removeProvider($provider) { |
|
| 88 | - $this->registeredProviders = array_filter( |
|
| 89 | - $this->registeredProviders, |
|
| 90 | - function ($element) use ($provider) { |
|
| 91 | - return ($element['class'] != $provider); |
|
| 92 | - } |
|
| 93 | - ); |
|
| 94 | - // force regeneration of providers on next search |
|
| 95 | - $this->providers = []; |
|
| 96 | - } |
|
| 83 | + /** |
|
| 84 | + * Remove one existing search provider |
|
| 85 | + * @param string $provider class name of a OC\Search\Provider |
|
| 86 | + */ |
|
| 87 | + public function removeProvider($provider) { |
|
| 88 | + $this->registeredProviders = array_filter( |
|
| 89 | + $this->registeredProviders, |
|
| 90 | + function ($element) use ($provider) { |
|
| 91 | + return ($element['class'] != $provider); |
|
| 92 | + } |
|
| 93 | + ); |
|
| 94 | + // force regeneration of providers on next search |
|
| 95 | + $this->providers = []; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Register a new search provider to search with |
|
| 100 | - * @param string $class class name of a OC\Search\Provider |
|
| 101 | - * @param array $options optional |
|
| 102 | - */ |
|
| 103 | - public function registerProvider($class, array $options = []) { |
|
| 104 | - $this->registeredProviders[] = ['class' => $class, 'options' => $options]; |
|
| 105 | - } |
|
| 98 | + /** |
|
| 99 | + * Register a new search provider to search with |
|
| 100 | + * @param string $class class name of a OC\Search\Provider |
|
| 101 | + * @param array $options optional |
|
| 102 | + */ |
|
| 103 | + public function registerProvider($class, array $options = []) { |
|
| 104 | + $this->registeredProviders[] = ['class' => $class, 'options' => $options]; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Create instances of all the registered search providers |
|
| 109 | - */ |
|
| 110 | - private function initProviders() { |
|
| 111 | - if (! empty($this->providers)) { |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - foreach ($this->registeredProviders as $provider) { |
|
| 115 | - $class = $provider['class']; |
|
| 116 | - $options = $provider['options']; |
|
| 117 | - $this->providers[] = new $class($options); |
|
| 118 | - } |
|
| 119 | - } |
|
| 107 | + /** |
|
| 108 | + * Create instances of all the registered search providers |
|
| 109 | + */ |
|
| 110 | + private function initProviders() { |
|
| 111 | + if (! empty($this->providers)) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + foreach ($this->registeredProviders as $provider) { |
|
| 115 | + $class = $provider['class']; |
|
| 116 | + $options = $provider['options']; |
|
| 117 | + $this->providers[] = new $class($options); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $this->initProviders(); |
| 53 | 53 | $results = []; |
| 54 | 54 | foreach ($this->providers as $provider) { |
| 55 | - if (! $provider->providesResultsFor($inApps)) { |
|
| 55 | + if (!$provider->providesResultsFor($inApps)) { |
|
| 56 | 56 | continue; |
| 57 | 57 | } |
| 58 | 58 | if ($provider instanceof PagedProvider) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | public function removeProvider($provider) { |
| 88 | 88 | $this->registeredProviders = array_filter( |
| 89 | 89 | $this->registeredProviders, |
| 90 | - function ($element) use ($provider) { |
|
| 90 | + function($element) use ($provider) { |
|
| 91 | 91 | return ($element['class'] != $provider); |
| 92 | 92 | } |
| 93 | 93 | ); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * Create instances of all the registered search providers |
| 109 | 109 | */ |
| 110 | 110 | private function initProviders() { |
| 111 | - if (! empty($this->providers)) { |
|
| 111 | + if (!empty($this->providers)) { |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | foreach ($this->registeredProviders as $provider) { |
@@ -39,135 +39,135 @@ |
||
| 39 | 39 | use OCP\IDBConnection; |
| 40 | 40 | |
| 41 | 41 | class MDB2SchemaManager { |
| 42 | - /** @var \OC\DB\Connection $conn */ |
|
| 43 | - protected $conn; |
|
| 42 | + /** @var \OC\DB\Connection $conn */ |
|
| 43 | + protected $conn; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param IDBConnection $conn |
|
| 47 | - */ |
|
| 48 | - public function __construct($conn) { |
|
| 49 | - $this->conn = $conn; |
|
| 50 | - } |
|
| 45 | + /** |
|
| 46 | + * @param IDBConnection $conn |
|
| 47 | + */ |
|
| 48 | + public function __construct($conn) { |
|
| 49 | + $this->conn = $conn; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * saves database scheme to xml file |
|
| 54 | - * @param string $file name of file |
|
| 55 | - * @return bool |
|
| 56 | - * |
|
| 57 | - * TODO: write more documentation |
|
| 58 | - */ |
|
| 59 | - public function getDbStructure($file) { |
|
| 60 | - return \OC\DB\MDB2SchemaWriter::saveSchemaToFile($file, $this->conn); |
|
| 61 | - } |
|
| 52 | + /** |
|
| 53 | + * saves database scheme to xml file |
|
| 54 | + * @param string $file name of file |
|
| 55 | + * @return bool |
|
| 56 | + * |
|
| 57 | + * TODO: write more documentation |
|
| 58 | + */ |
|
| 59 | + public function getDbStructure($file) { |
|
| 60 | + return \OC\DB\MDB2SchemaWriter::saveSchemaToFile($file, $this->conn); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Creates tables from XML file |
|
| 65 | - * @param string $file file to read structure from |
|
| 66 | - * @return bool |
|
| 67 | - * |
|
| 68 | - * TODO: write more documentation |
|
| 69 | - */ |
|
| 70 | - public function createDbFromStructure($file) { |
|
| 71 | - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); |
|
| 72 | - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
| 73 | - $toSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
| 74 | - return $this->executeSchemaChange($toSchema); |
|
| 75 | - } |
|
| 63 | + /** |
|
| 64 | + * Creates tables from XML file |
|
| 65 | + * @param string $file file to read structure from |
|
| 66 | + * @return bool |
|
| 67 | + * |
|
| 68 | + * TODO: write more documentation |
|
| 69 | + */ |
|
| 70 | + public function createDbFromStructure($file) { |
|
| 71 | + $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); |
|
| 72 | + $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
| 73 | + $toSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
| 74 | + return $this->executeSchemaChange($toSchema); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @return \OC\DB\Migrator |
|
| 79 | - */ |
|
| 80 | - public function getMigrator() { |
|
| 81 | - $random = \OC::$server->getSecureRandom(); |
|
| 82 | - $platform = $this->conn->getDatabasePlatform(); |
|
| 83 | - $config = \OC::$server->getConfig(); |
|
| 84 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 85 | - if ($platform instanceof SqlitePlatform) { |
|
| 86 | - return new SQLiteMigrator($this->conn, $random, $config, $dispatcher); |
|
| 87 | - } elseif ($platform instanceof OraclePlatform) { |
|
| 88 | - return new OracleMigrator($this->conn, $random, $config, $dispatcher); |
|
| 89 | - } elseif ($platform instanceof MySqlPlatform) { |
|
| 90 | - return new MySQLMigrator($this->conn, $random, $config, $dispatcher); |
|
| 91 | - } elseif ($platform instanceof PostgreSqlPlatform) { |
|
| 92 | - return new PostgreSqlMigrator($this->conn, $random, $config, $dispatcher); |
|
| 93 | - } else { |
|
| 94 | - return new Migrator($this->conn, $random, $config, $dispatcher); |
|
| 95 | - } |
|
| 96 | - } |
|
| 77 | + /** |
|
| 78 | + * @return \OC\DB\Migrator |
|
| 79 | + */ |
|
| 80 | + public function getMigrator() { |
|
| 81 | + $random = \OC::$server->getSecureRandom(); |
|
| 82 | + $platform = $this->conn->getDatabasePlatform(); |
|
| 83 | + $config = \OC::$server->getConfig(); |
|
| 84 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 85 | + if ($platform instanceof SqlitePlatform) { |
|
| 86 | + return new SQLiteMigrator($this->conn, $random, $config, $dispatcher); |
|
| 87 | + } elseif ($platform instanceof OraclePlatform) { |
|
| 88 | + return new OracleMigrator($this->conn, $random, $config, $dispatcher); |
|
| 89 | + } elseif ($platform instanceof MySqlPlatform) { |
|
| 90 | + return new MySQLMigrator($this->conn, $random, $config, $dispatcher); |
|
| 91 | + } elseif ($platform instanceof PostgreSqlPlatform) { |
|
| 92 | + return new PostgreSqlMigrator($this->conn, $random, $config, $dispatcher); |
|
| 93 | + } else { |
|
| 94 | + return new Migrator($this->conn, $random, $config, $dispatcher); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Reads database schema from file |
|
| 100 | - * |
|
| 101 | - * @param string $file file to read from |
|
| 102 | - * @return \Doctrine\DBAL\Schema\Schema |
|
| 103 | - */ |
|
| 104 | - private function readSchemaFromFile($file) { |
|
| 105 | - $platform = $this->conn->getDatabasePlatform(); |
|
| 106 | - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $platform); |
|
| 107 | - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
| 108 | - return $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
| 109 | - } |
|
| 98 | + /** |
|
| 99 | + * Reads database schema from file |
|
| 100 | + * |
|
| 101 | + * @param string $file file to read from |
|
| 102 | + * @return \Doctrine\DBAL\Schema\Schema |
|
| 103 | + */ |
|
| 104 | + private function readSchemaFromFile($file) { |
|
| 105 | + $platform = $this->conn->getDatabasePlatform(); |
|
| 106 | + $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $platform); |
|
| 107 | + $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
| 108 | + return $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * update the database scheme |
|
| 113 | - * @param string $file file to read structure from |
|
| 114 | - * @param bool $generateSql only return the sql needed for the upgrade |
|
| 115 | - * @return string|boolean |
|
| 116 | - */ |
|
| 117 | - public function updateDbFromStructure($file, $generateSql = false) { |
|
| 118 | - $toSchema = $this->readSchemaFromFile($file); |
|
| 119 | - $migrator = $this->getMigrator(); |
|
| 111 | + /** |
|
| 112 | + * update the database scheme |
|
| 113 | + * @param string $file file to read structure from |
|
| 114 | + * @param bool $generateSql only return the sql needed for the upgrade |
|
| 115 | + * @return string|boolean |
|
| 116 | + */ |
|
| 117 | + public function updateDbFromStructure($file, $generateSql = false) { |
|
| 118 | + $toSchema = $this->readSchemaFromFile($file); |
|
| 119 | + $migrator = $this->getMigrator(); |
|
| 120 | 120 | |
| 121 | - if ($generateSql) { |
|
| 122 | - return $migrator->generateChangeScript($toSchema); |
|
| 123 | - } else { |
|
| 124 | - $migrator->migrate($toSchema); |
|
| 125 | - return true; |
|
| 126 | - } |
|
| 127 | - } |
|
| 121 | + if ($generateSql) { |
|
| 122 | + return $migrator->generateChangeScript($toSchema); |
|
| 123 | + } else { |
|
| 124 | + $migrator->migrate($toSchema); |
|
| 125 | + return true; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * @param \Doctrine\DBAL\Schema\Schema $schema |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function generateChangeScript($schema) { |
|
| 134 | - $migrator = $this->getMigrator(); |
|
| 135 | - return $migrator->generateChangeScript($schema); |
|
| 136 | - } |
|
| 129 | + /** |
|
| 130 | + * @param \Doctrine\DBAL\Schema\Schema $schema |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function generateChangeScript($schema) { |
|
| 134 | + $migrator = $this->getMigrator(); |
|
| 135 | + return $migrator->generateChangeScript($schema); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * remove all tables defined in a database structure xml file |
|
| 140 | - * |
|
| 141 | - * @param string $file the xml file describing the tables |
|
| 142 | - */ |
|
| 143 | - public function removeDBStructure($file) { |
|
| 144 | - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); |
|
| 145 | - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
| 146 | - $fromSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
| 147 | - $toSchema = clone $fromSchema; |
|
| 148 | - foreach ($toSchema->getTables() as $table) { |
|
| 149 | - $toSchema->dropTable($table->getName()); |
|
| 150 | - } |
|
| 151 | - $comparator = new \Doctrine\DBAL\Schema\Comparator(); |
|
| 152 | - $schemaDiff = $comparator->compare($fromSchema, $toSchema); |
|
| 153 | - $this->executeSchemaChange($schemaDiff); |
|
| 154 | - } |
|
| 138 | + /** |
|
| 139 | + * remove all tables defined in a database structure xml file |
|
| 140 | + * |
|
| 141 | + * @param string $file the xml file describing the tables |
|
| 142 | + */ |
|
| 143 | + public function removeDBStructure($file) { |
|
| 144 | + $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); |
|
| 145 | + $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
| 146 | + $fromSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
| 147 | + $toSchema = clone $fromSchema; |
|
| 148 | + foreach ($toSchema->getTables() as $table) { |
|
| 149 | + $toSchema->dropTable($table->getName()); |
|
| 150 | + } |
|
| 151 | + $comparator = new \Doctrine\DBAL\Schema\Comparator(); |
|
| 152 | + $schemaDiff = $comparator->compare($fromSchema, $toSchema); |
|
| 153 | + $this->executeSchemaChange($schemaDiff); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - private function executeSchemaChange($schema) { |
|
| 161 | - $this->conn->beginTransaction(); |
|
| 162 | - foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) { |
|
| 163 | - $this->conn->query($sql); |
|
| 164 | - } |
|
| 165 | - $this->conn->commit(); |
|
| 156 | + /** |
|
| 157 | + * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + private function executeSchemaChange($schema) { |
|
| 161 | + $this->conn->beginTransaction(); |
|
| 162 | + foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) { |
|
| 163 | + $this->conn->query($sql); |
|
| 164 | + } |
|
| 165 | + $this->conn->commit(); |
|
| 166 | 166 | |
| 167 | - if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) { |
|
| 168 | - $this->conn->close(); |
|
| 169 | - $this->conn->connect(); |
|
| 170 | - } |
|
| 171 | - return true; |
|
| 172 | - } |
|
| 167 | + if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) { |
|
| 168 | + $this->conn->close(); |
|
| 169 | + $this->conn->connect(); |
|
| 170 | + } |
|
| 171 | + return true; |
|
| 172 | + } |
|
| 173 | 173 | } |
@@ -46,271 +46,271 @@ |
||
| 46 | 46 | |
| 47 | 47 | class Migrator { |
| 48 | 48 | |
| 49 | - /** @var \Doctrine\DBAL\Connection */ |
|
| 50 | - protected $connection; |
|
| 51 | - |
|
| 52 | - /** @var ISecureRandom */ |
|
| 53 | - private $random; |
|
| 54 | - |
|
| 55 | - /** @var IConfig */ |
|
| 56 | - protected $config; |
|
| 57 | - |
|
| 58 | - /** @var EventDispatcherInterface */ |
|
| 59 | - private $dispatcher; |
|
| 60 | - |
|
| 61 | - /** @var bool */ |
|
| 62 | - private $noEmit = false; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 66 | - * @param ISecureRandom $random |
|
| 67 | - * @param IConfig $config |
|
| 68 | - * @param EventDispatcherInterface $dispatcher |
|
| 69 | - */ |
|
| 70 | - public function __construct(\Doctrine\DBAL\Connection $connection, |
|
| 71 | - ISecureRandom $random, |
|
| 72 | - IConfig $config, |
|
| 73 | - EventDispatcherInterface $dispatcher = null) { |
|
| 74 | - $this->connection = $connection; |
|
| 75 | - $this->random = $random; |
|
| 76 | - $this->config = $config; |
|
| 77 | - $this->dispatcher = $dispatcher; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 82 | - */ |
|
| 83 | - public function migrate(Schema $targetSchema) { |
|
| 84 | - $this->noEmit = true; |
|
| 85 | - $this->applySchema($targetSchema); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function generateChangeScript(Schema $targetSchema) { |
|
| 93 | - $schemaDiff = $this->getDiff($targetSchema, $this->connection); |
|
| 94 | - |
|
| 95 | - $script = ''; |
|
| 96 | - $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform()); |
|
| 97 | - foreach ($sqls as $sql) { |
|
| 98 | - $script .= $this->convertStatementToScript($sql); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $script; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param Schema $targetSchema |
|
| 106 | - * @throws \OC\DB\MigrationException |
|
| 107 | - */ |
|
| 108 | - public function checkMigrate(Schema $targetSchema) { |
|
| 109 | - $this->noEmit = true; |
|
| 110 | - /**@var \Doctrine\DBAL\Schema\Table[] $tables */ |
|
| 111 | - $tables = $targetSchema->getTables(); |
|
| 112 | - $filterExpression = $this->getFilterExpression(); |
|
| 113 | - $this->connection->getConfiguration()-> |
|
| 114 | - setFilterSchemaAssetsExpression($filterExpression); |
|
| 115 | - $existingTables = $this->connection->getSchemaManager()->listTableNames(); |
|
| 116 | - |
|
| 117 | - $step = 0; |
|
| 118 | - foreach ($tables as $table) { |
|
| 119 | - if (strpos($table->getName(), '.')) { |
|
| 120 | - list(, $tableName) = explode('.', $table->getName()); |
|
| 121 | - } else { |
|
| 122 | - $tableName = $table->getName(); |
|
| 123 | - } |
|
| 124 | - $this->emitCheckStep($tableName, $step++, count($tables)); |
|
| 125 | - // don't need to check for new tables |
|
| 126 | - if (array_search($tableName, $existingTables) !== false) { |
|
| 127 | - $this->checkTableMigrate($table); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Create a unique name for the temporary table |
|
| 134 | - * |
|
| 135 | - * @param string $name |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - protected function generateTemporaryTableName($name) { |
|
| 139 | - return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Check the migration of a table on a copy so we can detect errors before messing with the real table |
|
| 144 | - * |
|
| 145 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 146 | - * @throws \OC\DB\MigrationException |
|
| 147 | - */ |
|
| 148 | - protected function checkTableMigrate(Table $table) { |
|
| 149 | - $name = $table->getName(); |
|
| 150 | - $tmpName = $this->generateTemporaryTableName($name); |
|
| 151 | - |
|
| 152 | - $this->copyTable($name, $tmpName); |
|
| 153 | - |
|
| 154 | - //create the migration schema for the temporary table |
|
| 155 | - $tmpTable = $this->renameTableSchema($table, $tmpName); |
|
| 156 | - $schemaConfig = new SchemaConfig(); |
|
| 157 | - $schemaConfig->setName($this->connection->getDatabase()); |
|
| 158 | - $schema = new Schema([$tmpTable], [], $schemaConfig); |
|
| 159 | - |
|
| 160 | - try { |
|
| 161 | - $this->applySchema($schema); |
|
| 162 | - $this->dropTable($tmpName); |
|
| 163 | - } catch (DBALException $e) { |
|
| 164 | - // pgsql needs to commit it's failed transaction before doing anything else |
|
| 165 | - if ($this->connection->isTransactionActive()) { |
|
| 166 | - $this->connection->commit(); |
|
| 167 | - } |
|
| 168 | - $this->dropTable($tmpName); |
|
| 169 | - throw new MigrationException($table->getName(), $e->getMessage()); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 175 | - * @param string $newName |
|
| 176 | - * @return \Doctrine\DBAL\Schema\Table |
|
| 177 | - */ |
|
| 178 | - protected function renameTableSchema(Table $table, $newName) { |
|
| 179 | - /** |
|
| 180 | - * @var \Doctrine\DBAL\Schema\Index[] $indexes |
|
| 181 | - */ |
|
| 182 | - $indexes = $table->getIndexes(); |
|
| 183 | - $newIndexes = []; |
|
| 184 | - foreach ($indexes as $index) { |
|
| 185 | - if ($index->isPrimary()) { |
|
| 186 | - // do not rename primary key |
|
| 187 | - $indexName = $index->getName(); |
|
| 188 | - } else { |
|
| 189 | - // avoid conflicts in index names |
|
| 190 | - $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER); |
|
| 191 | - } |
|
| 192 | - $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // foreign keys are not supported so we just set it to an empty array |
|
| 196 | - return new Table($newName, $table->getColumns(), $newIndexes, [], 0, $table->getOptions()); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - public function createSchema() { |
|
| 200 | - $filterExpression = $this->getFilterExpression(); |
|
| 201 | - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 202 | - return $this->connection->getSchemaManager()->createSchema(); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param Schema $targetSchema |
|
| 207 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 208 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 209 | - * @throws DBALException |
|
| 210 | - */ |
|
| 211 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 212 | - // adjust varchar columns with a length higher then getVarcharMaxLength to clob |
|
| 213 | - foreach ($targetSchema->getTables() as $table) { |
|
| 214 | - foreach ($table->getColumns() as $column) { |
|
| 215 | - if ($column->getType() instanceof StringType) { |
|
| 216 | - if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) { |
|
| 217 | - $column->setType(Type::getType('text')); |
|
| 218 | - $column->setLength(null); |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $filterExpression = $this->getFilterExpression(); |
|
| 225 | - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 226 | - $sourceSchema = $connection->getSchemaManager()->createSchema(); |
|
| 227 | - |
|
| 228 | - // remove tables we don't know about |
|
| 229 | - foreach ($sourceSchema->getTables() as $table) { |
|
| 230 | - if (!$targetSchema->hasTable($table->getName())) { |
|
| 231 | - $sourceSchema->dropTable($table->getName()); |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - // remove sequences we don't know about |
|
| 235 | - foreach ($sourceSchema->getSequences() as $table) { |
|
| 236 | - if (!$targetSchema->hasSequence($table->getName())) { |
|
| 237 | - $sourceSchema->dropSequence($table->getName()); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $comparator = new Comparator(); |
|
| 242 | - return $comparator->compare($sourceSchema, $targetSchema); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 247 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 248 | - */ |
|
| 249 | - protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) { |
|
| 250 | - if (is_null($connection)) { |
|
| 251 | - $connection = $this->connection; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $schemaDiff = $this->getDiff($targetSchema, $connection); |
|
| 255 | - |
|
| 256 | - $connection->beginTransaction(); |
|
| 257 | - $sqls = $schemaDiff->toSql($connection->getDatabasePlatform()); |
|
| 258 | - $step = 0; |
|
| 259 | - foreach ($sqls as $sql) { |
|
| 260 | - $this->emit($sql, $step++, count($sqls)); |
|
| 261 | - $connection->query($sql); |
|
| 262 | - } |
|
| 263 | - $connection->commit(); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param string $sourceName |
|
| 268 | - * @param string $targetName |
|
| 269 | - */ |
|
| 270 | - protected function copyTable($sourceName, $targetName) { |
|
| 271 | - $quotedSource = $this->connection->quoteIdentifier($sourceName); |
|
| 272 | - $quotedTarget = $this->connection->quoteIdentifier($targetName); |
|
| 273 | - |
|
| 274 | - $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')'); |
|
| 275 | - $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @param string $name |
|
| 280 | - */ |
|
| 281 | - protected function dropTable($name) { |
|
| 282 | - $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name)); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @param $statement |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - protected function convertStatementToScript($statement) { |
|
| 290 | - $script = $statement . ';'; |
|
| 291 | - $script .= PHP_EOL; |
|
| 292 | - $script .= PHP_EOL; |
|
| 293 | - return $script; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - protected function getFilterExpression() { |
|
| 297 | - return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - protected function emit($sql, $step, $max) { |
|
| 301 | - if ($this->noEmit) { |
|
| 302 | - return; |
|
| 303 | - } |
|
| 304 | - if (is_null($this->dispatcher)) { |
|
| 305 | - return; |
|
| 306 | - } |
|
| 307 | - $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - private function emitCheckStep($tableName, $step, $max) { |
|
| 311 | - if (is_null($this->dispatcher)) { |
|
| 312 | - return; |
|
| 313 | - } |
|
| 314 | - $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max])); |
|
| 315 | - } |
|
| 49 | + /** @var \Doctrine\DBAL\Connection */ |
|
| 50 | + protected $connection; |
|
| 51 | + |
|
| 52 | + /** @var ISecureRandom */ |
|
| 53 | + private $random; |
|
| 54 | + |
|
| 55 | + /** @var IConfig */ |
|
| 56 | + protected $config; |
|
| 57 | + |
|
| 58 | + /** @var EventDispatcherInterface */ |
|
| 59 | + private $dispatcher; |
|
| 60 | + |
|
| 61 | + /** @var bool */ |
|
| 62 | + private $noEmit = false; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 66 | + * @param ISecureRandom $random |
|
| 67 | + * @param IConfig $config |
|
| 68 | + * @param EventDispatcherInterface $dispatcher |
|
| 69 | + */ |
|
| 70 | + public function __construct(\Doctrine\DBAL\Connection $connection, |
|
| 71 | + ISecureRandom $random, |
|
| 72 | + IConfig $config, |
|
| 73 | + EventDispatcherInterface $dispatcher = null) { |
|
| 74 | + $this->connection = $connection; |
|
| 75 | + $this->random = $random; |
|
| 76 | + $this->config = $config; |
|
| 77 | + $this->dispatcher = $dispatcher; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 82 | + */ |
|
| 83 | + public function migrate(Schema $targetSchema) { |
|
| 84 | + $this->noEmit = true; |
|
| 85 | + $this->applySchema($targetSchema); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function generateChangeScript(Schema $targetSchema) { |
|
| 93 | + $schemaDiff = $this->getDiff($targetSchema, $this->connection); |
|
| 94 | + |
|
| 95 | + $script = ''; |
|
| 96 | + $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform()); |
|
| 97 | + foreach ($sqls as $sql) { |
|
| 98 | + $script .= $this->convertStatementToScript($sql); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $script; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param Schema $targetSchema |
|
| 106 | + * @throws \OC\DB\MigrationException |
|
| 107 | + */ |
|
| 108 | + public function checkMigrate(Schema $targetSchema) { |
|
| 109 | + $this->noEmit = true; |
|
| 110 | + /**@var \Doctrine\DBAL\Schema\Table[] $tables */ |
|
| 111 | + $tables = $targetSchema->getTables(); |
|
| 112 | + $filterExpression = $this->getFilterExpression(); |
|
| 113 | + $this->connection->getConfiguration()-> |
|
| 114 | + setFilterSchemaAssetsExpression($filterExpression); |
|
| 115 | + $existingTables = $this->connection->getSchemaManager()->listTableNames(); |
|
| 116 | + |
|
| 117 | + $step = 0; |
|
| 118 | + foreach ($tables as $table) { |
|
| 119 | + if (strpos($table->getName(), '.')) { |
|
| 120 | + list(, $tableName) = explode('.', $table->getName()); |
|
| 121 | + } else { |
|
| 122 | + $tableName = $table->getName(); |
|
| 123 | + } |
|
| 124 | + $this->emitCheckStep($tableName, $step++, count($tables)); |
|
| 125 | + // don't need to check for new tables |
|
| 126 | + if (array_search($tableName, $existingTables) !== false) { |
|
| 127 | + $this->checkTableMigrate($table); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Create a unique name for the temporary table |
|
| 134 | + * |
|
| 135 | + * @param string $name |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + protected function generateTemporaryTableName($name) { |
|
| 139 | + return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Check the migration of a table on a copy so we can detect errors before messing with the real table |
|
| 144 | + * |
|
| 145 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 146 | + * @throws \OC\DB\MigrationException |
|
| 147 | + */ |
|
| 148 | + protected function checkTableMigrate(Table $table) { |
|
| 149 | + $name = $table->getName(); |
|
| 150 | + $tmpName = $this->generateTemporaryTableName($name); |
|
| 151 | + |
|
| 152 | + $this->copyTable($name, $tmpName); |
|
| 153 | + |
|
| 154 | + //create the migration schema for the temporary table |
|
| 155 | + $tmpTable = $this->renameTableSchema($table, $tmpName); |
|
| 156 | + $schemaConfig = new SchemaConfig(); |
|
| 157 | + $schemaConfig->setName($this->connection->getDatabase()); |
|
| 158 | + $schema = new Schema([$tmpTable], [], $schemaConfig); |
|
| 159 | + |
|
| 160 | + try { |
|
| 161 | + $this->applySchema($schema); |
|
| 162 | + $this->dropTable($tmpName); |
|
| 163 | + } catch (DBALException $e) { |
|
| 164 | + // pgsql needs to commit it's failed transaction before doing anything else |
|
| 165 | + if ($this->connection->isTransactionActive()) { |
|
| 166 | + $this->connection->commit(); |
|
| 167 | + } |
|
| 168 | + $this->dropTable($tmpName); |
|
| 169 | + throw new MigrationException($table->getName(), $e->getMessage()); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 175 | + * @param string $newName |
|
| 176 | + * @return \Doctrine\DBAL\Schema\Table |
|
| 177 | + */ |
|
| 178 | + protected function renameTableSchema(Table $table, $newName) { |
|
| 179 | + /** |
|
| 180 | + * @var \Doctrine\DBAL\Schema\Index[] $indexes |
|
| 181 | + */ |
|
| 182 | + $indexes = $table->getIndexes(); |
|
| 183 | + $newIndexes = []; |
|
| 184 | + foreach ($indexes as $index) { |
|
| 185 | + if ($index->isPrimary()) { |
|
| 186 | + // do not rename primary key |
|
| 187 | + $indexName = $index->getName(); |
|
| 188 | + } else { |
|
| 189 | + // avoid conflicts in index names |
|
| 190 | + $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER); |
|
| 191 | + } |
|
| 192 | + $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // foreign keys are not supported so we just set it to an empty array |
|
| 196 | + return new Table($newName, $table->getColumns(), $newIndexes, [], 0, $table->getOptions()); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + public function createSchema() { |
|
| 200 | + $filterExpression = $this->getFilterExpression(); |
|
| 201 | + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 202 | + return $this->connection->getSchemaManager()->createSchema(); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param Schema $targetSchema |
|
| 207 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 208 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 209 | + * @throws DBALException |
|
| 210 | + */ |
|
| 211 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 212 | + // adjust varchar columns with a length higher then getVarcharMaxLength to clob |
|
| 213 | + foreach ($targetSchema->getTables() as $table) { |
|
| 214 | + foreach ($table->getColumns() as $column) { |
|
| 215 | + if ($column->getType() instanceof StringType) { |
|
| 216 | + if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) { |
|
| 217 | + $column->setType(Type::getType('text')); |
|
| 218 | + $column->setLength(null); |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $filterExpression = $this->getFilterExpression(); |
|
| 225 | + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 226 | + $sourceSchema = $connection->getSchemaManager()->createSchema(); |
|
| 227 | + |
|
| 228 | + // remove tables we don't know about |
|
| 229 | + foreach ($sourceSchema->getTables() as $table) { |
|
| 230 | + if (!$targetSchema->hasTable($table->getName())) { |
|
| 231 | + $sourceSchema->dropTable($table->getName()); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + // remove sequences we don't know about |
|
| 235 | + foreach ($sourceSchema->getSequences() as $table) { |
|
| 236 | + if (!$targetSchema->hasSequence($table->getName())) { |
|
| 237 | + $sourceSchema->dropSequence($table->getName()); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $comparator = new Comparator(); |
|
| 242 | + return $comparator->compare($sourceSchema, $targetSchema); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 247 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 248 | + */ |
|
| 249 | + protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) { |
|
| 250 | + if (is_null($connection)) { |
|
| 251 | + $connection = $this->connection; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $schemaDiff = $this->getDiff($targetSchema, $connection); |
|
| 255 | + |
|
| 256 | + $connection->beginTransaction(); |
|
| 257 | + $sqls = $schemaDiff->toSql($connection->getDatabasePlatform()); |
|
| 258 | + $step = 0; |
|
| 259 | + foreach ($sqls as $sql) { |
|
| 260 | + $this->emit($sql, $step++, count($sqls)); |
|
| 261 | + $connection->query($sql); |
|
| 262 | + } |
|
| 263 | + $connection->commit(); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param string $sourceName |
|
| 268 | + * @param string $targetName |
|
| 269 | + */ |
|
| 270 | + protected function copyTable($sourceName, $targetName) { |
|
| 271 | + $quotedSource = $this->connection->quoteIdentifier($sourceName); |
|
| 272 | + $quotedTarget = $this->connection->quoteIdentifier($targetName); |
|
| 273 | + |
|
| 274 | + $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')'); |
|
| 275 | + $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @param string $name |
|
| 280 | + */ |
|
| 281 | + protected function dropTable($name) { |
|
| 282 | + $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name)); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @param $statement |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + protected function convertStatementToScript($statement) { |
|
| 290 | + $script = $statement . ';'; |
|
| 291 | + $script .= PHP_EOL; |
|
| 292 | + $script .= PHP_EOL; |
|
| 293 | + return $script; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + protected function getFilterExpression() { |
|
| 297 | + return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + protected function emit($sql, $step, $max) { |
|
| 301 | + if ($this->noEmit) { |
|
| 302 | + return; |
|
| 303 | + } |
|
| 304 | + if (is_null($this->dispatcher)) { |
|
| 305 | + return; |
|
| 306 | + } |
|
| 307 | + $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + private function emitCheckStep($tableName, $step, $max) { |
|
| 311 | + if (is_null($this->dispatcher)) { |
|
| 312 | + return; |
|
| 313 | + } |
|
| 314 | + $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max])); |
|
| 315 | + } |
|
| 316 | 316 | } |
@@ -243,2067 +243,2067 @@ |
||
| 243 | 243 | */ |
| 244 | 244 | class Server extends ServerContainer implements IServerContainer { |
| 245 | 245 | |
| 246 | - /** @var string */ |
|
| 247 | - private $webRoot; |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param string $webRoot |
|
| 251 | - * @param \OC\Config $config |
|
| 252 | - */ |
|
| 253 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 254 | - parent::__construct(); |
|
| 255 | - $this->webRoot = $webRoot; |
|
| 256 | - |
|
| 257 | - // To find out if we are running from CLI or not |
|
| 258 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 259 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 260 | - |
|
| 261 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 262 | - return $c; |
|
| 263 | - }); |
|
| 264 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 265 | - return $c; |
|
| 266 | - }); |
|
| 267 | - |
|
| 268 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 269 | - /** @deprecated 19.0.0 */ |
|
| 270 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 271 | - |
|
| 272 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 273 | - /** @deprecated 19.0.0 */ |
|
| 274 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 275 | - |
|
| 276 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 277 | - /** @deprecated 19.0.0 */ |
|
| 278 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 279 | - |
|
| 280 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 281 | - /** @deprecated 19.0.0 */ |
|
| 282 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 283 | - |
|
| 284 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 285 | - |
|
| 286 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - $this->registerService(IPreview::class, function (Server $c) { |
|
| 290 | - return new PreviewManager( |
|
| 291 | - $c->getConfig(), |
|
| 292 | - $c->getRootFolder(), |
|
| 293 | - new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()), |
|
| 294 | - $c->getEventDispatcher(), |
|
| 295 | - $c->getGeneratorHelper(), |
|
| 296 | - $c->getSession()->get('user_id') |
|
| 297 | - ); |
|
| 298 | - }); |
|
| 299 | - /** @deprecated 19.0.0 */ |
|
| 300 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
| 301 | - |
|
| 302 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 303 | - return new \OC\Preview\Watcher( |
|
| 304 | - new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()) |
|
| 305 | - ); |
|
| 306 | - }); |
|
| 307 | - |
|
| 308 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 309 | - $view = new View(); |
|
| 310 | - $util = new Encryption\Util( |
|
| 311 | - $view, |
|
| 312 | - $c->getUserManager(), |
|
| 313 | - $c->getGroupManager(), |
|
| 314 | - $c->getConfig() |
|
| 315 | - ); |
|
| 316 | - return new Encryption\Manager( |
|
| 317 | - $c->getConfig(), |
|
| 318 | - $c->getLogger(), |
|
| 319 | - $c->getL10N('core'), |
|
| 320 | - new View(), |
|
| 321 | - $util, |
|
| 322 | - new ArrayCache() |
|
| 323 | - ); |
|
| 324 | - }); |
|
| 325 | - /** @deprecated 19.0.0 */ |
|
| 326 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 327 | - |
|
| 328 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 329 | - $util = new Encryption\Util( |
|
| 330 | - new View(), |
|
| 331 | - $c->getUserManager(), |
|
| 332 | - $c->getGroupManager(), |
|
| 333 | - $c->getConfig() |
|
| 334 | - ); |
|
| 335 | - return new Encryption\File( |
|
| 336 | - $util, |
|
| 337 | - $c->getRootFolder(), |
|
| 338 | - $c->getShareManager() |
|
| 339 | - ); |
|
| 340 | - }); |
|
| 341 | - |
|
| 342 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 343 | - $view = new View(); |
|
| 344 | - $util = new Encryption\Util( |
|
| 345 | - $view, |
|
| 346 | - $c->getUserManager(), |
|
| 347 | - $c->getGroupManager(), |
|
| 348 | - $c->getConfig() |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - return new Encryption\Keys\Storage($view, $util); |
|
| 352 | - }); |
|
| 353 | - /** @deprecated 20.0.0 */ |
|
| 354 | - $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
| 355 | - |
|
| 356 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 357 | - /** @deprecated 19.0.0 */ |
|
| 358 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
| 359 | - |
|
| 360 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 361 | - $config = $c->getConfig(); |
|
| 362 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 363 | - return new $factoryClass($this); |
|
| 364 | - }); |
|
| 365 | - $this->registerService(ISystemTagManager::class, function (Server $c) { |
|
| 366 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 367 | - }); |
|
| 368 | - /** @deprecated 19.0.0 */ |
|
| 369 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 370 | - |
|
| 371 | - $this->registerService(ISystemTagObjectMapper::class, function (Server $c) { |
|
| 372 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 373 | - }); |
|
| 374 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 375 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 376 | - $view = new View(); |
|
| 377 | - $root = new Root( |
|
| 378 | - $manager, |
|
| 379 | - $view, |
|
| 380 | - null, |
|
| 381 | - $c->getUserMountCache(), |
|
| 382 | - $this->getLogger(), |
|
| 383 | - $this->getUserManager() |
|
| 384 | - ); |
|
| 385 | - |
|
| 386 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 387 | - $previewConnector->connectWatcher(); |
|
| 388 | - |
|
| 389 | - return $root; |
|
| 390 | - }); |
|
| 391 | - $this->registerService(HookConnector::class, function (Server $c) { |
|
| 392 | - return new HookConnector( |
|
| 393 | - $c->query(IRootFolder::class), |
|
| 394 | - new View(), |
|
| 395 | - $c->query(\OC\EventDispatcher\SymfonyAdapter::class), |
|
| 396 | - $c->query(IEventDispatcher::class) |
|
| 397 | - ); |
|
| 398 | - }); |
|
| 399 | - |
|
| 400 | - /** @deprecated 19.0.0 */ |
|
| 401 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
| 402 | - |
|
| 403 | - $this->registerService(IRootFolder::class, function (Server $c) { |
|
| 404 | - return new LazyRoot(function () use ($c) { |
|
| 405 | - return $c->query('RootFolder'); |
|
| 406 | - }); |
|
| 407 | - }); |
|
| 408 | - /** @deprecated 19.0.0 */ |
|
| 409 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
| 410 | - |
|
| 411 | - /** @deprecated 19.0.0 */ |
|
| 412 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
| 413 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 414 | - |
|
| 415 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 416 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
| 417 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 418 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]); |
|
| 419 | - |
|
| 420 | - /** @var IEventDispatcher $dispatcher */ |
|
| 421 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 422 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
| 423 | - }); |
|
| 424 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 425 | - \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]); |
|
| 426 | - |
|
| 427 | - /** @var IEventDispatcher $dispatcher */ |
|
| 428 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 429 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
| 430 | - }); |
|
| 431 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 432 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]); |
|
| 433 | - |
|
| 434 | - /** @var IEventDispatcher $dispatcher */ |
|
| 435 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 436 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
| 437 | - }); |
|
| 438 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 439 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]); |
|
| 440 | - |
|
| 441 | - /** @var IEventDispatcher $dispatcher */ |
|
| 442 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 443 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
| 444 | - }); |
|
| 445 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 446 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 447 | - |
|
| 448 | - /** @var IEventDispatcher $dispatcher */ |
|
| 449 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 450 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
| 451 | - }); |
|
| 452 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 453 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 454 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 455 | - \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 456 | - |
|
| 457 | - /** @var IEventDispatcher $dispatcher */ |
|
| 458 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 459 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
| 460 | - }); |
|
| 461 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 462 | - /** @var IEventDispatcher $dispatcher */ |
|
| 463 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 464 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
| 465 | - }); |
|
| 466 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 467 | - /** @var IEventDispatcher $dispatcher */ |
|
| 468 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 469 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
| 470 | - }); |
|
| 471 | - return $groupManager; |
|
| 472 | - }); |
|
| 473 | - /** @deprecated 19.0.0 */ |
|
| 474 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 475 | - |
|
| 476 | - $this->registerService(Store::class, function (Server $c) { |
|
| 477 | - $session = $c->getSession(); |
|
| 478 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 479 | - $tokenProvider = $c->query(IProvider::class); |
|
| 480 | - } else { |
|
| 481 | - $tokenProvider = null; |
|
| 482 | - } |
|
| 483 | - $logger = $c->getLogger(); |
|
| 484 | - return new Store($session, $logger, $tokenProvider); |
|
| 485 | - }); |
|
| 486 | - $this->registerAlias(IStore::class, Store::class); |
|
| 487 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 488 | - |
|
| 489 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 490 | - $manager = $c->getUserManager(); |
|
| 491 | - $session = new \OC\Session\Memory(''); |
|
| 492 | - $timeFactory = new TimeFactory(); |
|
| 493 | - // Token providers might require a working database. This code |
|
| 494 | - // might however be called when ownCloud is not yet setup. |
|
| 495 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 496 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
| 497 | - } else { |
|
| 498 | - $defaultTokenProvider = null; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - $legacyDispatcher = $c->getEventDispatcher(); |
|
| 502 | - |
|
| 503 | - $userSession = new \OC\User\Session( |
|
| 504 | - $manager, |
|
| 505 | - $session, |
|
| 506 | - $timeFactory, |
|
| 507 | - $defaultTokenProvider, |
|
| 508 | - $c->getConfig(), |
|
| 509 | - $c->getSecureRandom(), |
|
| 510 | - $c->getLockdownManager(), |
|
| 511 | - $c->getLogger(), |
|
| 512 | - $c->query(IEventDispatcher::class) |
|
| 513 | - ); |
|
| 514 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 515 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 516 | - |
|
| 517 | - /** @var IEventDispatcher $dispatcher */ |
|
| 518 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 519 | - $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); |
|
| 520 | - }); |
|
| 521 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 522 | - /** @var \OC\User\User $user */ |
|
| 523 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 524 | - |
|
| 525 | - /** @var IEventDispatcher $dispatcher */ |
|
| 526 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 527 | - $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
|
| 528 | - }); |
|
| 529 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 530 | - /** @var \OC\User\User $user */ |
|
| 531 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 532 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 533 | - |
|
| 534 | - /** @var IEventDispatcher $dispatcher */ |
|
| 535 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 536 | - $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); |
|
| 537 | - }); |
|
| 538 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 539 | - /** @var \OC\User\User $user */ |
|
| 540 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 541 | - |
|
| 542 | - /** @var IEventDispatcher $dispatcher */ |
|
| 543 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 544 | - $dispatcher->dispatchTyped(new UserDeletedEvent($user)); |
|
| 545 | - }); |
|
| 546 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 547 | - /** @var \OC\User\User $user */ |
|
| 548 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 549 | - |
|
| 550 | - /** @var IEventDispatcher $dispatcher */ |
|
| 551 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 552 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 553 | - }); |
|
| 554 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 555 | - /** @var \OC\User\User $user */ |
|
| 556 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 557 | - |
|
| 558 | - /** @var IEventDispatcher $dispatcher */ |
|
| 559 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 560 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 561 | - }); |
|
| 562 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 563 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 564 | - |
|
| 565 | - /** @var IEventDispatcher $dispatcher */ |
|
| 566 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 567 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 568 | - }); |
|
| 569 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
| 570 | - /** @var \OC\User\User $user */ |
|
| 571 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 572 | - |
|
| 573 | - /** @var IEventDispatcher $dispatcher */ |
|
| 574 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 575 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
|
| 576 | - }); |
|
| 577 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 578 | - /** @var IEventDispatcher $dispatcher */ |
|
| 579 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 580 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 581 | - }); |
|
| 582 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 583 | - /** @var \OC\User\User $user */ |
|
| 584 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 585 | - |
|
| 586 | - /** @var IEventDispatcher $dispatcher */ |
|
| 587 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 588 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 589 | - }); |
|
| 590 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 591 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 592 | - |
|
| 593 | - /** @var IEventDispatcher $dispatcher */ |
|
| 594 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 595 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 596 | - }); |
|
| 597 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 598 | - /** @var IEventDispatcher $dispatcher */ |
|
| 599 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 600 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 601 | - }); |
|
| 602 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 603 | - /** @var \OC\User\User $user */ |
|
| 604 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 605 | - |
|
| 606 | - /** @var IEventDispatcher $dispatcher */ |
|
| 607 | - $dispatcher = $this->query(IEventDispatcher::class); |
|
| 608 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
| 609 | - }); |
|
| 610 | - return $userSession; |
|
| 611 | - }); |
|
| 612 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 613 | - /** @deprecated 19.0.0 */ |
|
| 614 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
| 615 | - |
|
| 616 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 617 | - |
|
| 618 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 619 | - /** @deprecated 19.0.0 */ |
|
| 620 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
| 621 | - |
|
| 622 | - /** @deprecated 19.0.0 */ |
|
| 623 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
| 624 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 625 | - |
|
| 626 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 627 | - return new \OC\SystemConfig($config); |
|
| 628 | - }); |
|
| 629 | - /** @deprecated 19.0.0 */ |
|
| 630 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
| 631 | - |
|
| 632 | - /** @deprecated 19.0.0 */ |
|
| 633 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
| 634 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 635 | - |
|
| 636 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 637 | - return new \OC\L10N\Factory( |
|
| 638 | - $c->getConfig(), |
|
| 639 | - $c->getRequest(), |
|
| 640 | - $c->getUserSession(), |
|
| 641 | - \OC::$SERVERROOT |
|
| 642 | - ); |
|
| 643 | - }); |
|
| 644 | - /** @deprecated 19.0.0 */ |
|
| 645 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
| 646 | - |
|
| 647 | - $this->registerService(IURLGenerator::class, function (Server $c) { |
|
| 648 | - $config = $c->getConfig(); |
|
| 649 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 650 | - $request = $c->getRequest(); |
|
| 651 | - return new \OC\URLGenerator( |
|
| 652 | - $config, |
|
| 653 | - $cacheFactory, |
|
| 654 | - $request |
|
| 655 | - ); |
|
| 656 | - }); |
|
| 657 | - /** @deprecated 19.0.0 */ |
|
| 658 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
| 659 | - |
|
| 660 | - /** @deprecated 19.0.0 */ |
|
| 661 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
| 662 | - /** @deprecated 19.0.0 */ |
|
| 663 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 664 | - |
|
| 665 | - $this->registerService(ICache::class, function ($c) { |
|
| 666 | - return new Cache\File(); |
|
| 667 | - }); |
|
| 668 | - /** @deprecated 19.0.0 */ |
|
| 669 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
| 670 | - |
|
| 671 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 672 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 673 | - ArrayCache::class, |
|
| 674 | - ArrayCache::class, |
|
| 675 | - ArrayCache::class |
|
| 676 | - ); |
|
| 677 | - $config = $c->getConfig(); |
|
| 678 | - |
|
| 679 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 680 | - $v = \OC_App::getAppVersions(); |
|
| 681 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 682 | - $version = implode(',', $v); |
|
| 683 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 684 | - $path = \OC::$SERVERROOT; |
|
| 685 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 686 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 687 | - $config->getSystemValue('memcache.local', null), |
|
| 688 | - $config->getSystemValue('memcache.distributed', null), |
|
| 689 | - $config->getSystemValue('memcache.locking', null) |
|
| 690 | - ); |
|
| 691 | - } |
|
| 692 | - return $arrayCacheFactory; |
|
| 693 | - }); |
|
| 694 | - /** @deprecated 19.0.0 */ |
|
| 695 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
| 696 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 697 | - |
|
| 698 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 699 | - $systemConfig = $c->getSystemConfig(); |
|
| 700 | - return new RedisFactory($systemConfig); |
|
| 701 | - }); |
|
| 702 | - |
|
| 703 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 704 | - $l10n = $this->get(IFactory::class)->get('activity'); |
|
| 705 | - return new \OC\Activity\Manager( |
|
| 706 | - $c->getRequest(), |
|
| 707 | - $c->getUserSession(), |
|
| 708 | - $c->getConfig(), |
|
| 709 | - $c->query(IValidator::class), |
|
| 710 | - $l10n |
|
| 711 | - ); |
|
| 712 | - }); |
|
| 713 | - /** @deprecated 19.0.0 */ |
|
| 714 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 715 | - |
|
| 716 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 717 | - return new \OC\Activity\EventMerger( |
|
| 718 | - $c->getL10N('lib') |
|
| 719 | - ); |
|
| 720 | - }); |
|
| 721 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 722 | - |
|
| 723 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 724 | - return new AvatarManager( |
|
| 725 | - $c->query(\OC\User\Manager::class), |
|
| 726 | - $c->getAppDataDir('avatar'), |
|
| 727 | - $c->getL10N('lib'), |
|
| 728 | - $c->getLogger(), |
|
| 729 | - $c->getConfig() |
|
| 730 | - ); |
|
| 731 | - }); |
|
| 732 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 733 | - /** @deprecated 19.0.0 */ |
|
| 734 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
| 735 | - |
|
| 736 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 737 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 738 | - |
|
| 739 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 740 | - $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 741 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
| 742 | - $logger = $factory->get($logType); |
|
| 743 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
| 744 | - |
|
| 745 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
| 746 | - }); |
|
| 747 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
| 748 | - /** @deprecated 19.0.0 */ |
|
| 749 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
| 750 | - // PSR-3 logger |
|
| 751 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 752 | - |
|
| 753 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 754 | - return new LogFactory($c, $this->getSystemConfig()); |
|
| 755 | - }); |
|
| 756 | - |
|
| 757 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 758 | - /** @deprecated 19.0.0 */ |
|
| 759 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
| 760 | - |
|
| 761 | - $this->registerService(IRouter::class, function (Server $c) { |
|
| 762 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 763 | - $logger = $c->getLogger(); |
|
| 764 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 765 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 766 | - } else { |
|
| 767 | - $router = new \OC\Route\Router($logger); |
|
| 768 | - } |
|
| 769 | - return $router; |
|
| 770 | - }); |
|
| 771 | - /** @deprecated 19.0.0 */ |
|
| 772 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
| 773 | - |
|
| 774 | - $this->registerAlias(ISearch::class, Search::class); |
|
| 775 | - /** @deprecated 19.0.0 */ |
|
| 776 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
| 777 | - |
|
| 778 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 779 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 780 | - $this->getMemCacheFactory(), |
|
| 781 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 782 | - ); |
|
| 783 | - }); |
|
| 784 | - |
|
| 785 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 786 | - /** @deprecated 19.0.0 */ |
|
| 787 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 788 | - |
|
| 789 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 790 | - /** @deprecated 19.0.0 */ |
|
| 791 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
| 792 | - |
|
| 793 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
| 794 | - /** @deprecated 19.0.0 */ |
|
| 795 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
| 796 | - |
|
| 797 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 798 | - /** @deprecated 19.0.0 */ |
|
| 799 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
| 800 | - |
|
| 801 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 802 | - $systemConfig = $c->getSystemConfig(); |
|
| 803 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 804 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 805 | - if (!$factory->isValidType($type)) { |
|
| 806 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 807 | - } |
|
| 808 | - $connectionParams = $factory->createConnectionParams(); |
|
| 809 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 810 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 811 | - return $connection; |
|
| 812 | - }); |
|
| 813 | - /** @deprecated 19.0.0 */ |
|
| 814 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - $this->registerService(IClientService::class, function (Server $c) { |
|
| 818 | - $user = \OC_User::getUser(); |
|
| 819 | - $uid = $user ? $user : null; |
|
| 820 | - return new ClientService( |
|
| 821 | - $c->getConfig(), |
|
| 822 | - $c->getLogger(), |
|
| 823 | - new \OC\Security\CertificateManager( |
|
| 824 | - $uid, |
|
| 825 | - new View(), |
|
| 826 | - $c->getConfig(), |
|
| 827 | - $c->getLogger(), |
|
| 828 | - $c->getSecureRandom() |
|
| 829 | - ) |
|
| 830 | - ); |
|
| 831 | - }); |
|
| 832 | - /** @deprecated 19.0.0 */ |
|
| 833 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 834 | - $this->registerService(IEventLogger::class, function (Server $c) { |
|
| 835 | - $eventLogger = new EventLogger(); |
|
| 836 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 837 | - // In debug mode, module is being activated by default |
|
| 838 | - $eventLogger->activate(); |
|
| 839 | - } |
|
| 840 | - return $eventLogger; |
|
| 841 | - }); |
|
| 842 | - /** @deprecated 19.0.0 */ |
|
| 843 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
| 844 | - |
|
| 845 | - $this->registerService(IQueryLogger::class, function (Server $c) { |
|
| 846 | - $queryLogger = new QueryLogger(); |
|
| 847 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 848 | - // In debug mode, module is being activated by default |
|
| 849 | - $queryLogger->activate(); |
|
| 850 | - } |
|
| 851 | - return $queryLogger; |
|
| 852 | - }); |
|
| 853 | - /** @deprecated 19.0.0 */ |
|
| 854 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
| 855 | - |
|
| 856 | - /** @deprecated 19.0.0 */ |
|
| 857 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
| 858 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 859 | - |
|
| 860 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 861 | - return new \OC\App\AppManager( |
|
| 862 | - $c->getUserSession(), |
|
| 863 | - $c->getConfig(), |
|
| 864 | - $c->query(\OC\AppConfig::class), |
|
| 865 | - $c->getGroupManager(), |
|
| 866 | - $c->getMemCacheFactory(), |
|
| 867 | - $c->getEventDispatcher(), |
|
| 868 | - $c->getLogger() |
|
| 869 | - ); |
|
| 870 | - }); |
|
| 871 | - /** @deprecated 19.0.0 */ |
|
| 872 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
| 873 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 874 | - |
|
| 875 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 876 | - /** @deprecated 19.0.0 */ |
|
| 877 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
| 878 | - |
|
| 879 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 880 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 881 | - |
|
| 882 | - return new DateTimeFormatter( |
|
| 883 | - $c->getDateTimeZone()->getTimeZone(), |
|
| 884 | - $c->getL10N('lib', $language) |
|
| 885 | - ); |
|
| 886 | - }); |
|
| 887 | - /** @deprecated 19.0.0 */ |
|
| 888 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
| 889 | - |
|
| 890 | - $this->registerService(IUserMountCache::class, function (Server $c) { |
|
| 891 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 892 | - $listener = new UserMountCacheListener($mountCache); |
|
| 893 | - $listener->listen($c->getUserManager()); |
|
| 894 | - return $mountCache; |
|
| 895 | - }); |
|
| 896 | - /** @deprecated 19.0.0 */ |
|
| 897 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
| 898 | - |
|
| 899 | - $this->registerService(IMountProviderCollection::class, function (Server $c) { |
|
| 900 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 901 | - $mountCache = $c->query(IUserMountCache::class); |
|
| 902 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 903 | - |
|
| 904 | - // builtin providers |
|
| 905 | - |
|
| 906 | - $config = $c->getConfig(); |
|
| 907 | - $logger = $c->getLogger(); |
|
| 908 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 909 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 910 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 911 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 912 | - |
|
| 913 | - return $manager; |
|
| 914 | - }); |
|
| 915 | - /** @deprecated 19.0.0 */ |
|
| 916 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
| 917 | - |
|
| 918 | - /** @deprecated 20.0.0 */ |
|
| 919 | - $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
| 920 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 921 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 922 | - if ($busClass) { |
|
| 923 | - [$app, $class] = explode('::', $busClass, 2); |
|
| 924 | - if ($c->getAppManager()->isInstalled($app)) { |
|
| 925 | - \OC_App::loadApp($app); |
|
| 926 | - return $c->query($class); |
|
| 927 | - } else { |
|
| 928 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 929 | - } |
|
| 930 | - } else { |
|
| 931 | - $jobList = $c->getJobList(); |
|
| 932 | - return new CronBus($jobList); |
|
| 933 | - } |
|
| 934 | - }); |
|
| 935 | - $this->registerAlias(IBus::class, 'AsyncCommandBus'); |
|
| 936 | - /** @deprecated 20.0.0 */ |
|
| 937 | - $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
| 938 | - /** @deprecated 19.0.0 */ |
|
| 939 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
| 940 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 941 | - // IConfig and IAppManager requires a working database. This code |
|
| 942 | - // might however be called when ownCloud is not yet setup. |
|
| 943 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 944 | - $config = $c->getConfig(); |
|
| 945 | - $appManager = $c->getAppManager(); |
|
| 946 | - } else { |
|
| 947 | - $config = null; |
|
| 948 | - $appManager = null; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return new Checker( |
|
| 952 | - new EnvironmentHelper(), |
|
| 953 | - new FileAccessHelper(), |
|
| 954 | - new AppLocator(), |
|
| 955 | - $config, |
|
| 956 | - $c->getMemCacheFactory(), |
|
| 957 | - $appManager, |
|
| 958 | - $c->getTempManager(), |
|
| 959 | - $c->getMimeTypeDetector() |
|
| 960 | - ); |
|
| 961 | - }); |
|
| 962 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 963 | - if (isset($this['urlParams'])) { |
|
| 964 | - $urlParams = $this['urlParams']; |
|
| 965 | - } else { |
|
| 966 | - $urlParams = []; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 970 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 971 | - ) { |
|
| 972 | - $stream = 'fakeinput://data'; |
|
| 973 | - } else { |
|
| 974 | - $stream = 'php://input'; |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - return new Request( |
|
| 978 | - [ |
|
| 979 | - 'get' => $_GET, |
|
| 980 | - 'post' => $_POST, |
|
| 981 | - 'files' => $_FILES, |
|
| 982 | - 'server' => $_SERVER, |
|
| 983 | - 'env' => $_ENV, |
|
| 984 | - 'cookies' => $_COOKIE, |
|
| 985 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 986 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 987 | - : '', |
|
| 988 | - 'urlParams' => $urlParams, |
|
| 989 | - ], |
|
| 990 | - $this->getSecureRandom(), |
|
| 991 | - $this->getConfig(), |
|
| 992 | - $this->getCsrfTokenManager(), |
|
| 993 | - $stream |
|
| 994 | - ); |
|
| 995 | - }); |
|
| 996 | - /** @deprecated 19.0.0 */ |
|
| 997 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
| 998 | - |
|
| 999 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 1000 | - return new Mailer( |
|
| 1001 | - $c->getConfig(), |
|
| 1002 | - $c->getLogger(), |
|
| 1003 | - $c->query(Defaults::class), |
|
| 1004 | - $c->getURLGenerator(), |
|
| 1005 | - $c->getL10N('lib'), |
|
| 1006 | - $c->query(IEventDispatcher::class), |
|
| 1007 | - $c->getL10NFactory() |
|
| 1008 | - ); |
|
| 1009 | - }); |
|
| 1010 | - /** @deprecated 19.0.0 */ |
|
| 1011 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
| 1012 | - |
|
| 1013 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 1014 | - $config = $c->getConfig(); |
|
| 1015 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 1016 | - if (is_null($factoryClass)) { |
|
| 1017 | - throw new \Exception('ldapProviderFactory not set'); |
|
| 1018 | - } |
|
| 1019 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 1020 | - $factory = new $factoryClass($this); |
|
| 1021 | - return $factory->getLDAPProvider(); |
|
| 1022 | - }); |
|
| 1023 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 1024 | - $ini = $c->getIniWrapper(); |
|
| 1025 | - $config = $c->getConfig(); |
|
| 1026 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 1027 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 1028 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 1029 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1030 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 1031 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 1032 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 1033 | - } |
|
| 1034 | - return new DBLockingProvider( |
|
| 1035 | - $c->getDatabaseConnection(), |
|
| 1036 | - $c->getLogger(), |
|
| 1037 | - new TimeFactory(), |
|
| 1038 | - $ttl, |
|
| 1039 | - !\OC::$CLI |
|
| 1040 | - ); |
|
| 1041 | - } |
|
| 1042 | - return new NoopLockingProvider(); |
|
| 1043 | - }); |
|
| 1044 | - /** @deprecated 19.0.0 */ |
|
| 1045 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
| 1046 | - |
|
| 1047 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 1048 | - /** @deprecated 19.0.0 */ |
|
| 1049 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
| 1050 | - |
|
| 1051 | - $this->registerService(IMimeTypeDetector::class, function (Server $c) { |
|
| 1052 | - return new \OC\Files\Type\Detection( |
|
| 1053 | - $c->getURLGenerator(), |
|
| 1054 | - $c->getLogger(), |
|
| 1055 | - \OC::$configDir, |
|
| 1056 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 1057 | - ); |
|
| 1058 | - }); |
|
| 1059 | - /** @deprecated 19.0.0 */ |
|
| 1060 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
| 1061 | - |
|
| 1062 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1063 | - /** @deprecated 19.0.0 */ |
|
| 1064 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
| 1065 | - $this->registerService(BundleFetcher::class, function () { |
|
| 1066 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 1067 | - }); |
|
| 1068 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1069 | - /** @deprecated 19.0.0 */ |
|
| 1070 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 1071 | - |
|
| 1072 | - $this->registerService(CapabilitiesManager::class, function (Server $c) { |
|
| 1073 | - $manager = new CapabilitiesManager($c->getLogger()); |
|
| 1074 | - $manager->registerCapability(function () use ($c) { |
|
| 1075 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 1076 | - }); |
|
| 1077 | - $manager->registerCapability(function () use ($c) { |
|
| 1078 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1079 | - }); |
|
| 1080 | - return $manager; |
|
| 1081 | - }); |
|
| 1082 | - /** @deprecated 19.0.0 */ |
|
| 1083 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
| 1084 | - |
|
| 1085 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1086 | - $config = $c->getConfig(); |
|
| 1087 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1088 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1089 | - $factory = new $factoryClass($this); |
|
| 1090 | - $manager = $factory->getManager(); |
|
| 1091 | - |
|
| 1092 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1093 | - $manager = $c->getUserManager(); |
|
| 1094 | - $user = $manager->get($id); |
|
| 1095 | - if (is_null($user)) { |
|
| 1096 | - $l = $c->getL10N('core'); |
|
| 1097 | - $displayName = $l->t('Unknown user'); |
|
| 1098 | - } else { |
|
| 1099 | - $displayName = $user->getDisplayName(); |
|
| 1100 | - } |
|
| 1101 | - return $displayName; |
|
| 1102 | - }); |
|
| 1103 | - |
|
| 1104 | - return $manager; |
|
| 1105 | - }); |
|
| 1106 | - /** @deprecated 19.0.0 */ |
|
| 1107 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
| 1108 | - |
|
| 1109 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1110 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1111 | - /* |
|
| 246 | + /** @var string */ |
|
| 247 | + private $webRoot; |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param string $webRoot |
|
| 251 | + * @param \OC\Config $config |
|
| 252 | + */ |
|
| 253 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 254 | + parent::__construct(); |
|
| 255 | + $this->webRoot = $webRoot; |
|
| 256 | + |
|
| 257 | + // To find out if we are running from CLI or not |
|
| 258 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 259 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 260 | + |
|
| 261 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 262 | + return $c; |
|
| 263 | + }); |
|
| 264 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 265 | + return $c; |
|
| 266 | + }); |
|
| 267 | + |
|
| 268 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 269 | + /** @deprecated 19.0.0 */ |
|
| 270 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 271 | + |
|
| 272 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 273 | + /** @deprecated 19.0.0 */ |
|
| 274 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 275 | + |
|
| 276 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 277 | + /** @deprecated 19.0.0 */ |
|
| 278 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 279 | + |
|
| 280 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 281 | + /** @deprecated 19.0.0 */ |
|
| 282 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 283 | + |
|
| 284 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 285 | + |
|
| 286 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + $this->registerService(IPreview::class, function (Server $c) { |
|
| 290 | + return new PreviewManager( |
|
| 291 | + $c->getConfig(), |
|
| 292 | + $c->getRootFolder(), |
|
| 293 | + new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()), |
|
| 294 | + $c->getEventDispatcher(), |
|
| 295 | + $c->getGeneratorHelper(), |
|
| 296 | + $c->getSession()->get('user_id') |
|
| 297 | + ); |
|
| 298 | + }); |
|
| 299 | + /** @deprecated 19.0.0 */ |
|
| 300 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
| 301 | + |
|
| 302 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 303 | + return new \OC\Preview\Watcher( |
|
| 304 | + new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()) |
|
| 305 | + ); |
|
| 306 | + }); |
|
| 307 | + |
|
| 308 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 309 | + $view = new View(); |
|
| 310 | + $util = new Encryption\Util( |
|
| 311 | + $view, |
|
| 312 | + $c->getUserManager(), |
|
| 313 | + $c->getGroupManager(), |
|
| 314 | + $c->getConfig() |
|
| 315 | + ); |
|
| 316 | + return new Encryption\Manager( |
|
| 317 | + $c->getConfig(), |
|
| 318 | + $c->getLogger(), |
|
| 319 | + $c->getL10N('core'), |
|
| 320 | + new View(), |
|
| 321 | + $util, |
|
| 322 | + new ArrayCache() |
|
| 323 | + ); |
|
| 324 | + }); |
|
| 325 | + /** @deprecated 19.0.0 */ |
|
| 326 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 327 | + |
|
| 328 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 329 | + $util = new Encryption\Util( |
|
| 330 | + new View(), |
|
| 331 | + $c->getUserManager(), |
|
| 332 | + $c->getGroupManager(), |
|
| 333 | + $c->getConfig() |
|
| 334 | + ); |
|
| 335 | + return new Encryption\File( |
|
| 336 | + $util, |
|
| 337 | + $c->getRootFolder(), |
|
| 338 | + $c->getShareManager() |
|
| 339 | + ); |
|
| 340 | + }); |
|
| 341 | + |
|
| 342 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 343 | + $view = new View(); |
|
| 344 | + $util = new Encryption\Util( |
|
| 345 | + $view, |
|
| 346 | + $c->getUserManager(), |
|
| 347 | + $c->getGroupManager(), |
|
| 348 | + $c->getConfig() |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + return new Encryption\Keys\Storage($view, $util); |
|
| 352 | + }); |
|
| 353 | + /** @deprecated 20.0.0 */ |
|
| 354 | + $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
| 355 | + |
|
| 356 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 357 | + /** @deprecated 19.0.0 */ |
|
| 358 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
| 359 | + |
|
| 360 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 361 | + $config = $c->getConfig(); |
|
| 362 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 363 | + return new $factoryClass($this); |
|
| 364 | + }); |
|
| 365 | + $this->registerService(ISystemTagManager::class, function (Server $c) { |
|
| 366 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 367 | + }); |
|
| 368 | + /** @deprecated 19.0.0 */ |
|
| 369 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 370 | + |
|
| 371 | + $this->registerService(ISystemTagObjectMapper::class, function (Server $c) { |
|
| 372 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 373 | + }); |
|
| 374 | + $this->registerService('RootFolder', function (Server $c) { |
|
| 375 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 376 | + $view = new View(); |
|
| 377 | + $root = new Root( |
|
| 378 | + $manager, |
|
| 379 | + $view, |
|
| 380 | + null, |
|
| 381 | + $c->getUserMountCache(), |
|
| 382 | + $this->getLogger(), |
|
| 383 | + $this->getUserManager() |
|
| 384 | + ); |
|
| 385 | + |
|
| 386 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 387 | + $previewConnector->connectWatcher(); |
|
| 388 | + |
|
| 389 | + return $root; |
|
| 390 | + }); |
|
| 391 | + $this->registerService(HookConnector::class, function (Server $c) { |
|
| 392 | + return new HookConnector( |
|
| 393 | + $c->query(IRootFolder::class), |
|
| 394 | + new View(), |
|
| 395 | + $c->query(\OC\EventDispatcher\SymfonyAdapter::class), |
|
| 396 | + $c->query(IEventDispatcher::class) |
|
| 397 | + ); |
|
| 398 | + }); |
|
| 399 | + |
|
| 400 | + /** @deprecated 19.0.0 */ |
|
| 401 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
| 402 | + |
|
| 403 | + $this->registerService(IRootFolder::class, function (Server $c) { |
|
| 404 | + return new LazyRoot(function () use ($c) { |
|
| 405 | + return $c->query('RootFolder'); |
|
| 406 | + }); |
|
| 407 | + }); |
|
| 408 | + /** @deprecated 19.0.0 */ |
|
| 409 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
| 410 | + |
|
| 411 | + /** @deprecated 19.0.0 */ |
|
| 412 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
| 413 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 414 | + |
|
| 415 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 416 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
| 417 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 418 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]); |
|
| 419 | + |
|
| 420 | + /** @var IEventDispatcher $dispatcher */ |
|
| 421 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 422 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
| 423 | + }); |
|
| 424 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 425 | + \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]); |
|
| 426 | + |
|
| 427 | + /** @var IEventDispatcher $dispatcher */ |
|
| 428 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 429 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
| 430 | + }); |
|
| 431 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 432 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]); |
|
| 433 | + |
|
| 434 | + /** @var IEventDispatcher $dispatcher */ |
|
| 435 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 436 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
| 437 | + }); |
|
| 438 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 439 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]); |
|
| 440 | + |
|
| 441 | + /** @var IEventDispatcher $dispatcher */ |
|
| 442 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 443 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
| 444 | + }); |
|
| 445 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 446 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 447 | + |
|
| 448 | + /** @var IEventDispatcher $dispatcher */ |
|
| 449 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 450 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
| 451 | + }); |
|
| 452 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 453 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 454 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 455 | + \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
|
| 456 | + |
|
| 457 | + /** @var IEventDispatcher $dispatcher */ |
|
| 458 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 459 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
| 460 | + }); |
|
| 461 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 462 | + /** @var IEventDispatcher $dispatcher */ |
|
| 463 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 464 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
| 465 | + }); |
|
| 466 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 467 | + /** @var IEventDispatcher $dispatcher */ |
|
| 468 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 469 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
| 470 | + }); |
|
| 471 | + return $groupManager; |
|
| 472 | + }); |
|
| 473 | + /** @deprecated 19.0.0 */ |
|
| 474 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 475 | + |
|
| 476 | + $this->registerService(Store::class, function (Server $c) { |
|
| 477 | + $session = $c->getSession(); |
|
| 478 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 479 | + $tokenProvider = $c->query(IProvider::class); |
|
| 480 | + } else { |
|
| 481 | + $tokenProvider = null; |
|
| 482 | + } |
|
| 483 | + $logger = $c->getLogger(); |
|
| 484 | + return new Store($session, $logger, $tokenProvider); |
|
| 485 | + }); |
|
| 486 | + $this->registerAlias(IStore::class, Store::class); |
|
| 487 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 488 | + |
|
| 489 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 490 | + $manager = $c->getUserManager(); |
|
| 491 | + $session = new \OC\Session\Memory(''); |
|
| 492 | + $timeFactory = new TimeFactory(); |
|
| 493 | + // Token providers might require a working database. This code |
|
| 494 | + // might however be called when ownCloud is not yet setup. |
|
| 495 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 496 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
| 497 | + } else { |
|
| 498 | + $defaultTokenProvider = null; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + $legacyDispatcher = $c->getEventDispatcher(); |
|
| 502 | + |
|
| 503 | + $userSession = new \OC\User\Session( |
|
| 504 | + $manager, |
|
| 505 | + $session, |
|
| 506 | + $timeFactory, |
|
| 507 | + $defaultTokenProvider, |
|
| 508 | + $c->getConfig(), |
|
| 509 | + $c->getSecureRandom(), |
|
| 510 | + $c->getLockdownManager(), |
|
| 511 | + $c->getLogger(), |
|
| 512 | + $c->query(IEventDispatcher::class) |
|
| 513 | + ); |
|
| 514 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 515 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 516 | + |
|
| 517 | + /** @var IEventDispatcher $dispatcher */ |
|
| 518 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 519 | + $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); |
|
| 520 | + }); |
|
| 521 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 522 | + /** @var \OC\User\User $user */ |
|
| 523 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 524 | + |
|
| 525 | + /** @var IEventDispatcher $dispatcher */ |
|
| 526 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 527 | + $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
|
| 528 | + }); |
|
| 529 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 530 | + /** @var \OC\User\User $user */ |
|
| 531 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 532 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 533 | + |
|
| 534 | + /** @var IEventDispatcher $dispatcher */ |
|
| 535 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 536 | + $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); |
|
| 537 | + }); |
|
| 538 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 539 | + /** @var \OC\User\User $user */ |
|
| 540 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 541 | + |
|
| 542 | + /** @var IEventDispatcher $dispatcher */ |
|
| 543 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 544 | + $dispatcher->dispatchTyped(new UserDeletedEvent($user)); |
|
| 545 | + }); |
|
| 546 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 547 | + /** @var \OC\User\User $user */ |
|
| 548 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 549 | + |
|
| 550 | + /** @var IEventDispatcher $dispatcher */ |
|
| 551 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 552 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 553 | + }); |
|
| 554 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 555 | + /** @var \OC\User\User $user */ |
|
| 556 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 557 | + |
|
| 558 | + /** @var IEventDispatcher $dispatcher */ |
|
| 559 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 560 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 561 | + }); |
|
| 562 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 563 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 564 | + |
|
| 565 | + /** @var IEventDispatcher $dispatcher */ |
|
| 566 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 567 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 568 | + }); |
|
| 569 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
| 570 | + /** @var \OC\User\User $user */ |
|
| 571 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 572 | + |
|
| 573 | + /** @var IEventDispatcher $dispatcher */ |
|
| 574 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 575 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
|
| 576 | + }); |
|
| 577 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 578 | + /** @var IEventDispatcher $dispatcher */ |
|
| 579 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 580 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 581 | + }); |
|
| 582 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 583 | + /** @var \OC\User\User $user */ |
|
| 584 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 585 | + |
|
| 586 | + /** @var IEventDispatcher $dispatcher */ |
|
| 587 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 588 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 589 | + }); |
|
| 590 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 591 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 592 | + |
|
| 593 | + /** @var IEventDispatcher $dispatcher */ |
|
| 594 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 595 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 596 | + }); |
|
| 597 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 598 | + /** @var IEventDispatcher $dispatcher */ |
|
| 599 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 600 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 601 | + }); |
|
| 602 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 603 | + /** @var \OC\User\User $user */ |
|
| 604 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 605 | + |
|
| 606 | + /** @var IEventDispatcher $dispatcher */ |
|
| 607 | + $dispatcher = $this->query(IEventDispatcher::class); |
|
| 608 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
| 609 | + }); |
|
| 610 | + return $userSession; |
|
| 611 | + }); |
|
| 612 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 613 | + /** @deprecated 19.0.0 */ |
|
| 614 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
| 615 | + |
|
| 616 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 617 | + |
|
| 618 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 619 | + /** @deprecated 19.0.0 */ |
|
| 620 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
| 621 | + |
|
| 622 | + /** @deprecated 19.0.0 */ |
|
| 623 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
| 624 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 625 | + |
|
| 626 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 627 | + return new \OC\SystemConfig($config); |
|
| 628 | + }); |
|
| 629 | + /** @deprecated 19.0.0 */ |
|
| 630 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
| 631 | + |
|
| 632 | + /** @deprecated 19.0.0 */ |
|
| 633 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
| 634 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 635 | + |
|
| 636 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 637 | + return new \OC\L10N\Factory( |
|
| 638 | + $c->getConfig(), |
|
| 639 | + $c->getRequest(), |
|
| 640 | + $c->getUserSession(), |
|
| 641 | + \OC::$SERVERROOT |
|
| 642 | + ); |
|
| 643 | + }); |
|
| 644 | + /** @deprecated 19.0.0 */ |
|
| 645 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
| 646 | + |
|
| 647 | + $this->registerService(IURLGenerator::class, function (Server $c) { |
|
| 648 | + $config = $c->getConfig(); |
|
| 649 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 650 | + $request = $c->getRequest(); |
|
| 651 | + return new \OC\URLGenerator( |
|
| 652 | + $config, |
|
| 653 | + $cacheFactory, |
|
| 654 | + $request |
|
| 655 | + ); |
|
| 656 | + }); |
|
| 657 | + /** @deprecated 19.0.0 */ |
|
| 658 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
| 659 | + |
|
| 660 | + /** @deprecated 19.0.0 */ |
|
| 661 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
| 662 | + /** @deprecated 19.0.0 */ |
|
| 663 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 664 | + |
|
| 665 | + $this->registerService(ICache::class, function ($c) { |
|
| 666 | + return new Cache\File(); |
|
| 667 | + }); |
|
| 668 | + /** @deprecated 19.0.0 */ |
|
| 669 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
| 670 | + |
|
| 671 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 672 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 673 | + ArrayCache::class, |
|
| 674 | + ArrayCache::class, |
|
| 675 | + ArrayCache::class |
|
| 676 | + ); |
|
| 677 | + $config = $c->getConfig(); |
|
| 678 | + |
|
| 679 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 680 | + $v = \OC_App::getAppVersions(); |
|
| 681 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 682 | + $version = implode(',', $v); |
|
| 683 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 684 | + $path = \OC::$SERVERROOT; |
|
| 685 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 686 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 687 | + $config->getSystemValue('memcache.local', null), |
|
| 688 | + $config->getSystemValue('memcache.distributed', null), |
|
| 689 | + $config->getSystemValue('memcache.locking', null) |
|
| 690 | + ); |
|
| 691 | + } |
|
| 692 | + return $arrayCacheFactory; |
|
| 693 | + }); |
|
| 694 | + /** @deprecated 19.0.0 */ |
|
| 695 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
| 696 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 697 | + |
|
| 698 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 699 | + $systemConfig = $c->getSystemConfig(); |
|
| 700 | + return new RedisFactory($systemConfig); |
|
| 701 | + }); |
|
| 702 | + |
|
| 703 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 704 | + $l10n = $this->get(IFactory::class)->get('activity'); |
|
| 705 | + return new \OC\Activity\Manager( |
|
| 706 | + $c->getRequest(), |
|
| 707 | + $c->getUserSession(), |
|
| 708 | + $c->getConfig(), |
|
| 709 | + $c->query(IValidator::class), |
|
| 710 | + $l10n |
|
| 711 | + ); |
|
| 712 | + }); |
|
| 713 | + /** @deprecated 19.0.0 */ |
|
| 714 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 715 | + |
|
| 716 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 717 | + return new \OC\Activity\EventMerger( |
|
| 718 | + $c->getL10N('lib') |
|
| 719 | + ); |
|
| 720 | + }); |
|
| 721 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 722 | + |
|
| 723 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 724 | + return new AvatarManager( |
|
| 725 | + $c->query(\OC\User\Manager::class), |
|
| 726 | + $c->getAppDataDir('avatar'), |
|
| 727 | + $c->getL10N('lib'), |
|
| 728 | + $c->getLogger(), |
|
| 729 | + $c->getConfig() |
|
| 730 | + ); |
|
| 731 | + }); |
|
| 732 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 733 | + /** @deprecated 19.0.0 */ |
|
| 734 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
| 735 | + |
|
| 736 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 737 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 738 | + |
|
| 739 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 740 | + $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 741 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
| 742 | + $logger = $factory->get($logType); |
|
| 743 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
| 744 | + |
|
| 745 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
| 746 | + }); |
|
| 747 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
| 748 | + /** @deprecated 19.0.0 */ |
|
| 749 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
| 750 | + // PSR-3 logger |
|
| 751 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 752 | + |
|
| 753 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 754 | + return new LogFactory($c, $this->getSystemConfig()); |
|
| 755 | + }); |
|
| 756 | + |
|
| 757 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 758 | + /** @deprecated 19.0.0 */ |
|
| 759 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
| 760 | + |
|
| 761 | + $this->registerService(IRouter::class, function (Server $c) { |
|
| 762 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 763 | + $logger = $c->getLogger(); |
|
| 764 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 765 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 766 | + } else { |
|
| 767 | + $router = new \OC\Route\Router($logger); |
|
| 768 | + } |
|
| 769 | + return $router; |
|
| 770 | + }); |
|
| 771 | + /** @deprecated 19.0.0 */ |
|
| 772 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
| 773 | + |
|
| 774 | + $this->registerAlias(ISearch::class, Search::class); |
|
| 775 | + /** @deprecated 19.0.0 */ |
|
| 776 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
| 777 | + |
|
| 778 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 779 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 780 | + $this->getMemCacheFactory(), |
|
| 781 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 782 | + ); |
|
| 783 | + }); |
|
| 784 | + |
|
| 785 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 786 | + /** @deprecated 19.0.0 */ |
|
| 787 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 788 | + |
|
| 789 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 790 | + /** @deprecated 19.0.0 */ |
|
| 791 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
| 792 | + |
|
| 793 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
| 794 | + /** @deprecated 19.0.0 */ |
|
| 795 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
| 796 | + |
|
| 797 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 798 | + /** @deprecated 19.0.0 */ |
|
| 799 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
| 800 | + |
|
| 801 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 802 | + $systemConfig = $c->getSystemConfig(); |
|
| 803 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 804 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 805 | + if (!$factory->isValidType($type)) { |
|
| 806 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 807 | + } |
|
| 808 | + $connectionParams = $factory->createConnectionParams(); |
|
| 809 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 810 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 811 | + return $connection; |
|
| 812 | + }); |
|
| 813 | + /** @deprecated 19.0.0 */ |
|
| 814 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + $this->registerService(IClientService::class, function (Server $c) { |
|
| 818 | + $user = \OC_User::getUser(); |
|
| 819 | + $uid = $user ? $user : null; |
|
| 820 | + return new ClientService( |
|
| 821 | + $c->getConfig(), |
|
| 822 | + $c->getLogger(), |
|
| 823 | + new \OC\Security\CertificateManager( |
|
| 824 | + $uid, |
|
| 825 | + new View(), |
|
| 826 | + $c->getConfig(), |
|
| 827 | + $c->getLogger(), |
|
| 828 | + $c->getSecureRandom() |
|
| 829 | + ) |
|
| 830 | + ); |
|
| 831 | + }); |
|
| 832 | + /** @deprecated 19.0.0 */ |
|
| 833 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 834 | + $this->registerService(IEventLogger::class, function (Server $c) { |
|
| 835 | + $eventLogger = new EventLogger(); |
|
| 836 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 837 | + // In debug mode, module is being activated by default |
|
| 838 | + $eventLogger->activate(); |
|
| 839 | + } |
|
| 840 | + return $eventLogger; |
|
| 841 | + }); |
|
| 842 | + /** @deprecated 19.0.0 */ |
|
| 843 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
| 844 | + |
|
| 845 | + $this->registerService(IQueryLogger::class, function (Server $c) { |
|
| 846 | + $queryLogger = new QueryLogger(); |
|
| 847 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 848 | + // In debug mode, module is being activated by default |
|
| 849 | + $queryLogger->activate(); |
|
| 850 | + } |
|
| 851 | + return $queryLogger; |
|
| 852 | + }); |
|
| 853 | + /** @deprecated 19.0.0 */ |
|
| 854 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
| 855 | + |
|
| 856 | + /** @deprecated 19.0.0 */ |
|
| 857 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
| 858 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 859 | + |
|
| 860 | + $this->registerService(AppManager::class, function (Server $c) { |
|
| 861 | + return new \OC\App\AppManager( |
|
| 862 | + $c->getUserSession(), |
|
| 863 | + $c->getConfig(), |
|
| 864 | + $c->query(\OC\AppConfig::class), |
|
| 865 | + $c->getGroupManager(), |
|
| 866 | + $c->getMemCacheFactory(), |
|
| 867 | + $c->getEventDispatcher(), |
|
| 868 | + $c->getLogger() |
|
| 869 | + ); |
|
| 870 | + }); |
|
| 871 | + /** @deprecated 19.0.0 */ |
|
| 872 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
| 873 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 874 | + |
|
| 875 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 876 | + /** @deprecated 19.0.0 */ |
|
| 877 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
| 878 | + |
|
| 879 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 880 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 881 | + |
|
| 882 | + return new DateTimeFormatter( |
|
| 883 | + $c->getDateTimeZone()->getTimeZone(), |
|
| 884 | + $c->getL10N('lib', $language) |
|
| 885 | + ); |
|
| 886 | + }); |
|
| 887 | + /** @deprecated 19.0.0 */ |
|
| 888 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
| 889 | + |
|
| 890 | + $this->registerService(IUserMountCache::class, function (Server $c) { |
|
| 891 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 892 | + $listener = new UserMountCacheListener($mountCache); |
|
| 893 | + $listener->listen($c->getUserManager()); |
|
| 894 | + return $mountCache; |
|
| 895 | + }); |
|
| 896 | + /** @deprecated 19.0.0 */ |
|
| 897 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
| 898 | + |
|
| 899 | + $this->registerService(IMountProviderCollection::class, function (Server $c) { |
|
| 900 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 901 | + $mountCache = $c->query(IUserMountCache::class); |
|
| 902 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 903 | + |
|
| 904 | + // builtin providers |
|
| 905 | + |
|
| 906 | + $config = $c->getConfig(); |
|
| 907 | + $logger = $c->getLogger(); |
|
| 908 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 909 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 910 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 911 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 912 | + |
|
| 913 | + return $manager; |
|
| 914 | + }); |
|
| 915 | + /** @deprecated 19.0.0 */ |
|
| 916 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
| 917 | + |
|
| 918 | + /** @deprecated 20.0.0 */ |
|
| 919 | + $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
| 920 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 921 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 922 | + if ($busClass) { |
|
| 923 | + [$app, $class] = explode('::', $busClass, 2); |
|
| 924 | + if ($c->getAppManager()->isInstalled($app)) { |
|
| 925 | + \OC_App::loadApp($app); |
|
| 926 | + return $c->query($class); |
|
| 927 | + } else { |
|
| 928 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 929 | + } |
|
| 930 | + } else { |
|
| 931 | + $jobList = $c->getJobList(); |
|
| 932 | + return new CronBus($jobList); |
|
| 933 | + } |
|
| 934 | + }); |
|
| 935 | + $this->registerAlias(IBus::class, 'AsyncCommandBus'); |
|
| 936 | + /** @deprecated 20.0.0 */ |
|
| 937 | + $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
| 938 | + /** @deprecated 19.0.0 */ |
|
| 939 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
| 940 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 941 | + // IConfig and IAppManager requires a working database. This code |
|
| 942 | + // might however be called when ownCloud is not yet setup. |
|
| 943 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 944 | + $config = $c->getConfig(); |
|
| 945 | + $appManager = $c->getAppManager(); |
|
| 946 | + } else { |
|
| 947 | + $config = null; |
|
| 948 | + $appManager = null; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return new Checker( |
|
| 952 | + new EnvironmentHelper(), |
|
| 953 | + new FileAccessHelper(), |
|
| 954 | + new AppLocator(), |
|
| 955 | + $config, |
|
| 956 | + $c->getMemCacheFactory(), |
|
| 957 | + $appManager, |
|
| 958 | + $c->getTempManager(), |
|
| 959 | + $c->getMimeTypeDetector() |
|
| 960 | + ); |
|
| 961 | + }); |
|
| 962 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 963 | + if (isset($this['urlParams'])) { |
|
| 964 | + $urlParams = $this['urlParams']; |
|
| 965 | + } else { |
|
| 966 | + $urlParams = []; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 970 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 971 | + ) { |
|
| 972 | + $stream = 'fakeinput://data'; |
|
| 973 | + } else { |
|
| 974 | + $stream = 'php://input'; |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + return new Request( |
|
| 978 | + [ |
|
| 979 | + 'get' => $_GET, |
|
| 980 | + 'post' => $_POST, |
|
| 981 | + 'files' => $_FILES, |
|
| 982 | + 'server' => $_SERVER, |
|
| 983 | + 'env' => $_ENV, |
|
| 984 | + 'cookies' => $_COOKIE, |
|
| 985 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 986 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 987 | + : '', |
|
| 988 | + 'urlParams' => $urlParams, |
|
| 989 | + ], |
|
| 990 | + $this->getSecureRandom(), |
|
| 991 | + $this->getConfig(), |
|
| 992 | + $this->getCsrfTokenManager(), |
|
| 993 | + $stream |
|
| 994 | + ); |
|
| 995 | + }); |
|
| 996 | + /** @deprecated 19.0.0 */ |
|
| 997 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
| 998 | + |
|
| 999 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 1000 | + return new Mailer( |
|
| 1001 | + $c->getConfig(), |
|
| 1002 | + $c->getLogger(), |
|
| 1003 | + $c->query(Defaults::class), |
|
| 1004 | + $c->getURLGenerator(), |
|
| 1005 | + $c->getL10N('lib'), |
|
| 1006 | + $c->query(IEventDispatcher::class), |
|
| 1007 | + $c->getL10NFactory() |
|
| 1008 | + ); |
|
| 1009 | + }); |
|
| 1010 | + /** @deprecated 19.0.0 */ |
|
| 1011 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
| 1012 | + |
|
| 1013 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
| 1014 | + $config = $c->getConfig(); |
|
| 1015 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 1016 | + if (is_null($factoryClass)) { |
|
| 1017 | + throw new \Exception('ldapProviderFactory not set'); |
|
| 1018 | + } |
|
| 1019 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 1020 | + $factory = new $factoryClass($this); |
|
| 1021 | + return $factory->getLDAPProvider(); |
|
| 1022 | + }); |
|
| 1023 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 1024 | + $ini = $c->getIniWrapper(); |
|
| 1025 | + $config = $c->getConfig(); |
|
| 1026 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 1027 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 1028 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 1029 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1030 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 1031 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 1032 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 1033 | + } |
|
| 1034 | + return new DBLockingProvider( |
|
| 1035 | + $c->getDatabaseConnection(), |
|
| 1036 | + $c->getLogger(), |
|
| 1037 | + new TimeFactory(), |
|
| 1038 | + $ttl, |
|
| 1039 | + !\OC::$CLI |
|
| 1040 | + ); |
|
| 1041 | + } |
|
| 1042 | + return new NoopLockingProvider(); |
|
| 1043 | + }); |
|
| 1044 | + /** @deprecated 19.0.0 */ |
|
| 1045 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
| 1046 | + |
|
| 1047 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 1048 | + /** @deprecated 19.0.0 */ |
|
| 1049 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
| 1050 | + |
|
| 1051 | + $this->registerService(IMimeTypeDetector::class, function (Server $c) { |
|
| 1052 | + return new \OC\Files\Type\Detection( |
|
| 1053 | + $c->getURLGenerator(), |
|
| 1054 | + $c->getLogger(), |
|
| 1055 | + \OC::$configDir, |
|
| 1056 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 1057 | + ); |
|
| 1058 | + }); |
|
| 1059 | + /** @deprecated 19.0.0 */ |
|
| 1060 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
| 1061 | + |
|
| 1062 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1063 | + /** @deprecated 19.0.0 */ |
|
| 1064 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
| 1065 | + $this->registerService(BundleFetcher::class, function () { |
|
| 1066 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 1067 | + }); |
|
| 1068 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1069 | + /** @deprecated 19.0.0 */ |
|
| 1070 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 1071 | + |
|
| 1072 | + $this->registerService(CapabilitiesManager::class, function (Server $c) { |
|
| 1073 | + $manager = new CapabilitiesManager($c->getLogger()); |
|
| 1074 | + $manager->registerCapability(function () use ($c) { |
|
| 1075 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 1076 | + }); |
|
| 1077 | + $manager->registerCapability(function () use ($c) { |
|
| 1078 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1079 | + }); |
|
| 1080 | + return $manager; |
|
| 1081 | + }); |
|
| 1082 | + /** @deprecated 19.0.0 */ |
|
| 1083 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
| 1084 | + |
|
| 1085 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1086 | + $config = $c->getConfig(); |
|
| 1087 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1088 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1089 | + $factory = new $factoryClass($this); |
|
| 1090 | + $manager = $factory->getManager(); |
|
| 1091 | + |
|
| 1092 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1093 | + $manager = $c->getUserManager(); |
|
| 1094 | + $user = $manager->get($id); |
|
| 1095 | + if (is_null($user)) { |
|
| 1096 | + $l = $c->getL10N('core'); |
|
| 1097 | + $displayName = $l->t('Unknown user'); |
|
| 1098 | + } else { |
|
| 1099 | + $displayName = $user->getDisplayName(); |
|
| 1100 | + } |
|
| 1101 | + return $displayName; |
|
| 1102 | + }); |
|
| 1103 | + |
|
| 1104 | + return $manager; |
|
| 1105 | + }); |
|
| 1106 | + /** @deprecated 19.0.0 */ |
|
| 1107 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
| 1108 | + |
|
| 1109 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1110 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1111 | + /* |
|
| 1112 | 1112 | * Dark magic for autoloader. |
| 1113 | 1113 | * If we do a class_exists it will try to load the class which will |
| 1114 | 1114 | * make composer cache the result. Resulting in errors when enabling |
| 1115 | 1115 | * the theming app. |
| 1116 | 1116 | */ |
| 1117 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 1118 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 1119 | - $classExists = true; |
|
| 1120 | - } else { |
|
| 1121 | - $classExists = false; |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1125 | - return new ThemingDefaults( |
|
| 1126 | - $c->getConfig(), |
|
| 1127 | - $c->getL10N('theming'), |
|
| 1128 | - $c->getURLGenerator(), |
|
| 1129 | - $c->getMemCacheFactory(), |
|
| 1130 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
| 1131 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
| 1132 | - $c->getAppManager(), |
|
| 1133 | - $c->getNavigationManager() |
|
| 1134 | - ); |
|
| 1135 | - } |
|
| 1136 | - return new \OC_Defaults(); |
|
| 1137 | - }); |
|
| 1138 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1139 | - return new JSCombiner( |
|
| 1140 | - $c->getAppDataDir('js'), |
|
| 1141 | - $c->getURLGenerator(), |
|
| 1142 | - $this->getMemCacheFactory(), |
|
| 1143 | - $c->getSystemConfig(), |
|
| 1144 | - $c->getLogger() |
|
| 1145 | - ); |
|
| 1146 | - }); |
|
| 1147 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1148 | - /** @deprecated 19.0.0 */ |
|
| 1149 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1150 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1151 | - |
|
| 1152 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 1153 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 1154 | - $request = new Request( |
|
| 1155 | - [ |
|
| 1156 | - 'get' => $_GET, |
|
| 1157 | - 'post' => $_POST, |
|
| 1158 | - 'files' => $_FILES, |
|
| 1159 | - 'server' => $_SERVER, |
|
| 1160 | - 'env' => $_ENV, |
|
| 1161 | - 'cookies' => $_COOKIE, |
|
| 1162 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1163 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1164 | - : null, |
|
| 1165 | - ], |
|
| 1166 | - $c->getSecureRandom(), |
|
| 1167 | - $c->getConfig() |
|
| 1168 | - ); |
|
| 1169 | - |
|
| 1170 | - return new CryptoWrapper( |
|
| 1171 | - $c->getConfig(), |
|
| 1172 | - $c->getCrypto(), |
|
| 1173 | - $c->getSecureRandom(), |
|
| 1174 | - $request |
|
| 1175 | - ); |
|
| 1176 | - }); |
|
| 1177 | - /** @deprecated 19.0.0 */ |
|
| 1178 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
| 1179 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1180 | - return new SessionStorage($c->getSession()); |
|
| 1181 | - }); |
|
| 1182 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1183 | - /** @deprecated 19.0.0 */ |
|
| 1184 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
| 1185 | - |
|
| 1186 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1187 | - $config = $c->getConfig(); |
|
| 1188 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1189 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1190 | - $factory = new $factoryClass($this); |
|
| 1191 | - |
|
| 1192 | - $manager = new \OC\Share20\Manager( |
|
| 1193 | - $c->getLogger(), |
|
| 1194 | - $c->getConfig(), |
|
| 1195 | - $c->getSecureRandom(), |
|
| 1196 | - $c->getHasher(), |
|
| 1197 | - $c->getMountManager(), |
|
| 1198 | - $c->getGroupManager(), |
|
| 1199 | - $c->getL10N('lib'), |
|
| 1200 | - $c->getL10NFactory(), |
|
| 1201 | - $factory, |
|
| 1202 | - $c->getUserManager(), |
|
| 1203 | - $c->getLazyRootFolder(), |
|
| 1204 | - $c->getEventDispatcher(), |
|
| 1205 | - $c->getMailer(), |
|
| 1206 | - $c->getURLGenerator(), |
|
| 1207 | - $c->getThemingDefaults(), |
|
| 1208 | - $c->query(IEventDispatcher::class) |
|
| 1209 | - ); |
|
| 1210 | - |
|
| 1211 | - return $manager; |
|
| 1212 | - }); |
|
| 1213 | - /** @deprecated 19.0.0 */ |
|
| 1214 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1215 | - |
|
| 1216 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1217 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1218 | - |
|
| 1219 | - // register default plugins |
|
| 1220 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1221 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1222 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1223 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1224 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1225 | - |
|
| 1226 | - return $instance; |
|
| 1227 | - }); |
|
| 1228 | - /** @deprecated 19.0.0 */ |
|
| 1229 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1230 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1231 | - |
|
| 1232 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1233 | - |
|
| 1234 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1235 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1236 | - |
|
| 1237 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 1238 | - $manager = new \OC\Settings\Manager( |
|
| 1239 | - $c->getLogger(), |
|
| 1240 | - $c->getL10NFactory(), |
|
| 1241 | - $c->getURLGenerator(), |
|
| 1242 | - $c |
|
| 1243 | - ); |
|
| 1244 | - return $manager; |
|
| 1245 | - }); |
|
| 1246 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1247 | - return new \OC\Files\AppData\Factory( |
|
| 1248 | - $c->getRootFolder(), |
|
| 1249 | - $c->getSystemConfig() |
|
| 1250 | - ); |
|
| 1251 | - }); |
|
| 1252 | - |
|
| 1253 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1254 | - return new LockdownManager(function () use ($c) { |
|
| 1255 | - return $c->getSession(); |
|
| 1256 | - }); |
|
| 1257 | - }); |
|
| 1258 | - |
|
| 1259 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1260 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1261 | - }); |
|
| 1262 | - |
|
| 1263 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1264 | - return new CloudIdManager(); |
|
| 1265 | - }); |
|
| 1266 | - |
|
| 1267 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1268 | - |
|
| 1269 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
| 1270 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
| 1271 | - }); |
|
| 1272 | - |
|
| 1273 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1274 | - return new CloudFederationFactory(); |
|
| 1275 | - }); |
|
| 1276 | - |
|
| 1277 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1278 | - /** @deprecated 19.0.0 */ |
|
| 1279 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1280 | - |
|
| 1281 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1282 | - /** @deprecated 19.0.0 */ |
|
| 1283 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1284 | - |
|
| 1285 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1286 | - return new Defaults( |
|
| 1287 | - $c->getThemingDefaults() |
|
| 1288 | - ); |
|
| 1289 | - }); |
|
| 1290 | - /** @deprecated 19.0.0 */ |
|
| 1291 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
| 1292 | - |
|
| 1293 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1294 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1295 | - }); |
|
| 1296 | - |
|
| 1297 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1298 | - return new ShareHelper( |
|
| 1299 | - $c->query(\OCP\Share\IManager::class) |
|
| 1300 | - ); |
|
| 1301 | - }); |
|
| 1302 | - |
|
| 1303 | - $this->registerService(Installer::class, function (Server $c) { |
|
| 1304 | - return new Installer( |
|
| 1305 | - $c->getAppFetcher(), |
|
| 1306 | - $c->getHTTPClientService(), |
|
| 1307 | - $c->getTempManager(), |
|
| 1308 | - $c->getLogger(), |
|
| 1309 | - $c->getConfig(), |
|
| 1310 | - \OC::$CLI |
|
| 1311 | - ); |
|
| 1312 | - }); |
|
| 1313 | - |
|
| 1314 | - $this->registerService(IApiFactory::class, function (Server $c) { |
|
| 1315 | - return new ApiFactory($c->getHTTPClientService()); |
|
| 1316 | - }); |
|
| 1317 | - |
|
| 1318 | - $this->registerService(IInstanceFactory::class, function (Server $c) { |
|
| 1319 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1320 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
| 1321 | - }); |
|
| 1322 | - |
|
| 1323 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1324 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1325 | - |
|
| 1326 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1327 | - |
|
| 1328 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1329 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1330 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1331 | - |
|
| 1332 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1333 | - |
|
| 1334 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1335 | - |
|
| 1336 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1337 | - |
|
| 1338 | - $this->connectDispatcher(); |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - public function boot() { |
|
| 1342 | - /** @var HookConnector $hookConnector */ |
|
| 1343 | - $hookConnector = $this->query(HookConnector::class); |
|
| 1344 | - $hookConnector->viewToNode(); |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - /** |
|
| 1348 | - * @return \OCP\Calendar\IManager |
|
| 1349 | - * @deprecated |
|
| 1350 | - */ |
|
| 1351 | - public function getCalendarManager() { |
|
| 1352 | - return $this->query(\OC\Calendar\Manager::class); |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - /** |
|
| 1356 | - * @return \OCP\Calendar\Resource\IManager |
|
| 1357 | - * @deprecated |
|
| 1358 | - */ |
|
| 1359 | - public function getCalendarResourceBackendManager() { |
|
| 1360 | - return $this->query(\OC\Calendar\Resource\Manager::class); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * @return \OCP\Calendar\Room\IManager |
|
| 1365 | - * @deprecated |
|
| 1366 | - */ |
|
| 1367 | - public function getCalendarRoomBackendManager() { |
|
| 1368 | - return $this->query(\OC\Calendar\Room\Manager::class); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - private function connectDispatcher() { |
|
| 1372 | - $dispatcher = $this->getEventDispatcher(); |
|
| 1373 | - |
|
| 1374 | - // Delete avatar on user deletion |
|
| 1375 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1376 | - $logger = $this->getLogger(); |
|
| 1377 | - $manager = $this->getAvatarManager(); |
|
| 1378 | - /** @var IUser $user */ |
|
| 1379 | - $user = $e->getSubject(); |
|
| 1380 | - |
|
| 1381 | - try { |
|
| 1382 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1383 | - $avatar->remove(); |
|
| 1384 | - } catch (NotFoundException $e) { |
|
| 1385 | - // no avatar to remove |
|
| 1386 | - } catch (\Exception $e) { |
|
| 1387 | - // Ignore exceptions |
|
| 1388 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1389 | - } |
|
| 1390 | - }); |
|
| 1391 | - |
|
| 1392 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1393 | - $manager = $this->getAvatarManager(); |
|
| 1394 | - /** @var IUser $user */ |
|
| 1395 | - $user = $e->getSubject(); |
|
| 1396 | - $feature = $e->getArgument('feature'); |
|
| 1397 | - $oldValue = $e->getArgument('oldValue'); |
|
| 1398 | - $value = $e->getArgument('value'); |
|
| 1399 | - |
|
| 1400 | - // We only change the avatar on display name changes |
|
| 1401 | - if ($feature !== 'displayName') { |
|
| 1402 | - return; |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - try { |
|
| 1406 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1407 | - $avatar->userChanged($feature, $oldValue, $value); |
|
| 1408 | - } catch (NotFoundException $e) { |
|
| 1409 | - // no avatar to remove |
|
| 1410 | - } |
|
| 1411 | - }); |
|
| 1412 | - |
|
| 1413 | - /** @var IEventDispatcher $eventDispatched */ |
|
| 1414 | - $eventDispatched = $this->query(IEventDispatcher::class); |
|
| 1415 | - $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - /** |
|
| 1419 | - * @return \OCP\Contacts\IManager |
|
| 1420 | - * @deprecated |
|
| 1421 | - */ |
|
| 1422 | - public function getContactsManager() { |
|
| 1423 | - return $this->query(\OCP\Contacts\IManager::class); |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * @return \OC\Encryption\Manager |
|
| 1428 | - * @deprecated |
|
| 1429 | - */ |
|
| 1430 | - public function getEncryptionManager() { |
|
| 1431 | - return $this->query(\OCP\Encryption\IManager::class); |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - /** |
|
| 1435 | - * @return \OC\Encryption\File |
|
| 1436 | - * @deprecated |
|
| 1437 | - */ |
|
| 1438 | - public function getEncryptionFilesHelper() { |
|
| 1439 | - return $this->query('EncryptionFileHelper'); |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - /** |
|
| 1443 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1444 | - * @deprecated |
|
| 1445 | - */ |
|
| 1446 | - public function getEncryptionKeyStorage() { |
|
| 1447 | - return $this->query('EncryptionKeyStorage'); |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - /** |
|
| 1451 | - * The current request object holding all information about the request |
|
| 1452 | - * currently being processed is returned from this method. |
|
| 1453 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1454 | - * |
|
| 1455 | - * @return \OCP\IRequest |
|
| 1456 | - * @deprecated |
|
| 1457 | - */ |
|
| 1458 | - public function getRequest() { |
|
| 1459 | - return $this->query(IRequest::class); |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - /** |
|
| 1463 | - * Returns the preview manager which can create preview images for a given file |
|
| 1464 | - * |
|
| 1465 | - * @return IPreview |
|
| 1466 | - * @deprecated |
|
| 1467 | - */ |
|
| 1468 | - public function getPreviewManager() { |
|
| 1469 | - return $this->query(IPreview::class); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - /** |
|
| 1473 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1474 | - * |
|
| 1475 | - * @see \OCP\ITagManager::load() |
|
| 1476 | - * @return ITagManager |
|
| 1477 | - * @deprecated |
|
| 1478 | - */ |
|
| 1479 | - public function getTagManager() { |
|
| 1480 | - return $this->query(ITagManager::class); |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - /** |
|
| 1484 | - * Returns the system-tag manager |
|
| 1485 | - * |
|
| 1486 | - * @return ISystemTagManager |
|
| 1487 | - * |
|
| 1488 | - * @since 9.0.0 |
|
| 1489 | - * @deprecated |
|
| 1490 | - */ |
|
| 1491 | - public function getSystemTagManager() { |
|
| 1492 | - return $this->query(ISystemTagManager::class); |
|
| 1493 | - } |
|
| 1494 | - |
|
| 1495 | - /** |
|
| 1496 | - * Returns the system-tag object mapper |
|
| 1497 | - * |
|
| 1498 | - * @return ISystemTagObjectMapper |
|
| 1499 | - * |
|
| 1500 | - * @since 9.0.0 |
|
| 1501 | - * @deprecated |
|
| 1502 | - */ |
|
| 1503 | - public function getSystemTagObjectMapper() { |
|
| 1504 | - return $this->query(ISystemTagObjectMapper::class); |
|
| 1505 | - } |
|
| 1506 | - |
|
| 1507 | - /** |
|
| 1508 | - * Returns the avatar manager, used for avatar functionality |
|
| 1509 | - * |
|
| 1510 | - * @return IAvatarManager |
|
| 1511 | - * @deprecated |
|
| 1512 | - */ |
|
| 1513 | - public function getAvatarManager() { |
|
| 1514 | - return $this->query(IAvatarManager::class); |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * Returns the root folder of ownCloud's data directory |
|
| 1519 | - * |
|
| 1520 | - * @return IRootFolder |
|
| 1521 | - * @deprecated |
|
| 1522 | - */ |
|
| 1523 | - public function getRootFolder() { |
|
| 1524 | - return $this->query(IRootFolder::class); |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * Returns the root folder of ownCloud's data directory |
|
| 1529 | - * This is the lazy variant so this gets only initialized once it |
|
| 1530 | - * is actually used. |
|
| 1531 | - * |
|
| 1532 | - * @return IRootFolder |
|
| 1533 | - */ |
|
| 1534 | - public function getLazyRootFolder() { |
|
| 1535 | - return $this->query(IRootFolder::class); |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - /** |
|
| 1539 | - * Returns a view to ownCloud's files folder |
|
| 1540 | - * |
|
| 1541 | - * @param string $userId user ID |
|
| 1542 | - * @return \OCP\Files\Folder|null |
|
| 1543 | - * @deprecated |
|
| 1544 | - */ |
|
| 1545 | - public function getUserFolder($userId = null) { |
|
| 1546 | - if ($userId === null) { |
|
| 1547 | - $user = $this->getUserSession()->getUser(); |
|
| 1548 | - if (!$user) { |
|
| 1549 | - return null; |
|
| 1550 | - } |
|
| 1551 | - $userId = $user->getUID(); |
|
| 1552 | - } |
|
| 1553 | - $root = $this->getRootFolder(); |
|
| 1554 | - return $root->getUserFolder($userId); |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - /** |
|
| 1558 | - * @return \OC\User\Manager |
|
| 1559 | - * @deprecated |
|
| 1560 | - */ |
|
| 1561 | - public function getUserManager() { |
|
| 1562 | - return $this->query(IUserManager::class); |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - /** |
|
| 1566 | - * @return \OC\Group\Manager |
|
| 1567 | - * @deprecated |
|
| 1568 | - */ |
|
| 1569 | - public function getGroupManager() { |
|
| 1570 | - return $this->query(IGroupManager::class); |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - /** |
|
| 1574 | - * @return \OC\User\Session |
|
| 1575 | - * @deprecated |
|
| 1576 | - */ |
|
| 1577 | - public function getUserSession() { |
|
| 1578 | - return $this->query(IUserSession::class); |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - /** |
|
| 1582 | - * @return \OCP\ISession |
|
| 1583 | - * @deprecated |
|
| 1584 | - */ |
|
| 1585 | - public function getSession() { |
|
| 1586 | - return $this->getUserSession()->getSession(); |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - /** |
|
| 1590 | - * @param \OCP\ISession $session |
|
| 1591 | - */ |
|
| 1592 | - public function setSession(\OCP\ISession $session) { |
|
| 1593 | - $this->query(SessionStorage::class)->setSession($session); |
|
| 1594 | - $this->getUserSession()->setSession($session); |
|
| 1595 | - $this->query(Store::class)->setSession($session); |
|
| 1596 | - } |
|
| 1597 | - |
|
| 1598 | - /** |
|
| 1599 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1600 | - * @deprecated |
|
| 1601 | - */ |
|
| 1602 | - public function getTwoFactorAuthManager() { |
|
| 1603 | - return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - /** |
|
| 1607 | - * @return \OC\NavigationManager |
|
| 1608 | - * @deprecated |
|
| 1609 | - */ |
|
| 1610 | - public function getNavigationManager() { |
|
| 1611 | - return $this->query(INavigationManager::class); |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - /** |
|
| 1615 | - * @return \OCP\IConfig |
|
| 1616 | - * @deprecated |
|
| 1617 | - */ |
|
| 1618 | - public function getConfig() { |
|
| 1619 | - return $this->query(AllConfig::class); |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * @return \OC\SystemConfig |
|
| 1624 | - * @deprecated |
|
| 1625 | - */ |
|
| 1626 | - public function getSystemConfig() { |
|
| 1627 | - return $this->query(SystemConfig::class); |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * Returns the app config manager |
|
| 1632 | - * |
|
| 1633 | - * @return IAppConfig |
|
| 1634 | - * @deprecated |
|
| 1635 | - */ |
|
| 1636 | - public function getAppConfig() { |
|
| 1637 | - return $this->query(IAppConfig::class); |
|
| 1638 | - } |
|
| 1639 | - |
|
| 1640 | - /** |
|
| 1641 | - * @return IFactory |
|
| 1642 | - * @deprecated |
|
| 1643 | - */ |
|
| 1644 | - public function getL10NFactory() { |
|
| 1645 | - return $this->query(IFactory::class); |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * get an L10N instance |
|
| 1650 | - * |
|
| 1651 | - * @param string $app appid |
|
| 1652 | - * @param string $lang |
|
| 1653 | - * @return IL10N |
|
| 1654 | - * @deprecated |
|
| 1655 | - */ |
|
| 1656 | - public function getL10N($app, $lang = null) { |
|
| 1657 | - return $this->getL10NFactory()->get($app, $lang); |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * @return IURLGenerator |
|
| 1662 | - * @deprecated |
|
| 1663 | - */ |
|
| 1664 | - public function getURLGenerator() { |
|
| 1665 | - return $this->query(IURLGenerator::class); |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - /** |
|
| 1669 | - * @return AppFetcher |
|
| 1670 | - * @deprecated |
|
| 1671 | - */ |
|
| 1672 | - public function getAppFetcher() { |
|
| 1673 | - return $this->query(AppFetcher::class); |
|
| 1674 | - } |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1678 | - * getMemCacheFactory() instead. |
|
| 1679 | - * |
|
| 1680 | - * @return ICache |
|
| 1681 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1682 | - */ |
|
| 1683 | - public function getCache() { |
|
| 1684 | - return $this->query(ICache::class); |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * Returns an \OCP\CacheFactory instance |
|
| 1689 | - * |
|
| 1690 | - * @return \OCP\ICacheFactory |
|
| 1691 | - * @deprecated |
|
| 1692 | - */ |
|
| 1693 | - public function getMemCacheFactory() { |
|
| 1694 | - return $this->query(Factory::class); |
|
| 1695 | - } |
|
| 1696 | - |
|
| 1697 | - /** |
|
| 1698 | - * Returns an \OC\RedisFactory instance |
|
| 1699 | - * |
|
| 1700 | - * @return \OC\RedisFactory |
|
| 1701 | - * @deprecated |
|
| 1702 | - */ |
|
| 1703 | - public function getGetRedisFactory() { |
|
| 1704 | - return $this->query('RedisFactory'); |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - |
|
| 1708 | - /** |
|
| 1709 | - * Returns the current session |
|
| 1710 | - * |
|
| 1711 | - * @return \OCP\IDBConnection |
|
| 1712 | - * @deprecated |
|
| 1713 | - */ |
|
| 1714 | - public function getDatabaseConnection() { |
|
| 1715 | - return $this->query(IDBConnection::class); |
|
| 1716 | - } |
|
| 1717 | - |
|
| 1718 | - /** |
|
| 1719 | - * Returns the activity manager |
|
| 1720 | - * |
|
| 1721 | - * @return \OCP\Activity\IManager |
|
| 1722 | - * @deprecated |
|
| 1723 | - */ |
|
| 1724 | - public function getActivityManager() { |
|
| 1725 | - return $this->query(\OCP\Activity\IManager::class); |
|
| 1726 | - } |
|
| 1727 | - |
|
| 1728 | - /** |
|
| 1729 | - * Returns an job list for controlling background jobs |
|
| 1730 | - * |
|
| 1731 | - * @return IJobList |
|
| 1732 | - * @deprecated |
|
| 1733 | - */ |
|
| 1734 | - public function getJobList() { |
|
| 1735 | - return $this->query(IJobList::class); |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - /** |
|
| 1739 | - * Returns a logger instance |
|
| 1740 | - * |
|
| 1741 | - * @return ILogger |
|
| 1742 | - * @deprecated |
|
| 1743 | - */ |
|
| 1744 | - public function getLogger() { |
|
| 1745 | - return $this->query(ILogger::class); |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - /** |
|
| 1749 | - * @return ILogFactory |
|
| 1750 | - * @throws \OCP\AppFramework\QueryException |
|
| 1751 | - * @deprecated |
|
| 1752 | - */ |
|
| 1753 | - public function getLogFactory() { |
|
| 1754 | - return $this->query(ILogFactory::class); |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - /** |
|
| 1758 | - * Returns a router for generating and matching urls |
|
| 1759 | - * |
|
| 1760 | - * @return IRouter |
|
| 1761 | - * @deprecated |
|
| 1762 | - */ |
|
| 1763 | - public function getRouter() { |
|
| 1764 | - return $this->query(IRouter::class); |
|
| 1765 | - } |
|
| 1766 | - |
|
| 1767 | - /** |
|
| 1768 | - * Returns a search instance |
|
| 1769 | - * |
|
| 1770 | - * @return ISearch |
|
| 1771 | - * @deprecated |
|
| 1772 | - */ |
|
| 1773 | - public function getSearch() { |
|
| 1774 | - return $this->query(ISearch::class); |
|
| 1775 | - } |
|
| 1776 | - |
|
| 1777 | - /** |
|
| 1778 | - * Returns a SecureRandom instance |
|
| 1779 | - * |
|
| 1780 | - * @return \OCP\Security\ISecureRandom |
|
| 1781 | - * @deprecated |
|
| 1782 | - */ |
|
| 1783 | - public function getSecureRandom() { |
|
| 1784 | - return $this->query(ISecureRandom::class); |
|
| 1785 | - } |
|
| 1786 | - |
|
| 1787 | - /** |
|
| 1788 | - * Returns a Crypto instance |
|
| 1789 | - * |
|
| 1790 | - * @return ICrypto |
|
| 1791 | - * @deprecated |
|
| 1792 | - */ |
|
| 1793 | - public function getCrypto() { |
|
| 1794 | - return $this->query(ICrypto::class); |
|
| 1795 | - } |
|
| 1796 | - |
|
| 1797 | - /** |
|
| 1798 | - * Returns a Hasher instance |
|
| 1799 | - * |
|
| 1800 | - * @return IHasher |
|
| 1801 | - * @deprecated |
|
| 1802 | - */ |
|
| 1803 | - public function getHasher() { |
|
| 1804 | - return $this->query(IHasher::class); |
|
| 1805 | - } |
|
| 1806 | - |
|
| 1807 | - /** |
|
| 1808 | - * Returns a CredentialsManager instance |
|
| 1809 | - * |
|
| 1810 | - * @return ICredentialsManager |
|
| 1811 | - * @deprecated |
|
| 1812 | - */ |
|
| 1813 | - public function getCredentialsManager() { |
|
| 1814 | - return $this->query(ICredentialsManager::class); |
|
| 1815 | - } |
|
| 1816 | - |
|
| 1817 | - /** |
|
| 1818 | - * Get the certificate manager for the user |
|
| 1819 | - * |
|
| 1820 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1821 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1822 | - * @deprecated |
|
| 1823 | - */ |
|
| 1824 | - public function getCertificateManager($userId = '') { |
|
| 1825 | - if ($userId === '') { |
|
| 1826 | - $userSession = $this->getUserSession(); |
|
| 1827 | - $user = $userSession->getUser(); |
|
| 1828 | - if (is_null($user)) { |
|
| 1829 | - return null; |
|
| 1830 | - } |
|
| 1831 | - $userId = $user->getUID(); |
|
| 1832 | - } |
|
| 1833 | - return new CertificateManager( |
|
| 1834 | - $userId, |
|
| 1835 | - new View(), |
|
| 1836 | - $this->getConfig(), |
|
| 1837 | - $this->getLogger(), |
|
| 1838 | - $this->getSecureRandom() |
|
| 1839 | - ); |
|
| 1840 | - } |
|
| 1841 | - |
|
| 1842 | - /** |
|
| 1843 | - * Returns an instance of the HTTP client service |
|
| 1844 | - * |
|
| 1845 | - * @return IClientService |
|
| 1846 | - * @deprecated |
|
| 1847 | - */ |
|
| 1848 | - public function getHTTPClientService() { |
|
| 1849 | - return $this->query(IClientService::class); |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - /** |
|
| 1853 | - * Create a new event source |
|
| 1854 | - * |
|
| 1855 | - * @return \OCP\IEventSource |
|
| 1856 | - * @deprecated |
|
| 1857 | - */ |
|
| 1858 | - public function createEventSource() { |
|
| 1859 | - return new \OC_EventSource(); |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - /** |
|
| 1863 | - * Get the active event logger |
|
| 1864 | - * |
|
| 1865 | - * The returned logger only logs data when debug mode is enabled |
|
| 1866 | - * |
|
| 1867 | - * @return IEventLogger |
|
| 1868 | - * @deprecated |
|
| 1869 | - */ |
|
| 1870 | - public function getEventLogger() { |
|
| 1871 | - return $this->query(IEventLogger::class); |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - /** |
|
| 1875 | - * Get the active query logger |
|
| 1876 | - * |
|
| 1877 | - * The returned logger only logs data when debug mode is enabled |
|
| 1878 | - * |
|
| 1879 | - * @return IQueryLogger |
|
| 1880 | - * @deprecated |
|
| 1881 | - */ |
|
| 1882 | - public function getQueryLogger() { |
|
| 1883 | - return $this->query(IQueryLogger::class); |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - /** |
|
| 1887 | - * Get the manager for temporary files and folders |
|
| 1888 | - * |
|
| 1889 | - * @return \OCP\ITempManager |
|
| 1890 | - * @deprecated |
|
| 1891 | - */ |
|
| 1892 | - public function getTempManager() { |
|
| 1893 | - return $this->query(ITempManager::class); |
|
| 1894 | - } |
|
| 1895 | - |
|
| 1896 | - /** |
|
| 1897 | - * Get the app manager |
|
| 1898 | - * |
|
| 1899 | - * @return \OCP\App\IAppManager |
|
| 1900 | - * @deprecated |
|
| 1901 | - */ |
|
| 1902 | - public function getAppManager() { |
|
| 1903 | - return $this->query(IAppManager::class); |
|
| 1904 | - } |
|
| 1905 | - |
|
| 1906 | - /** |
|
| 1907 | - * Creates a new mailer |
|
| 1908 | - * |
|
| 1909 | - * @return IMailer |
|
| 1910 | - * @deprecated |
|
| 1911 | - */ |
|
| 1912 | - public function getMailer() { |
|
| 1913 | - return $this->query(IMailer::class); |
|
| 1914 | - } |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * Get the webroot |
|
| 1918 | - * |
|
| 1919 | - * @return string |
|
| 1920 | - * @deprecated |
|
| 1921 | - */ |
|
| 1922 | - public function getWebRoot() { |
|
| 1923 | - return $this->webRoot; |
|
| 1924 | - } |
|
| 1925 | - |
|
| 1926 | - /** |
|
| 1927 | - * @return \OC\OCSClient |
|
| 1928 | - * @deprecated |
|
| 1929 | - */ |
|
| 1930 | - public function getOcsClient() { |
|
| 1931 | - return $this->query('OcsClient'); |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - /** |
|
| 1935 | - * @return IDateTimeZone |
|
| 1936 | - * @deprecated |
|
| 1937 | - */ |
|
| 1938 | - public function getDateTimeZone() { |
|
| 1939 | - return $this->query(IDateTimeZone::class); |
|
| 1940 | - } |
|
| 1941 | - |
|
| 1942 | - /** |
|
| 1943 | - * @return IDateTimeFormatter |
|
| 1944 | - * @deprecated |
|
| 1945 | - */ |
|
| 1946 | - public function getDateTimeFormatter() { |
|
| 1947 | - return $this->query(IDateTimeFormatter::class); |
|
| 1948 | - } |
|
| 1949 | - |
|
| 1950 | - /** |
|
| 1951 | - * @return IMountProviderCollection |
|
| 1952 | - * @deprecated |
|
| 1953 | - */ |
|
| 1954 | - public function getMountProviderCollection() { |
|
| 1955 | - return $this->query(IMountProviderCollection::class); |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - /** |
|
| 1959 | - * Get the IniWrapper |
|
| 1960 | - * |
|
| 1961 | - * @return IniGetWrapper |
|
| 1962 | - * @deprecated |
|
| 1963 | - */ |
|
| 1964 | - public function getIniWrapper() { |
|
| 1965 | - return $this->query('IniWrapper'); |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - /** |
|
| 1969 | - * @return \OCP\Command\IBus |
|
| 1970 | - * @deprecated |
|
| 1971 | - */ |
|
| 1972 | - public function getCommandBus() { |
|
| 1973 | - return $this->query('AsyncCommandBus'); |
|
| 1974 | - } |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * Get the trusted domain helper |
|
| 1978 | - * |
|
| 1979 | - * @return TrustedDomainHelper |
|
| 1980 | - * @deprecated |
|
| 1981 | - */ |
|
| 1982 | - public function getTrustedDomainHelper() { |
|
| 1983 | - return $this->query('TrustedDomainHelper'); |
|
| 1984 | - } |
|
| 1985 | - |
|
| 1986 | - /** |
|
| 1987 | - * Get the locking provider |
|
| 1988 | - * |
|
| 1989 | - * @return ILockingProvider |
|
| 1990 | - * @since 8.1.0 |
|
| 1991 | - * @deprecated |
|
| 1992 | - */ |
|
| 1993 | - public function getLockingProvider() { |
|
| 1994 | - return $this->query(ILockingProvider::class); |
|
| 1995 | - } |
|
| 1996 | - |
|
| 1997 | - /** |
|
| 1998 | - * @return IMountManager |
|
| 1999 | - * @deprecated |
|
| 2000 | - **/ |
|
| 2001 | - public function getMountManager() { |
|
| 2002 | - return $this->query(IMountManager::class); |
|
| 2003 | - } |
|
| 2004 | - |
|
| 2005 | - /** |
|
| 2006 | - * @return IUserMountCache |
|
| 2007 | - * @deprecated |
|
| 2008 | - */ |
|
| 2009 | - public function getUserMountCache() { |
|
| 2010 | - return $this->query(IUserMountCache::class); |
|
| 2011 | - } |
|
| 2012 | - |
|
| 2013 | - /** |
|
| 2014 | - * Get the MimeTypeDetector |
|
| 2015 | - * |
|
| 2016 | - * @return IMimeTypeDetector |
|
| 2017 | - * @deprecated |
|
| 2018 | - */ |
|
| 2019 | - public function getMimeTypeDetector() { |
|
| 2020 | - return $this->query(IMimeTypeDetector::class); |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - /** |
|
| 2024 | - * Get the MimeTypeLoader |
|
| 2025 | - * |
|
| 2026 | - * @return IMimeTypeLoader |
|
| 2027 | - * @deprecated |
|
| 2028 | - */ |
|
| 2029 | - public function getMimeTypeLoader() { |
|
| 2030 | - return $this->query(IMimeTypeLoader::class); |
|
| 2031 | - } |
|
| 2032 | - |
|
| 2033 | - /** |
|
| 2034 | - * Get the manager of all the capabilities |
|
| 2035 | - * |
|
| 2036 | - * @return CapabilitiesManager |
|
| 2037 | - * @deprecated |
|
| 2038 | - */ |
|
| 2039 | - public function getCapabilitiesManager() { |
|
| 2040 | - return $this->query(CapabilitiesManager::class); |
|
| 2041 | - } |
|
| 2042 | - |
|
| 2043 | - /** |
|
| 2044 | - * Get the EventDispatcher |
|
| 2045 | - * |
|
| 2046 | - * @return EventDispatcherInterface |
|
| 2047 | - * @since 8.2.0 |
|
| 2048 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
| 2049 | - */ |
|
| 2050 | - public function getEventDispatcher() { |
|
| 2051 | - return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * Get the Notification Manager |
|
| 2056 | - * |
|
| 2057 | - * @return \OCP\Notification\IManager |
|
| 2058 | - * @since 8.2.0 |
|
| 2059 | - * @deprecated |
|
| 2060 | - */ |
|
| 2061 | - public function getNotificationManager() { |
|
| 2062 | - return $this->query(\OCP\Notification\IManager::class); |
|
| 2063 | - } |
|
| 2064 | - |
|
| 2065 | - /** |
|
| 2066 | - * @return ICommentsManager |
|
| 2067 | - * @deprecated |
|
| 2068 | - */ |
|
| 2069 | - public function getCommentsManager() { |
|
| 2070 | - return $this->query(ICommentsManager::class); |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - /** |
|
| 2074 | - * @return \OCA\Theming\ThemingDefaults |
|
| 2075 | - * @deprecated |
|
| 2076 | - */ |
|
| 2077 | - public function getThemingDefaults() { |
|
| 2078 | - return $this->query('ThemingDefaults'); |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - /** |
|
| 2082 | - * @return \OC\IntegrityCheck\Checker |
|
| 2083 | - * @deprecated |
|
| 2084 | - */ |
|
| 2085 | - public function getIntegrityCodeChecker() { |
|
| 2086 | - return $this->query('IntegrityCodeChecker'); |
|
| 2087 | - } |
|
| 2088 | - |
|
| 2089 | - /** |
|
| 2090 | - * @return \OC\Session\CryptoWrapper |
|
| 2091 | - * @deprecated |
|
| 2092 | - */ |
|
| 2093 | - public function getSessionCryptoWrapper() { |
|
| 2094 | - return $this->query('CryptoWrapper'); |
|
| 2095 | - } |
|
| 2096 | - |
|
| 2097 | - /** |
|
| 2098 | - * @return CsrfTokenManager |
|
| 2099 | - * @deprecated |
|
| 2100 | - */ |
|
| 2101 | - public function getCsrfTokenManager() { |
|
| 2102 | - return $this->query(CsrfTokenManager::class); |
|
| 2103 | - } |
|
| 2104 | - |
|
| 2105 | - /** |
|
| 2106 | - * @return Throttler |
|
| 2107 | - * @deprecated |
|
| 2108 | - */ |
|
| 2109 | - public function getBruteForceThrottler() { |
|
| 2110 | - return $this->query(Throttler::class); |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - /** |
|
| 2114 | - * @return IContentSecurityPolicyManager |
|
| 2115 | - * @deprecated |
|
| 2116 | - */ |
|
| 2117 | - public function getContentSecurityPolicyManager() { |
|
| 2118 | - return $this->query(ContentSecurityPolicyManager::class); |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - /** |
|
| 2122 | - * @return ContentSecurityPolicyNonceManager |
|
| 2123 | - * @deprecated |
|
| 2124 | - */ |
|
| 2125 | - public function getContentSecurityPolicyNonceManager() { |
|
| 2126 | - return $this->query(ContentSecurityPolicyNonceManager::class); |
|
| 2127 | - } |
|
| 2128 | - |
|
| 2129 | - /** |
|
| 2130 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2131 | - * |
|
| 2132 | - * @return \OCA\Files_External\Service\BackendService |
|
| 2133 | - * @deprecated |
|
| 2134 | - */ |
|
| 2135 | - public function getStoragesBackendService() { |
|
| 2136 | - return $this->query(BackendService::class); |
|
| 2137 | - } |
|
| 2138 | - |
|
| 2139 | - /** |
|
| 2140 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2141 | - * |
|
| 2142 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2143 | - * @deprecated |
|
| 2144 | - */ |
|
| 2145 | - public function getGlobalStoragesService() { |
|
| 2146 | - return $this->query(GlobalStoragesService::class); |
|
| 2147 | - } |
|
| 2148 | - |
|
| 2149 | - /** |
|
| 2150 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2151 | - * |
|
| 2152 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2153 | - * @deprecated |
|
| 2154 | - */ |
|
| 2155 | - public function getUserGlobalStoragesService() { |
|
| 2156 | - return $this->query(UserGlobalStoragesService::class); |
|
| 2157 | - } |
|
| 2158 | - |
|
| 2159 | - /** |
|
| 2160 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2161 | - * |
|
| 2162 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2163 | - * @deprecated |
|
| 2164 | - */ |
|
| 2165 | - public function getUserStoragesService() { |
|
| 2166 | - return $this->query(UserStoragesService::class); |
|
| 2167 | - } |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * @return \OCP\Share\IManager |
|
| 2171 | - * @deprecated |
|
| 2172 | - */ |
|
| 2173 | - public function getShareManager() { |
|
| 2174 | - return $this->query(\OCP\Share\IManager::class); |
|
| 2175 | - } |
|
| 2176 | - |
|
| 2177 | - /** |
|
| 2178 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2179 | - * @deprecated |
|
| 2180 | - */ |
|
| 2181 | - public function getCollaboratorSearch() { |
|
| 2182 | - return $this->query(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2183 | - } |
|
| 2184 | - |
|
| 2185 | - /** |
|
| 2186 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2187 | - * @deprecated |
|
| 2188 | - */ |
|
| 2189 | - public function getAutoCompleteManager() { |
|
| 2190 | - return $this->query(IManager::class); |
|
| 2191 | - } |
|
| 2192 | - |
|
| 2193 | - /** |
|
| 2194 | - * Returns the LDAP Provider |
|
| 2195 | - * |
|
| 2196 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 2197 | - * @deprecated |
|
| 2198 | - */ |
|
| 2199 | - public function getLDAPProvider() { |
|
| 2200 | - return $this->query('LDAPProvider'); |
|
| 2201 | - } |
|
| 2202 | - |
|
| 2203 | - /** |
|
| 2204 | - * @return \OCP\Settings\IManager |
|
| 2205 | - * @deprecated |
|
| 2206 | - */ |
|
| 2207 | - public function getSettingsManager() { |
|
| 2208 | - return $this->query('SettingsManager'); |
|
| 2209 | - } |
|
| 2210 | - |
|
| 2211 | - /** |
|
| 2212 | - * @return \OCP\Files\IAppData |
|
| 2213 | - * @deprecated |
|
| 2214 | - */ |
|
| 2215 | - public function getAppDataDir($app) { |
|
| 2216 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2217 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 2218 | - return $factory->get($app); |
|
| 2219 | - } |
|
| 2220 | - |
|
| 2221 | - /** |
|
| 2222 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 2223 | - * @deprecated |
|
| 2224 | - */ |
|
| 2225 | - public function getLockdownManager() { |
|
| 2226 | - return $this->query('LockdownManager'); |
|
| 2227 | - } |
|
| 2228 | - |
|
| 2229 | - /** |
|
| 2230 | - * @return \OCP\Federation\ICloudIdManager |
|
| 2231 | - * @deprecated |
|
| 2232 | - */ |
|
| 2233 | - public function getCloudIdManager() { |
|
| 2234 | - return $this->query(ICloudIdManager::class); |
|
| 2235 | - } |
|
| 2236 | - |
|
| 2237 | - /** |
|
| 2238 | - * @return \OCP\GlobalScale\IConfig |
|
| 2239 | - * @deprecated |
|
| 2240 | - */ |
|
| 2241 | - public function getGlobalScaleConfig() { |
|
| 2242 | - return $this->query(IConfig::class); |
|
| 2243 | - } |
|
| 2244 | - |
|
| 2245 | - /** |
|
| 2246 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2247 | - * @deprecated |
|
| 2248 | - */ |
|
| 2249 | - public function getCloudFederationProviderManager() { |
|
| 2250 | - return $this->query(ICloudFederationProviderManager::class); |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - /** |
|
| 2254 | - * @return \OCP\Remote\Api\IApiFactory |
|
| 2255 | - * @deprecated |
|
| 2256 | - */ |
|
| 2257 | - public function getRemoteApiFactory() { |
|
| 2258 | - return $this->query(IApiFactory::class); |
|
| 2259 | - } |
|
| 2260 | - |
|
| 2261 | - /** |
|
| 2262 | - * @return \OCP\Federation\ICloudFederationFactory |
|
| 2263 | - * @deprecated |
|
| 2264 | - */ |
|
| 2265 | - public function getCloudFederationFactory() { |
|
| 2266 | - return $this->query(ICloudFederationFactory::class); |
|
| 2267 | - } |
|
| 2268 | - |
|
| 2269 | - /** |
|
| 2270 | - * @return \OCP\Remote\IInstanceFactory |
|
| 2271 | - * @deprecated |
|
| 2272 | - */ |
|
| 2273 | - public function getRemoteInstanceFactory() { |
|
| 2274 | - return $this->query(IInstanceFactory::class); |
|
| 2275 | - } |
|
| 2276 | - |
|
| 2277 | - /** |
|
| 2278 | - * @return IStorageFactory |
|
| 2279 | - * @deprecated |
|
| 2280 | - */ |
|
| 2281 | - public function getStorageFactory() { |
|
| 2282 | - return $this->query(IStorageFactory::class); |
|
| 2283 | - } |
|
| 2284 | - |
|
| 2285 | - /** |
|
| 2286 | - * Get the Preview GeneratorHelper |
|
| 2287 | - * |
|
| 2288 | - * @return GeneratorHelper |
|
| 2289 | - * @since 17.0.0 |
|
| 2290 | - * @deprecated |
|
| 2291 | - */ |
|
| 2292 | - public function getGeneratorHelper() { |
|
| 2293 | - return $this->query(\OC\Preview\GeneratorHelper::class); |
|
| 2294 | - } |
|
| 2295 | - |
|
| 2296 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2297 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2298 | - try { |
|
| 2299 | - /** @var ILogger $logger */ |
|
| 2300 | - $logger = $container->get(ILogger::class); |
|
| 2301 | - $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2302 | - } catch (ContainerExceptionInterface $e) { |
|
| 2303 | - // Could not get logger. Continue |
|
| 2304 | - } |
|
| 2305 | - |
|
| 2306 | - return $container->get($target); |
|
| 2307 | - }, false); |
|
| 2308 | - } |
|
| 1117 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 1118 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 1119 | + $classExists = true; |
|
| 1120 | + } else { |
|
| 1121 | + $classExists = false; |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1125 | + return new ThemingDefaults( |
|
| 1126 | + $c->getConfig(), |
|
| 1127 | + $c->getL10N('theming'), |
|
| 1128 | + $c->getURLGenerator(), |
|
| 1129 | + $c->getMemCacheFactory(), |
|
| 1130 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
| 1131 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
| 1132 | + $c->getAppManager(), |
|
| 1133 | + $c->getNavigationManager() |
|
| 1134 | + ); |
|
| 1135 | + } |
|
| 1136 | + return new \OC_Defaults(); |
|
| 1137 | + }); |
|
| 1138 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1139 | + return new JSCombiner( |
|
| 1140 | + $c->getAppDataDir('js'), |
|
| 1141 | + $c->getURLGenerator(), |
|
| 1142 | + $this->getMemCacheFactory(), |
|
| 1143 | + $c->getSystemConfig(), |
|
| 1144 | + $c->getLogger() |
|
| 1145 | + ); |
|
| 1146 | + }); |
|
| 1147 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1148 | + /** @deprecated 19.0.0 */ |
|
| 1149 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1150 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1151 | + |
|
| 1152 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 1153 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 1154 | + $request = new Request( |
|
| 1155 | + [ |
|
| 1156 | + 'get' => $_GET, |
|
| 1157 | + 'post' => $_POST, |
|
| 1158 | + 'files' => $_FILES, |
|
| 1159 | + 'server' => $_SERVER, |
|
| 1160 | + 'env' => $_ENV, |
|
| 1161 | + 'cookies' => $_COOKIE, |
|
| 1162 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1163 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1164 | + : null, |
|
| 1165 | + ], |
|
| 1166 | + $c->getSecureRandom(), |
|
| 1167 | + $c->getConfig() |
|
| 1168 | + ); |
|
| 1169 | + |
|
| 1170 | + return new CryptoWrapper( |
|
| 1171 | + $c->getConfig(), |
|
| 1172 | + $c->getCrypto(), |
|
| 1173 | + $c->getSecureRandom(), |
|
| 1174 | + $request |
|
| 1175 | + ); |
|
| 1176 | + }); |
|
| 1177 | + /** @deprecated 19.0.0 */ |
|
| 1178 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
| 1179 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1180 | + return new SessionStorage($c->getSession()); |
|
| 1181 | + }); |
|
| 1182 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1183 | + /** @deprecated 19.0.0 */ |
|
| 1184 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
| 1185 | + |
|
| 1186 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1187 | + $config = $c->getConfig(); |
|
| 1188 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1189 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1190 | + $factory = new $factoryClass($this); |
|
| 1191 | + |
|
| 1192 | + $manager = new \OC\Share20\Manager( |
|
| 1193 | + $c->getLogger(), |
|
| 1194 | + $c->getConfig(), |
|
| 1195 | + $c->getSecureRandom(), |
|
| 1196 | + $c->getHasher(), |
|
| 1197 | + $c->getMountManager(), |
|
| 1198 | + $c->getGroupManager(), |
|
| 1199 | + $c->getL10N('lib'), |
|
| 1200 | + $c->getL10NFactory(), |
|
| 1201 | + $factory, |
|
| 1202 | + $c->getUserManager(), |
|
| 1203 | + $c->getLazyRootFolder(), |
|
| 1204 | + $c->getEventDispatcher(), |
|
| 1205 | + $c->getMailer(), |
|
| 1206 | + $c->getURLGenerator(), |
|
| 1207 | + $c->getThemingDefaults(), |
|
| 1208 | + $c->query(IEventDispatcher::class) |
|
| 1209 | + ); |
|
| 1210 | + |
|
| 1211 | + return $manager; |
|
| 1212 | + }); |
|
| 1213 | + /** @deprecated 19.0.0 */ |
|
| 1214 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1215 | + |
|
| 1216 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1217 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1218 | + |
|
| 1219 | + // register default plugins |
|
| 1220 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1221 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1222 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1223 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1224 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1225 | + |
|
| 1226 | + return $instance; |
|
| 1227 | + }); |
|
| 1228 | + /** @deprecated 19.0.0 */ |
|
| 1229 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1230 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1231 | + |
|
| 1232 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1233 | + |
|
| 1234 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1235 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1236 | + |
|
| 1237 | + $this->registerService('SettingsManager', function (Server $c) { |
|
| 1238 | + $manager = new \OC\Settings\Manager( |
|
| 1239 | + $c->getLogger(), |
|
| 1240 | + $c->getL10NFactory(), |
|
| 1241 | + $c->getURLGenerator(), |
|
| 1242 | + $c |
|
| 1243 | + ); |
|
| 1244 | + return $manager; |
|
| 1245 | + }); |
|
| 1246 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1247 | + return new \OC\Files\AppData\Factory( |
|
| 1248 | + $c->getRootFolder(), |
|
| 1249 | + $c->getSystemConfig() |
|
| 1250 | + ); |
|
| 1251 | + }); |
|
| 1252 | + |
|
| 1253 | + $this->registerService('LockdownManager', function (Server $c) { |
|
| 1254 | + return new LockdownManager(function () use ($c) { |
|
| 1255 | + return $c->getSession(); |
|
| 1256 | + }); |
|
| 1257 | + }); |
|
| 1258 | + |
|
| 1259 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1260 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1261 | + }); |
|
| 1262 | + |
|
| 1263 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1264 | + return new CloudIdManager(); |
|
| 1265 | + }); |
|
| 1266 | + |
|
| 1267 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1268 | + |
|
| 1269 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
| 1270 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
| 1271 | + }); |
|
| 1272 | + |
|
| 1273 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1274 | + return new CloudFederationFactory(); |
|
| 1275 | + }); |
|
| 1276 | + |
|
| 1277 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1278 | + /** @deprecated 19.0.0 */ |
|
| 1279 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1280 | + |
|
| 1281 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1282 | + /** @deprecated 19.0.0 */ |
|
| 1283 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1284 | + |
|
| 1285 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1286 | + return new Defaults( |
|
| 1287 | + $c->getThemingDefaults() |
|
| 1288 | + ); |
|
| 1289 | + }); |
|
| 1290 | + /** @deprecated 19.0.0 */ |
|
| 1291 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
| 1292 | + |
|
| 1293 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1294 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1295 | + }); |
|
| 1296 | + |
|
| 1297 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1298 | + return new ShareHelper( |
|
| 1299 | + $c->query(\OCP\Share\IManager::class) |
|
| 1300 | + ); |
|
| 1301 | + }); |
|
| 1302 | + |
|
| 1303 | + $this->registerService(Installer::class, function (Server $c) { |
|
| 1304 | + return new Installer( |
|
| 1305 | + $c->getAppFetcher(), |
|
| 1306 | + $c->getHTTPClientService(), |
|
| 1307 | + $c->getTempManager(), |
|
| 1308 | + $c->getLogger(), |
|
| 1309 | + $c->getConfig(), |
|
| 1310 | + \OC::$CLI |
|
| 1311 | + ); |
|
| 1312 | + }); |
|
| 1313 | + |
|
| 1314 | + $this->registerService(IApiFactory::class, function (Server $c) { |
|
| 1315 | + return new ApiFactory($c->getHTTPClientService()); |
|
| 1316 | + }); |
|
| 1317 | + |
|
| 1318 | + $this->registerService(IInstanceFactory::class, function (Server $c) { |
|
| 1319 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1320 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
| 1321 | + }); |
|
| 1322 | + |
|
| 1323 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1324 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1325 | + |
|
| 1326 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1327 | + |
|
| 1328 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1329 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1330 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1331 | + |
|
| 1332 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1333 | + |
|
| 1334 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1335 | + |
|
| 1336 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1337 | + |
|
| 1338 | + $this->connectDispatcher(); |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + public function boot() { |
|
| 1342 | + /** @var HookConnector $hookConnector */ |
|
| 1343 | + $hookConnector = $this->query(HookConnector::class); |
|
| 1344 | + $hookConnector->viewToNode(); |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + /** |
|
| 1348 | + * @return \OCP\Calendar\IManager |
|
| 1349 | + * @deprecated |
|
| 1350 | + */ |
|
| 1351 | + public function getCalendarManager() { |
|
| 1352 | + return $this->query(\OC\Calendar\Manager::class); |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + /** |
|
| 1356 | + * @return \OCP\Calendar\Resource\IManager |
|
| 1357 | + * @deprecated |
|
| 1358 | + */ |
|
| 1359 | + public function getCalendarResourceBackendManager() { |
|
| 1360 | + return $this->query(\OC\Calendar\Resource\Manager::class); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * @return \OCP\Calendar\Room\IManager |
|
| 1365 | + * @deprecated |
|
| 1366 | + */ |
|
| 1367 | + public function getCalendarRoomBackendManager() { |
|
| 1368 | + return $this->query(\OC\Calendar\Room\Manager::class); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + private function connectDispatcher() { |
|
| 1372 | + $dispatcher = $this->getEventDispatcher(); |
|
| 1373 | + |
|
| 1374 | + // Delete avatar on user deletion |
|
| 1375 | + $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1376 | + $logger = $this->getLogger(); |
|
| 1377 | + $manager = $this->getAvatarManager(); |
|
| 1378 | + /** @var IUser $user */ |
|
| 1379 | + $user = $e->getSubject(); |
|
| 1380 | + |
|
| 1381 | + try { |
|
| 1382 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1383 | + $avatar->remove(); |
|
| 1384 | + } catch (NotFoundException $e) { |
|
| 1385 | + // no avatar to remove |
|
| 1386 | + } catch (\Exception $e) { |
|
| 1387 | + // Ignore exceptions |
|
| 1388 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1389 | + } |
|
| 1390 | + }); |
|
| 1391 | + |
|
| 1392 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1393 | + $manager = $this->getAvatarManager(); |
|
| 1394 | + /** @var IUser $user */ |
|
| 1395 | + $user = $e->getSubject(); |
|
| 1396 | + $feature = $e->getArgument('feature'); |
|
| 1397 | + $oldValue = $e->getArgument('oldValue'); |
|
| 1398 | + $value = $e->getArgument('value'); |
|
| 1399 | + |
|
| 1400 | + // We only change the avatar on display name changes |
|
| 1401 | + if ($feature !== 'displayName') { |
|
| 1402 | + return; |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + try { |
|
| 1406 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1407 | + $avatar->userChanged($feature, $oldValue, $value); |
|
| 1408 | + } catch (NotFoundException $e) { |
|
| 1409 | + // no avatar to remove |
|
| 1410 | + } |
|
| 1411 | + }); |
|
| 1412 | + |
|
| 1413 | + /** @var IEventDispatcher $eventDispatched */ |
|
| 1414 | + $eventDispatched = $this->query(IEventDispatcher::class); |
|
| 1415 | + $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + /** |
|
| 1419 | + * @return \OCP\Contacts\IManager |
|
| 1420 | + * @deprecated |
|
| 1421 | + */ |
|
| 1422 | + public function getContactsManager() { |
|
| 1423 | + return $this->query(\OCP\Contacts\IManager::class); |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * @return \OC\Encryption\Manager |
|
| 1428 | + * @deprecated |
|
| 1429 | + */ |
|
| 1430 | + public function getEncryptionManager() { |
|
| 1431 | + return $this->query(\OCP\Encryption\IManager::class); |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + /** |
|
| 1435 | + * @return \OC\Encryption\File |
|
| 1436 | + * @deprecated |
|
| 1437 | + */ |
|
| 1438 | + public function getEncryptionFilesHelper() { |
|
| 1439 | + return $this->query('EncryptionFileHelper'); |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + /** |
|
| 1443 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1444 | + * @deprecated |
|
| 1445 | + */ |
|
| 1446 | + public function getEncryptionKeyStorage() { |
|
| 1447 | + return $this->query('EncryptionKeyStorage'); |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + /** |
|
| 1451 | + * The current request object holding all information about the request |
|
| 1452 | + * currently being processed is returned from this method. |
|
| 1453 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1454 | + * |
|
| 1455 | + * @return \OCP\IRequest |
|
| 1456 | + * @deprecated |
|
| 1457 | + */ |
|
| 1458 | + public function getRequest() { |
|
| 1459 | + return $this->query(IRequest::class); |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + /** |
|
| 1463 | + * Returns the preview manager which can create preview images for a given file |
|
| 1464 | + * |
|
| 1465 | + * @return IPreview |
|
| 1466 | + * @deprecated |
|
| 1467 | + */ |
|
| 1468 | + public function getPreviewManager() { |
|
| 1469 | + return $this->query(IPreview::class); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + /** |
|
| 1473 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1474 | + * |
|
| 1475 | + * @see \OCP\ITagManager::load() |
|
| 1476 | + * @return ITagManager |
|
| 1477 | + * @deprecated |
|
| 1478 | + */ |
|
| 1479 | + public function getTagManager() { |
|
| 1480 | + return $this->query(ITagManager::class); |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + /** |
|
| 1484 | + * Returns the system-tag manager |
|
| 1485 | + * |
|
| 1486 | + * @return ISystemTagManager |
|
| 1487 | + * |
|
| 1488 | + * @since 9.0.0 |
|
| 1489 | + * @deprecated |
|
| 1490 | + */ |
|
| 1491 | + public function getSystemTagManager() { |
|
| 1492 | + return $this->query(ISystemTagManager::class); |
|
| 1493 | + } |
|
| 1494 | + |
|
| 1495 | + /** |
|
| 1496 | + * Returns the system-tag object mapper |
|
| 1497 | + * |
|
| 1498 | + * @return ISystemTagObjectMapper |
|
| 1499 | + * |
|
| 1500 | + * @since 9.0.0 |
|
| 1501 | + * @deprecated |
|
| 1502 | + */ |
|
| 1503 | + public function getSystemTagObjectMapper() { |
|
| 1504 | + return $this->query(ISystemTagObjectMapper::class); |
|
| 1505 | + } |
|
| 1506 | + |
|
| 1507 | + /** |
|
| 1508 | + * Returns the avatar manager, used for avatar functionality |
|
| 1509 | + * |
|
| 1510 | + * @return IAvatarManager |
|
| 1511 | + * @deprecated |
|
| 1512 | + */ |
|
| 1513 | + public function getAvatarManager() { |
|
| 1514 | + return $this->query(IAvatarManager::class); |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * Returns the root folder of ownCloud's data directory |
|
| 1519 | + * |
|
| 1520 | + * @return IRootFolder |
|
| 1521 | + * @deprecated |
|
| 1522 | + */ |
|
| 1523 | + public function getRootFolder() { |
|
| 1524 | + return $this->query(IRootFolder::class); |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + /** |
|
| 1528 | + * Returns the root folder of ownCloud's data directory |
|
| 1529 | + * This is the lazy variant so this gets only initialized once it |
|
| 1530 | + * is actually used. |
|
| 1531 | + * |
|
| 1532 | + * @return IRootFolder |
|
| 1533 | + */ |
|
| 1534 | + public function getLazyRootFolder() { |
|
| 1535 | + return $this->query(IRootFolder::class); |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + /** |
|
| 1539 | + * Returns a view to ownCloud's files folder |
|
| 1540 | + * |
|
| 1541 | + * @param string $userId user ID |
|
| 1542 | + * @return \OCP\Files\Folder|null |
|
| 1543 | + * @deprecated |
|
| 1544 | + */ |
|
| 1545 | + public function getUserFolder($userId = null) { |
|
| 1546 | + if ($userId === null) { |
|
| 1547 | + $user = $this->getUserSession()->getUser(); |
|
| 1548 | + if (!$user) { |
|
| 1549 | + return null; |
|
| 1550 | + } |
|
| 1551 | + $userId = $user->getUID(); |
|
| 1552 | + } |
|
| 1553 | + $root = $this->getRootFolder(); |
|
| 1554 | + return $root->getUserFolder($userId); |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + /** |
|
| 1558 | + * @return \OC\User\Manager |
|
| 1559 | + * @deprecated |
|
| 1560 | + */ |
|
| 1561 | + public function getUserManager() { |
|
| 1562 | + return $this->query(IUserManager::class); |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + /** |
|
| 1566 | + * @return \OC\Group\Manager |
|
| 1567 | + * @deprecated |
|
| 1568 | + */ |
|
| 1569 | + public function getGroupManager() { |
|
| 1570 | + return $this->query(IGroupManager::class); |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + /** |
|
| 1574 | + * @return \OC\User\Session |
|
| 1575 | + * @deprecated |
|
| 1576 | + */ |
|
| 1577 | + public function getUserSession() { |
|
| 1578 | + return $this->query(IUserSession::class); |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + /** |
|
| 1582 | + * @return \OCP\ISession |
|
| 1583 | + * @deprecated |
|
| 1584 | + */ |
|
| 1585 | + public function getSession() { |
|
| 1586 | + return $this->getUserSession()->getSession(); |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + /** |
|
| 1590 | + * @param \OCP\ISession $session |
|
| 1591 | + */ |
|
| 1592 | + public function setSession(\OCP\ISession $session) { |
|
| 1593 | + $this->query(SessionStorage::class)->setSession($session); |
|
| 1594 | + $this->getUserSession()->setSession($session); |
|
| 1595 | + $this->query(Store::class)->setSession($session); |
|
| 1596 | + } |
|
| 1597 | + |
|
| 1598 | + /** |
|
| 1599 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1600 | + * @deprecated |
|
| 1601 | + */ |
|
| 1602 | + public function getTwoFactorAuthManager() { |
|
| 1603 | + return $this->query(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + /** |
|
| 1607 | + * @return \OC\NavigationManager |
|
| 1608 | + * @deprecated |
|
| 1609 | + */ |
|
| 1610 | + public function getNavigationManager() { |
|
| 1611 | + return $this->query(INavigationManager::class); |
|
| 1612 | + } |
|
| 1613 | + |
|
| 1614 | + /** |
|
| 1615 | + * @return \OCP\IConfig |
|
| 1616 | + * @deprecated |
|
| 1617 | + */ |
|
| 1618 | + public function getConfig() { |
|
| 1619 | + return $this->query(AllConfig::class); |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * @return \OC\SystemConfig |
|
| 1624 | + * @deprecated |
|
| 1625 | + */ |
|
| 1626 | + public function getSystemConfig() { |
|
| 1627 | + return $this->query(SystemConfig::class); |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * Returns the app config manager |
|
| 1632 | + * |
|
| 1633 | + * @return IAppConfig |
|
| 1634 | + * @deprecated |
|
| 1635 | + */ |
|
| 1636 | + public function getAppConfig() { |
|
| 1637 | + return $this->query(IAppConfig::class); |
|
| 1638 | + } |
|
| 1639 | + |
|
| 1640 | + /** |
|
| 1641 | + * @return IFactory |
|
| 1642 | + * @deprecated |
|
| 1643 | + */ |
|
| 1644 | + public function getL10NFactory() { |
|
| 1645 | + return $this->query(IFactory::class); |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * get an L10N instance |
|
| 1650 | + * |
|
| 1651 | + * @param string $app appid |
|
| 1652 | + * @param string $lang |
|
| 1653 | + * @return IL10N |
|
| 1654 | + * @deprecated |
|
| 1655 | + */ |
|
| 1656 | + public function getL10N($app, $lang = null) { |
|
| 1657 | + return $this->getL10NFactory()->get($app, $lang); |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * @return IURLGenerator |
|
| 1662 | + * @deprecated |
|
| 1663 | + */ |
|
| 1664 | + public function getURLGenerator() { |
|
| 1665 | + return $this->query(IURLGenerator::class); |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + /** |
|
| 1669 | + * @return AppFetcher |
|
| 1670 | + * @deprecated |
|
| 1671 | + */ |
|
| 1672 | + public function getAppFetcher() { |
|
| 1673 | + return $this->query(AppFetcher::class); |
|
| 1674 | + } |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1678 | + * getMemCacheFactory() instead. |
|
| 1679 | + * |
|
| 1680 | + * @return ICache |
|
| 1681 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1682 | + */ |
|
| 1683 | + public function getCache() { |
|
| 1684 | + return $this->query(ICache::class); |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * Returns an \OCP\CacheFactory instance |
|
| 1689 | + * |
|
| 1690 | + * @return \OCP\ICacheFactory |
|
| 1691 | + * @deprecated |
|
| 1692 | + */ |
|
| 1693 | + public function getMemCacheFactory() { |
|
| 1694 | + return $this->query(Factory::class); |
|
| 1695 | + } |
|
| 1696 | + |
|
| 1697 | + /** |
|
| 1698 | + * Returns an \OC\RedisFactory instance |
|
| 1699 | + * |
|
| 1700 | + * @return \OC\RedisFactory |
|
| 1701 | + * @deprecated |
|
| 1702 | + */ |
|
| 1703 | + public function getGetRedisFactory() { |
|
| 1704 | + return $this->query('RedisFactory'); |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + |
|
| 1708 | + /** |
|
| 1709 | + * Returns the current session |
|
| 1710 | + * |
|
| 1711 | + * @return \OCP\IDBConnection |
|
| 1712 | + * @deprecated |
|
| 1713 | + */ |
|
| 1714 | + public function getDatabaseConnection() { |
|
| 1715 | + return $this->query(IDBConnection::class); |
|
| 1716 | + } |
|
| 1717 | + |
|
| 1718 | + /** |
|
| 1719 | + * Returns the activity manager |
|
| 1720 | + * |
|
| 1721 | + * @return \OCP\Activity\IManager |
|
| 1722 | + * @deprecated |
|
| 1723 | + */ |
|
| 1724 | + public function getActivityManager() { |
|
| 1725 | + return $this->query(\OCP\Activity\IManager::class); |
|
| 1726 | + } |
|
| 1727 | + |
|
| 1728 | + /** |
|
| 1729 | + * Returns an job list for controlling background jobs |
|
| 1730 | + * |
|
| 1731 | + * @return IJobList |
|
| 1732 | + * @deprecated |
|
| 1733 | + */ |
|
| 1734 | + public function getJobList() { |
|
| 1735 | + return $this->query(IJobList::class); |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + /** |
|
| 1739 | + * Returns a logger instance |
|
| 1740 | + * |
|
| 1741 | + * @return ILogger |
|
| 1742 | + * @deprecated |
|
| 1743 | + */ |
|
| 1744 | + public function getLogger() { |
|
| 1745 | + return $this->query(ILogger::class); |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + /** |
|
| 1749 | + * @return ILogFactory |
|
| 1750 | + * @throws \OCP\AppFramework\QueryException |
|
| 1751 | + * @deprecated |
|
| 1752 | + */ |
|
| 1753 | + public function getLogFactory() { |
|
| 1754 | + return $this->query(ILogFactory::class); |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + /** |
|
| 1758 | + * Returns a router for generating and matching urls |
|
| 1759 | + * |
|
| 1760 | + * @return IRouter |
|
| 1761 | + * @deprecated |
|
| 1762 | + */ |
|
| 1763 | + public function getRouter() { |
|
| 1764 | + return $this->query(IRouter::class); |
|
| 1765 | + } |
|
| 1766 | + |
|
| 1767 | + /** |
|
| 1768 | + * Returns a search instance |
|
| 1769 | + * |
|
| 1770 | + * @return ISearch |
|
| 1771 | + * @deprecated |
|
| 1772 | + */ |
|
| 1773 | + public function getSearch() { |
|
| 1774 | + return $this->query(ISearch::class); |
|
| 1775 | + } |
|
| 1776 | + |
|
| 1777 | + /** |
|
| 1778 | + * Returns a SecureRandom instance |
|
| 1779 | + * |
|
| 1780 | + * @return \OCP\Security\ISecureRandom |
|
| 1781 | + * @deprecated |
|
| 1782 | + */ |
|
| 1783 | + public function getSecureRandom() { |
|
| 1784 | + return $this->query(ISecureRandom::class); |
|
| 1785 | + } |
|
| 1786 | + |
|
| 1787 | + /** |
|
| 1788 | + * Returns a Crypto instance |
|
| 1789 | + * |
|
| 1790 | + * @return ICrypto |
|
| 1791 | + * @deprecated |
|
| 1792 | + */ |
|
| 1793 | + public function getCrypto() { |
|
| 1794 | + return $this->query(ICrypto::class); |
|
| 1795 | + } |
|
| 1796 | + |
|
| 1797 | + /** |
|
| 1798 | + * Returns a Hasher instance |
|
| 1799 | + * |
|
| 1800 | + * @return IHasher |
|
| 1801 | + * @deprecated |
|
| 1802 | + */ |
|
| 1803 | + public function getHasher() { |
|
| 1804 | + return $this->query(IHasher::class); |
|
| 1805 | + } |
|
| 1806 | + |
|
| 1807 | + /** |
|
| 1808 | + * Returns a CredentialsManager instance |
|
| 1809 | + * |
|
| 1810 | + * @return ICredentialsManager |
|
| 1811 | + * @deprecated |
|
| 1812 | + */ |
|
| 1813 | + public function getCredentialsManager() { |
|
| 1814 | + return $this->query(ICredentialsManager::class); |
|
| 1815 | + } |
|
| 1816 | + |
|
| 1817 | + /** |
|
| 1818 | + * Get the certificate manager for the user |
|
| 1819 | + * |
|
| 1820 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1821 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1822 | + * @deprecated |
|
| 1823 | + */ |
|
| 1824 | + public function getCertificateManager($userId = '') { |
|
| 1825 | + if ($userId === '') { |
|
| 1826 | + $userSession = $this->getUserSession(); |
|
| 1827 | + $user = $userSession->getUser(); |
|
| 1828 | + if (is_null($user)) { |
|
| 1829 | + return null; |
|
| 1830 | + } |
|
| 1831 | + $userId = $user->getUID(); |
|
| 1832 | + } |
|
| 1833 | + return new CertificateManager( |
|
| 1834 | + $userId, |
|
| 1835 | + new View(), |
|
| 1836 | + $this->getConfig(), |
|
| 1837 | + $this->getLogger(), |
|
| 1838 | + $this->getSecureRandom() |
|
| 1839 | + ); |
|
| 1840 | + } |
|
| 1841 | + |
|
| 1842 | + /** |
|
| 1843 | + * Returns an instance of the HTTP client service |
|
| 1844 | + * |
|
| 1845 | + * @return IClientService |
|
| 1846 | + * @deprecated |
|
| 1847 | + */ |
|
| 1848 | + public function getHTTPClientService() { |
|
| 1849 | + return $this->query(IClientService::class); |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + /** |
|
| 1853 | + * Create a new event source |
|
| 1854 | + * |
|
| 1855 | + * @return \OCP\IEventSource |
|
| 1856 | + * @deprecated |
|
| 1857 | + */ |
|
| 1858 | + public function createEventSource() { |
|
| 1859 | + return new \OC_EventSource(); |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + /** |
|
| 1863 | + * Get the active event logger |
|
| 1864 | + * |
|
| 1865 | + * The returned logger only logs data when debug mode is enabled |
|
| 1866 | + * |
|
| 1867 | + * @return IEventLogger |
|
| 1868 | + * @deprecated |
|
| 1869 | + */ |
|
| 1870 | + public function getEventLogger() { |
|
| 1871 | + return $this->query(IEventLogger::class); |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + /** |
|
| 1875 | + * Get the active query logger |
|
| 1876 | + * |
|
| 1877 | + * The returned logger only logs data when debug mode is enabled |
|
| 1878 | + * |
|
| 1879 | + * @return IQueryLogger |
|
| 1880 | + * @deprecated |
|
| 1881 | + */ |
|
| 1882 | + public function getQueryLogger() { |
|
| 1883 | + return $this->query(IQueryLogger::class); |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + /** |
|
| 1887 | + * Get the manager for temporary files and folders |
|
| 1888 | + * |
|
| 1889 | + * @return \OCP\ITempManager |
|
| 1890 | + * @deprecated |
|
| 1891 | + */ |
|
| 1892 | + public function getTempManager() { |
|
| 1893 | + return $this->query(ITempManager::class); |
|
| 1894 | + } |
|
| 1895 | + |
|
| 1896 | + /** |
|
| 1897 | + * Get the app manager |
|
| 1898 | + * |
|
| 1899 | + * @return \OCP\App\IAppManager |
|
| 1900 | + * @deprecated |
|
| 1901 | + */ |
|
| 1902 | + public function getAppManager() { |
|
| 1903 | + return $this->query(IAppManager::class); |
|
| 1904 | + } |
|
| 1905 | + |
|
| 1906 | + /** |
|
| 1907 | + * Creates a new mailer |
|
| 1908 | + * |
|
| 1909 | + * @return IMailer |
|
| 1910 | + * @deprecated |
|
| 1911 | + */ |
|
| 1912 | + public function getMailer() { |
|
| 1913 | + return $this->query(IMailer::class); |
|
| 1914 | + } |
|
| 1915 | + |
|
| 1916 | + /** |
|
| 1917 | + * Get the webroot |
|
| 1918 | + * |
|
| 1919 | + * @return string |
|
| 1920 | + * @deprecated |
|
| 1921 | + */ |
|
| 1922 | + public function getWebRoot() { |
|
| 1923 | + return $this->webRoot; |
|
| 1924 | + } |
|
| 1925 | + |
|
| 1926 | + /** |
|
| 1927 | + * @return \OC\OCSClient |
|
| 1928 | + * @deprecated |
|
| 1929 | + */ |
|
| 1930 | + public function getOcsClient() { |
|
| 1931 | + return $this->query('OcsClient'); |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + /** |
|
| 1935 | + * @return IDateTimeZone |
|
| 1936 | + * @deprecated |
|
| 1937 | + */ |
|
| 1938 | + public function getDateTimeZone() { |
|
| 1939 | + return $this->query(IDateTimeZone::class); |
|
| 1940 | + } |
|
| 1941 | + |
|
| 1942 | + /** |
|
| 1943 | + * @return IDateTimeFormatter |
|
| 1944 | + * @deprecated |
|
| 1945 | + */ |
|
| 1946 | + public function getDateTimeFormatter() { |
|
| 1947 | + return $this->query(IDateTimeFormatter::class); |
|
| 1948 | + } |
|
| 1949 | + |
|
| 1950 | + /** |
|
| 1951 | + * @return IMountProviderCollection |
|
| 1952 | + * @deprecated |
|
| 1953 | + */ |
|
| 1954 | + public function getMountProviderCollection() { |
|
| 1955 | + return $this->query(IMountProviderCollection::class); |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + /** |
|
| 1959 | + * Get the IniWrapper |
|
| 1960 | + * |
|
| 1961 | + * @return IniGetWrapper |
|
| 1962 | + * @deprecated |
|
| 1963 | + */ |
|
| 1964 | + public function getIniWrapper() { |
|
| 1965 | + return $this->query('IniWrapper'); |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + /** |
|
| 1969 | + * @return \OCP\Command\IBus |
|
| 1970 | + * @deprecated |
|
| 1971 | + */ |
|
| 1972 | + public function getCommandBus() { |
|
| 1973 | + return $this->query('AsyncCommandBus'); |
|
| 1974 | + } |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * Get the trusted domain helper |
|
| 1978 | + * |
|
| 1979 | + * @return TrustedDomainHelper |
|
| 1980 | + * @deprecated |
|
| 1981 | + */ |
|
| 1982 | + public function getTrustedDomainHelper() { |
|
| 1983 | + return $this->query('TrustedDomainHelper'); |
|
| 1984 | + } |
|
| 1985 | + |
|
| 1986 | + /** |
|
| 1987 | + * Get the locking provider |
|
| 1988 | + * |
|
| 1989 | + * @return ILockingProvider |
|
| 1990 | + * @since 8.1.0 |
|
| 1991 | + * @deprecated |
|
| 1992 | + */ |
|
| 1993 | + public function getLockingProvider() { |
|
| 1994 | + return $this->query(ILockingProvider::class); |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + /** |
|
| 1998 | + * @return IMountManager |
|
| 1999 | + * @deprecated |
|
| 2000 | + **/ |
|
| 2001 | + public function getMountManager() { |
|
| 2002 | + return $this->query(IMountManager::class); |
|
| 2003 | + } |
|
| 2004 | + |
|
| 2005 | + /** |
|
| 2006 | + * @return IUserMountCache |
|
| 2007 | + * @deprecated |
|
| 2008 | + */ |
|
| 2009 | + public function getUserMountCache() { |
|
| 2010 | + return $this->query(IUserMountCache::class); |
|
| 2011 | + } |
|
| 2012 | + |
|
| 2013 | + /** |
|
| 2014 | + * Get the MimeTypeDetector |
|
| 2015 | + * |
|
| 2016 | + * @return IMimeTypeDetector |
|
| 2017 | + * @deprecated |
|
| 2018 | + */ |
|
| 2019 | + public function getMimeTypeDetector() { |
|
| 2020 | + return $this->query(IMimeTypeDetector::class); |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + /** |
|
| 2024 | + * Get the MimeTypeLoader |
|
| 2025 | + * |
|
| 2026 | + * @return IMimeTypeLoader |
|
| 2027 | + * @deprecated |
|
| 2028 | + */ |
|
| 2029 | + public function getMimeTypeLoader() { |
|
| 2030 | + return $this->query(IMimeTypeLoader::class); |
|
| 2031 | + } |
|
| 2032 | + |
|
| 2033 | + /** |
|
| 2034 | + * Get the manager of all the capabilities |
|
| 2035 | + * |
|
| 2036 | + * @return CapabilitiesManager |
|
| 2037 | + * @deprecated |
|
| 2038 | + */ |
|
| 2039 | + public function getCapabilitiesManager() { |
|
| 2040 | + return $this->query(CapabilitiesManager::class); |
|
| 2041 | + } |
|
| 2042 | + |
|
| 2043 | + /** |
|
| 2044 | + * Get the EventDispatcher |
|
| 2045 | + * |
|
| 2046 | + * @return EventDispatcherInterface |
|
| 2047 | + * @since 8.2.0 |
|
| 2048 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
| 2049 | + */ |
|
| 2050 | + public function getEventDispatcher() { |
|
| 2051 | + return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + /** |
|
| 2055 | + * Get the Notification Manager |
|
| 2056 | + * |
|
| 2057 | + * @return \OCP\Notification\IManager |
|
| 2058 | + * @since 8.2.0 |
|
| 2059 | + * @deprecated |
|
| 2060 | + */ |
|
| 2061 | + public function getNotificationManager() { |
|
| 2062 | + return $this->query(\OCP\Notification\IManager::class); |
|
| 2063 | + } |
|
| 2064 | + |
|
| 2065 | + /** |
|
| 2066 | + * @return ICommentsManager |
|
| 2067 | + * @deprecated |
|
| 2068 | + */ |
|
| 2069 | + public function getCommentsManager() { |
|
| 2070 | + return $this->query(ICommentsManager::class); |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + /** |
|
| 2074 | + * @return \OCA\Theming\ThemingDefaults |
|
| 2075 | + * @deprecated |
|
| 2076 | + */ |
|
| 2077 | + public function getThemingDefaults() { |
|
| 2078 | + return $this->query('ThemingDefaults'); |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + /** |
|
| 2082 | + * @return \OC\IntegrityCheck\Checker |
|
| 2083 | + * @deprecated |
|
| 2084 | + */ |
|
| 2085 | + public function getIntegrityCodeChecker() { |
|
| 2086 | + return $this->query('IntegrityCodeChecker'); |
|
| 2087 | + } |
|
| 2088 | + |
|
| 2089 | + /** |
|
| 2090 | + * @return \OC\Session\CryptoWrapper |
|
| 2091 | + * @deprecated |
|
| 2092 | + */ |
|
| 2093 | + public function getSessionCryptoWrapper() { |
|
| 2094 | + return $this->query('CryptoWrapper'); |
|
| 2095 | + } |
|
| 2096 | + |
|
| 2097 | + /** |
|
| 2098 | + * @return CsrfTokenManager |
|
| 2099 | + * @deprecated |
|
| 2100 | + */ |
|
| 2101 | + public function getCsrfTokenManager() { |
|
| 2102 | + return $this->query(CsrfTokenManager::class); |
|
| 2103 | + } |
|
| 2104 | + |
|
| 2105 | + /** |
|
| 2106 | + * @return Throttler |
|
| 2107 | + * @deprecated |
|
| 2108 | + */ |
|
| 2109 | + public function getBruteForceThrottler() { |
|
| 2110 | + return $this->query(Throttler::class); |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + /** |
|
| 2114 | + * @return IContentSecurityPolicyManager |
|
| 2115 | + * @deprecated |
|
| 2116 | + */ |
|
| 2117 | + public function getContentSecurityPolicyManager() { |
|
| 2118 | + return $this->query(ContentSecurityPolicyManager::class); |
|
| 2119 | + } |
|
| 2120 | + |
|
| 2121 | + /** |
|
| 2122 | + * @return ContentSecurityPolicyNonceManager |
|
| 2123 | + * @deprecated |
|
| 2124 | + */ |
|
| 2125 | + public function getContentSecurityPolicyNonceManager() { |
|
| 2126 | + return $this->query(ContentSecurityPolicyNonceManager::class); |
|
| 2127 | + } |
|
| 2128 | + |
|
| 2129 | + /** |
|
| 2130 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2131 | + * |
|
| 2132 | + * @return \OCA\Files_External\Service\BackendService |
|
| 2133 | + * @deprecated |
|
| 2134 | + */ |
|
| 2135 | + public function getStoragesBackendService() { |
|
| 2136 | + return $this->query(BackendService::class); |
|
| 2137 | + } |
|
| 2138 | + |
|
| 2139 | + /** |
|
| 2140 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2141 | + * |
|
| 2142 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2143 | + * @deprecated |
|
| 2144 | + */ |
|
| 2145 | + public function getGlobalStoragesService() { |
|
| 2146 | + return $this->query(GlobalStoragesService::class); |
|
| 2147 | + } |
|
| 2148 | + |
|
| 2149 | + /** |
|
| 2150 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2151 | + * |
|
| 2152 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2153 | + * @deprecated |
|
| 2154 | + */ |
|
| 2155 | + public function getUserGlobalStoragesService() { |
|
| 2156 | + return $this->query(UserGlobalStoragesService::class); |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + /** |
|
| 2160 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2161 | + * |
|
| 2162 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2163 | + * @deprecated |
|
| 2164 | + */ |
|
| 2165 | + public function getUserStoragesService() { |
|
| 2166 | + return $this->query(UserStoragesService::class); |
|
| 2167 | + } |
|
| 2168 | + |
|
| 2169 | + /** |
|
| 2170 | + * @return \OCP\Share\IManager |
|
| 2171 | + * @deprecated |
|
| 2172 | + */ |
|
| 2173 | + public function getShareManager() { |
|
| 2174 | + return $this->query(\OCP\Share\IManager::class); |
|
| 2175 | + } |
|
| 2176 | + |
|
| 2177 | + /** |
|
| 2178 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2179 | + * @deprecated |
|
| 2180 | + */ |
|
| 2181 | + public function getCollaboratorSearch() { |
|
| 2182 | + return $this->query(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2183 | + } |
|
| 2184 | + |
|
| 2185 | + /** |
|
| 2186 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2187 | + * @deprecated |
|
| 2188 | + */ |
|
| 2189 | + public function getAutoCompleteManager() { |
|
| 2190 | + return $this->query(IManager::class); |
|
| 2191 | + } |
|
| 2192 | + |
|
| 2193 | + /** |
|
| 2194 | + * Returns the LDAP Provider |
|
| 2195 | + * |
|
| 2196 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 2197 | + * @deprecated |
|
| 2198 | + */ |
|
| 2199 | + public function getLDAPProvider() { |
|
| 2200 | + return $this->query('LDAPProvider'); |
|
| 2201 | + } |
|
| 2202 | + |
|
| 2203 | + /** |
|
| 2204 | + * @return \OCP\Settings\IManager |
|
| 2205 | + * @deprecated |
|
| 2206 | + */ |
|
| 2207 | + public function getSettingsManager() { |
|
| 2208 | + return $this->query('SettingsManager'); |
|
| 2209 | + } |
|
| 2210 | + |
|
| 2211 | + /** |
|
| 2212 | + * @return \OCP\Files\IAppData |
|
| 2213 | + * @deprecated |
|
| 2214 | + */ |
|
| 2215 | + public function getAppDataDir($app) { |
|
| 2216 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2217 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 2218 | + return $factory->get($app); |
|
| 2219 | + } |
|
| 2220 | + |
|
| 2221 | + /** |
|
| 2222 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 2223 | + * @deprecated |
|
| 2224 | + */ |
|
| 2225 | + public function getLockdownManager() { |
|
| 2226 | + return $this->query('LockdownManager'); |
|
| 2227 | + } |
|
| 2228 | + |
|
| 2229 | + /** |
|
| 2230 | + * @return \OCP\Federation\ICloudIdManager |
|
| 2231 | + * @deprecated |
|
| 2232 | + */ |
|
| 2233 | + public function getCloudIdManager() { |
|
| 2234 | + return $this->query(ICloudIdManager::class); |
|
| 2235 | + } |
|
| 2236 | + |
|
| 2237 | + /** |
|
| 2238 | + * @return \OCP\GlobalScale\IConfig |
|
| 2239 | + * @deprecated |
|
| 2240 | + */ |
|
| 2241 | + public function getGlobalScaleConfig() { |
|
| 2242 | + return $this->query(IConfig::class); |
|
| 2243 | + } |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2247 | + * @deprecated |
|
| 2248 | + */ |
|
| 2249 | + public function getCloudFederationProviderManager() { |
|
| 2250 | + return $this->query(ICloudFederationProviderManager::class); |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + /** |
|
| 2254 | + * @return \OCP\Remote\Api\IApiFactory |
|
| 2255 | + * @deprecated |
|
| 2256 | + */ |
|
| 2257 | + public function getRemoteApiFactory() { |
|
| 2258 | + return $this->query(IApiFactory::class); |
|
| 2259 | + } |
|
| 2260 | + |
|
| 2261 | + /** |
|
| 2262 | + * @return \OCP\Federation\ICloudFederationFactory |
|
| 2263 | + * @deprecated |
|
| 2264 | + */ |
|
| 2265 | + public function getCloudFederationFactory() { |
|
| 2266 | + return $this->query(ICloudFederationFactory::class); |
|
| 2267 | + } |
|
| 2268 | + |
|
| 2269 | + /** |
|
| 2270 | + * @return \OCP\Remote\IInstanceFactory |
|
| 2271 | + * @deprecated |
|
| 2272 | + */ |
|
| 2273 | + public function getRemoteInstanceFactory() { |
|
| 2274 | + return $this->query(IInstanceFactory::class); |
|
| 2275 | + } |
|
| 2276 | + |
|
| 2277 | + /** |
|
| 2278 | + * @return IStorageFactory |
|
| 2279 | + * @deprecated |
|
| 2280 | + */ |
|
| 2281 | + public function getStorageFactory() { |
|
| 2282 | + return $this->query(IStorageFactory::class); |
|
| 2283 | + } |
|
| 2284 | + |
|
| 2285 | + /** |
|
| 2286 | + * Get the Preview GeneratorHelper |
|
| 2287 | + * |
|
| 2288 | + * @return GeneratorHelper |
|
| 2289 | + * @since 17.0.0 |
|
| 2290 | + * @deprecated |
|
| 2291 | + */ |
|
| 2292 | + public function getGeneratorHelper() { |
|
| 2293 | + return $this->query(\OC\Preview\GeneratorHelper::class); |
|
| 2294 | + } |
|
| 2295 | + |
|
| 2296 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2297 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2298 | + try { |
|
| 2299 | + /** @var ILogger $logger */ |
|
| 2300 | + $logger = $container->get(ILogger::class); |
|
| 2301 | + $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2302 | + } catch (ContainerExceptionInterface $e) { |
|
| 2303 | + // Could not get logger. Continue |
|
| 2304 | + } |
|
| 2305 | + |
|
| 2306 | + return $container->get($target); |
|
| 2307 | + }, false); |
|
| 2308 | + } |
|
| 2309 | 2309 | } |
@@ -258,10 +258,10 @@ discard block |
||
| 258 | 258 | $this->registerParameter('isCLI', \OC::$CLI); |
| 259 | 259 | $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
| 260 | 260 | |
| 261 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 261 | + $this->registerService(ContainerInterface::class, function(ContainerInterface $c) { |
|
| 262 | 262 | return $c; |
| 263 | 263 | }); |
| 264 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 264 | + $this->registerService(\OCP\IServerContainer::class, function(ContainerInterface $c) { |
|
| 265 | 265 | return $c; |
| 266 | 266 | }); |
| 267 | 267 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
| 287 | 287 | |
| 288 | 288 | |
| 289 | - $this->registerService(IPreview::class, function (Server $c) { |
|
| 289 | + $this->registerService(IPreview::class, function(Server $c) { |
|
| 290 | 290 | return new PreviewManager( |
| 291 | 291 | $c->getConfig(), |
| 292 | 292 | $c->getRootFolder(), |
@@ -299,13 +299,13 @@ discard block |
||
| 299 | 299 | /** @deprecated 19.0.0 */ |
| 300 | 300 | $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
| 301 | 301 | |
| 302 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 302 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
| 303 | 303 | return new \OC\Preview\Watcher( |
| 304 | 304 | new \OC\Preview\Storage\Root($c->getRootFolder(), $c->getSystemConfig()) |
| 305 | 305 | ); |
| 306 | 306 | }); |
| 307 | 307 | |
| 308 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 308 | + $this->registerService(\OCP\Encryption\IManager::class, function(Server $c) { |
|
| 309 | 309 | $view = new View(); |
| 310 | 310 | $util = new Encryption\Util( |
| 311 | 311 | $view, |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | /** @deprecated 19.0.0 */ |
| 326 | 326 | $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
| 327 | 327 | |
| 328 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 328 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
| 329 | 329 | $util = new Encryption\Util( |
| 330 | 330 | new View(), |
| 331 | 331 | $c->getUserManager(), |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | ); |
| 340 | 340 | }); |
| 341 | 341 | |
| 342 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 342 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
| 343 | 343 | $view = new View(); |
| 344 | 344 | $util = new Encryption\Util( |
| 345 | 345 | $view, |
@@ -357,21 +357,21 @@ discard block |
||
| 357 | 357 | /** @deprecated 19.0.0 */ |
| 358 | 358 | $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
| 359 | 359 | |
| 360 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 360 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
| 361 | 361 | $config = $c->getConfig(); |
| 362 | 362 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
| 363 | 363 | return new $factoryClass($this); |
| 364 | 364 | }); |
| 365 | - $this->registerService(ISystemTagManager::class, function (Server $c) { |
|
| 365 | + $this->registerService(ISystemTagManager::class, function(Server $c) { |
|
| 366 | 366 | return $c->query('SystemTagManagerFactory')->getManager(); |
| 367 | 367 | }); |
| 368 | 368 | /** @deprecated 19.0.0 */ |
| 369 | 369 | $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
| 370 | 370 | |
| 371 | - $this->registerService(ISystemTagObjectMapper::class, function (Server $c) { |
|
| 371 | + $this->registerService(ISystemTagObjectMapper::class, function(Server $c) { |
|
| 372 | 372 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
| 373 | 373 | }); |
| 374 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 374 | + $this->registerService('RootFolder', function(Server $c) { |
|
| 375 | 375 | $manager = \OC\Files\Filesystem::getMountManager(null); |
| 376 | 376 | $view = new View(); |
| 377 | 377 | $root = new Root( |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | return $root; |
| 390 | 390 | }); |
| 391 | - $this->registerService(HookConnector::class, function (Server $c) { |
|
| 391 | + $this->registerService(HookConnector::class, function(Server $c) { |
|
| 392 | 392 | return new HookConnector( |
| 393 | 393 | $c->query(IRootFolder::class), |
| 394 | 394 | new View(), |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | /** @deprecated 19.0.0 */ |
| 401 | 401 | $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
| 402 | 402 | |
| 403 | - $this->registerService(IRootFolder::class, function (Server $c) { |
|
| 404 | - return new LazyRoot(function () use ($c) { |
|
| 403 | + $this->registerService(IRootFolder::class, function(Server $c) { |
|
| 404 | + return new LazyRoot(function() use ($c) { |
|
| 405 | 405 | return $c->query('RootFolder'); |
| 406 | 406 | }); |
| 407 | 407 | }); |
@@ -412,44 +412,44 @@ discard block |
||
| 412 | 412 | $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
| 413 | 413 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
| 414 | 414 | |
| 415 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 415 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
| 416 | 416 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
| 417 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 417 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
| 418 | 418 | \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]); |
| 419 | 419 | |
| 420 | 420 | /** @var IEventDispatcher $dispatcher */ |
| 421 | 421 | $dispatcher = $this->query(IEventDispatcher::class); |
| 422 | 422 | $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
| 423 | 423 | }); |
| 424 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 424 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $group) { |
|
| 425 | 425 | \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $group->getGID()]); |
| 426 | 426 | |
| 427 | 427 | /** @var IEventDispatcher $dispatcher */ |
| 428 | 428 | $dispatcher = $this->query(IEventDispatcher::class); |
| 429 | 429 | $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
| 430 | 430 | }); |
| 431 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 431 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
| 432 | 432 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]); |
| 433 | 433 | |
| 434 | 434 | /** @var IEventDispatcher $dispatcher */ |
| 435 | 435 | $dispatcher = $this->query(IEventDispatcher::class); |
| 436 | 436 | $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
| 437 | 437 | }); |
| 438 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 438 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
| 439 | 439 | \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]); |
| 440 | 440 | |
| 441 | 441 | /** @var IEventDispatcher $dispatcher */ |
| 442 | 442 | $dispatcher = $this->query(IEventDispatcher::class); |
| 443 | 443 | $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
| 444 | 444 | }); |
| 445 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 445 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 446 | 446 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]); |
| 447 | 447 | |
| 448 | 448 | /** @var IEventDispatcher $dispatcher */ |
| 449 | 449 | $dispatcher = $this->query(IEventDispatcher::class); |
| 450 | 450 | $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
| 451 | 451 | }); |
| 452 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 452 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 453 | 453 | \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
| 454 | 454 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
| 455 | 455 | \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
@@ -458,12 +458,12 @@ discard block |
||
| 458 | 458 | $dispatcher = $this->query(IEventDispatcher::class); |
| 459 | 459 | $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
| 460 | 460 | }); |
| 461 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 461 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 462 | 462 | /** @var IEventDispatcher $dispatcher */ |
| 463 | 463 | $dispatcher = $this->query(IEventDispatcher::class); |
| 464 | 464 | $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
| 465 | 465 | }); |
| 466 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 466 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 467 | 467 | /** @var IEventDispatcher $dispatcher */ |
| 468 | 468 | $dispatcher = $this->query(IEventDispatcher::class); |
| 469 | 469 | $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | /** @deprecated 19.0.0 */ |
| 474 | 474 | $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
| 475 | 475 | |
| 476 | - $this->registerService(Store::class, function (Server $c) { |
|
| 476 | + $this->registerService(Store::class, function(Server $c) { |
|
| 477 | 477 | $session = $c->getSession(); |
| 478 | 478 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
| 479 | 479 | $tokenProvider = $c->query(IProvider::class); |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | $this->registerAlias(IStore::class, Store::class); |
| 487 | 487 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
| 488 | 488 | |
| 489 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 489 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
| 490 | 490 | $manager = $c->getUserManager(); |
| 491 | 491 | $session = new \OC\Session\Memory(''); |
| 492 | 492 | $timeFactory = new TimeFactory(); |
@@ -511,14 +511,14 @@ discard block |
||
| 511 | 511 | $c->getLogger(), |
| 512 | 512 | $c->query(IEventDispatcher::class) |
| 513 | 513 | ); |
| 514 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 514 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 515 | 515 | \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
| 516 | 516 | |
| 517 | 517 | /** @var IEventDispatcher $dispatcher */ |
| 518 | 518 | $dispatcher = $this->query(IEventDispatcher::class); |
| 519 | 519 | $dispatcher->dispatchTyped(new BeforeUserCreatedEvent($uid, $password)); |
| 520 | 520 | }); |
| 521 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 521 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 522 | 522 | /** @var \OC\User\User $user */ |
| 523 | 523 | \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
| 524 | 524 | |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | $dispatcher = $this->query(IEventDispatcher::class); |
| 527 | 527 | $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password)); |
| 528 | 528 | }); |
| 529 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 529 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($legacyDispatcher) { |
|
| 530 | 530 | /** @var \OC\User\User $user */ |
| 531 | 531 | \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
| 532 | 532 | $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | $dispatcher = $this->query(IEventDispatcher::class); |
| 536 | 536 | $dispatcher->dispatchTyped(new BeforeUserDeletedEvent($user)); |
| 537 | 537 | }); |
| 538 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 538 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 539 | 539 | /** @var \OC\User\User $user */ |
| 540 | 540 | \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
| 541 | 541 | |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | $dispatcher = $this->query(IEventDispatcher::class); |
| 544 | 544 | $dispatcher->dispatchTyped(new UserDeletedEvent($user)); |
| 545 | 545 | }); |
| 546 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 546 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 547 | 547 | /** @var \OC\User\User $user */ |
| 548 | 548 | \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
| 549 | 549 | |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | $dispatcher = $this->query(IEventDispatcher::class); |
| 552 | 552 | $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
| 553 | 553 | }); |
| 554 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 554 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 555 | 555 | /** @var \OC\User\User $user */ |
| 556 | 556 | \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
| 557 | 557 | |
@@ -559,14 +559,14 @@ discard block |
||
| 559 | 559 | $dispatcher = $this->query(IEventDispatcher::class); |
| 560 | 560 | $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
| 561 | 561 | }); |
| 562 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 562 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 563 | 563 | \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
| 564 | 564 | |
| 565 | 565 | /** @var IEventDispatcher $dispatcher */ |
| 566 | 566 | $dispatcher = $this->query(IEventDispatcher::class); |
| 567 | 567 | $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
| 568 | 568 | }); |
| 569 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
| 569 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password, $isTokenLogin) { |
|
| 570 | 570 | /** @var \OC\User\User $user */ |
| 571 | 571 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
| 572 | 572 | |
@@ -574,12 +574,12 @@ discard block |
||
| 574 | 574 | $dispatcher = $this->query(IEventDispatcher::class); |
| 575 | 575 | $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $password, $isTokenLogin)); |
| 576 | 576 | }); |
| 577 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 577 | + $userSession->listen('\OC\User', 'preRememberedLogin', function($uid) { |
|
| 578 | 578 | /** @var IEventDispatcher $dispatcher */ |
| 579 | 579 | $dispatcher = $this->query(IEventDispatcher::class); |
| 580 | 580 | $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
| 581 | 581 | }); |
| 582 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 582 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
| 583 | 583 | /** @var \OC\User\User $user */ |
| 584 | 584 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
| 585 | 585 | |
@@ -587,19 +587,19 @@ discard block |
||
| 587 | 587 | $dispatcher = $this->query(IEventDispatcher::class); |
| 588 | 588 | $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
| 589 | 589 | }); |
| 590 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 590 | + $userSession->listen('\OC\User', 'logout', function($user) { |
|
| 591 | 591 | \OC_Hook::emit('OC_User', 'logout', []); |
| 592 | 592 | |
| 593 | 593 | /** @var IEventDispatcher $dispatcher */ |
| 594 | 594 | $dispatcher = $this->query(IEventDispatcher::class); |
| 595 | 595 | $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
| 596 | 596 | }); |
| 597 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 597 | + $userSession->listen('\OC\User', 'postLogout', function($user) { |
|
| 598 | 598 | /** @var IEventDispatcher $dispatcher */ |
| 599 | 599 | $dispatcher = $this->query(IEventDispatcher::class); |
| 600 | 600 | $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
| 601 | 601 | }); |
| 602 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 602 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
| 603 | 603 | /** @var \OC\User\User $user */ |
| 604 | 604 | \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
| 605 | 605 | |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
| 624 | 624 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 625 | 625 | |
| 626 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 626 | + $this->registerService(\OC\SystemConfig::class, function($c) use ($config) { |
|
| 627 | 627 | return new \OC\SystemConfig($config); |
| 628 | 628 | }); |
| 629 | 629 | /** @deprecated 19.0.0 */ |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
| 634 | 634 | $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
| 635 | 635 | |
| 636 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 636 | + $this->registerService(IFactory::class, function(Server $c) { |
|
| 637 | 637 | return new \OC\L10N\Factory( |
| 638 | 638 | $c->getConfig(), |
| 639 | 639 | $c->getRequest(), |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | /** @deprecated 19.0.0 */ |
| 645 | 645 | $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
| 646 | 646 | |
| 647 | - $this->registerService(IURLGenerator::class, function (Server $c) { |
|
| 647 | + $this->registerService(IURLGenerator::class, function(Server $c) { |
|
| 648 | 648 | $config = $c->getConfig(); |
| 649 | 649 | $cacheFactory = $c->getMemCacheFactory(); |
| 650 | 650 | $request = $c->getRequest(); |
@@ -662,13 +662,13 @@ discard block |
||
| 662 | 662 | /** @deprecated 19.0.0 */ |
| 663 | 663 | $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
| 664 | 664 | |
| 665 | - $this->registerService(ICache::class, function ($c) { |
|
| 665 | + $this->registerService(ICache::class, function($c) { |
|
| 666 | 666 | return new Cache\File(); |
| 667 | 667 | }); |
| 668 | 668 | /** @deprecated 19.0.0 */ |
| 669 | 669 | $this->registerDeprecatedAlias('UserCache', ICache::class); |
| 670 | 670 | |
| 671 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 671 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 672 | 672 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
| 673 | 673 | ArrayCache::class, |
| 674 | 674 | ArrayCache::class, |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | $version = implode(',', $v); |
| 683 | 683 | $instanceId = \OC_Util::getInstanceId(); |
| 684 | 684 | $path = \OC::$SERVERROOT; |
| 685 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 685 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
| 686 | 686 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
| 687 | 687 | $config->getSystemValue('memcache.local', null), |
| 688 | 688 | $config->getSystemValue('memcache.distributed', null), |
@@ -695,12 +695,12 @@ discard block |
||
| 695 | 695 | $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
| 696 | 696 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 697 | 697 | |
| 698 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 698 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 699 | 699 | $systemConfig = $c->getSystemConfig(); |
| 700 | 700 | return new RedisFactory($systemConfig); |
| 701 | 701 | }); |
| 702 | 702 | |
| 703 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 703 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 704 | 704 | $l10n = $this->get(IFactory::class)->get('activity'); |
| 705 | 705 | return new \OC\Activity\Manager( |
| 706 | 706 | $c->getRequest(), |
@@ -713,14 +713,14 @@ discard block |
||
| 713 | 713 | /** @deprecated 19.0.0 */ |
| 714 | 714 | $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
| 715 | 715 | |
| 716 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 716 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 717 | 717 | return new \OC\Activity\EventMerger( |
| 718 | 718 | $c->getL10N('lib') |
| 719 | 719 | ); |
| 720 | 720 | }); |
| 721 | 721 | $this->registerAlias(IValidator::class, Validator::class); |
| 722 | 722 | |
| 723 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 723 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
| 724 | 724 | return new AvatarManager( |
| 725 | 725 | $c->query(\OC\User\Manager::class), |
| 726 | 726 | $c->getAppDataDir('avatar'), |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
| 737 | 737 | $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
| 738 | 738 | |
| 739 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 739 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
| 740 | 740 | $logType = $c->query(AllConfig::class)->getSystemValue('log_type', 'file'); |
| 741 | 741 | $factory = new LogFactory($c, $this->getSystemConfig()); |
| 742 | 742 | $logger = $factory->get($logType); |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | // PSR-3 logger |
| 751 | 751 | $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
| 752 | 752 | |
| 753 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 753 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
| 754 | 754 | return new LogFactory($c, $this->getSystemConfig()); |
| 755 | 755 | }); |
| 756 | 756 | |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | /** @deprecated 19.0.0 */ |
| 759 | 759 | $this->registerDeprecatedAlias('JobList', IJobList::class); |
| 760 | 760 | |
| 761 | - $this->registerService(IRouter::class, function (Server $c) { |
|
| 761 | + $this->registerService(IRouter::class, function(Server $c) { |
|
| 762 | 762 | $cacheFactory = $c->getMemCacheFactory(); |
| 763 | 763 | $logger = $c->getLogger(); |
| 764 | 764 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | /** @deprecated 19.0.0 */ |
| 776 | 776 | $this->registerDeprecatedAlias('Search', ISearch::class); |
| 777 | 777 | |
| 778 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 778 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 779 | 779 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
| 780 | 780 | $this->getMemCacheFactory(), |
| 781 | 781 | new \OC\AppFramework\Utility\TimeFactory() |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | /** @deprecated 19.0.0 */ |
| 799 | 799 | $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
| 800 | 800 | |
| 801 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 801 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
| 802 | 802 | $systemConfig = $c->getSystemConfig(); |
| 803 | 803 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
| 804 | 804 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -814,7 +814,7 @@ discard block |
||
| 814 | 814 | $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
| 815 | 815 | |
| 816 | 816 | |
| 817 | - $this->registerService(IClientService::class, function (Server $c) { |
|
| 817 | + $this->registerService(IClientService::class, function(Server $c) { |
|
| 818 | 818 | $user = \OC_User::getUser(); |
| 819 | 819 | $uid = $user ? $user : null; |
| 820 | 820 | return new ClientService( |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | }); |
| 832 | 832 | /** @deprecated 19.0.0 */ |
| 833 | 833 | $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
| 834 | - $this->registerService(IEventLogger::class, function (Server $c) { |
|
| 834 | + $this->registerService(IEventLogger::class, function(Server $c) { |
|
| 835 | 835 | $eventLogger = new EventLogger(); |
| 836 | 836 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 837 | 837 | // In debug mode, module is being activated by default |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | /** @deprecated 19.0.0 */ |
| 843 | 843 | $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
| 844 | 844 | |
| 845 | - $this->registerService(IQueryLogger::class, function (Server $c) { |
|
| 845 | + $this->registerService(IQueryLogger::class, function(Server $c) { |
|
| 846 | 846 | $queryLogger = new QueryLogger(); |
| 847 | 847 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 848 | 848 | // In debug mode, module is being activated by default |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | $this->registerDeprecatedAlias('TempManager', TempManager::class); |
| 858 | 858 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 859 | 859 | |
| 860 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 860 | + $this->registerService(AppManager::class, function(Server $c) { |
|
| 861 | 861 | return new \OC\App\AppManager( |
| 862 | 862 | $c->getUserSession(), |
| 863 | 863 | $c->getConfig(), |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | /** @deprecated 19.0.0 */ |
| 877 | 877 | $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
| 878 | 878 | |
| 879 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 879 | + $this->registerService(IDateTimeFormatter::class, function(Server $c) { |
|
| 880 | 880 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
| 881 | 881 | |
| 882 | 882 | return new DateTimeFormatter( |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | /** @deprecated 19.0.0 */ |
| 888 | 888 | $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
| 889 | 889 | |
| 890 | - $this->registerService(IUserMountCache::class, function (Server $c) { |
|
| 890 | + $this->registerService(IUserMountCache::class, function(Server $c) { |
|
| 891 | 891 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
| 892 | 892 | $listener = new UserMountCacheListener($mountCache); |
| 893 | 893 | $listener->listen($c->getUserManager()); |
@@ -896,7 +896,7 @@ discard block |
||
| 896 | 896 | /** @deprecated 19.0.0 */ |
| 897 | 897 | $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
| 898 | 898 | |
| 899 | - $this->registerService(IMountProviderCollection::class, function (Server $c) { |
|
| 899 | + $this->registerService(IMountProviderCollection::class, function(Server $c) { |
|
| 900 | 900 | $loader = \OC\Files\Filesystem::getLoader(); |
| 901 | 901 | $mountCache = $c->query(IUserMountCache::class); |
| 902 | 902 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | |
| 918 | 918 | /** @deprecated 20.0.0 */ |
| 919 | 919 | $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
| 920 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 920 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
| 921 | 921 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
| 922 | 922 | if ($busClass) { |
| 923 | 923 | [$app, $class] = explode('::', $busClass, 2); |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
| 938 | 938 | /** @deprecated 19.0.0 */ |
| 939 | 939 | $this->registerDeprecatedAlias('Throttler', Throttler::class); |
| 940 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 940 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
| 941 | 941 | // IConfig and IAppManager requires a working database. This code |
| 942 | 942 | // might however be called when ownCloud is not yet setup. |
| 943 | 943 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | $c->getMimeTypeDetector() |
| 960 | 960 | ); |
| 961 | 961 | }); |
| 962 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 962 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
| 963 | 963 | if (isset($this['urlParams'])) { |
| 964 | 964 | $urlParams = $this['urlParams']; |
| 965 | 965 | } else { |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | /** @deprecated 19.0.0 */ |
| 997 | 997 | $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
| 998 | 998 | |
| 999 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 999 | + $this->registerService(IMailer::class, function(Server $c) { |
|
| 1000 | 1000 | return new Mailer( |
| 1001 | 1001 | $c->getConfig(), |
| 1002 | 1002 | $c->getLogger(), |
@@ -1010,7 +1010,7 @@ discard block |
||
| 1010 | 1010 | /** @deprecated 19.0.0 */ |
| 1011 | 1011 | $this->registerDeprecatedAlias('Mailer', IMailer::class); |
| 1012 | 1012 | |
| 1013 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 1013 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
| 1014 | 1014 | $config = $c->getConfig(); |
| 1015 | 1015 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 1016 | 1016 | if (is_null($factoryClass)) { |
@@ -1020,7 +1020,7 @@ discard block |
||
| 1020 | 1020 | $factory = new $factoryClass($this); |
| 1021 | 1021 | return $factory->getLDAPProvider(); |
| 1022 | 1022 | }); |
| 1023 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 1023 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
| 1024 | 1024 | $ini = $c->getIniWrapper(); |
| 1025 | 1025 | $config = $c->getConfig(); |
| 1026 | 1026 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -1048,12 +1048,12 @@ discard block |
||
| 1048 | 1048 | /** @deprecated 19.0.0 */ |
| 1049 | 1049 | $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
| 1050 | 1050 | |
| 1051 | - $this->registerService(IMimeTypeDetector::class, function (Server $c) { |
|
| 1051 | + $this->registerService(IMimeTypeDetector::class, function(Server $c) { |
|
| 1052 | 1052 | return new \OC\Files\Type\Detection( |
| 1053 | 1053 | $c->getURLGenerator(), |
| 1054 | 1054 | $c->getLogger(), |
| 1055 | 1055 | \OC::$configDir, |
| 1056 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 1056 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 1057 | 1057 | ); |
| 1058 | 1058 | }); |
| 1059 | 1059 | /** @deprecated 19.0.0 */ |
@@ -1062,19 +1062,19 @@ discard block |
||
| 1062 | 1062 | $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
| 1063 | 1063 | /** @deprecated 19.0.0 */ |
| 1064 | 1064 | $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
| 1065 | - $this->registerService(BundleFetcher::class, function () { |
|
| 1065 | + $this->registerService(BundleFetcher::class, function() { |
|
| 1066 | 1066 | return new BundleFetcher($this->getL10N('lib')); |
| 1067 | 1067 | }); |
| 1068 | 1068 | $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
| 1069 | 1069 | /** @deprecated 19.0.0 */ |
| 1070 | 1070 | $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
| 1071 | 1071 | |
| 1072 | - $this->registerService(CapabilitiesManager::class, function (Server $c) { |
|
| 1072 | + $this->registerService(CapabilitiesManager::class, function(Server $c) { |
|
| 1073 | 1073 | $manager = new CapabilitiesManager($c->getLogger()); |
| 1074 | - $manager->registerCapability(function () use ($c) { |
|
| 1074 | + $manager->registerCapability(function() use ($c) { |
|
| 1075 | 1075 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
| 1076 | 1076 | }); |
| 1077 | - $manager->registerCapability(function () use ($c) { |
|
| 1077 | + $manager->registerCapability(function() use ($c) { |
|
| 1078 | 1078 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
| 1079 | 1079 | }); |
| 1080 | 1080 | return $manager; |
@@ -1082,14 +1082,14 @@ discard block |
||
| 1082 | 1082 | /** @deprecated 19.0.0 */ |
| 1083 | 1083 | $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
| 1084 | 1084 | |
| 1085 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1085 | + $this->registerService(ICommentsManager::class, function(Server $c) { |
|
| 1086 | 1086 | $config = $c->getConfig(); |
| 1087 | 1087 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
| 1088 | 1088 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
| 1089 | 1089 | $factory = new $factoryClass($this); |
| 1090 | 1090 | $manager = $factory->getManager(); |
| 1091 | 1091 | |
| 1092 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1092 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
| 1093 | 1093 | $manager = $c->getUserManager(); |
| 1094 | 1094 | $user = $manager->get($id); |
| 1095 | 1095 | if (is_null($user)) { |
@@ -1107,7 +1107,7 @@ discard block |
||
| 1107 | 1107 | $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
| 1108 | 1108 | |
| 1109 | 1109 | $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
| 1110 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1110 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 1111 | 1111 | /* |
| 1112 | 1112 | * Dark magic for autoloader. |
| 1113 | 1113 | * If we do a class_exists it will try to load the class which will |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | } |
| 1136 | 1136 | return new \OC_Defaults(); |
| 1137 | 1137 | }); |
| 1138 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1138 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
| 1139 | 1139 | return new JSCombiner( |
| 1140 | 1140 | $c->getAppDataDir('js'), |
| 1141 | 1141 | $c->getURLGenerator(), |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
| 1150 | 1150 | $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
| 1151 | 1151 | |
| 1152 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 1152 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
| 1153 | 1153 | // FIXME: Instantiiated here due to cyclic dependency |
| 1154 | 1154 | $request = new Request( |
| 1155 | 1155 | [ |
@@ -1176,14 +1176,14 @@ discard block |
||
| 1176 | 1176 | }); |
| 1177 | 1177 | /** @deprecated 19.0.0 */ |
| 1178 | 1178 | $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
| 1179 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1179 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
| 1180 | 1180 | return new SessionStorage($c->getSession()); |
| 1181 | 1181 | }); |
| 1182 | 1182 | $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
| 1183 | 1183 | /** @deprecated 19.0.0 */ |
| 1184 | 1184 | $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
| 1185 | 1185 | |
| 1186 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1186 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
| 1187 | 1187 | $config = $c->getConfig(); |
| 1188 | 1188 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
| 1189 | 1189 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1213,7 +1213,7 @@ discard block |
||
| 1213 | 1213 | /** @deprecated 19.0.0 */ |
| 1214 | 1214 | $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
| 1215 | 1215 | |
| 1216 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1216 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
| 1217 | 1217 | $instance = new Collaboration\Collaborators\Search($c); |
| 1218 | 1218 | |
| 1219 | 1219 | // register default plugins |
@@ -1234,7 +1234,7 @@ discard block |
||
| 1234 | 1234 | $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
| 1235 | 1235 | $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
| 1236 | 1236 | |
| 1237 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 1237 | + $this->registerService('SettingsManager', function(Server $c) { |
|
| 1238 | 1238 | $manager = new \OC\Settings\Manager( |
| 1239 | 1239 | $c->getLogger(), |
| 1240 | 1240 | $c->getL10NFactory(), |
@@ -1243,34 +1243,34 @@ discard block |
||
| 1243 | 1243 | ); |
| 1244 | 1244 | return $manager; |
| 1245 | 1245 | }); |
| 1246 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1246 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
| 1247 | 1247 | return new \OC\Files\AppData\Factory( |
| 1248 | 1248 | $c->getRootFolder(), |
| 1249 | 1249 | $c->getSystemConfig() |
| 1250 | 1250 | ); |
| 1251 | 1251 | }); |
| 1252 | 1252 | |
| 1253 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1254 | - return new LockdownManager(function () use ($c) { |
|
| 1253 | + $this->registerService('LockdownManager', function(Server $c) { |
|
| 1254 | + return new LockdownManager(function() use ($c) { |
|
| 1255 | 1255 | return $c->getSession(); |
| 1256 | 1256 | }); |
| 1257 | 1257 | }); |
| 1258 | 1258 | |
| 1259 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1259 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
| 1260 | 1260 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
| 1261 | 1261 | }); |
| 1262 | 1262 | |
| 1263 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1263 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
| 1264 | 1264 | return new CloudIdManager(); |
| 1265 | 1265 | }); |
| 1266 | 1266 | |
| 1267 | 1267 | $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
| 1268 | 1268 | |
| 1269 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
| 1269 | + $this->registerService(ICloudFederationProviderManager::class, function(Server $c) { |
|
| 1270 | 1270 | return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
| 1271 | 1271 | }); |
| 1272 | 1272 | |
| 1273 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1273 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
| 1274 | 1274 | return new CloudFederationFactory(); |
| 1275 | 1275 | }); |
| 1276 | 1276 | |
@@ -1282,7 +1282,7 @@ discard block |
||
| 1282 | 1282 | /** @deprecated 19.0.0 */ |
| 1283 | 1283 | $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1284 | 1284 | |
| 1285 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1285 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1286 | 1286 | return new Defaults( |
| 1287 | 1287 | $c->getThemingDefaults() |
| 1288 | 1288 | ); |
@@ -1290,17 +1290,17 @@ discard block |
||
| 1290 | 1290 | /** @deprecated 19.0.0 */ |
| 1291 | 1291 | $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
| 1292 | 1292 | |
| 1293 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1293 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
| 1294 | 1294 | return $c->query(\OCP\IUserSession::class)->getSession(); |
| 1295 | 1295 | }); |
| 1296 | 1296 | |
| 1297 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1297 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
| 1298 | 1298 | return new ShareHelper( |
| 1299 | 1299 | $c->query(\OCP\Share\IManager::class) |
| 1300 | 1300 | ); |
| 1301 | 1301 | }); |
| 1302 | 1302 | |
| 1303 | - $this->registerService(Installer::class, function (Server $c) { |
|
| 1303 | + $this->registerService(Installer::class, function(Server $c) { |
|
| 1304 | 1304 | return new Installer( |
| 1305 | 1305 | $c->getAppFetcher(), |
| 1306 | 1306 | $c->getHTTPClientService(), |
@@ -1311,11 +1311,11 @@ discard block |
||
| 1311 | 1311 | ); |
| 1312 | 1312 | }); |
| 1313 | 1313 | |
| 1314 | - $this->registerService(IApiFactory::class, function (Server $c) { |
|
| 1314 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
| 1315 | 1315 | return new ApiFactory($c->getHTTPClientService()); |
| 1316 | 1316 | }); |
| 1317 | 1317 | |
| 1318 | - $this->registerService(IInstanceFactory::class, function (Server $c) { |
|
| 1318 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
| 1319 | 1319 | $memcacheFactory = $c->getMemCacheFactory(); |
| 1320 | 1320 | return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
| 1321 | 1321 | }); |
@@ -1372,7 +1372,7 @@ discard block |
||
| 1372 | 1372 | $dispatcher = $this->getEventDispatcher(); |
| 1373 | 1373 | |
| 1374 | 1374 | // Delete avatar on user deletion |
| 1375 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1375 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
| 1376 | 1376 | $logger = $this->getLogger(); |
| 1377 | 1377 | $manager = $this->getAvatarManager(); |
| 1378 | 1378 | /** @var IUser $user */ |
@@ -1385,11 +1385,11 @@ discard block |
||
| 1385 | 1385 | // no avatar to remove |
| 1386 | 1386 | } catch (\Exception $e) { |
| 1387 | 1387 | // Ignore exceptions |
| 1388 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1388 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
| 1389 | 1389 | } |
| 1390 | 1390 | }); |
| 1391 | 1391 | |
| 1392 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1392 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
| 1393 | 1393 | $manager = $this->getAvatarManager(); |
| 1394 | 1394 | /** @var IUser $user */ |
| 1395 | 1395 | $user = $e->getSubject(); |
@@ -2294,11 +2294,11 @@ discard block |
||
| 2294 | 2294 | } |
| 2295 | 2295 | |
| 2296 | 2296 | private function registerDeprecatedAlias(string $alias, string $target) { |
| 2297 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2297 | + $this->registerService($alias, function(ContainerInterface $container) use ($target, $alias) { |
|
| 2298 | 2298 | try { |
| 2299 | 2299 | /** @var ILogger $logger */ |
| 2300 | 2300 | $logger = $container->get(ILogger::class); |
| 2301 | - $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2301 | + $logger->debug('The requested alias "'.$alias.'" is depreacted. Please request "'.$target.'" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2302 | 2302 | } catch (ContainerExceptionInterface $e) { |
| 2303 | 2303 | // Could not get logger. Continue |
| 2304 | 2304 | } |
@@ -44,389 +44,389 @@ |
||
| 44 | 44 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 45 | 45 | |
| 46 | 46 | class PreviewManager implements IPreview { |
| 47 | - /** @var IConfig */ |
|
| 48 | - protected $config; |
|
| 47 | + /** @var IConfig */ |
|
| 48 | + protected $config; |
|
| 49 | 49 | |
| 50 | - /** @var IRootFolder */ |
|
| 51 | - protected $rootFolder; |
|
| 50 | + /** @var IRootFolder */ |
|
| 51 | + protected $rootFolder; |
|
| 52 | 52 | |
| 53 | - /** @var IAppData */ |
|
| 54 | - protected $appData; |
|
| 53 | + /** @var IAppData */ |
|
| 54 | + protected $appData; |
|
| 55 | 55 | |
| 56 | - /** @var EventDispatcherInterface */ |
|
| 57 | - protected $eventDispatcher; |
|
| 56 | + /** @var EventDispatcherInterface */ |
|
| 57 | + protected $eventDispatcher; |
|
| 58 | 58 | |
| 59 | - /** @var Generator */ |
|
| 60 | - private $generator; |
|
| 59 | + /** @var Generator */ |
|
| 60 | + private $generator; |
|
| 61 | 61 | |
| 62 | - /** @var GeneratorHelper */ |
|
| 63 | - private $helper; |
|
| 64 | - |
|
| 65 | - /** @var bool */ |
|
| 66 | - protected $providerListDirty = false; |
|
| 67 | - |
|
| 68 | - /** @var bool */ |
|
| 69 | - protected $registeredCoreProviders = false; |
|
| 70 | - |
|
| 71 | - /** @var array */ |
|
| 72 | - protected $providers = []; |
|
| 73 | - |
|
| 74 | - /** @var array mime type => support status */ |
|
| 75 | - protected $mimeTypeSupportMap = []; |
|
| 76 | - |
|
| 77 | - /** @var array */ |
|
| 78 | - protected $defaultProviders; |
|
| 79 | - |
|
| 80 | - /** @var string */ |
|
| 81 | - protected $userId; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * PreviewManager constructor. |
|
| 85 | - * |
|
| 86 | - * @param IConfig $config |
|
| 87 | - * @param IRootFolder $rootFolder |
|
| 88 | - * @param IAppData $appData |
|
| 89 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 90 | - * @param string $userId |
|
| 91 | - */ |
|
| 92 | - public function __construct(IConfig $config, |
|
| 93 | - IRootFolder $rootFolder, |
|
| 94 | - IAppData $appData, |
|
| 95 | - EventDispatcherInterface $eventDispatcher, |
|
| 96 | - GeneratorHelper $helper, |
|
| 97 | - $userId) { |
|
| 98 | - $this->config = $config; |
|
| 99 | - $this->rootFolder = $rootFolder; |
|
| 100 | - $this->appData = $appData; |
|
| 101 | - $this->eventDispatcher = $eventDispatcher; |
|
| 102 | - $this->helper = $helper; |
|
| 103 | - $this->userId = $userId; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * In order to improve lazy loading a closure can be registered which will be |
|
| 108 | - * called in case preview providers are actually requested |
|
| 109 | - * |
|
| 110 | - * $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2 |
|
| 111 | - * |
|
| 112 | - * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
| 113 | - * @param \Closure $callable |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - public function registerProvider($mimeTypeRegex, \Closure $callable) { |
|
| 117 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 118 | - return; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if (!isset($this->providers[$mimeTypeRegex])) { |
|
| 122 | - $this->providers[$mimeTypeRegex] = []; |
|
| 123 | - } |
|
| 124 | - $this->providers[$mimeTypeRegex][] = $callable; |
|
| 125 | - $this->providerListDirty = true; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Get all providers |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - public function getProviders() { |
|
| 133 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 134 | - return []; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $this->registerCoreProviders(); |
|
| 138 | - if ($this->providerListDirty) { |
|
| 139 | - $keys = array_map('strlen', array_keys($this->providers)); |
|
| 140 | - array_multisort($keys, SORT_DESC, $this->providers); |
|
| 141 | - $this->providerListDirty = false; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $this->providers; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Does the manager have any providers |
|
| 149 | - * @return bool |
|
| 150 | - */ |
|
| 151 | - public function hasProviders() { |
|
| 152 | - $this->registerCoreProviders(); |
|
| 153 | - return !empty($this->providers); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - private function getGenerator(): Generator { |
|
| 157 | - if ($this->generator === null) { |
|
| 158 | - $this->generator = new Generator( |
|
| 159 | - $this->config, |
|
| 160 | - $this, |
|
| 161 | - $this->appData, |
|
| 162 | - new GeneratorHelper( |
|
| 163 | - $this->rootFolder, |
|
| 164 | - $this->config |
|
| 165 | - ), |
|
| 166 | - $this->eventDispatcher |
|
| 167 | - ); |
|
| 168 | - } |
|
| 169 | - return $this->generator; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Returns a preview of a file |
|
| 174 | - * |
|
| 175 | - * The cache is searched first and if nothing usable was found then a preview is |
|
| 176 | - * generated by one of the providers |
|
| 177 | - * |
|
| 178 | - * @param File $file |
|
| 179 | - * @param int $width |
|
| 180 | - * @param int $height |
|
| 181 | - * @param bool $crop |
|
| 182 | - * @param string $mode |
|
| 183 | - * @param string $mimeType |
|
| 184 | - * @return ISimpleFile |
|
| 185 | - * @throws NotFoundException |
|
| 186 | - * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 187 | - * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
| 188 | - */ |
|
| 189 | - public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { |
|
| 190 | - return $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Generates previews of a file |
|
| 195 | - * |
|
| 196 | - * @param File $file |
|
| 197 | - * @param array $specifications |
|
| 198 | - * @param string $mimeType |
|
| 199 | - * @return ISimpleFile the last preview that was generated |
|
| 200 | - * @throws NotFoundException |
|
| 201 | - * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 202 | - * @since 19.0.0 |
|
| 203 | - */ |
|
| 204 | - public function generatePreviews(File $file, array $specifications, $mimeType = null) { |
|
| 205 | - return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * returns true if the passed mime type is supported |
|
| 210 | - * |
|
| 211 | - * @param string $mimeType |
|
| 212 | - * @return boolean |
|
| 213 | - */ |
|
| 214 | - public function isMimeSupported($mimeType = '*') { |
|
| 215 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 216 | - return false; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if (isset($this->mimeTypeSupportMap[$mimeType])) { |
|
| 220 | - return $this->mimeTypeSupportMap[$mimeType]; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $this->registerCoreProviders(); |
|
| 224 | - $providerMimeTypes = array_keys($this->providers); |
|
| 225 | - foreach ($providerMimeTypes as $supportedMimeType) { |
|
| 226 | - if (preg_match($supportedMimeType, $mimeType)) { |
|
| 227 | - $this->mimeTypeSupportMap[$mimeType] = true; |
|
| 228 | - return true; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - $this->mimeTypeSupportMap[$mimeType] = false; |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Check if a preview can be generated for a file |
|
| 237 | - * |
|
| 238 | - * @param \OCP\Files\FileInfo $file |
|
| 239 | - * @return bool |
|
| 240 | - */ |
|
| 241 | - public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 242 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $this->registerCoreProviders(); |
|
| 247 | - if (!$this->isMimeSupported($file->getMimetype())) { |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $mount = $file->getMountPoint(); |
|
| 252 | - if ($mount and !$mount->getOption('previews', true)) { |
|
| 253 | - return false; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - foreach ($this->providers as $supportedMimeType => $providers) { |
|
| 257 | - if (preg_match($supportedMimeType, $file->getMimetype())) { |
|
| 258 | - foreach ($providers as $providerClosure) { |
|
| 259 | - $provider = $this->helper->getProvider($providerClosure); |
|
| 260 | - if (!($provider instanceof IProviderV2)) { |
|
| 261 | - continue; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if ($provider->isAvailable($file)) { |
|
| 265 | - return true; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - return false; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * List of enabled default providers |
|
| 275 | - * |
|
| 276 | - * The following providers are enabled by default: |
|
| 277 | - * - OC\Preview\PNG |
|
| 278 | - * - OC\Preview\JPEG |
|
| 279 | - * - OC\Preview\GIF |
|
| 280 | - * - OC\Preview\BMP |
|
| 281 | - * - OC\Preview\HEIC |
|
| 282 | - * - OC\Preview\XBitmap |
|
| 283 | - * - OC\Preview\MarkDown |
|
| 284 | - * - OC\Preview\MP3 |
|
| 285 | - * - OC\Preview\TXT |
|
| 286 | - * |
|
| 287 | - * The following providers are disabled by default due to performance or privacy concerns: |
|
| 288 | - * - OC\Preview\Font |
|
| 289 | - * - OC\Preview\Illustrator |
|
| 290 | - * - OC\Preview\Movie |
|
| 291 | - * - OC\Preview\MSOfficeDoc |
|
| 292 | - * - OC\Preview\MSOffice2003 |
|
| 293 | - * - OC\Preview\MSOffice2007 |
|
| 294 | - * - OC\Preview\OpenDocument |
|
| 295 | - * - OC\Preview\PDF |
|
| 296 | - * - OC\Preview\Photoshop |
|
| 297 | - * - OC\Preview\Postscript |
|
| 298 | - * - OC\Preview\StarOffice |
|
| 299 | - * - OC\Preview\SVG |
|
| 300 | - * - OC\Preview\TIFF |
|
| 301 | - * |
|
| 302 | - * @return array |
|
| 303 | - */ |
|
| 304 | - protected function getEnabledDefaultProvider() { |
|
| 305 | - if ($this->defaultProviders !== null) { |
|
| 306 | - return $this->defaultProviders; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $imageProviders = [ |
|
| 310 | - Preview\PNG::class, |
|
| 311 | - Preview\JPEG::class, |
|
| 312 | - Preview\GIF::class, |
|
| 313 | - Preview\BMP::class, |
|
| 314 | - Preview\HEIC::class, |
|
| 315 | - Preview\XBitmap::class, |
|
| 316 | - Preview\Krita::class, |
|
| 317 | - ]; |
|
| 318 | - |
|
| 319 | - $this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([ |
|
| 320 | - Preview\MarkDown::class, |
|
| 321 | - Preview\MP3::class, |
|
| 322 | - Preview\TXT::class, |
|
| 323 | - Preview\OpenDocument::class, |
|
| 324 | - ], $imageProviders)); |
|
| 325 | - |
|
| 326 | - if (in_array(Preview\Image::class, $this->defaultProviders)) { |
|
| 327 | - $this->defaultProviders = array_merge($this->defaultProviders, $imageProviders); |
|
| 328 | - } |
|
| 329 | - $this->defaultProviders = array_unique($this->defaultProviders); |
|
| 330 | - return $this->defaultProviders; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Register the default providers (if enabled) |
|
| 335 | - * |
|
| 336 | - * @param string $class |
|
| 337 | - * @param string $mimeType |
|
| 338 | - */ |
|
| 339 | - protected function registerCoreProvider($class, $mimeType, $options = []) { |
|
| 340 | - if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
| 341 | - $this->registerProvider($mimeType, function () use ($class, $options) { |
|
| 342 | - return new $class($options); |
|
| 343 | - }); |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Register the default providers (if enabled) |
|
| 349 | - */ |
|
| 350 | - protected function registerCoreProviders() { |
|
| 351 | - if ($this->registeredCoreProviders) { |
|
| 352 | - return; |
|
| 353 | - } |
|
| 354 | - $this->registeredCoreProviders = true; |
|
| 355 | - |
|
| 356 | - $this->registerCoreProvider(Preview\TXT::class, '/text\/plain/'); |
|
| 357 | - $this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/'); |
|
| 358 | - $this->registerCoreProvider(Preview\PNG::class, '/image\/png/'); |
|
| 359 | - $this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/'); |
|
| 360 | - $this->registerCoreProvider(Preview\GIF::class, '/image\/gif/'); |
|
| 361 | - $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/'); |
|
| 362 | - $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/'); |
|
| 363 | - $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/'); |
|
| 364 | - $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/'); |
|
| 365 | - $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
| 366 | - |
|
| 367 | - // SVG, Office and Bitmap require imagick |
|
| 368 | - if (extension_loaded('imagick')) { |
|
| 369 | - $checkImagick = new \Imagick(); |
|
| 370 | - |
|
| 371 | - $imagickProviders = [ |
|
| 372 | - 'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class], |
|
| 373 | - 'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class], |
|
| 374 | - 'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class], |
|
| 375 | - 'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class], |
|
| 376 | - 'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class], |
|
| 377 | - 'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class], |
|
| 378 | - 'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class], |
|
| 379 | - 'HEIC' => ['mimetype' => '/image\/hei(f|c)/', 'class' => Preview\HEIC::class], |
|
| 380 | - ]; |
|
| 381 | - |
|
| 382 | - foreach ($imagickProviders as $queryFormat => $provider) { |
|
| 383 | - $class = $provider['class']; |
|
| 384 | - if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
| 385 | - continue; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if (count($checkImagick->queryFormats($queryFormat)) === 1) { |
|
| 389 | - $this->registerCoreProvider($class, $provider['mimetype']); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (count($checkImagick->queryFormats('PDF')) === 1) { |
|
| 394 | - if (\OC_Helper::is_function_enabled('shell_exec')) { |
|
| 395 | - $officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null)); |
|
| 396 | - |
|
| 397 | - if (!$officeFound) { |
|
| 398 | - //let's see if there is libreoffice or openoffice on this machine |
|
| 399 | - $whichLibreOffice = shell_exec('command -v libreoffice'); |
|
| 400 | - $officeFound = !empty($whichLibreOffice); |
|
| 401 | - if (!$officeFound) { |
|
| 402 | - $whichOpenOffice = shell_exec('command -v openoffice'); |
|
| 403 | - $officeFound = !empty($whichOpenOffice); |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - if ($officeFound) { |
|
| 408 | - $this->registerCoreProvider(Preview\MSOfficeDoc::class, '/application\/msword/'); |
|
| 409 | - $this->registerCoreProvider(Preview\MSOffice2003::class, '/application\/vnd.ms-.*/'); |
|
| 410 | - $this->registerCoreProvider(Preview\MSOffice2007::class, '/application\/vnd.openxmlformats-officedocument.*/'); |
|
| 411 | - $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
| 412 | - $this->registerCoreProvider(Preview\StarOffice::class, '/application\/vnd.sun.xml.*/'); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // Video requires avconv or ffmpeg |
|
| 419 | - if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) { |
|
| 420 | - $avconvBinary = \OC_Helper::findBinaryPath('avconv'); |
|
| 421 | - $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg'); |
|
| 422 | - |
|
| 423 | - if ($avconvBinary || $ffmpegBinary) { |
|
| 424 | - // FIXME // a bit hacky but didn't want to use subclasses |
|
| 425 | - \OC\Preview\Movie::$avconvBinary = $avconvBinary; |
|
| 426 | - \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; |
|
| 427 | - |
|
| 428 | - $this->registerCoreProvider(Preview\Movie::class, '/video\/.*/'); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 62 | + /** @var GeneratorHelper */ |
|
| 63 | + private $helper; |
|
| 64 | + |
|
| 65 | + /** @var bool */ |
|
| 66 | + protected $providerListDirty = false; |
|
| 67 | + |
|
| 68 | + /** @var bool */ |
|
| 69 | + protected $registeredCoreProviders = false; |
|
| 70 | + |
|
| 71 | + /** @var array */ |
|
| 72 | + protected $providers = []; |
|
| 73 | + |
|
| 74 | + /** @var array mime type => support status */ |
|
| 75 | + protected $mimeTypeSupportMap = []; |
|
| 76 | + |
|
| 77 | + /** @var array */ |
|
| 78 | + protected $defaultProviders; |
|
| 79 | + |
|
| 80 | + /** @var string */ |
|
| 81 | + protected $userId; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * PreviewManager constructor. |
|
| 85 | + * |
|
| 86 | + * @param IConfig $config |
|
| 87 | + * @param IRootFolder $rootFolder |
|
| 88 | + * @param IAppData $appData |
|
| 89 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 90 | + * @param string $userId |
|
| 91 | + */ |
|
| 92 | + public function __construct(IConfig $config, |
|
| 93 | + IRootFolder $rootFolder, |
|
| 94 | + IAppData $appData, |
|
| 95 | + EventDispatcherInterface $eventDispatcher, |
|
| 96 | + GeneratorHelper $helper, |
|
| 97 | + $userId) { |
|
| 98 | + $this->config = $config; |
|
| 99 | + $this->rootFolder = $rootFolder; |
|
| 100 | + $this->appData = $appData; |
|
| 101 | + $this->eventDispatcher = $eventDispatcher; |
|
| 102 | + $this->helper = $helper; |
|
| 103 | + $this->userId = $userId; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * In order to improve lazy loading a closure can be registered which will be |
|
| 108 | + * called in case preview providers are actually requested |
|
| 109 | + * |
|
| 110 | + * $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2 |
|
| 111 | + * |
|
| 112 | + * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
| 113 | + * @param \Closure $callable |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + public function registerProvider($mimeTypeRegex, \Closure $callable) { |
|
| 117 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if (!isset($this->providers[$mimeTypeRegex])) { |
|
| 122 | + $this->providers[$mimeTypeRegex] = []; |
|
| 123 | + } |
|
| 124 | + $this->providers[$mimeTypeRegex][] = $callable; |
|
| 125 | + $this->providerListDirty = true; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Get all providers |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + public function getProviders() { |
|
| 133 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 134 | + return []; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $this->registerCoreProviders(); |
|
| 138 | + if ($this->providerListDirty) { |
|
| 139 | + $keys = array_map('strlen', array_keys($this->providers)); |
|
| 140 | + array_multisort($keys, SORT_DESC, $this->providers); |
|
| 141 | + $this->providerListDirty = false; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $this->providers; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Does the manager have any providers |
|
| 149 | + * @return bool |
|
| 150 | + */ |
|
| 151 | + public function hasProviders() { |
|
| 152 | + $this->registerCoreProviders(); |
|
| 153 | + return !empty($this->providers); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + private function getGenerator(): Generator { |
|
| 157 | + if ($this->generator === null) { |
|
| 158 | + $this->generator = new Generator( |
|
| 159 | + $this->config, |
|
| 160 | + $this, |
|
| 161 | + $this->appData, |
|
| 162 | + new GeneratorHelper( |
|
| 163 | + $this->rootFolder, |
|
| 164 | + $this->config |
|
| 165 | + ), |
|
| 166 | + $this->eventDispatcher |
|
| 167 | + ); |
|
| 168 | + } |
|
| 169 | + return $this->generator; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Returns a preview of a file |
|
| 174 | + * |
|
| 175 | + * The cache is searched first and if nothing usable was found then a preview is |
|
| 176 | + * generated by one of the providers |
|
| 177 | + * |
|
| 178 | + * @param File $file |
|
| 179 | + * @param int $width |
|
| 180 | + * @param int $height |
|
| 181 | + * @param bool $crop |
|
| 182 | + * @param string $mode |
|
| 183 | + * @param string $mimeType |
|
| 184 | + * @return ISimpleFile |
|
| 185 | + * @throws NotFoundException |
|
| 186 | + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 187 | + * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
| 188 | + */ |
|
| 189 | + public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { |
|
| 190 | + return $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Generates previews of a file |
|
| 195 | + * |
|
| 196 | + * @param File $file |
|
| 197 | + * @param array $specifications |
|
| 198 | + * @param string $mimeType |
|
| 199 | + * @return ISimpleFile the last preview that was generated |
|
| 200 | + * @throws NotFoundException |
|
| 201 | + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 202 | + * @since 19.0.0 |
|
| 203 | + */ |
|
| 204 | + public function generatePreviews(File $file, array $specifications, $mimeType = null) { |
|
| 205 | + return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * returns true if the passed mime type is supported |
|
| 210 | + * |
|
| 211 | + * @param string $mimeType |
|
| 212 | + * @return boolean |
|
| 213 | + */ |
|
| 214 | + public function isMimeSupported($mimeType = '*') { |
|
| 215 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if (isset($this->mimeTypeSupportMap[$mimeType])) { |
|
| 220 | + return $this->mimeTypeSupportMap[$mimeType]; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $this->registerCoreProviders(); |
|
| 224 | + $providerMimeTypes = array_keys($this->providers); |
|
| 225 | + foreach ($providerMimeTypes as $supportedMimeType) { |
|
| 226 | + if (preg_match($supportedMimeType, $mimeType)) { |
|
| 227 | + $this->mimeTypeSupportMap[$mimeType] = true; |
|
| 228 | + return true; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + $this->mimeTypeSupportMap[$mimeType] = false; |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Check if a preview can be generated for a file |
|
| 237 | + * |
|
| 238 | + * @param \OCP\Files\FileInfo $file |
|
| 239 | + * @return bool |
|
| 240 | + */ |
|
| 241 | + public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 242 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $this->registerCoreProviders(); |
|
| 247 | + if (!$this->isMimeSupported($file->getMimetype())) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $mount = $file->getMountPoint(); |
|
| 252 | + if ($mount and !$mount->getOption('previews', true)) { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + foreach ($this->providers as $supportedMimeType => $providers) { |
|
| 257 | + if (preg_match($supportedMimeType, $file->getMimetype())) { |
|
| 258 | + foreach ($providers as $providerClosure) { |
|
| 259 | + $provider = $this->helper->getProvider($providerClosure); |
|
| 260 | + if (!($provider instanceof IProviderV2)) { |
|
| 261 | + continue; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if ($provider->isAvailable($file)) { |
|
| 265 | + return true; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + return false; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * List of enabled default providers |
|
| 275 | + * |
|
| 276 | + * The following providers are enabled by default: |
|
| 277 | + * - OC\Preview\PNG |
|
| 278 | + * - OC\Preview\JPEG |
|
| 279 | + * - OC\Preview\GIF |
|
| 280 | + * - OC\Preview\BMP |
|
| 281 | + * - OC\Preview\HEIC |
|
| 282 | + * - OC\Preview\XBitmap |
|
| 283 | + * - OC\Preview\MarkDown |
|
| 284 | + * - OC\Preview\MP3 |
|
| 285 | + * - OC\Preview\TXT |
|
| 286 | + * |
|
| 287 | + * The following providers are disabled by default due to performance or privacy concerns: |
|
| 288 | + * - OC\Preview\Font |
|
| 289 | + * - OC\Preview\Illustrator |
|
| 290 | + * - OC\Preview\Movie |
|
| 291 | + * - OC\Preview\MSOfficeDoc |
|
| 292 | + * - OC\Preview\MSOffice2003 |
|
| 293 | + * - OC\Preview\MSOffice2007 |
|
| 294 | + * - OC\Preview\OpenDocument |
|
| 295 | + * - OC\Preview\PDF |
|
| 296 | + * - OC\Preview\Photoshop |
|
| 297 | + * - OC\Preview\Postscript |
|
| 298 | + * - OC\Preview\StarOffice |
|
| 299 | + * - OC\Preview\SVG |
|
| 300 | + * - OC\Preview\TIFF |
|
| 301 | + * |
|
| 302 | + * @return array |
|
| 303 | + */ |
|
| 304 | + protected function getEnabledDefaultProvider() { |
|
| 305 | + if ($this->defaultProviders !== null) { |
|
| 306 | + return $this->defaultProviders; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $imageProviders = [ |
|
| 310 | + Preview\PNG::class, |
|
| 311 | + Preview\JPEG::class, |
|
| 312 | + Preview\GIF::class, |
|
| 313 | + Preview\BMP::class, |
|
| 314 | + Preview\HEIC::class, |
|
| 315 | + Preview\XBitmap::class, |
|
| 316 | + Preview\Krita::class, |
|
| 317 | + ]; |
|
| 318 | + |
|
| 319 | + $this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([ |
|
| 320 | + Preview\MarkDown::class, |
|
| 321 | + Preview\MP3::class, |
|
| 322 | + Preview\TXT::class, |
|
| 323 | + Preview\OpenDocument::class, |
|
| 324 | + ], $imageProviders)); |
|
| 325 | + |
|
| 326 | + if (in_array(Preview\Image::class, $this->defaultProviders)) { |
|
| 327 | + $this->defaultProviders = array_merge($this->defaultProviders, $imageProviders); |
|
| 328 | + } |
|
| 329 | + $this->defaultProviders = array_unique($this->defaultProviders); |
|
| 330 | + return $this->defaultProviders; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Register the default providers (if enabled) |
|
| 335 | + * |
|
| 336 | + * @param string $class |
|
| 337 | + * @param string $mimeType |
|
| 338 | + */ |
|
| 339 | + protected function registerCoreProvider($class, $mimeType, $options = []) { |
|
| 340 | + if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
| 341 | + $this->registerProvider($mimeType, function () use ($class, $options) { |
|
| 342 | + return new $class($options); |
|
| 343 | + }); |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Register the default providers (if enabled) |
|
| 349 | + */ |
|
| 350 | + protected function registerCoreProviders() { |
|
| 351 | + if ($this->registeredCoreProviders) { |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | + $this->registeredCoreProviders = true; |
|
| 355 | + |
|
| 356 | + $this->registerCoreProvider(Preview\TXT::class, '/text\/plain/'); |
|
| 357 | + $this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/'); |
|
| 358 | + $this->registerCoreProvider(Preview\PNG::class, '/image\/png/'); |
|
| 359 | + $this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/'); |
|
| 360 | + $this->registerCoreProvider(Preview\GIF::class, '/image\/gif/'); |
|
| 361 | + $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/'); |
|
| 362 | + $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/'); |
|
| 363 | + $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/'); |
|
| 364 | + $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/'); |
|
| 365 | + $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
| 366 | + |
|
| 367 | + // SVG, Office and Bitmap require imagick |
|
| 368 | + if (extension_loaded('imagick')) { |
|
| 369 | + $checkImagick = new \Imagick(); |
|
| 370 | + |
|
| 371 | + $imagickProviders = [ |
|
| 372 | + 'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class], |
|
| 373 | + 'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class], |
|
| 374 | + 'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class], |
|
| 375 | + 'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class], |
|
| 376 | + 'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class], |
|
| 377 | + 'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class], |
|
| 378 | + 'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class], |
|
| 379 | + 'HEIC' => ['mimetype' => '/image\/hei(f|c)/', 'class' => Preview\HEIC::class], |
|
| 380 | + ]; |
|
| 381 | + |
|
| 382 | + foreach ($imagickProviders as $queryFormat => $provider) { |
|
| 383 | + $class = $provider['class']; |
|
| 384 | + if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
| 385 | + continue; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if (count($checkImagick->queryFormats($queryFormat)) === 1) { |
|
| 389 | + $this->registerCoreProvider($class, $provider['mimetype']); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (count($checkImagick->queryFormats('PDF')) === 1) { |
|
| 394 | + if (\OC_Helper::is_function_enabled('shell_exec')) { |
|
| 395 | + $officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null)); |
|
| 396 | + |
|
| 397 | + if (!$officeFound) { |
|
| 398 | + //let's see if there is libreoffice or openoffice on this machine |
|
| 399 | + $whichLibreOffice = shell_exec('command -v libreoffice'); |
|
| 400 | + $officeFound = !empty($whichLibreOffice); |
|
| 401 | + if (!$officeFound) { |
|
| 402 | + $whichOpenOffice = shell_exec('command -v openoffice'); |
|
| 403 | + $officeFound = !empty($whichOpenOffice); |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + if ($officeFound) { |
|
| 408 | + $this->registerCoreProvider(Preview\MSOfficeDoc::class, '/application\/msword/'); |
|
| 409 | + $this->registerCoreProvider(Preview\MSOffice2003::class, '/application\/vnd.ms-.*/'); |
|
| 410 | + $this->registerCoreProvider(Preview\MSOffice2007::class, '/application\/vnd.openxmlformats-officedocument.*/'); |
|
| 411 | + $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
| 412 | + $this->registerCoreProvider(Preview\StarOffice::class, '/application\/vnd.sun.xml.*/'); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // Video requires avconv or ffmpeg |
|
| 419 | + if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) { |
|
| 420 | + $avconvBinary = \OC_Helper::findBinaryPath('avconv'); |
|
| 421 | + $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg'); |
|
| 422 | + |
|
| 423 | + if ($avconvBinary || $ffmpegBinary) { |
|
| 424 | + // FIXME // a bit hacky but didn't want to use subclasses |
|
| 425 | + \OC\Preview\Movie::$avconvBinary = $avconvBinary; |
|
| 426 | + \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; |
|
| 427 | + |
|
| 428 | + $this->registerCoreProvider(Preview\Movie::class, '/video\/.*/'); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | 432 | } |
@@ -71,1414 +71,1414 @@ |
||
| 71 | 71 | use OCP\IUserSession; |
| 72 | 72 | |
| 73 | 73 | class OC_Util { |
| 74 | - public static $scripts = []; |
|
| 75 | - public static $styles = []; |
|
| 76 | - public static $headers = []; |
|
| 77 | - private static $rootMounted = false; |
|
| 78 | - private static $fsSetup = false; |
|
| 79 | - |
|
| 80 | - /** @var array Local cache of version.php */ |
|
| 81 | - private static $versionCache = null; |
|
| 82 | - |
|
| 83 | - protected static function getAppManager() { |
|
| 84 | - return \OC::$server->getAppManager(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - private static function initLocalStorageRootFS() { |
|
| 88 | - // mount local file backend as root |
|
| 89 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 90 | - //first set up the local "root" storage |
|
| 91 | - \OC\Files\Filesystem::initMountManager(); |
|
| 92 | - if (!self::$rootMounted) { |
|
| 93 | - \OC\Files\Filesystem::mount(LocalRootStorage::class, ['datadir' => $configDataDirectory], '/'); |
|
| 94 | - self::$rootMounted = true; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * mounting an object storage as the root fs will in essence remove the |
|
| 100 | - * necessity of a data folder being present. |
|
| 101 | - * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 102 | - * |
|
| 103 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 104 | - * @suppress PhanDeprecatedFunction |
|
| 105 | - */ |
|
| 106 | - private static function initObjectStoreRootFS($config) { |
|
| 107 | - // check misconfiguration |
|
| 108 | - if (empty($config['class'])) { |
|
| 109 | - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
| 110 | - } |
|
| 111 | - if (!isset($config['arguments'])) { |
|
| 112 | - $config['arguments'] = []; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // instantiate object store implementation |
|
| 116 | - $name = $config['class']; |
|
| 117 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 118 | - $segments = explode('\\', $name); |
|
| 119 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 120 | - } |
|
| 121 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 122 | - // mount with plain / root object store implementation |
|
| 123 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 124 | - |
|
| 125 | - // mount object storage as root |
|
| 126 | - \OC\Files\Filesystem::initMountManager(); |
|
| 127 | - if (!self::$rootMounted) { |
|
| 128 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 129 | - self::$rootMounted = true; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * mounting an object storage as the root fs will in essence remove the |
|
| 135 | - * necessity of a data folder being present. |
|
| 136 | - * |
|
| 137 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 138 | - * @suppress PhanDeprecatedFunction |
|
| 139 | - */ |
|
| 140 | - private static function initObjectStoreMultibucketRootFS($config) { |
|
| 141 | - // check misconfiguration |
|
| 142 | - if (empty($config['class'])) { |
|
| 143 | - \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
| 144 | - } |
|
| 145 | - if (!isset($config['arguments'])) { |
|
| 146 | - $config['arguments'] = []; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // instantiate object store implementation |
|
| 150 | - $name = $config['class']; |
|
| 151 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 152 | - $segments = explode('\\', $name); |
|
| 153 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if (!isset($config['arguments']['bucket'])) { |
|
| 157 | - $config['arguments']['bucket'] = ''; |
|
| 158 | - } |
|
| 159 | - // put the root FS always in first bucket for multibucket configuration |
|
| 160 | - $config['arguments']['bucket'] .= '0'; |
|
| 161 | - |
|
| 162 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 163 | - // mount with plain / root object store implementation |
|
| 164 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 165 | - |
|
| 166 | - // mount object storage as root |
|
| 167 | - \OC\Files\Filesystem::initMountManager(); |
|
| 168 | - if (!self::$rootMounted) { |
|
| 169 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 170 | - self::$rootMounted = true; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Can be set up |
|
| 176 | - * |
|
| 177 | - * @param string $user |
|
| 178 | - * @return boolean |
|
| 179 | - * @description configure the initial filesystem based on the configuration |
|
| 180 | - * @suppress PhanDeprecatedFunction |
|
| 181 | - * @suppress PhanAccessMethodInternal |
|
| 182 | - */ |
|
| 183 | - public static function setupFS($user = '') { |
|
| 184 | - //setting up the filesystem twice can only lead to trouble |
|
| 185 | - if (self::$fsSetup) { |
|
| 186 | - return false; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 190 | - |
|
| 191 | - // If we are not forced to load a specific user we load the one that is logged in |
|
| 192 | - if ($user === null) { |
|
| 193 | - $user = ''; |
|
| 194 | - } elseif ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 195 | - $user = OC_User::getUser(); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - // load all filesystem apps before, so no setup-hook gets lost |
|
| 199 | - OC_App::loadApps(['filesystem']); |
|
| 200 | - |
|
| 201 | - // the filesystem will finish when $user is not empty, |
|
| 202 | - // mark fs setup here to avoid doing the setup from loading |
|
| 203 | - // OC_Filesystem |
|
| 204 | - if ($user != '') { |
|
| 205 | - self::$fsSetup = true; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - \OC\Files\Filesystem::initMountManager(); |
|
| 209 | - |
|
| 210 | - $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 211 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 212 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 213 | - /** @var \OC\Files\Storage\Common $storage */ |
|
| 214 | - $storage->setMountOptions($mount->getOptions()); |
|
| 215 | - } |
|
| 216 | - return $storage; |
|
| 217 | - }); |
|
| 218 | - |
|
| 219 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 220 | - if (!$mount->getOption('enable_sharing', true)) { |
|
| 221 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 222 | - 'storage' => $storage, |
|
| 223 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 224 | - ]); |
|
| 225 | - } |
|
| 226 | - return $storage; |
|
| 227 | - }); |
|
| 228 | - |
|
| 229 | - // install storage availability wrapper, before most other wrappers |
|
| 230 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 231 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 232 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 233 | - } |
|
| 234 | - return $storage; |
|
| 235 | - }); |
|
| 236 | - |
|
| 237 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 238 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 239 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 240 | - } |
|
| 241 | - return $storage; |
|
| 242 | - }); |
|
| 243 | - |
|
| 244 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 245 | - // set up quota for home storages, even for other users |
|
| 246 | - // which can happen when using sharing |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @var \OC\Files\Storage\Storage $storage |
|
| 250 | - */ |
|
| 251 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 252 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 253 | - ) { |
|
| 254 | - /** @var \OC\Files\Storage\Home $storage */ |
|
| 255 | - if (is_object($storage->getUser())) { |
|
| 256 | - $quota = OC_Util::getUserQuota($storage->getUser()); |
|
| 257 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 258 | - return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - return $storage; |
|
| 264 | - }); |
|
| 265 | - |
|
| 266 | - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 267 | - /* |
|
| 74 | + public static $scripts = []; |
|
| 75 | + public static $styles = []; |
|
| 76 | + public static $headers = []; |
|
| 77 | + private static $rootMounted = false; |
|
| 78 | + private static $fsSetup = false; |
|
| 79 | + |
|
| 80 | + /** @var array Local cache of version.php */ |
|
| 81 | + private static $versionCache = null; |
|
| 82 | + |
|
| 83 | + protected static function getAppManager() { |
|
| 84 | + return \OC::$server->getAppManager(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + private static function initLocalStorageRootFS() { |
|
| 88 | + // mount local file backend as root |
|
| 89 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 90 | + //first set up the local "root" storage |
|
| 91 | + \OC\Files\Filesystem::initMountManager(); |
|
| 92 | + if (!self::$rootMounted) { |
|
| 93 | + \OC\Files\Filesystem::mount(LocalRootStorage::class, ['datadir' => $configDataDirectory], '/'); |
|
| 94 | + self::$rootMounted = true; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * mounting an object storage as the root fs will in essence remove the |
|
| 100 | + * necessity of a data folder being present. |
|
| 101 | + * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 102 | + * |
|
| 103 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 104 | + * @suppress PhanDeprecatedFunction |
|
| 105 | + */ |
|
| 106 | + private static function initObjectStoreRootFS($config) { |
|
| 107 | + // check misconfiguration |
|
| 108 | + if (empty($config['class'])) { |
|
| 109 | + \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
| 110 | + } |
|
| 111 | + if (!isset($config['arguments'])) { |
|
| 112 | + $config['arguments'] = []; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // instantiate object store implementation |
|
| 116 | + $name = $config['class']; |
|
| 117 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 118 | + $segments = explode('\\', $name); |
|
| 119 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 120 | + } |
|
| 121 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 122 | + // mount with plain / root object store implementation |
|
| 123 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 124 | + |
|
| 125 | + // mount object storage as root |
|
| 126 | + \OC\Files\Filesystem::initMountManager(); |
|
| 127 | + if (!self::$rootMounted) { |
|
| 128 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 129 | + self::$rootMounted = true; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * mounting an object storage as the root fs will in essence remove the |
|
| 135 | + * necessity of a data folder being present. |
|
| 136 | + * |
|
| 137 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 138 | + * @suppress PhanDeprecatedFunction |
|
| 139 | + */ |
|
| 140 | + private static function initObjectStoreMultibucketRootFS($config) { |
|
| 141 | + // check misconfiguration |
|
| 142 | + if (empty($config['class'])) { |
|
| 143 | + \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR); |
|
| 144 | + } |
|
| 145 | + if (!isset($config['arguments'])) { |
|
| 146 | + $config['arguments'] = []; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // instantiate object store implementation |
|
| 150 | + $name = $config['class']; |
|
| 151 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 152 | + $segments = explode('\\', $name); |
|
| 153 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if (!isset($config['arguments']['bucket'])) { |
|
| 157 | + $config['arguments']['bucket'] = ''; |
|
| 158 | + } |
|
| 159 | + // put the root FS always in first bucket for multibucket configuration |
|
| 160 | + $config['arguments']['bucket'] .= '0'; |
|
| 161 | + |
|
| 162 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 163 | + // mount with plain / root object store implementation |
|
| 164 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 165 | + |
|
| 166 | + // mount object storage as root |
|
| 167 | + \OC\Files\Filesystem::initMountManager(); |
|
| 168 | + if (!self::$rootMounted) { |
|
| 169 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 170 | + self::$rootMounted = true; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Can be set up |
|
| 176 | + * |
|
| 177 | + * @param string $user |
|
| 178 | + * @return boolean |
|
| 179 | + * @description configure the initial filesystem based on the configuration |
|
| 180 | + * @suppress PhanDeprecatedFunction |
|
| 181 | + * @suppress PhanAccessMethodInternal |
|
| 182 | + */ |
|
| 183 | + public static function setupFS($user = '') { |
|
| 184 | + //setting up the filesystem twice can only lead to trouble |
|
| 185 | + if (self::$fsSetup) { |
|
| 186 | + return false; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 190 | + |
|
| 191 | + // If we are not forced to load a specific user we load the one that is logged in |
|
| 192 | + if ($user === null) { |
|
| 193 | + $user = ''; |
|
| 194 | + } elseif ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 195 | + $user = OC_User::getUser(); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + // load all filesystem apps before, so no setup-hook gets lost |
|
| 199 | + OC_App::loadApps(['filesystem']); |
|
| 200 | + |
|
| 201 | + // the filesystem will finish when $user is not empty, |
|
| 202 | + // mark fs setup here to avoid doing the setup from loading |
|
| 203 | + // OC_Filesystem |
|
| 204 | + if ($user != '') { |
|
| 205 | + self::$fsSetup = true; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + \OC\Files\Filesystem::initMountManager(); |
|
| 209 | + |
|
| 210 | + $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 211 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 212 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 213 | + /** @var \OC\Files\Storage\Common $storage */ |
|
| 214 | + $storage->setMountOptions($mount->getOptions()); |
|
| 215 | + } |
|
| 216 | + return $storage; |
|
| 217 | + }); |
|
| 218 | + |
|
| 219 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 220 | + if (!$mount->getOption('enable_sharing', true)) { |
|
| 221 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 222 | + 'storage' => $storage, |
|
| 223 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 224 | + ]); |
|
| 225 | + } |
|
| 226 | + return $storage; |
|
| 227 | + }); |
|
| 228 | + |
|
| 229 | + // install storage availability wrapper, before most other wrappers |
|
| 230 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 231 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 232 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 233 | + } |
|
| 234 | + return $storage; |
|
| 235 | + }); |
|
| 236 | + |
|
| 237 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 238 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 239 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 240 | + } |
|
| 241 | + return $storage; |
|
| 242 | + }); |
|
| 243 | + |
|
| 244 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 245 | + // set up quota for home storages, even for other users |
|
| 246 | + // which can happen when using sharing |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @var \OC\Files\Storage\Storage $storage |
|
| 250 | + */ |
|
| 251 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 252 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 253 | + ) { |
|
| 254 | + /** @var \OC\Files\Storage\Home $storage */ |
|
| 255 | + if (is_object($storage->getUser())) { |
|
| 256 | + $quota = OC_Util::getUserQuota($storage->getUser()); |
|
| 257 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 258 | + return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + return $storage; |
|
| 264 | + }); |
|
| 265 | + |
|
| 266 | + \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 267 | + /* |
|
| 268 | 268 | * Do not allow any operations that modify the storage |
| 269 | 269 | */ |
| 270 | - if ($mount->getOption('readonly', false)) { |
|
| 271 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 272 | - 'storage' => $storage, |
|
| 273 | - 'mask' => \OCP\Constants::PERMISSION_ALL & ~( |
|
| 274 | - \OCP\Constants::PERMISSION_UPDATE | |
|
| 275 | - \OCP\Constants::PERMISSION_CREATE | |
|
| 276 | - \OCP\Constants::PERMISSION_DELETE |
|
| 277 | - ), |
|
| 278 | - ]); |
|
| 279 | - } |
|
| 280 | - return $storage; |
|
| 281 | - }); |
|
| 282 | - |
|
| 283 | - OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]); |
|
| 284 | - |
|
| 285 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
| 286 | - |
|
| 287 | - //check if we are using an object storage |
|
| 288 | - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 289 | - $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
| 290 | - |
|
| 291 | - // use the same order as in ObjectHomeMountProvider |
|
| 292 | - if (isset($objectStoreMultibucket)) { |
|
| 293 | - self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
| 294 | - } elseif (isset($objectStore)) { |
|
| 295 | - self::initObjectStoreRootFS($objectStore); |
|
| 296 | - } else { |
|
| 297 | - self::initLocalStorageRootFS(); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */ |
|
| 301 | - $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class); |
|
| 302 | - /** @var \OCP\Files\Mount\IMountPoint[] $rootMountProviders */ |
|
| 303 | - $rootMountProviders = $mountProviderCollection->getRootMounts(); |
|
| 304 | - |
|
| 305 | - /** @var \OC\Files\Mount\Manager $mountManager */ |
|
| 306 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 307 | - foreach ($rootMountProviders as $rootMountProvider) { |
|
| 308 | - $mountManager->addMount($rootMountProvider); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { |
|
| 312 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - //if we aren't logged in, there is no use to set up the filesystem |
|
| 317 | - if ($user != "") { |
|
| 318 | - $userDir = '/' . $user . '/files'; |
|
| 319 | - |
|
| 320 | - //jail the user into his "home" directory |
|
| 321 | - \OC\Files\Filesystem::init($user, $userDir); |
|
| 322 | - |
|
| 323 | - OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user, 'user_dir' => $userDir]); |
|
| 324 | - } |
|
| 325 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 326 | - return true; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * check if a password is required for each public link |
|
| 331 | - * |
|
| 332 | - * @return boolean |
|
| 333 | - * @suppress PhanDeprecatedFunction |
|
| 334 | - */ |
|
| 335 | - public static function isPublicLinkPasswordRequired() { |
|
| 336 | - $enforcePassword = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 337 | - return $enforcePassword === 'yes'; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * check if sharing is disabled for the current user |
|
| 342 | - * @param IConfig $config |
|
| 343 | - * @param IGroupManager $groupManager |
|
| 344 | - * @param IUser|null $user |
|
| 345 | - * @return bool |
|
| 346 | - */ |
|
| 347 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 348 | - if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 349 | - $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 350 | - $excludedGroups = json_decode($groupsList); |
|
| 351 | - if (is_null($excludedGroups)) { |
|
| 352 | - $excludedGroups = explode(',', $groupsList); |
|
| 353 | - $newValue = json_encode($excludedGroups); |
|
| 354 | - $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 355 | - } |
|
| 356 | - $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 357 | - if (!empty($usersGroups)) { |
|
| 358 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 359 | - // if the user is only in groups which are disabled for sharing then |
|
| 360 | - // sharing is also disabled for the user |
|
| 361 | - if (empty($remainingGroups)) { |
|
| 362 | - return true; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - return false; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * check if share API enforces a default expire date |
|
| 371 | - * |
|
| 372 | - * @return boolean |
|
| 373 | - * @suppress PhanDeprecatedFunction |
|
| 374 | - */ |
|
| 375 | - public static function isDefaultExpireDateEnforced() { |
|
| 376 | - $isDefaultExpireDateEnabled = \OC::$server->getConfig()->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 377 | - $enforceDefaultExpireDate = false; |
|
| 378 | - if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 379 | - $value = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 380 | - $enforceDefaultExpireDate = $value === 'yes'; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return $enforceDefaultExpireDate; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Get the quota of a user |
|
| 388 | - * |
|
| 389 | - * @param IUser|null $user |
|
| 390 | - * @return float Quota bytes |
|
| 391 | - */ |
|
| 392 | - public static function getUserQuota(?IUser $user) { |
|
| 393 | - if (is_null($user)) { |
|
| 394 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 395 | - } |
|
| 396 | - $userQuota = $user->getQuota(); |
|
| 397 | - if ($userQuota === 'none') { |
|
| 398 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 399 | - } |
|
| 400 | - return OC_Helper::computerFileSize($userQuota); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * copies the skeleton to the users /files |
|
| 405 | - * |
|
| 406 | - * @param string $userId |
|
| 407 | - * @param \OCP\Files\Folder $userDirectory |
|
| 408 | - * @throws \OCP\Files\NotFoundException |
|
| 409 | - * @throws \OCP\Files\NotPermittedException |
|
| 410 | - * @suppress PhanDeprecatedFunction |
|
| 411 | - */ |
|
| 412 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 413 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 414 | - $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 415 | - $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
| 416 | - |
|
| 417 | - if (!file_exists($skeletonDirectory)) { |
|
| 418 | - $dialectStart = strpos($userLang, '_'); |
|
| 419 | - if ($dialectStart !== false) { |
|
| 420 | - $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
| 421 | - } |
|
| 422 | - if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
| 423 | - $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
| 424 | - } |
|
| 425 | - if (!file_exists($skeletonDirectory)) { |
|
| 426 | - $skeletonDirectory = ''; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 431 | - |
|
| 432 | - if ($instanceId === null) { |
|
| 433 | - throw new \RuntimeException('no instance id!'); |
|
| 434 | - } |
|
| 435 | - $appdata = 'appdata_' . $instanceId; |
|
| 436 | - if ($userId === $appdata) { |
|
| 437 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - if (!empty($skeletonDirectory)) { |
|
| 441 | - \OCP\Util::writeLog( |
|
| 442 | - 'files_skeleton', |
|
| 443 | - 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 444 | - ILogger::DEBUG |
|
| 445 | - ); |
|
| 446 | - self::copyr($skeletonDirectory, $userDirectory); |
|
| 447 | - // update the file cache |
|
| 448 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * copies a directory recursively by using streams |
|
| 454 | - * |
|
| 455 | - * @param string $source |
|
| 456 | - * @param \OCP\Files\Folder $target |
|
| 457 | - * @return void |
|
| 458 | - */ |
|
| 459 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 460 | - $logger = \OC::$server->getLogger(); |
|
| 461 | - |
|
| 462 | - // Verify if folder exists |
|
| 463 | - $dir = opendir($source); |
|
| 464 | - if ($dir === false) { |
|
| 465 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 466 | - return; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - // Copy the files |
|
| 470 | - while (false !== ($file = readdir($dir))) { |
|
| 471 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 472 | - if (is_dir($source . '/' . $file)) { |
|
| 473 | - $child = $target->newFolder($file); |
|
| 474 | - self::copyr($source . '/' . $file, $child); |
|
| 475 | - } else { |
|
| 476 | - $child = $target->newFile($file); |
|
| 477 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 478 | - if ($sourceStream === false) { |
|
| 479 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 480 | - closedir($dir); |
|
| 481 | - return; |
|
| 482 | - } |
|
| 483 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - closedir($dir); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * @return void |
|
| 492 | - * @suppress PhanUndeclaredMethod |
|
| 493 | - */ |
|
| 494 | - public static function tearDownFS() { |
|
| 495 | - \OC\Files\Filesystem::tearDown(); |
|
| 496 | - \OC::$server->getRootFolder()->clearCache(); |
|
| 497 | - self::$fsSetup = false; |
|
| 498 | - self::$rootMounted = false; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * get the current installed version of ownCloud |
|
| 503 | - * |
|
| 504 | - * @return array |
|
| 505 | - */ |
|
| 506 | - public static function getVersion() { |
|
| 507 | - OC_Util::loadVersion(); |
|
| 508 | - return self::$versionCache['OC_Version']; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * get the current installed version string of ownCloud |
|
| 513 | - * |
|
| 514 | - * @return string |
|
| 515 | - */ |
|
| 516 | - public static function getVersionString() { |
|
| 517 | - OC_Util::loadVersion(); |
|
| 518 | - return self::$versionCache['OC_VersionString']; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @deprecated the value is of no use anymore |
|
| 523 | - * @return string |
|
| 524 | - */ |
|
| 525 | - public static function getEditionString() { |
|
| 526 | - return ''; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * @description get the update channel of the current installed of ownCloud. |
|
| 531 | - * @return string |
|
| 532 | - */ |
|
| 533 | - public static function getChannel() { |
|
| 534 | - OC_Util::loadVersion(); |
|
| 535 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @description get the build number of the current installed of ownCloud. |
|
| 540 | - * @return string |
|
| 541 | - */ |
|
| 542 | - public static function getBuild() { |
|
| 543 | - OC_Util::loadVersion(); |
|
| 544 | - return self::$versionCache['OC_Build']; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * @description load the version.php into the session as cache |
|
| 549 | - * @suppress PhanUndeclaredVariable |
|
| 550 | - */ |
|
| 551 | - private static function loadVersion() { |
|
| 552 | - if (self::$versionCache !== null) { |
|
| 553 | - return; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 557 | - require OC::$SERVERROOT . '/version.php'; |
|
| 558 | - /** @var int $timestamp */ |
|
| 559 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 560 | - /** @var string $OC_Version */ |
|
| 561 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
| 562 | - /** @var string $OC_VersionString */ |
|
| 563 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 564 | - /** @var string $OC_Build */ |
|
| 565 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
| 566 | - |
|
| 567 | - /** @var string $OC_Channel */ |
|
| 568 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 573 | - * |
|
| 574 | - * @param string $application application to get the files from |
|
| 575 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 576 | - * @param string $file the file inside of the above folder |
|
| 577 | - * @return string the path |
|
| 578 | - */ |
|
| 579 | - private static function generatePath($application, $directory, $file) { |
|
| 580 | - if (is_null($file)) { |
|
| 581 | - $file = $application; |
|
| 582 | - $application = ""; |
|
| 583 | - } |
|
| 584 | - if (!empty($application)) { |
|
| 585 | - return "$application/$directory/$file"; |
|
| 586 | - } else { |
|
| 587 | - return "$directory/$file"; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * add a javascript file |
|
| 593 | - * |
|
| 594 | - * @param string $application application id |
|
| 595 | - * @param string|null $file filename |
|
| 596 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 597 | - * @return void |
|
| 598 | - */ |
|
| 599 | - public static function addScript($application, $file = null, $prepend = false) { |
|
| 600 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
| 601 | - |
|
| 602 | - // core js files need separate handling |
|
| 603 | - if ($application !== 'core' && $file !== null) { |
|
| 604 | - self::addTranslations($application); |
|
| 605 | - } |
|
| 606 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * add a javascript file from the vendor sub folder |
|
| 611 | - * |
|
| 612 | - * @param string $application application id |
|
| 613 | - * @param string|null $file filename |
|
| 614 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 615 | - * @return void |
|
| 616 | - */ |
|
| 617 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 618 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 619 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * add a translation JS file |
|
| 624 | - * |
|
| 625 | - * @param string $application application id |
|
| 626 | - * @param string|null $languageCode language code, defaults to the current language |
|
| 627 | - * @param bool|null $prepend prepend the Script to the beginning of the list |
|
| 628 | - */ |
|
| 629 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 630 | - if (is_null($languageCode)) { |
|
| 631 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 632 | - } |
|
| 633 | - if (!empty($application)) { |
|
| 634 | - $path = "$application/l10n/$languageCode"; |
|
| 635 | - } else { |
|
| 636 | - $path = "l10n/$languageCode"; |
|
| 637 | - } |
|
| 638 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * add a css file |
|
| 643 | - * |
|
| 644 | - * @param string $application application id |
|
| 645 | - * @param string|null $file filename |
|
| 646 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 647 | - * @return void |
|
| 648 | - */ |
|
| 649 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
| 650 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
| 651 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * add a css file from the vendor sub folder |
|
| 656 | - * |
|
| 657 | - * @param string $application application id |
|
| 658 | - * @param string|null $file filename |
|
| 659 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 660 | - * @return void |
|
| 661 | - */ |
|
| 662 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 663 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 664 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * add an external resource css/js file |
|
| 669 | - * |
|
| 670 | - * @param string $application application id |
|
| 671 | - * @param bool $prepend prepend the file to the beginning of the list |
|
| 672 | - * @param string $path |
|
| 673 | - * @param string $type (script or style) |
|
| 674 | - * @return void |
|
| 675 | - */ |
|
| 676 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 677 | - if ($type === "style") { |
|
| 678 | - if (!in_array($path, self::$styles)) { |
|
| 679 | - if ($prepend === true) { |
|
| 680 | - array_unshift(self::$styles, $path); |
|
| 681 | - } else { |
|
| 682 | - self::$styles[] = $path; |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - } elseif ($type === "script") { |
|
| 686 | - if (!in_array($path, self::$scripts)) { |
|
| 687 | - if ($prepend === true) { |
|
| 688 | - array_unshift(self::$scripts, $path); |
|
| 689 | - } else { |
|
| 690 | - self::$scripts [] = $path; |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Add a custom element to the header |
|
| 698 | - * If $text is null then the element will be written as empty element. |
|
| 699 | - * So use "" to get a closing tag. |
|
| 700 | - * @param string $tag tag name of the element |
|
| 701 | - * @param array $attributes array of attributes for the element |
|
| 702 | - * @param string $text the text content for the element |
|
| 703 | - * @param bool $prepend prepend the header to the beginning of the list |
|
| 704 | - */ |
|
| 705 | - public static function addHeader($tag, $attributes, $text = null, $prepend = false) { |
|
| 706 | - $header = [ |
|
| 707 | - 'tag' => $tag, |
|
| 708 | - 'attributes' => $attributes, |
|
| 709 | - 'text' => $text |
|
| 710 | - ]; |
|
| 711 | - if ($prepend === true) { |
|
| 712 | - array_unshift(self::$headers, $header); |
|
| 713 | - } else { |
|
| 714 | - self::$headers[] = $header; |
|
| 715 | - } |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * check if the current server configuration is suitable for ownCloud |
|
| 720 | - * |
|
| 721 | - * @param \OC\SystemConfig $config |
|
| 722 | - * @return array arrays with error messages and hints |
|
| 723 | - */ |
|
| 724 | - public static function checkServer(\OC\SystemConfig $config) { |
|
| 725 | - $l = \OC::$server->getL10N('lib'); |
|
| 726 | - $errors = []; |
|
| 727 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 728 | - |
|
| 729 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 730 | - // this check needs to be done every time |
|
| 731 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 735 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 736 | - return $errors; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - $webServerRestart = false; |
|
| 740 | - $setup = new \OC\Setup( |
|
| 741 | - $config, |
|
| 742 | - \OC::$server->getIniWrapper(), |
|
| 743 | - \OC::$server->getL10N('lib'), |
|
| 744 | - \OC::$server->query(\OCP\Defaults::class), |
|
| 745 | - \OC::$server->getLogger(), |
|
| 746 | - \OC::$server->getSecureRandom(), |
|
| 747 | - \OC::$server->query(\OC\Installer::class) |
|
| 748 | - ); |
|
| 749 | - |
|
| 750 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 751 | - |
|
| 752 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
| 753 | - if (empty($availableDatabases)) { |
|
| 754 | - $errors[] = [ |
|
| 755 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 756 | - 'hint' => '' //TODO: sane hint |
|
| 757 | - ]; |
|
| 758 | - $webServerRestart = true; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - // Check if config folder is writable. |
|
| 762 | - if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 763 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 764 | - $errors[] = [ |
|
| 765 | - 'error' => $l->t('Cannot write into "config" directory'), |
|
| 766 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 767 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 768 | - . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 769 | - [ $urlGenerator->linkToDocs('admin-config') ]) |
|
| 770 | - ]; |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - // Check if there is a writable install folder. |
|
| 775 | - if ($config->getValue('appstoreenabled', true)) { |
|
| 776 | - if (OC_App::getInstallPath() === null |
|
| 777 | - || !is_writable(OC_App::getInstallPath()) |
|
| 778 | - || !is_readable(OC_App::getInstallPath()) |
|
| 779 | - ) { |
|
| 780 | - $errors[] = [ |
|
| 781 | - 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 782 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
| 783 | - . ' or disabling the appstore in the config file.') |
|
| 784 | - ]; |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - // Create root dir. |
|
| 788 | - if ($config->getValue('installed', false)) { |
|
| 789 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 790 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 791 | - if ($success) { |
|
| 792 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 793 | - } else { |
|
| 794 | - $errors[] = [ |
|
| 795 | - 'error' => $l->t('Cannot create "data" directory'), |
|
| 796 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
| 797 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 798 | - ]; |
|
| 799 | - } |
|
| 800 | - } elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 801 | - // is_writable doesn't work for NFS mounts, so try to write a file and check if it exists. |
|
| 802 | - $testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_')); |
|
| 803 | - $handle = fopen($testFile, 'w'); |
|
| 804 | - if (!$handle || fwrite($handle, 'Test write operation') === false) { |
|
| 805 | - $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
| 806 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 807 | - $errors[] = [ |
|
| 808 | - 'error' => 'Your data directory is not writable', |
|
| 809 | - 'hint' => $permissionsHint |
|
| 810 | - ]; |
|
| 811 | - } else { |
|
| 812 | - fclose($handle); |
|
| 813 | - unlink($testFile); |
|
| 814 | - } |
|
| 815 | - } else { |
|
| 816 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 817 | - } |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - if (!OC_Util::isSetLocaleWorking()) { |
|
| 821 | - $errors[] = [ |
|
| 822 | - 'error' => $l->t('Setting locale to %s failed', |
|
| 823 | - ['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 824 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']), |
|
| 825 | - 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 826 | - ]; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - // Contains the dependencies that should be checked against |
|
| 830 | - // classes = class_exists |
|
| 831 | - // functions = function_exists |
|
| 832 | - // defined = defined |
|
| 833 | - // ini = ini_get |
|
| 834 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
| 835 | - // When adding new checks always verify that they pass on Travis as well |
|
| 836 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 837 | - $dependencies = [ |
|
| 838 | - 'classes' => [ |
|
| 839 | - 'ZipArchive' => 'zip', |
|
| 840 | - 'DOMDocument' => 'dom', |
|
| 841 | - 'XMLWriter' => 'XMLWriter', |
|
| 842 | - 'XMLReader' => 'XMLReader', |
|
| 843 | - ], |
|
| 844 | - 'functions' => [ |
|
| 845 | - 'xml_parser_create' => 'libxml', |
|
| 846 | - 'mb_strcut' => 'mbstring', |
|
| 847 | - 'ctype_digit' => 'ctype', |
|
| 848 | - 'json_encode' => 'JSON', |
|
| 849 | - 'gd_info' => 'GD', |
|
| 850 | - 'gzencode' => 'zlib', |
|
| 851 | - 'iconv' => 'iconv', |
|
| 852 | - 'simplexml_load_string' => 'SimpleXML', |
|
| 853 | - 'hash' => 'HASH Message Digest Framework', |
|
| 854 | - 'curl_init' => 'cURL', |
|
| 855 | - 'openssl_verify' => 'OpenSSL', |
|
| 856 | - ], |
|
| 857 | - 'defined' => [ |
|
| 858 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 859 | - ], |
|
| 860 | - 'ini' => [ |
|
| 861 | - 'default_charset' => 'UTF-8', |
|
| 862 | - ], |
|
| 863 | - ]; |
|
| 864 | - $missingDependencies = []; |
|
| 865 | - $invalidIniSettings = []; |
|
| 866 | - |
|
| 867 | - $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 868 | - foreach ($dependencies['classes'] as $class => $module) { |
|
| 869 | - if (!class_exists($class)) { |
|
| 870 | - $missingDependencies[] = $module; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - foreach ($dependencies['functions'] as $function => $module) { |
|
| 874 | - if (!function_exists($function)) { |
|
| 875 | - $missingDependencies[] = $module; |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
| 879 | - if (!defined($defined)) { |
|
| 880 | - $missingDependencies[] = $module; |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 884 | - if (is_bool($expected)) { |
|
| 885 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 886 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 887 | - } |
|
| 888 | - } |
|
| 889 | - if (is_int($expected)) { |
|
| 890 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 891 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - if (is_string($expected)) { |
|
| 895 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 896 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - foreach ($missingDependencies as $missingDependency) { |
|
| 902 | - $errors[] = [ |
|
| 903 | - 'error' => $l->t('PHP module %s not installed.', [$missingDependency]), |
|
| 904 | - 'hint' => $l->t('Please ask your server administrator to install the module.'), |
|
| 905 | - ]; |
|
| 906 | - $webServerRestart = true; |
|
| 907 | - } |
|
| 908 | - foreach ($invalidIniSettings as $setting) { |
|
| 909 | - if (is_bool($setting[1])) { |
|
| 910 | - $setting[1] = $setting[1] ? 'on' : 'off'; |
|
| 911 | - } |
|
| 912 | - $errors[] = [ |
|
| 913 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 914 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 915 | - ]; |
|
| 916 | - $webServerRestart = true; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
| 921 | - * module is installed as it will return null if the checking setting is |
|
| 922 | - * not available and thus a check on the boolean value fails. |
|
| 923 | - * |
|
| 924 | - * TODO: Should probably be implemented in the above generic dependency |
|
| 925 | - * check somehow in the long-term. |
|
| 926 | - */ |
|
| 927 | - if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 928 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 929 | - $errors[] = [ |
|
| 930 | - 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 931 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 932 | - ]; |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - if (function_exists('xml_parser_create') && |
|
| 936 | - LIBXML_LOADED_VERSION < 20700) { |
|
| 937 | - $version = LIBXML_LOADED_VERSION; |
|
| 938 | - $major = floor($version/10000); |
|
| 939 | - $version -= ($major * 10000); |
|
| 940 | - $minor = floor($version/100); |
|
| 941 | - $version -= ($minor * 100); |
|
| 942 | - $patch = $version; |
|
| 943 | - $errors[] = [ |
|
| 944 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 945 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 946 | - ]; |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - if (!self::isAnnotationsWorking()) { |
|
| 950 | - $errors[] = [ |
|
| 951 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 952 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 953 | - ]; |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - if (!\OC::$CLI && $webServerRestart) { |
|
| 957 | - $errors[] = [ |
|
| 958 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 959 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 960 | - ]; |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 964 | - |
|
| 965 | - // Cache the result of this function |
|
| 966 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 967 | - |
|
| 968 | - return $errors; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Check the database version |
|
| 973 | - * |
|
| 974 | - * @return array errors array |
|
| 975 | - */ |
|
| 976 | - public static function checkDatabaseVersion() { |
|
| 977 | - $l = \OC::$server->getL10N('lib'); |
|
| 978 | - $errors = []; |
|
| 979 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 980 | - if ($dbType === 'pgsql') { |
|
| 981 | - // check PostgreSQL version |
|
| 982 | - try { |
|
| 983 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 984 | - $data = $result->fetchRow(); |
|
| 985 | - if (isset($data['server_version'])) { |
|
| 986 | - $version = $data['server_version']; |
|
| 987 | - if (version_compare($version, '9.0.0', '<')) { |
|
| 988 | - $errors[] = [ |
|
| 989 | - 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 990 | - 'hint' => $l->t('Please upgrade your database version') |
|
| 991 | - ]; |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 995 | - $logger = \OC::$server->getLogger(); |
|
| 996 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 997 | - $logger->logException($e); |
|
| 998 | - } |
|
| 999 | - } |
|
| 1000 | - return $errors; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - /** |
|
| 1004 | - * Check for correct file permissions of data directory |
|
| 1005 | - * |
|
| 1006 | - * @param string $dataDirectory |
|
| 1007 | - * @return array arrays with error messages and hints |
|
| 1008 | - */ |
|
| 1009 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 1010 | - if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
| 1011 | - return []; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 1015 | - if (substr($perms, -1) !== '0') { |
|
| 1016 | - chmod($dataDirectory, 0770); |
|
| 1017 | - clearstatcache(); |
|
| 1018 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 1019 | - if ($perms[2] !== '0') { |
|
| 1020 | - $l = \OC::$server->getL10N('lib'); |
|
| 1021 | - return [[ |
|
| 1022 | - 'error' => $l->t('Your data directory is readable by other users'), |
|
| 1023 | - 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'), |
|
| 1024 | - ]]; |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1027 | - return []; |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * Check that the data directory exists and is valid by |
|
| 1032 | - * checking the existence of the ".ocdata" file. |
|
| 1033 | - * |
|
| 1034 | - * @param string $dataDirectory data directory path |
|
| 1035 | - * @return array errors found |
|
| 1036 | - */ |
|
| 1037 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 1038 | - $l = \OC::$server->getL10N('lib'); |
|
| 1039 | - $errors = []; |
|
| 1040 | - if ($dataDirectory[0] !== '/') { |
|
| 1041 | - $errors[] = [ |
|
| 1042 | - 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 1043 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 1044 | - ]; |
|
| 1045 | - } |
|
| 1046 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 1047 | - $errors[] = [ |
|
| 1048 | - 'error' => $l->t('Your data directory is invalid'), |
|
| 1049 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 1050 | - ' in the root of the data directory.') |
|
| 1051 | - ]; |
|
| 1052 | - } |
|
| 1053 | - return $errors; |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * Check if the user is logged in, redirects to home if not. With |
|
| 1058 | - * redirect URL parameter to the request URI. |
|
| 1059 | - * |
|
| 1060 | - * @return void |
|
| 1061 | - */ |
|
| 1062 | - public static function checkLoggedIn() { |
|
| 1063 | - // Check if we are a user |
|
| 1064 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1065 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1066 | - 'core.login.showLoginForm', |
|
| 1067 | - [ |
|
| 1068 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 1069 | - ] |
|
| 1070 | - ) |
|
| 1071 | - ); |
|
| 1072 | - exit(); |
|
| 1073 | - } |
|
| 1074 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 1075 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 1076 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1077 | - exit(); |
|
| 1078 | - } |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * Check if the user is a admin, redirects to home if not |
|
| 1083 | - * |
|
| 1084 | - * @return void |
|
| 1085 | - */ |
|
| 1086 | - public static function checkAdminUser() { |
|
| 1087 | - OC_Util::checkLoggedIn(); |
|
| 1088 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 1089 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1090 | - exit(); |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * Returns the URL of the default page |
|
| 1096 | - * based on the system configuration and |
|
| 1097 | - * the apps visible for the current user |
|
| 1098 | - * |
|
| 1099 | - * @return string URL |
|
| 1100 | - * @suppress PhanDeprecatedFunction |
|
| 1101 | - */ |
|
| 1102 | - public static function getDefaultPageUrl() { |
|
| 1103 | - /** @var IConfig $config */ |
|
| 1104 | - $config = \OC::$server->get(IConfig::class); |
|
| 1105 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1106 | - // Deny the redirect if the URL contains a @ |
|
| 1107 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1108 | - if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1109 | - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1110 | - } else { |
|
| 1111 | - $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); |
|
| 1112 | - if ($defaultPage) { |
|
| 1113 | - $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1114 | - } else { |
|
| 1115 | - $appId = 'files'; |
|
| 1116 | - $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'dashboard,files')); |
|
| 1117 | - |
|
| 1118 | - /** @var IUserSession $userSession */ |
|
| 1119 | - $userSession = \OC::$server->get(IUserSession::class); |
|
| 1120 | - $user = $userSession->getUser(); |
|
| 1121 | - if ($user) { |
|
| 1122 | - $userDefaultApps = explode(',', $config->getUserValue($user->getUID(), 'core', 'defaultapp')); |
|
| 1123 | - $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps)); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - // find the first app that is enabled for the current user |
|
| 1127 | - foreach ($defaultApps as $defaultApp) { |
|
| 1128 | - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1129 | - if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1130 | - $appId = $defaultApp; |
|
| 1131 | - break; |
|
| 1132 | - } |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1136 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1137 | - } else { |
|
| 1138 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - return $location; |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - /** |
|
| 1146 | - * Redirect to the user default page |
|
| 1147 | - * |
|
| 1148 | - * @return void |
|
| 1149 | - */ |
|
| 1150 | - public static function redirectToDefaultPage() { |
|
| 1151 | - $location = self::getDefaultPageUrl(); |
|
| 1152 | - header('Location: ' . $location); |
|
| 1153 | - exit(); |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - /** |
|
| 1157 | - * get an id unique for this instance |
|
| 1158 | - * |
|
| 1159 | - * @return string |
|
| 1160 | - */ |
|
| 1161 | - public static function getInstanceId() { |
|
| 1162 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1163 | - if (is_null($id)) { |
|
| 1164 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1165 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1166 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1167 | - } |
|
| 1168 | - return $id; |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - /** |
|
| 1172 | - * Public function to sanitize HTML |
|
| 1173 | - * |
|
| 1174 | - * This function is used to sanitize HTML and should be applied on any |
|
| 1175 | - * string or array of strings before displaying it on a web page. |
|
| 1176 | - * |
|
| 1177 | - * @param string|array $value |
|
| 1178 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1179 | - */ |
|
| 1180 | - public static function sanitizeHTML($value) { |
|
| 1181 | - if (is_array($value)) { |
|
| 1182 | - $value = array_map(function ($value) { |
|
| 1183 | - return self::sanitizeHTML($value); |
|
| 1184 | - }, $value); |
|
| 1185 | - } else { |
|
| 1186 | - // Specify encoding for PHP<5.4 |
|
| 1187 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1188 | - } |
|
| 1189 | - return $value; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - /** |
|
| 1193 | - * Public function to encode url parameters |
|
| 1194 | - * |
|
| 1195 | - * This function is used to encode path to file before output. |
|
| 1196 | - * Encoding is done according to RFC 3986 with one exception: |
|
| 1197 | - * Character '/' is preserved as is. |
|
| 1198 | - * |
|
| 1199 | - * @param string $component part of URI to encode |
|
| 1200 | - * @return string |
|
| 1201 | - */ |
|
| 1202 | - public static function encodePath($component) { |
|
| 1203 | - $encoded = rawurlencode($component); |
|
| 1204 | - $encoded = str_replace('%2F', '/', $encoded); |
|
| 1205 | - return $encoded; |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - |
|
| 1209 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1210 | - // php dev server does not support htaccess |
|
| 1211 | - if (php_sapi_name() === 'cli-server') { |
|
| 1212 | - return false; |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - // testdata |
|
| 1216 | - $fileName = '/htaccesstest.txt'; |
|
| 1217 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1218 | - |
|
| 1219 | - // creating a test file |
|
| 1220 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1221 | - |
|
| 1222 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1223 | - return false; |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - $fp = @fopen($testFile, 'w'); |
|
| 1227 | - if (!$fp) { |
|
| 1228 | - throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1229 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1230 | - } |
|
| 1231 | - fwrite($fp, $testContent); |
|
| 1232 | - fclose($fp); |
|
| 1233 | - |
|
| 1234 | - return $testContent; |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * Check if the .htaccess file is working |
|
| 1239 | - * @param \OCP\IConfig $config |
|
| 1240 | - * @return bool |
|
| 1241 | - * @throws Exception |
|
| 1242 | - * @throws \OC\HintException If the test file can't get written. |
|
| 1243 | - */ |
|
| 1244 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1245 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1246 | - return true; |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - $testContent = $this->createHtaccessTestFile($config); |
|
| 1250 | - if ($testContent === false) { |
|
| 1251 | - return false; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - $fileName = '/htaccesstest.txt'; |
|
| 1255 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1256 | - |
|
| 1257 | - // accessing the file via http |
|
| 1258 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1259 | - try { |
|
| 1260 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1261 | - } catch (\Exception $e) { |
|
| 1262 | - $content = false; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - if (strpos($url, 'https:') === 0) { |
|
| 1266 | - $url = 'http:' . substr($url, 6); |
|
| 1267 | - } else { |
|
| 1268 | - $url = 'https:' . substr($url, 5); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - try { |
|
| 1272 | - $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1273 | - } catch (\Exception $e) { |
|
| 1274 | - $fallbackContent = false; |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - // cleanup |
|
| 1278 | - @unlink($testFile); |
|
| 1279 | - |
|
| 1280 | - /* |
|
| 270 | + if ($mount->getOption('readonly', false)) { |
|
| 271 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 272 | + 'storage' => $storage, |
|
| 273 | + 'mask' => \OCP\Constants::PERMISSION_ALL & ~( |
|
| 274 | + \OCP\Constants::PERMISSION_UPDATE | |
|
| 275 | + \OCP\Constants::PERMISSION_CREATE | |
|
| 276 | + \OCP\Constants::PERMISSION_DELETE |
|
| 277 | + ), |
|
| 278 | + ]); |
|
| 279 | + } |
|
| 280 | + return $storage; |
|
| 281 | + }); |
|
| 282 | + |
|
| 283 | + OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]); |
|
| 284 | + |
|
| 285 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
| 286 | + |
|
| 287 | + //check if we are using an object storage |
|
| 288 | + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 289 | + $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
| 290 | + |
|
| 291 | + // use the same order as in ObjectHomeMountProvider |
|
| 292 | + if (isset($objectStoreMultibucket)) { |
|
| 293 | + self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
| 294 | + } elseif (isset($objectStore)) { |
|
| 295 | + self::initObjectStoreRootFS($objectStore); |
|
| 296 | + } else { |
|
| 297 | + self::initLocalStorageRootFS(); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */ |
|
| 301 | + $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class); |
|
| 302 | + /** @var \OCP\Files\Mount\IMountPoint[] $rootMountProviders */ |
|
| 303 | + $rootMountProviders = $mountProviderCollection->getRootMounts(); |
|
| 304 | + |
|
| 305 | + /** @var \OC\Files\Mount\Manager $mountManager */ |
|
| 306 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 307 | + foreach ($rootMountProviders as $rootMountProvider) { |
|
| 308 | + $mountManager->addMount($rootMountProvider); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { |
|
| 312 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + //if we aren't logged in, there is no use to set up the filesystem |
|
| 317 | + if ($user != "") { |
|
| 318 | + $userDir = '/' . $user . '/files'; |
|
| 319 | + |
|
| 320 | + //jail the user into his "home" directory |
|
| 321 | + \OC\Files\Filesystem::init($user, $userDir); |
|
| 322 | + |
|
| 323 | + OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user, 'user_dir' => $userDir]); |
|
| 324 | + } |
|
| 325 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 326 | + return true; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * check if a password is required for each public link |
|
| 331 | + * |
|
| 332 | + * @return boolean |
|
| 333 | + * @suppress PhanDeprecatedFunction |
|
| 334 | + */ |
|
| 335 | + public static function isPublicLinkPasswordRequired() { |
|
| 336 | + $enforcePassword = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 337 | + return $enforcePassword === 'yes'; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * check if sharing is disabled for the current user |
|
| 342 | + * @param IConfig $config |
|
| 343 | + * @param IGroupManager $groupManager |
|
| 344 | + * @param IUser|null $user |
|
| 345 | + * @return bool |
|
| 346 | + */ |
|
| 347 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 348 | + if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 349 | + $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 350 | + $excludedGroups = json_decode($groupsList); |
|
| 351 | + if (is_null($excludedGroups)) { |
|
| 352 | + $excludedGroups = explode(',', $groupsList); |
|
| 353 | + $newValue = json_encode($excludedGroups); |
|
| 354 | + $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 355 | + } |
|
| 356 | + $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 357 | + if (!empty($usersGroups)) { |
|
| 358 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 359 | + // if the user is only in groups which are disabled for sharing then |
|
| 360 | + // sharing is also disabled for the user |
|
| 361 | + if (empty($remainingGroups)) { |
|
| 362 | + return true; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + return false; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * check if share API enforces a default expire date |
|
| 371 | + * |
|
| 372 | + * @return boolean |
|
| 373 | + * @suppress PhanDeprecatedFunction |
|
| 374 | + */ |
|
| 375 | + public static function isDefaultExpireDateEnforced() { |
|
| 376 | + $isDefaultExpireDateEnabled = \OC::$server->getConfig()->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 377 | + $enforceDefaultExpireDate = false; |
|
| 378 | + if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 379 | + $value = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 380 | + $enforceDefaultExpireDate = $value === 'yes'; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return $enforceDefaultExpireDate; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Get the quota of a user |
|
| 388 | + * |
|
| 389 | + * @param IUser|null $user |
|
| 390 | + * @return float Quota bytes |
|
| 391 | + */ |
|
| 392 | + public static function getUserQuota(?IUser $user) { |
|
| 393 | + if (is_null($user)) { |
|
| 394 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 395 | + } |
|
| 396 | + $userQuota = $user->getQuota(); |
|
| 397 | + if ($userQuota === 'none') { |
|
| 398 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 399 | + } |
|
| 400 | + return OC_Helper::computerFileSize($userQuota); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * copies the skeleton to the users /files |
|
| 405 | + * |
|
| 406 | + * @param string $userId |
|
| 407 | + * @param \OCP\Files\Folder $userDirectory |
|
| 408 | + * @throws \OCP\Files\NotFoundException |
|
| 409 | + * @throws \OCP\Files\NotPermittedException |
|
| 410 | + * @suppress PhanDeprecatedFunction |
|
| 411 | + */ |
|
| 412 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 413 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 414 | + $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 415 | + $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
| 416 | + |
|
| 417 | + if (!file_exists($skeletonDirectory)) { |
|
| 418 | + $dialectStart = strpos($userLang, '_'); |
|
| 419 | + if ($dialectStart !== false) { |
|
| 420 | + $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
| 421 | + } |
|
| 422 | + if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
| 423 | + $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
| 424 | + } |
|
| 425 | + if (!file_exists($skeletonDirectory)) { |
|
| 426 | + $skeletonDirectory = ''; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 431 | + |
|
| 432 | + if ($instanceId === null) { |
|
| 433 | + throw new \RuntimeException('no instance id!'); |
|
| 434 | + } |
|
| 435 | + $appdata = 'appdata_' . $instanceId; |
|
| 436 | + if ($userId === $appdata) { |
|
| 437 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + if (!empty($skeletonDirectory)) { |
|
| 441 | + \OCP\Util::writeLog( |
|
| 442 | + 'files_skeleton', |
|
| 443 | + 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 444 | + ILogger::DEBUG |
|
| 445 | + ); |
|
| 446 | + self::copyr($skeletonDirectory, $userDirectory); |
|
| 447 | + // update the file cache |
|
| 448 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * copies a directory recursively by using streams |
|
| 454 | + * |
|
| 455 | + * @param string $source |
|
| 456 | + * @param \OCP\Files\Folder $target |
|
| 457 | + * @return void |
|
| 458 | + */ |
|
| 459 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 460 | + $logger = \OC::$server->getLogger(); |
|
| 461 | + |
|
| 462 | + // Verify if folder exists |
|
| 463 | + $dir = opendir($source); |
|
| 464 | + if ($dir === false) { |
|
| 465 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 466 | + return; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + // Copy the files |
|
| 470 | + while (false !== ($file = readdir($dir))) { |
|
| 471 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 472 | + if (is_dir($source . '/' . $file)) { |
|
| 473 | + $child = $target->newFolder($file); |
|
| 474 | + self::copyr($source . '/' . $file, $child); |
|
| 475 | + } else { |
|
| 476 | + $child = $target->newFile($file); |
|
| 477 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 478 | + if ($sourceStream === false) { |
|
| 479 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 480 | + closedir($dir); |
|
| 481 | + return; |
|
| 482 | + } |
|
| 483 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + closedir($dir); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @return void |
|
| 492 | + * @suppress PhanUndeclaredMethod |
|
| 493 | + */ |
|
| 494 | + public static function tearDownFS() { |
|
| 495 | + \OC\Files\Filesystem::tearDown(); |
|
| 496 | + \OC::$server->getRootFolder()->clearCache(); |
|
| 497 | + self::$fsSetup = false; |
|
| 498 | + self::$rootMounted = false; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * get the current installed version of ownCloud |
|
| 503 | + * |
|
| 504 | + * @return array |
|
| 505 | + */ |
|
| 506 | + public static function getVersion() { |
|
| 507 | + OC_Util::loadVersion(); |
|
| 508 | + return self::$versionCache['OC_Version']; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * get the current installed version string of ownCloud |
|
| 513 | + * |
|
| 514 | + * @return string |
|
| 515 | + */ |
|
| 516 | + public static function getVersionString() { |
|
| 517 | + OC_Util::loadVersion(); |
|
| 518 | + return self::$versionCache['OC_VersionString']; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @deprecated the value is of no use anymore |
|
| 523 | + * @return string |
|
| 524 | + */ |
|
| 525 | + public static function getEditionString() { |
|
| 526 | + return ''; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * @description get the update channel of the current installed of ownCloud. |
|
| 531 | + * @return string |
|
| 532 | + */ |
|
| 533 | + public static function getChannel() { |
|
| 534 | + OC_Util::loadVersion(); |
|
| 535 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @description get the build number of the current installed of ownCloud. |
|
| 540 | + * @return string |
|
| 541 | + */ |
|
| 542 | + public static function getBuild() { |
|
| 543 | + OC_Util::loadVersion(); |
|
| 544 | + return self::$versionCache['OC_Build']; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * @description load the version.php into the session as cache |
|
| 549 | + * @suppress PhanUndeclaredVariable |
|
| 550 | + */ |
|
| 551 | + private static function loadVersion() { |
|
| 552 | + if (self::$versionCache !== null) { |
|
| 553 | + return; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 557 | + require OC::$SERVERROOT . '/version.php'; |
|
| 558 | + /** @var int $timestamp */ |
|
| 559 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 560 | + /** @var string $OC_Version */ |
|
| 561 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
| 562 | + /** @var string $OC_VersionString */ |
|
| 563 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 564 | + /** @var string $OC_Build */ |
|
| 565 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
| 566 | + |
|
| 567 | + /** @var string $OC_Channel */ |
|
| 568 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 573 | + * |
|
| 574 | + * @param string $application application to get the files from |
|
| 575 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 576 | + * @param string $file the file inside of the above folder |
|
| 577 | + * @return string the path |
|
| 578 | + */ |
|
| 579 | + private static function generatePath($application, $directory, $file) { |
|
| 580 | + if (is_null($file)) { |
|
| 581 | + $file = $application; |
|
| 582 | + $application = ""; |
|
| 583 | + } |
|
| 584 | + if (!empty($application)) { |
|
| 585 | + return "$application/$directory/$file"; |
|
| 586 | + } else { |
|
| 587 | + return "$directory/$file"; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * add a javascript file |
|
| 593 | + * |
|
| 594 | + * @param string $application application id |
|
| 595 | + * @param string|null $file filename |
|
| 596 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 597 | + * @return void |
|
| 598 | + */ |
|
| 599 | + public static function addScript($application, $file = null, $prepend = false) { |
|
| 600 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
| 601 | + |
|
| 602 | + // core js files need separate handling |
|
| 603 | + if ($application !== 'core' && $file !== null) { |
|
| 604 | + self::addTranslations($application); |
|
| 605 | + } |
|
| 606 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * add a javascript file from the vendor sub folder |
|
| 611 | + * |
|
| 612 | + * @param string $application application id |
|
| 613 | + * @param string|null $file filename |
|
| 614 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 615 | + * @return void |
|
| 616 | + */ |
|
| 617 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 618 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 619 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * add a translation JS file |
|
| 624 | + * |
|
| 625 | + * @param string $application application id |
|
| 626 | + * @param string|null $languageCode language code, defaults to the current language |
|
| 627 | + * @param bool|null $prepend prepend the Script to the beginning of the list |
|
| 628 | + */ |
|
| 629 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 630 | + if (is_null($languageCode)) { |
|
| 631 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 632 | + } |
|
| 633 | + if (!empty($application)) { |
|
| 634 | + $path = "$application/l10n/$languageCode"; |
|
| 635 | + } else { |
|
| 636 | + $path = "l10n/$languageCode"; |
|
| 637 | + } |
|
| 638 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * add a css file |
|
| 643 | + * |
|
| 644 | + * @param string $application application id |
|
| 645 | + * @param string|null $file filename |
|
| 646 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 647 | + * @return void |
|
| 648 | + */ |
|
| 649 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
| 650 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
| 651 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * add a css file from the vendor sub folder |
|
| 656 | + * |
|
| 657 | + * @param string $application application id |
|
| 658 | + * @param string|null $file filename |
|
| 659 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 660 | + * @return void |
|
| 661 | + */ |
|
| 662 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 663 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 664 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * add an external resource css/js file |
|
| 669 | + * |
|
| 670 | + * @param string $application application id |
|
| 671 | + * @param bool $prepend prepend the file to the beginning of the list |
|
| 672 | + * @param string $path |
|
| 673 | + * @param string $type (script or style) |
|
| 674 | + * @return void |
|
| 675 | + */ |
|
| 676 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 677 | + if ($type === "style") { |
|
| 678 | + if (!in_array($path, self::$styles)) { |
|
| 679 | + if ($prepend === true) { |
|
| 680 | + array_unshift(self::$styles, $path); |
|
| 681 | + } else { |
|
| 682 | + self::$styles[] = $path; |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + } elseif ($type === "script") { |
|
| 686 | + if (!in_array($path, self::$scripts)) { |
|
| 687 | + if ($prepend === true) { |
|
| 688 | + array_unshift(self::$scripts, $path); |
|
| 689 | + } else { |
|
| 690 | + self::$scripts [] = $path; |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Add a custom element to the header |
|
| 698 | + * If $text is null then the element will be written as empty element. |
|
| 699 | + * So use "" to get a closing tag. |
|
| 700 | + * @param string $tag tag name of the element |
|
| 701 | + * @param array $attributes array of attributes for the element |
|
| 702 | + * @param string $text the text content for the element |
|
| 703 | + * @param bool $prepend prepend the header to the beginning of the list |
|
| 704 | + */ |
|
| 705 | + public static function addHeader($tag, $attributes, $text = null, $prepend = false) { |
|
| 706 | + $header = [ |
|
| 707 | + 'tag' => $tag, |
|
| 708 | + 'attributes' => $attributes, |
|
| 709 | + 'text' => $text |
|
| 710 | + ]; |
|
| 711 | + if ($prepend === true) { |
|
| 712 | + array_unshift(self::$headers, $header); |
|
| 713 | + } else { |
|
| 714 | + self::$headers[] = $header; |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * check if the current server configuration is suitable for ownCloud |
|
| 720 | + * |
|
| 721 | + * @param \OC\SystemConfig $config |
|
| 722 | + * @return array arrays with error messages and hints |
|
| 723 | + */ |
|
| 724 | + public static function checkServer(\OC\SystemConfig $config) { |
|
| 725 | + $l = \OC::$server->getL10N('lib'); |
|
| 726 | + $errors = []; |
|
| 727 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 728 | + |
|
| 729 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 730 | + // this check needs to be done every time |
|
| 731 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 735 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 736 | + return $errors; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + $webServerRestart = false; |
|
| 740 | + $setup = new \OC\Setup( |
|
| 741 | + $config, |
|
| 742 | + \OC::$server->getIniWrapper(), |
|
| 743 | + \OC::$server->getL10N('lib'), |
|
| 744 | + \OC::$server->query(\OCP\Defaults::class), |
|
| 745 | + \OC::$server->getLogger(), |
|
| 746 | + \OC::$server->getSecureRandom(), |
|
| 747 | + \OC::$server->query(\OC\Installer::class) |
|
| 748 | + ); |
|
| 749 | + |
|
| 750 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 751 | + |
|
| 752 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
| 753 | + if (empty($availableDatabases)) { |
|
| 754 | + $errors[] = [ |
|
| 755 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 756 | + 'hint' => '' //TODO: sane hint |
|
| 757 | + ]; |
|
| 758 | + $webServerRestart = true; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + // Check if config folder is writable. |
|
| 762 | + if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 763 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 764 | + $errors[] = [ |
|
| 765 | + 'error' => $l->t('Cannot write into "config" directory'), |
|
| 766 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 767 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 768 | + . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 769 | + [ $urlGenerator->linkToDocs('admin-config') ]) |
|
| 770 | + ]; |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + // Check if there is a writable install folder. |
|
| 775 | + if ($config->getValue('appstoreenabled', true)) { |
|
| 776 | + if (OC_App::getInstallPath() === null |
|
| 777 | + || !is_writable(OC_App::getInstallPath()) |
|
| 778 | + || !is_readable(OC_App::getInstallPath()) |
|
| 779 | + ) { |
|
| 780 | + $errors[] = [ |
|
| 781 | + 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 782 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
| 783 | + . ' or disabling the appstore in the config file.') |
|
| 784 | + ]; |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + // Create root dir. |
|
| 788 | + if ($config->getValue('installed', false)) { |
|
| 789 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 790 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 791 | + if ($success) { |
|
| 792 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 793 | + } else { |
|
| 794 | + $errors[] = [ |
|
| 795 | + 'error' => $l->t('Cannot create "data" directory'), |
|
| 796 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
| 797 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 798 | + ]; |
|
| 799 | + } |
|
| 800 | + } elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 801 | + // is_writable doesn't work for NFS mounts, so try to write a file and check if it exists. |
|
| 802 | + $testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_')); |
|
| 803 | + $handle = fopen($testFile, 'w'); |
|
| 804 | + if (!$handle || fwrite($handle, 'Test write operation') === false) { |
|
| 805 | + $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
| 806 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 807 | + $errors[] = [ |
|
| 808 | + 'error' => 'Your data directory is not writable', |
|
| 809 | + 'hint' => $permissionsHint |
|
| 810 | + ]; |
|
| 811 | + } else { |
|
| 812 | + fclose($handle); |
|
| 813 | + unlink($testFile); |
|
| 814 | + } |
|
| 815 | + } else { |
|
| 816 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 817 | + } |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + if (!OC_Util::isSetLocaleWorking()) { |
|
| 821 | + $errors[] = [ |
|
| 822 | + 'error' => $l->t('Setting locale to %s failed', |
|
| 823 | + ['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 824 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']), |
|
| 825 | + 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 826 | + ]; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + // Contains the dependencies that should be checked against |
|
| 830 | + // classes = class_exists |
|
| 831 | + // functions = function_exists |
|
| 832 | + // defined = defined |
|
| 833 | + // ini = ini_get |
|
| 834 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
| 835 | + // When adding new checks always verify that they pass on Travis as well |
|
| 836 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 837 | + $dependencies = [ |
|
| 838 | + 'classes' => [ |
|
| 839 | + 'ZipArchive' => 'zip', |
|
| 840 | + 'DOMDocument' => 'dom', |
|
| 841 | + 'XMLWriter' => 'XMLWriter', |
|
| 842 | + 'XMLReader' => 'XMLReader', |
|
| 843 | + ], |
|
| 844 | + 'functions' => [ |
|
| 845 | + 'xml_parser_create' => 'libxml', |
|
| 846 | + 'mb_strcut' => 'mbstring', |
|
| 847 | + 'ctype_digit' => 'ctype', |
|
| 848 | + 'json_encode' => 'JSON', |
|
| 849 | + 'gd_info' => 'GD', |
|
| 850 | + 'gzencode' => 'zlib', |
|
| 851 | + 'iconv' => 'iconv', |
|
| 852 | + 'simplexml_load_string' => 'SimpleXML', |
|
| 853 | + 'hash' => 'HASH Message Digest Framework', |
|
| 854 | + 'curl_init' => 'cURL', |
|
| 855 | + 'openssl_verify' => 'OpenSSL', |
|
| 856 | + ], |
|
| 857 | + 'defined' => [ |
|
| 858 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 859 | + ], |
|
| 860 | + 'ini' => [ |
|
| 861 | + 'default_charset' => 'UTF-8', |
|
| 862 | + ], |
|
| 863 | + ]; |
|
| 864 | + $missingDependencies = []; |
|
| 865 | + $invalidIniSettings = []; |
|
| 866 | + |
|
| 867 | + $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 868 | + foreach ($dependencies['classes'] as $class => $module) { |
|
| 869 | + if (!class_exists($class)) { |
|
| 870 | + $missingDependencies[] = $module; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + foreach ($dependencies['functions'] as $function => $module) { |
|
| 874 | + if (!function_exists($function)) { |
|
| 875 | + $missingDependencies[] = $module; |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
| 879 | + if (!defined($defined)) { |
|
| 880 | + $missingDependencies[] = $module; |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 884 | + if (is_bool($expected)) { |
|
| 885 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 886 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 887 | + } |
|
| 888 | + } |
|
| 889 | + if (is_int($expected)) { |
|
| 890 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 891 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + if (is_string($expected)) { |
|
| 895 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 896 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + foreach ($missingDependencies as $missingDependency) { |
|
| 902 | + $errors[] = [ |
|
| 903 | + 'error' => $l->t('PHP module %s not installed.', [$missingDependency]), |
|
| 904 | + 'hint' => $l->t('Please ask your server administrator to install the module.'), |
|
| 905 | + ]; |
|
| 906 | + $webServerRestart = true; |
|
| 907 | + } |
|
| 908 | + foreach ($invalidIniSettings as $setting) { |
|
| 909 | + if (is_bool($setting[1])) { |
|
| 910 | + $setting[1] = $setting[1] ? 'on' : 'off'; |
|
| 911 | + } |
|
| 912 | + $errors[] = [ |
|
| 913 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 914 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 915 | + ]; |
|
| 916 | + $webServerRestart = true; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
| 921 | + * module is installed as it will return null if the checking setting is |
|
| 922 | + * not available and thus a check on the boolean value fails. |
|
| 923 | + * |
|
| 924 | + * TODO: Should probably be implemented in the above generic dependency |
|
| 925 | + * check somehow in the long-term. |
|
| 926 | + */ |
|
| 927 | + if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 928 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 929 | + $errors[] = [ |
|
| 930 | + 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 931 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 932 | + ]; |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + if (function_exists('xml_parser_create') && |
|
| 936 | + LIBXML_LOADED_VERSION < 20700) { |
|
| 937 | + $version = LIBXML_LOADED_VERSION; |
|
| 938 | + $major = floor($version/10000); |
|
| 939 | + $version -= ($major * 10000); |
|
| 940 | + $minor = floor($version/100); |
|
| 941 | + $version -= ($minor * 100); |
|
| 942 | + $patch = $version; |
|
| 943 | + $errors[] = [ |
|
| 944 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 945 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 946 | + ]; |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + if (!self::isAnnotationsWorking()) { |
|
| 950 | + $errors[] = [ |
|
| 951 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 952 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 953 | + ]; |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + if (!\OC::$CLI && $webServerRestart) { |
|
| 957 | + $errors[] = [ |
|
| 958 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 959 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 960 | + ]; |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 964 | + |
|
| 965 | + // Cache the result of this function |
|
| 966 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 967 | + |
|
| 968 | + return $errors; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Check the database version |
|
| 973 | + * |
|
| 974 | + * @return array errors array |
|
| 975 | + */ |
|
| 976 | + public static function checkDatabaseVersion() { |
|
| 977 | + $l = \OC::$server->getL10N('lib'); |
|
| 978 | + $errors = []; |
|
| 979 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 980 | + if ($dbType === 'pgsql') { |
|
| 981 | + // check PostgreSQL version |
|
| 982 | + try { |
|
| 983 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 984 | + $data = $result->fetchRow(); |
|
| 985 | + if (isset($data['server_version'])) { |
|
| 986 | + $version = $data['server_version']; |
|
| 987 | + if (version_compare($version, '9.0.0', '<')) { |
|
| 988 | + $errors[] = [ |
|
| 989 | + 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 990 | + 'hint' => $l->t('Please upgrade your database version') |
|
| 991 | + ]; |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 995 | + $logger = \OC::$server->getLogger(); |
|
| 996 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 997 | + $logger->logException($e); |
|
| 998 | + } |
|
| 999 | + } |
|
| 1000 | + return $errors; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + /** |
|
| 1004 | + * Check for correct file permissions of data directory |
|
| 1005 | + * |
|
| 1006 | + * @param string $dataDirectory |
|
| 1007 | + * @return array arrays with error messages and hints |
|
| 1008 | + */ |
|
| 1009 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 1010 | + if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
| 1011 | + return []; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 1015 | + if (substr($perms, -1) !== '0') { |
|
| 1016 | + chmod($dataDirectory, 0770); |
|
| 1017 | + clearstatcache(); |
|
| 1018 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 1019 | + if ($perms[2] !== '0') { |
|
| 1020 | + $l = \OC::$server->getL10N('lib'); |
|
| 1021 | + return [[ |
|
| 1022 | + 'error' => $l->t('Your data directory is readable by other users'), |
|
| 1023 | + 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'), |
|
| 1024 | + ]]; |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | + return []; |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * Check that the data directory exists and is valid by |
|
| 1032 | + * checking the existence of the ".ocdata" file. |
|
| 1033 | + * |
|
| 1034 | + * @param string $dataDirectory data directory path |
|
| 1035 | + * @return array errors found |
|
| 1036 | + */ |
|
| 1037 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 1038 | + $l = \OC::$server->getL10N('lib'); |
|
| 1039 | + $errors = []; |
|
| 1040 | + if ($dataDirectory[0] !== '/') { |
|
| 1041 | + $errors[] = [ |
|
| 1042 | + 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 1043 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 1044 | + ]; |
|
| 1045 | + } |
|
| 1046 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 1047 | + $errors[] = [ |
|
| 1048 | + 'error' => $l->t('Your data directory is invalid'), |
|
| 1049 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 1050 | + ' in the root of the data directory.') |
|
| 1051 | + ]; |
|
| 1052 | + } |
|
| 1053 | + return $errors; |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * Check if the user is logged in, redirects to home if not. With |
|
| 1058 | + * redirect URL parameter to the request URI. |
|
| 1059 | + * |
|
| 1060 | + * @return void |
|
| 1061 | + */ |
|
| 1062 | + public static function checkLoggedIn() { |
|
| 1063 | + // Check if we are a user |
|
| 1064 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1065 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1066 | + 'core.login.showLoginForm', |
|
| 1067 | + [ |
|
| 1068 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 1069 | + ] |
|
| 1070 | + ) |
|
| 1071 | + ); |
|
| 1072 | + exit(); |
|
| 1073 | + } |
|
| 1074 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 1075 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 1076 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1077 | + exit(); |
|
| 1078 | + } |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * Check if the user is a admin, redirects to home if not |
|
| 1083 | + * |
|
| 1084 | + * @return void |
|
| 1085 | + */ |
|
| 1086 | + public static function checkAdminUser() { |
|
| 1087 | + OC_Util::checkLoggedIn(); |
|
| 1088 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 1089 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1090 | + exit(); |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * Returns the URL of the default page |
|
| 1096 | + * based on the system configuration and |
|
| 1097 | + * the apps visible for the current user |
|
| 1098 | + * |
|
| 1099 | + * @return string URL |
|
| 1100 | + * @suppress PhanDeprecatedFunction |
|
| 1101 | + */ |
|
| 1102 | + public static function getDefaultPageUrl() { |
|
| 1103 | + /** @var IConfig $config */ |
|
| 1104 | + $config = \OC::$server->get(IConfig::class); |
|
| 1105 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1106 | + // Deny the redirect if the URL contains a @ |
|
| 1107 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1108 | + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1109 | + $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1110 | + } else { |
|
| 1111 | + $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); |
|
| 1112 | + if ($defaultPage) { |
|
| 1113 | + $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1114 | + } else { |
|
| 1115 | + $appId = 'files'; |
|
| 1116 | + $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'dashboard,files')); |
|
| 1117 | + |
|
| 1118 | + /** @var IUserSession $userSession */ |
|
| 1119 | + $userSession = \OC::$server->get(IUserSession::class); |
|
| 1120 | + $user = $userSession->getUser(); |
|
| 1121 | + if ($user) { |
|
| 1122 | + $userDefaultApps = explode(',', $config->getUserValue($user->getUID(), 'core', 'defaultapp')); |
|
| 1123 | + $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps)); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + // find the first app that is enabled for the current user |
|
| 1127 | + foreach ($defaultApps as $defaultApp) { |
|
| 1128 | + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1129 | + if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1130 | + $appId = $defaultApp; |
|
| 1131 | + break; |
|
| 1132 | + } |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1136 | + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1137 | + } else { |
|
| 1138 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + } |
|
| 1142 | + return $location; |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + /** |
|
| 1146 | + * Redirect to the user default page |
|
| 1147 | + * |
|
| 1148 | + * @return void |
|
| 1149 | + */ |
|
| 1150 | + public static function redirectToDefaultPage() { |
|
| 1151 | + $location = self::getDefaultPageUrl(); |
|
| 1152 | + header('Location: ' . $location); |
|
| 1153 | + exit(); |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + /** |
|
| 1157 | + * get an id unique for this instance |
|
| 1158 | + * |
|
| 1159 | + * @return string |
|
| 1160 | + */ |
|
| 1161 | + public static function getInstanceId() { |
|
| 1162 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1163 | + if (is_null($id)) { |
|
| 1164 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1165 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1166 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1167 | + } |
|
| 1168 | + return $id; |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + /** |
|
| 1172 | + * Public function to sanitize HTML |
|
| 1173 | + * |
|
| 1174 | + * This function is used to sanitize HTML and should be applied on any |
|
| 1175 | + * string or array of strings before displaying it on a web page. |
|
| 1176 | + * |
|
| 1177 | + * @param string|array $value |
|
| 1178 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1179 | + */ |
|
| 1180 | + public static function sanitizeHTML($value) { |
|
| 1181 | + if (is_array($value)) { |
|
| 1182 | + $value = array_map(function ($value) { |
|
| 1183 | + return self::sanitizeHTML($value); |
|
| 1184 | + }, $value); |
|
| 1185 | + } else { |
|
| 1186 | + // Specify encoding for PHP<5.4 |
|
| 1187 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1188 | + } |
|
| 1189 | + return $value; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + /** |
|
| 1193 | + * Public function to encode url parameters |
|
| 1194 | + * |
|
| 1195 | + * This function is used to encode path to file before output. |
|
| 1196 | + * Encoding is done according to RFC 3986 with one exception: |
|
| 1197 | + * Character '/' is preserved as is. |
|
| 1198 | + * |
|
| 1199 | + * @param string $component part of URI to encode |
|
| 1200 | + * @return string |
|
| 1201 | + */ |
|
| 1202 | + public static function encodePath($component) { |
|
| 1203 | + $encoded = rawurlencode($component); |
|
| 1204 | + $encoded = str_replace('%2F', '/', $encoded); |
|
| 1205 | + return $encoded; |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + |
|
| 1209 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1210 | + // php dev server does not support htaccess |
|
| 1211 | + if (php_sapi_name() === 'cli-server') { |
|
| 1212 | + return false; |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + // testdata |
|
| 1216 | + $fileName = '/htaccesstest.txt'; |
|
| 1217 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1218 | + |
|
| 1219 | + // creating a test file |
|
| 1220 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1221 | + |
|
| 1222 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1223 | + return false; |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + $fp = @fopen($testFile, 'w'); |
|
| 1227 | + if (!$fp) { |
|
| 1228 | + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1229 | + 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1230 | + } |
|
| 1231 | + fwrite($fp, $testContent); |
|
| 1232 | + fclose($fp); |
|
| 1233 | + |
|
| 1234 | + return $testContent; |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * Check if the .htaccess file is working |
|
| 1239 | + * @param \OCP\IConfig $config |
|
| 1240 | + * @return bool |
|
| 1241 | + * @throws Exception |
|
| 1242 | + * @throws \OC\HintException If the test file can't get written. |
|
| 1243 | + */ |
|
| 1244 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1245 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1246 | + return true; |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + $testContent = $this->createHtaccessTestFile($config); |
|
| 1250 | + if ($testContent === false) { |
|
| 1251 | + return false; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + $fileName = '/htaccesstest.txt'; |
|
| 1255 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1256 | + |
|
| 1257 | + // accessing the file via http |
|
| 1258 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1259 | + try { |
|
| 1260 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1261 | + } catch (\Exception $e) { |
|
| 1262 | + $content = false; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + if (strpos($url, 'https:') === 0) { |
|
| 1266 | + $url = 'http:' . substr($url, 6); |
|
| 1267 | + } else { |
|
| 1268 | + $url = 'https:' . substr($url, 5); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + try { |
|
| 1272 | + $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1273 | + } catch (\Exception $e) { |
|
| 1274 | + $fallbackContent = false; |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + // cleanup |
|
| 1278 | + @unlink($testFile); |
|
| 1279 | + |
|
| 1280 | + /* |
|
| 1281 | 1281 | * If the content is not equal to test content our .htaccess |
| 1282 | 1282 | * is working as required |
| 1283 | 1283 | */ |
| 1284 | - return $content !== $testContent && $fallbackContent !== $testContent; |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - /** |
|
| 1288 | - * Check if the setlocal call does not work. This can happen if the right |
|
| 1289 | - * local packages are not available on the server. |
|
| 1290 | - * |
|
| 1291 | - * @return bool |
|
| 1292 | - */ |
|
| 1293 | - public static function isSetLocaleWorking() { |
|
| 1294 | - \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1295 | - if ('' === basename('§')) { |
|
| 1296 | - return false; |
|
| 1297 | - } |
|
| 1298 | - return true; |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - /** |
|
| 1302 | - * Check if it's possible to get the inline annotations |
|
| 1303 | - * |
|
| 1304 | - * @return bool |
|
| 1305 | - */ |
|
| 1306 | - public static function isAnnotationsWorking() { |
|
| 1307 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1308 | - $docs = $reflection->getDocComment(); |
|
| 1309 | - |
|
| 1310 | - return (is_string($docs) && strlen($docs) > 50); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - /** |
|
| 1314 | - * Check if the PHP module fileinfo is loaded. |
|
| 1315 | - * |
|
| 1316 | - * @return bool |
|
| 1317 | - */ |
|
| 1318 | - public static function fileInfoLoaded() { |
|
| 1319 | - return function_exists('finfo_open'); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - /** |
|
| 1323 | - * clear all levels of output buffering |
|
| 1324 | - * |
|
| 1325 | - * @return void |
|
| 1326 | - */ |
|
| 1327 | - public static function obEnd() { |
|
| 1328 | - while (ob_get_level()) { |
|
| 1329 | - ob_end_clean(); |
|
| 1330 | - } |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - /** |
|
| 1334 | - * Checks whether the server is running on Mac OS X |
|
| 1335 | - * |
|
| 1336 | - * @return bool true if running on Mac OS X, false otherwise |
|
| 1337 | - */ |
|
| 1338 | - public static function runningOnMac() { |
|
| 1339 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - /** |
|
| 1343 | - * Handles the case that there may not be a theme, then check if a "default" |
|
| 1344 | - * theme exists and take that one |
|
| 1345 | - * |
|
| 1346 | - * @return string the theme |
|
| 1347 | - */ |
|
| 1348 | - public static function getTheme() { |
|
| 1349 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1350 | - |
|
| 1351 | - if ($theme === '') { |
|
| 1352 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1353 | - $theme = 'default'; |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - return $theme; |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - /** |
|
| 1361 | - * Normalize a unicode string |
|
| 1362 | - * |
|
| 1363 | - * @param string $value a not normalized string |
|
| 1364 | - * @return bool|string |
|
| 1365 | - */ |
|
| 1366 | - public static function normalizeUnicode($value) { |
|
| 1367 | - if (Normalizer::isNormalized($value)) { |
|
| 1368 | - return $value; |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - $normalizedValue = Normalizer::normalize($value); |
|
| 1372 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1373 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1374 | - return $value; |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - return $normalizedValue; |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - /** |
|
| 1381 | - * A human readable string is generated based on version and build number |
|
| 1382 | - * |
|
| 1383 | - * @return string |
|
| 1384 | - */ |
|
| 1385 | - public static function getHumanVersion() { |
|
| 1386 | - $version = OC_Util::getVersionString(); |
|
| 1387 | - $build = OC_Util::getBuild(); |
|
| 1388 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1389 | - $version .= ' Build:' . $build; |
|
| 1390 | - } |
|
| 1391 | - return $version; |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * Returns whether the given file name is valid |
|
| 1396 | - * |
|
| 1397 | - * @param string $file file name to check |
|
| 1398 | - * @return bool true if the file name is valid, false otherwise |
|
| 1399 | - * @deprecated use \OC\Files\View::verifyPath() |
|
| 1400 | - */ |
|
| 1401 | - public static function isValidFileName($file) { |
|
| 1402 | - $trimmed = trim($file); |
|
| 1403 | - if ($trimmed === '') { |
|
| 1404 | - return false; |
|
| 1405 | - } |
|
| 1406 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1407 | - return false; |
|
| 1408 | - } |
|
| 1409 | - |
|
| 1410 | - // detect part files |
|
| 1411 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1412 | - return false; |
|
| 1413 | - } |
|
| 1414 | - |
|
| 1415 | - foreach (str_split($trimmed) as $char) { |
|
| 1416 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1417 | - return false; |
|
| 1418 | - } |
|
| 1419 | - } |
|
| 1420 | - return true; |
|
| 1421 | - } |
|
| 1422 | - |
|
| 1423 | - /** |
|
| 1424 | - * Check whether the instance needs to perform an upgrade, |
|
| 1425 | - * either when the core version is higher or any app requires |
|
| 1426 | - * an upgrade. |
|
| 1427 | - * |
|
| 1428 | - * @param \OC\SystemConfig $config |
|
| 1429 | - * @return bool whether the core or any app needs an upgrade |
|
| 1430 | - * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1431 | - */ |
|
| 1432 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1433 | - if ($config->getValue('installed', false)) { |
|
| 1434 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1435 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1436 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1437 | - if ($versionDiff > 0) { |
|
| 1438 | - return true; |
|
| 1439 | - } elseif ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1440 | - // downgrade with debug |
|
| 1441 | - $installedMajor = explode('.', $installedVersion); |
|
| 1442 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1443 | - $currentMajor = explode('.', $currentVersion); |
|
| 1444 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1445 | - if ($installedMajor === $currentMajor) { |
|
| 1446 | - // Same major, allow downgrade for developers |
|
| 1447 | - return true; |
|
| 1448 | - } else { |
|
| 1449 | - // downgrade attempt, throw exception |
|
| 1450 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1451 | - } |
|
| 1452 | - } elseif ($versionDiff < 0) { |
|
| 1453 | - // downgrade attempt, throw exception |
|
| 1454 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - // also check for upgrades for apps (independently from the user) |
|
| 1458 | - $apps = \OC_App::getEnabledApps(false, true); |
|
| 1459 | - $shouldUpgrade = false; |
|
| 1460 | - foreach ($apps as $app) { |
|
| 1461 | - if (\OC_App::shouldUpgrade($app)) { |
|
| 1462 | - $shouldUpgrade = true; |
|
| 1463 | - break; |
|
| 1464 | - } |
|
| 1465 | - } |
|
| 1466 | - return $shouldUpgrade; |
|
| 1467 | - } else { |
|
| 1468 | - return false; |
|
| 1469 | - } |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - /** |
|
| 1473 | - * is this Internet explorer ? |
|
| 1474 | - * |
|
| 1475 | - * @return boolean |
|
| 1476 | - */ |
|
| 1477 | - public static function isIe() { |
|
| 1478 | - if (!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
| 1479 | - return false; |
|
| 1480 | - } |
|
| 1481 | - |
|
| 1482 | - return preg_match(Request::USER_AGENT_IE, $_SERVER['HTTP_USER_AGENT']) === 1; |
|
| 1483 | - } |
|
| 1284 | + return $content !== $testContent && $fallbackContent !== $testContent; |
|
| 1285 | + } |
|
| 1286 | + |
|
| 1287 | + /** |
|
| 1288 | + * Check if the setlocal call does not work. This can happen if the right |
|
| 1289 | + * local packages are not available on the server. |
|
| 1290 | + * |
|
| 1291 | + * @return bool |
|
| 1292 | + */ |
|
| 1293 | + public static function isSetLocaleWorking() { |
|
| 1294 | + \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1295 | + if ('' === basename('§')) { |
|
| 1296 | + return false; |
|
| 1297 | + } |
|
| 1298 | + return true; |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + /** |
|
| 1302 | + * Check if it's possible to get the inline annotations |
|
| 1303 | + * |
|
| 1304 | + * @return bool |
|
| 1305 | + */ |
|
| 1306 | + public static function isAnnotationsWorking() { |
|
| 1307 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1308 | + $docs = $reflection->getDocComment(); |
|
| 1309 | + |
|
| 1310 | + return (is_string($docs) && strlen($docs) > 50); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + /** |
|
| 1314 | + * Check if the PHP module fileinfo is loaded. |
|
| 1315 | + * |
|
| 1316 | + * @return bool |
|
| 1317 | + */ |
|
| 1318 | + public static function fileInfoLoaded() { |
|
| 1319 | + return function_exists('finfo_open'); |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + /** |
|
| 1323 | + * clear all levels of output buffering |
|
| 1324 | + * |
|
| 1325 | + * @return void |
|
| 1326 | + */ |
|
| 1327 | + public static function obEnd() { |
|
| 1328 | + while (ob_get_level()) { |
|
| 1329 | + ob_end_clean(); |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + /** |
|
| 1334 | + * Checks whether the server is running on Mac OS X |
|
| 1335 | + * |
|
| 1336 | + * @return bool true if running on Mac OS X, false otherwise |
|
| 1337 | + */ |
|
| 1338 | + public static function runningOnMac() { |
|
| 1339 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + /** |
|
| 1343 | + * Handles the case that there may not be a theme, then check if a "default" |
|
| 1344 | + * theme exists and take that one |
|
| 1345 | + * |
|
| 1346 | + * @return string the theme |
|
| 1347 | + */ |
|
| 1348 | + public static function getTheme() { |
|
| 1349 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1350 | + |
|
| 1351 | + if ($theme === '') { |
|
| 1352 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1353 | + $theme = 'default'; |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + return $theme; |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + /** |
|
| 1361 | + * Normalize a unicode string |
|
| 1362 | + * |
|
| 1363 | + * @param string $value a not normalized string |
|
| 1364 | + * @return bool|string |
|
| 1365 | + */ |
|
| 1366 | + public static function normalizeUnicode($value) { |
|
| 1367 | + if (Normalizer::isNormalized($value)) { |
|
| 1368 | + return $value; |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + $normalizedValue = Normalizer::normalize($value); |
|
| 1372 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1373 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1374 | + return $value; |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + return $normalizedValue; |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + /** |
|
| 1381 | + * A human readable string is generated based on version and build number |
|
| 1382 | + * |
|
| 1383 | + * @return string |
|
| 1384 | + */ |
|
| 1385 | + public static function getHumanVersion() { |
|
| 1386 | + $version = OC_Util::getVersionString(); |
|
| 1387 | + $build = OC_Util::getBuild(); |
|
| 1388 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1389 | + $version .= ' Build:' . $build; |
|
| 1390 | + } |
|
| 1391 | + return $version; |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * Returns whether the given file name is valid |
|
| 1396 | + * |
|
| 1397 | + * @param string $file file name to check |
|
| 1398 | + * @return bool true if the file name is valid, false otherwise |
|
| 1399 | + * @deprecated use \OC\Files\View::verifyPath() |
|
| 1400 | + */ |
|
| 1401 | + public static function isValidFileName($file) { |
|
| 1402 | + $trimmed = trim($file); |
|
| 1403 | + if ($trimmed === '') { |
|
| 1404 | + return false; |
|
| 1405 | + } |
|
| 1406 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1407 | + return false; |
|
| 1408 | + } |
|
| 1409 | + |
|
| 1410 | + // detect part files |
|
| 1411 | + if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1412 | + return false; |
|
| 1413 | + } |
|
| 1414 | + |
|
| 1415 | + foreach (str_split($trimmed) as $char) { |
|
| 1416 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1417 | + return false; |
|
| 1418 | + } |
|
| 1419 | + } |
|
| 1420 | + return true; |
|
| 1421 | + } |
|
| 1422 | + |
|
| 1423 | + /** |
|
| 1424 | + * Check whether the instance needs to perform an upgrade, |
|
| 1425 | + * either when the core version is higher or any app requires |
|
| 1426 | + * an upgrade. |
|
| 1427 | + * |
|
| 1428 | + * @param \OC\SystemConfig $config |
|
| 1429 | + * @return bool whether the core or any app needs an upgrade |
|
| 1430 | + * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1431 | + */ |
|
| 1432 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1433 | + if ($config->getValue('installed', false)) { |
|
| 1434 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1435 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1436 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1437 | + if ($versionDiff > 0) { |
|
| 1438 | + return true; |
|
| 1439 | + } elseif ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1440 | + // downgrade with debug |
|
| 1441 | + $installedMajor = explode('.', $installedVersion); |
|
| 1442 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1443 | + $currentMajor = explode('.', $currentVersion); |
|
| 1444 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1445 | + if ($installedMajor === $currentMajor) { |
|
| 1446 | + // Same major, allow downgrade for developers |
|
| 1447 | + return true; |
|
| 1448 | + } else { |
|
| 1449 | + // downgrade attempt, throw exception |
|
| 1450 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1451 | + } |
|
| 1452 | + } elseif ($versionDiff < 0) { |
|
| 1453 | + // downgrade attempt, throw exception |
|
| 1454 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + // also check for upgrades for apps (independently from the user) |
|
| 1458 | + $apps = \OC_App::getEnabledApps(false, true); |
|
| 1459 | + $shouldUpgrade = false; |
|
| 1460 | + foreach ($apps as $app) { |
|
| 1461 | + if (\OC_App::shouldUpgrade($app)) { |
|
| 1462 | + $shouldUpgrade = true; |
|
| 1463 | + break; |
|
| 1464 | + } |
|
| 1465 | + } |
|
| 1466 | + return $shouldUpgrade; |
|
| 1467 | + } else { |
|
| 1468 | + return false; |
|
| 1469 | + } |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + /** |
|
| 1473 | + * is this Internet explorer ? |
|
| 1474 | + * |
|
| 1475 | + * @return boolean |
|
| 1476 | + */ |
|
| 1477 | + public static function isIe() { |
|
| 1478 | + if (!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
| 1479 | + return false; |
|
| 1480 | + } |
|
| 1481 | + |
|
| 1482 | + return preg_match(Request::USER_AGENT_IE, $_SERVER['HTTP_USER_AGENT']) === 1; |
|
| 1483 | + } |
|
| 1484 | 1484 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | private static function initLocalStorageRootFS() { |
| 88 | 88 | // mount local file backend as root |
| 89 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 89 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT."/data"); |
|
| 90 | 90 | //first set up the local "root" storage |
| 91 | 91 | \OC\Files\Filesystem::initMountManager(); |
| 92 | 92 | if (!self::$rootMounted) { |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | \OC\Files\Filesystem::initMountManager(); |
| 209 | 209 | |
| 210 | 210 | $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
| 211 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 211 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 212 | 212 | if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
| 213 | 213 | /** @var \OC\Files\Storage\Common $storage */ |
| 214 | 214 | $storage->setMountOptions($mount->getOptions()); |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | return $storage; |
| 217 | 217 | }); |
| 218 | 218 | |
| 219 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 219 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 220 | 220 | if (!$mount->getOption('enable_sharing', true)) { |
| 221 | 221 | return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
| 222 | 222 | 'storage' => $storage, |
@@ -227,21 +227,21 @@ discard block |
||
| 227 | 227 | }); |
| 228 | 228 | |
| 229 | 229 | // install storage availability wrapper, before most other wrappers |
| 230 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 230 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 231 | 231 | if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 232 | 232 | return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
| 233 | 233 | } |
| 234 | 234 | return $storage; |
| 235 | 235 | }); |
| 236 | 236 | |
| 237 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 237 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 238 | 238 | if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 239 | 239 | return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
| 240 | 240 | } |
| 241 | 241 | return $storage; |
| 242 | 242 | }); |
| 243 | 243 | |
| 244 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 244 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) { |
|
| 245 | 245 | // set up quota for home storages, even for other users |
| 246 | 246 | // which can happen when using sharing |
| 247 | 247 | |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | return $storage; |
| 264 | 264 | }); |
| 265 | 265 | |
| 266 | - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 266 | + \OC\Files\Filesystem::addStorageWrapper('readonly', function($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 267 | 267 | /* |
| 268 | 268 | * Do not allow any operations that modify the storage |
| 269 | 269 | */ |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | //if we aren't logged in, there is no use to set up the filesystem |
| 317 | 317 | if ($user != "") { |
| 318 | - $userDir = '/' . $user . '/files'; |
|
| 318 | + $userDir = '/'.$user.'/files'; |
|
| 319 | 319 | |
| 320 | 320 | //jail the user into his "home" directory |
| 321 | 321 | \OC\Files\Filesystem::init($user, $userDir); |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | * @suppress PhanDeprecatedFunction |
| 411 | 411 | */ |
| 412 | 412 | public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
| 413 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 413 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT.'/core/skeleton'); |
|
| 414 | 414 | $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
| 415 | 415 | $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
| 416 | 416 | |
@@ -432,9 +432,9 @@ discard block |
||
| 432 | 432 | if ($instanceId === null) { |
| 433 | 433 | throw new \RuntimeException('no instance id!'); |
| 434 | 434 | } |
| 435 | - $appdata = 'appdata_' . $instanceId; |
|
| 435 | + $appdata = 'appdata_'.$instanceId; |
|
| 436 | 436 | if ($userId === $appdata) { |
| 437 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 437 | + throw new \RuntimeException('username is reserved name: '.$appdata); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | if (!empty($skeletonDirectory)) { |
@@ -469,14 +469,14 @@ discard block |
||
| 469 | 469 | // Copy the files |
| 470 | 470 | while (false !== ($file = readdir($dir))) { |
| 471 | 471 | if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
| 472 | - if (is_dir($source . '/' . $file)) { |
|
| 472 | + if (is_dir($source.'/'.$file)) { |
|
| 473 | 473 | $child = $target->newFolder($file); |
| 474 | - self::copyr($source . '/' . $file, $child); |
|
| 474 | + self::copyr($source.'/'.$file, $child); |
|
| 475 | 475 | } else { |
| 476 | 476 | $child = $target->newFile($file); |
| 477 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 477 | + $sourceStream = fopen($source.'/'.$file, 'r'); |
|
| 478 | 478 | if ($sourceStream === false) { |
| 479 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 479 | + $logger->error(sprintf('Could not fopen "%s"', $source.'/'.$file), ['app' => 'core']); |
|
| 480 | 480 | closedir($dir); |
| 481 | 481 | return; |
| 482 | 482 | } |
@@ -553,8 +553,8 @@ discard block |
||
| 553 | 553 | return; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 557 | - require OC::$SERVERROOT . '/version.php'; |
|
| 556 | + $timestamp = filemtime(OC::$SERVERROOT.'/version.php'); |
|
| 557 | + require OC::$SERVERROOT.'/version.php'; |
|
| 558 | 558 | /** @var int $timestamp */ |
| 559 | 559 | self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
| 560 | 560 | /** @var string $OC_Version */ |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | public static function checkServer(\OC\SystemConfig $config) { |
| 725 | 725 | $l = \OC::$server->getL10N('lib'); |
| 726 | 726 | $errors = []; |
| 727 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 727 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT.'/data'); |
|
| 728 | 728 | |
| 729 | 729 | if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
| 730 | 730 | // this check needs to be done every time |
@@ -764,9 +764,9 @@ discard block |
||
| 764 | 764 | $errors[] = [ |
| 765 | 765 | 'error' => $l->t('Cannot write into "config" directory'), |
| 766 | 766 | 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
| 767 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 767 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]).'. ' |
|
| 768 | 768 | . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
| 769 | - [ $urlGenerator->linkToDocs('admin-config') ]) |
|
| 769 | + [$urlGenerator->linkToDocs('admin-config')]) |
|
| 770 | 770 | ]; |
| 771 | 771 | } |
| 772 | 772 | } |
@@ -935,13 +935,13 @@ discard block |
||
| 935 | 935 | if (function_exists('xml_parser_create') && |
| 936 | 936 | LIBXML_LOADED_VERSION < 20700) { |
| 937 | 937 | $version = LIBXML_LOADED_VERSION; |
| 938 | - $major = floor($version/10000); |
|
| 938 | + $major = floor($version / 10000); |
|
| 939 | 939 | $version -= ($major * 10000); |
| 940 | - $minor = floor($version/100); |
|
| 940 | + $minor = floor($version / 100); |
|
| 941 | 941 | $version -= ($minor * 100); |
| 942 | 942 | $patch = $version; |
| 943 | 943 | $errors[] = [ |
| 944 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 944 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major.'.'.$minor.'.'.$patch]), |
|
| 945 | 945 | 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
| 946 | 946 | ]; |
| 947 | 947 | } |
@@ -1043,10 +1043,10 @@ discard block |
||
| 1043 | 1043 | 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
| 1044 | 1044 | ]; |
| 1045 | 1045 | } |
| 1046 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 1046 | + if (!file_exists($dataDirectory.'/.ocdata')) { |
|
| 1047 | 1047 | $errors[] = [ |
| 1048 | 1048 | 'error' => $l->t('Your data directory is invalid'), |
| 1049 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 1049 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"'. |
|
| 1050 | 1050 | ' in the root of the data directory.') |
| 1051 | 1051 | ]; |
| 1052 | 1052 | } |
@@ -1062,7 +1062,7 @@ discard block |
||
| 1062 | 1062 | public static function checkLoggedIn() { |
| 1063 | 1063 | // Check if we are a user |
| 1064 | 1064 | if (!\OC::$server->getUserSession()->isLoggedIn()) { |
| 1065 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1065 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute( |
|
| 1066 | 1066 | 'core.login.showLoginForm', |
| 1067 | 1067 | [ |
| 1068 | 1068 | 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
@@ -1073,7 +1073,7 @@ discard block |
||
| 1073 | 1073 | } |
| 1074 | 1074 | // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
| 1075 | 1075 | if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
| 1076 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1076 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1077 | 1077 | exit(); |
| 1078 | 1078 | } |
| 1079 | 1079 | } |
@@ -1086,7 +1086,7 @@ discard block |
||
| 1086 | 1086 | public static function checkAdminUser() { |
| 1087 | 1087 | OC_Util::checkLoggedIn(); |
| 1088 | 1088 | if (!OC_User::isAdminUser(OC_User::getUser())) { |
| 1089 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1089 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1090 | 1090 | exit(); |
| 1091 | 1091 | } |
| 1092 | 1092 | } |
@@ -1133,9 +1133,9 @@ discard block |
||
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
| 1136 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1136 | + $location = $urlGenerator->getAbsoluteURL('/apps/'.$appId.'/'); |
|
| 1137 | 1137 | } else { |
| 1138 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1138 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/'.$appId.'/'); |
|
| 1139 | 1139 | } |
| 1140 | 1140 | } |
| 1141 | 1141 | } |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | */ |
| 1150 | 1150 | public static function redirectToDefaultPage() { |
| 1151 | 1151 | $location = self::getDefaultPageUrl(); |
| 1152 | - header('Location: ' . $location); |
|
| 1152 | + header('Location: '.$location); |
|
| 1153 | 1153 | exit(); |
| 1154 | 1154 | } |
| 1155 | 1155 | |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
| 1163 | 1163 | if (is_null($id)) { |
| 1164 | 1164 | // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
| 1165 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1165 | + $id = 'oc'.\OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1166 | 1166 | \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
| 1167 | 1167 | } |
| 1168 | 1168 | return $id; |
@@ -1179,12 +1179,12 @@ discard block |
||
| 1179 | 1179 | */ |
| 1180 | 1180 | public static function sanitizeHTML($value) { |
| 1181 | 1181 | if (is_array($value)) { |
| 1182 | - $value = array_map(function ($value) { |
|
| 1182 | + $value = array_map(function($value) { |
|
| 1183 | 1183 | return self::sanitizeHTML($value); |
| 1184 | 1184 | }, $value); |
| 1185 | 1185 | } else { |
| 1186 | 1186 | // Specify encoding for PHP<5.4 |
| 1187 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1187 | + $value = htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | return $value; |
| 1190 | 1190 | } |
@@ -1217,7 +1217,7 @@ discard block |
||
| 1217 | 1217 | $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
| 1218 | 1218 | |
| 1219 | 1219 | // creating a test file |
| 1220 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1220 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1221 | 1221 | |
| 1222 | 1222 | if (file_exists($testFile)) {// already running this test, possible recursive call |
| 1223 | 1223 | return false; |
@@ -1226,7 +1226,7 @@ discard block |
||
| 1226 | 1226 | $fp = @fopen($testFile, 'w'); |
| 1227 | 1227 | if (!$fp) { |
| 1228 | 1228 | throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
| 1229 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1229 | + 'Make sure it is possible for the webserver to write to '.$testFile); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | fwrite($fp, $testContent); |
| 1232 | 1232 | fclose($fp); |
@@ -1252,10 +1252,10 @@ discard block |
||
| 1252 | 1252 | } |
| 1253 | 1253 | |
| 1254 | 1254 | $fileName = '/htaccesstest.txt'; |
| 1255 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1255 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1256 | 1256 | |
| 1257 | 1257 | // accessing the file via http |
| 1258 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1258 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT.'/data'.$fileName); |
|
| 1259 | 1259 | try { |
| 1260 | 1260 | $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
| 1261 | 1261 | } catch (\Exception $e) { |
@@ -1263,9 +1263,9 @@ discard block |
||
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | 1265 | if (strpos($url, 'https:') === 0) { |
| 1266 | - $url = 'http:' . substr($url, 6); |
|
| 1266 | + $url = 'http:'.substr($url, 6); |
|
| 1267 | 1267 | } else { |
| 1268 | - $url = 'https:' . substr($url, 5); |
|
| 1268 | + $url = 'https:'.substr($url, 5); |
|
| 1269 | 1269 | } |
| 1270 | 1270 | |
| 1271 | 1271 | try { |
@@ -1349,7 +1349,7 @@ discard block |
||
| 1349 | 1349 | $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
| 1350 | 1350 | |
| 1351 | 1351 | if ($theme === '') { |
| 1352 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1352 | + if (is_dir(OC::$SERVERROOT.'/themes/default')) { |
|
| 1353 | 1353 | $theme = 'default'; |
| 1354 | 1354 | } |
| 1355 | 1355 | } |
@@ -1370,7 +1370,7 @@ discard block |
||
| 1370 | 1370 | |
| 1371 | 1371 | $normalizedValue = Normalizer::normalize($value); |
| 1372 | 1372 | if ($normalizedValue === null || $normalizedValue === false) { |
| 1373 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1373 | + \OC::$server->getLogger()->warning('normalizing failed for "'.$value.'"', ['app' => 'core']); |
|
| 1374 | 1374 | return $value; |
| 1375 | 1375 | } |
| 1376 | 1376 | |
@@ -1386,7 +1386,7 @@ discard block |
||
| 1386 | 1386 | $version = OC_Util::getVersionString(); |
| 1387 | 1387 | $build = OC_Util::getBuild(); |
| 1388 | 1388 | if (!empty($build) and OC_Util::getChannel() === 'daily') { |
| 1389 | - $version .= ' Build:' . $build; |
|
| 1389 | + $version .= ' Build:'.$build; |
|
| 1390 | 1390 | } |
| 1391 | 1391 | return $version; |
| 1392 | 1392 | } |
@@ -1408,7 +1408,7 @@ discard block |
||
| 1408 | 1408 | } |
| 1409 | 1409 | |
| 1410 | 1410 | // detect part files |
| 1411 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1411 | + if (preg_match('/'.\OCP\Files\FileInfo::BLACKLIST_FILES_REGEX.'/', $trimmed) !== 0) { |
|
| 1412 | 1412 | return false; |
| 1413 | 1413 | } |
| 1414 | 1414 | |
@@ -1439,19 +1439,19 @@ discard block |
||
| 1439 | 1439 | } elseif ($config->getValue('debug', false) && $versionDiff < 0) { |
| 1440 | 1440 | // downgrade with debug |
| 1441 | 1441 | $installedMajor = explode('.', $installedVersion); |
| 1442 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1442 | + $installedMajor = $installedMajor[0].'.'.$installedMajor[1]; |
|
| 1443 | 1443 | $currentMajor = explode('.', $currentVersion); |
| 1444 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1444 | + $currentMajor = $currentMajor[0].'.'.$currentMajor[1]; |
|
| 1445 | 1445 | if ($installedMajor === $currentMajor) { |
| 1446 | 1446 | // Same major, allow downgrade for developers |
| 1447 | 1447 | return true; |
| 1448 | 1448 | } else { |
| 1449 | 1449 | // downgrade attempt, throw exception |
| 1450 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1450 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1451 | 1451 | } |
| 1452 | 1452 | } elseif ($versionDiff < 0) { |
| 1453 | 1453 | // downgrade attempt, throw exception |
| 1454 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1454 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | // also check for upgrades for apps (independently from the user) |
@@ -41,98 +41,98 @@ |
||
| 41 | 41 | |
| 42 | 42 | class ResetPassword extends Command { |
| 43 | 43 | |
| 44 | - /** @var IUserManager */ |
|
| 45 | - protected $userManager; |
|
| 46 | - |
|
| 47 | - public function __construct(IUserManager $userManager) { |
|
| 48 | - $this->userManager = $userManager; |
|
| 49 | - parent::__construct(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - protected function configure() { |
|
| 53 | - $this |
|
| 54 | - ->setName('user:resetpassword') |
|
| 55 | - ->setDescription('Resets the password of the named user') |
|
| 56 | - ->addArgument( |
|
| 57 | - 'user', |
|
| 58 | - InputArgument::REQUIRED, |
|
| 59 | - 'Username to reset password' |
|
| 60 | - ) |
|
| 61 | - ->addOption( |
|
| 62 | - 'password-from-env', |
|
| 63 | - null, |
|
| 64 | - InputOption::VALUE_NONE, |
|
| 65 | - 'read password from environment variable OC_PASS' |
|
| 66 | - ) |
|
| 67 | - ; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 71 | - $username = $input->getArgument('user'); |
|
| 72 | - |
|
| 73 | - $user = $this->userManager->get($username); |
|
| 74 | - if (is_null($user)) { |
|
| 75 | - $output->writeln('<error>User does not exist</error>'); |
|
| 76 | - return 1; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ($input->getOption('password-from-env')) { |
|
| 80 | - $password = getenv('OC_PASS'); |
|
| 81 | - if (!$password) { |
|
| 82 | - $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
| 83 | - return 1; |
|
| 84 | - } |
|
| 85 | - } elseif ($input->isInteractive()) { |
|
| 86 | - /** @var QuestionHelper $helper */ |
|
| 87 | - $helper = $this->getHelper('question'); |
|
| 88 | - |
|
| 89 | - if (\OCP\App::isEnabled('encryption')) { |
|
| 90 | - $output->writeln( |
|
| 91 | - '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - $question = new ConfirmationQuestion('Do you want to continue?'); |
|
| 95 | - if (!$helper->ask($input, $output, $question)) { |
|
| 96 | - return 1; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $question = new Question('Enter a new password: '); |
|
| 101 | - $question->setHidden(true); |
|
| 102 | - $password = $helper->ask($input, $output, $question); |
|
| 103 | - |
|
| 104 | - if ($password === null) { |
|
| 105 | - $output->writeln("<error>Password cannot be empty!</error>"); |
|
| 106 | - return 1; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $question = new Question('Confirm the new password: '); |
|
| 110 | - $question->setHidden(true); |
|
| 111 | - $confirm = $helper->ask($input, $output, $question); |
|
| 112 | - |
|
| 113 | - if ($password !== $confirm) { |
|
| 114 | - $output->writeln("<error>Passwords did not match!</error>"); |
|
| 115 | - return 1; |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
| 119 | - return 1; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - try { |
|
| 124 | - $success = $user->setPassword($password); |
|
| 125 | - } catch (\Exception $e) { |
|
| 126 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 127 | - return 1; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($success) { |
|
| 131 | - $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
| 132 | - } else { |
|
| 133 | - $output->writeln("<error>Error while resetting password!</error>"); |
|
| 134 | - return 1; |
|
| 135 | - } |
|
| 136 | - return 0; |
|
| 137 | - } |
|
| 44 | + /** @var IUserManager */ |
|
| 45 | + protected $userManager; |
|
| 46 | + |
|
| 47 | + public function __construct(IUserManager $userManager) { |
|
| 48 | + $this->userManager = $userManager; |
|
| 49 | + parent::__construct(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + protected function configure() { |
|
| 53 | + $this |
|
| 54 | + ->setName('user:resetpassword') |
|
| 55 | + ->setDescription('Resets the password of the named user') |
|
| 56 | + ->addArgument( |
|
| 57 | + 'user', |
|
| 58 | + InputArgument::REQUIRED, |
|
| 59 | + 'Username to reset password' |
|
| 60 | + ) |
|
| 61 | + ->addOption( |
|
| 62 | + 'password-from-env', |
|
| 63 | + null, |
|
| 64 | + InputOption::VALUE_NONE, |
|
| 65 | + 'read password from environment variable OC_PASS' |
|
| 66 | + ) |
|
| 67 | + ; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 71 | + $username = $input->getArgument('user'); |
|
| 72 | + |
|
| 73 | + $user = $this->userManager->get($username); |
|
| 74 | + if (is_null($user)) { |
|
| 75 | + $output->writeln('<error>User does not exist</error>'); |
|
| 76 | + return 1; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ($input->getOption('password-from-env')) { |
|
| 80 | + $password = getenv('OC_PASS'); |
|
| 81 | + if (!$password) { |
|
| 82 | + $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
| 83 | + return 1; |
|
| 84 | + } |
|
| 85 | + } elseif ($input->isInteractive()) { |
|
| 86 | + /** @var QuestionHelper $helper */ |
|
| 87 | + $helper = $this->getHelper('question'); |
|
| 88 | + |
|
| 89 | + if (\OCP\App::isEnabled('encryption')) { |
|
| 90 | + $output->writeln( |
|
| 91 | + '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + $question = new ConfirmationQuestion('Do you want to continue?'); |
|
| 95 | + if (!$helper->ask($input, $output, $question)) { |
|
| 96 | + return 1; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $question = new Question('Enter a new password: '); |
|
| 101 | + $question->setHidden(true); |
|
| 102 | + $password = $helper->ask($input, $output, $question); |
|
| 103 | + |
|
| 104 | + if ($password === null) { |
|
| 105 | + $output->writeln("<error>Password cannot be empty!</error>"); |
|
| 106 | + return 1; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $question = new Question('Confirm the new password: '); |
|
| 110 | + $question->setHidden(true); |
|
| 111 | + $confirm = $helper->ask($input, $output, $question); |
|
| 112 | + |
|
| 113 | + if ($password !== $confirm) { |
|
| 114 | + $output->writeln("<error>Passwords did not match!</error>"); |
|
| 115 | + return 1; |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
| 119 | + return 1; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + try { |
|
| 124 | + $success = $user->setPassword($password); |
|
| 125 | + } catch (\Exception $e) { |
|
| 126 | + $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 127 | + return 1; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($success) { |
|
| 131 | + $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
| 132 | + } else { |
|
| 133 | + $output->writeln("<error>Error while resetting password!</error>"); |
|
| 134 | + return 1; |
|
| 135 | + } |
|
| 136 | + return 0; |
|
| 137 | + } |
|
| 138 | 138 | } |
@@ -1,9 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | - /** @var array $_ */ |
|
| 3 | - /** @var \OCP\IL10N $l */ |
|
| 4 | - style('core', 'guest'); |
|
| 5 | - style('core', 'publicshareauth'); |
|
| 6 | - script('core', 'publicshareauth'); |
|
| 2 | + /** @var array $_ */ |
|
| 3 | + /** @var \OCP\IL10N $l */ |
|
| 4 | + style('core', 'guest'); |
|
| 5 | + style('core', 'publicshareauth'); |
|
| 6 | + script('core', 'publicshareauth'); |
|
| 7 | 7 | ?> |
| 8 | 8 | <form method="post"> |
| 9 | 9 | <fieldset class="warning"> |
@@ -4,11 +4,11 @@ |
||
| 4 | 4 | /** @var \OCP\Defaults $theme */ |
| 5 | 5 | // @codeCoverageIgnoreStart |
| 6 | 6 | if (!isset($_)) {//standalone page is not supported anymore - redirect to / |
| 7 | - require_once '../../lib/base.php'; |
|
| 7 | + require_once '../../lib/base.php'; |
|
| 8 | 8 | |
| 9 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 10 | - header('Location: ' . $urlGenerator->getAbsoluteURL('/')); |
|
| 11 | - exit; |
|
| 9 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 10 | + header('Location: ' . $urlGenerator->getAbsoluteURL('/')); |
|
| 11 | + exit; |
|
| 12 | 12 | } |
| 13 | 13 | // @codeCoverageIgnoreEnd |
| 14 | 14 | ?> |