@@ -25,33 +25,33 @@ |
||
| 25 | 25 | use OCP\Files\Search\ISearchOrder; |
| 26 | 26 | |
| 27 | 27 | class SearchOrder implements ISearchOrder { |
| 28 | - /** @var string */ |
|
| 29 | - private $direction; |
|
| 30 | - /** @var string */ |
|
| 31 | - private $field; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $direction; |
|
| 30 | + /** @var string */ |
|
| 31 | + private $field; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * SearchOrder constructor. |
|
| 35 | - * |
|
| 36 | - * @param string $direction |
|
| 37 | - * @param string $field |
|
| 38 | - */ |
|
| 39 | - public function __construct($direction, $field) { |
|
| 40 | - $this->direction = $direction; |
|
| 41 | - $this->field = $field; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * SearchOrder constructor. |
|
| 35 | + * |
|
| 36 | + * @param string $direction |
|
| 37 | + * @param string $field |
|
| 38 | + */ |
|
| 39 | + public function __construct($direction, $field) { |
|
| 40 | + $this->direction = $direction; |
|
| 41 | + $this->field = $field; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getDirection() { |
|
| 48 | - return $this->direction; |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getDirection() { |
|
| 48 | + return $this->direction; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function getField() { |
|
| 55 | - return $this->field; |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function getField() { |
|
| 55 | + return $this->field; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -25,33 +25,33 @@ |
||
| 25 | 25 | use OCP\Files\Search\ISearchOperator; |
| 26 | 26 | |
| 27 | 27 | class SearchBinaryOperator implements ISearchBinaryOperator { |
| 28 | - /** @var string */ |
|
| 29 | - private $type; |
|
| 30 | - /** @var ISearchOperator[] */ |
|
| 31 | - private $arguments; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $type; |
|
| 30 | + /** @var ISearchOperator[] */ |
|
| 31 | + private $arguments; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * SearchBinaryOperator constructor. |
|
| 35 | - * |
|
| 36 | - * @param string $type |
|
| 37 | - * @param ISearchOperator[] $arguments |
|
| 38 | - */ |
|
| 39 | - public function __construct($type, array $arguments) { |
|
| 40 | - $this->type = $type; |
|
| 41 | - $this->arguments = $arguments; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * SearchBinaryOperator constructor. |
|
| 35 | + * |
|
| 36 | + * @param string $type |
|
| 37 | + * @param ISearchOperator[] $arguments |
|
| 38 | + */ |
|
| 39 | + public function __construct($type, array $arguments) { |
|
| 40 | + $this->type = $type; |
|
| 41 | + $this->arguments = $arguments; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getType() { |
|
| 48 | - return $this->type; |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getType() { |
|
| 48 | + return $this->type; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return ISearchOperator[] |
|
| 53 | - */ |
|
| 54 | - public function getArguments() { |
|
| 55 | - return $this->arguments; |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * @return ISearchOperator[] |
|
| 53 | + */ |
|
| 54 | + public function getArguments() { |
|
| 55 | + return $this->arguments; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | $updatedEntries = $builder->execute(); |
| 73 | 73 | if ($updatedEntries > 0) { |
| 74 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
| 74 | + $out->info('Fixed file share permissions for '.$updatedEntries.' shares'); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | if ($deletedEntries) { |
| 110 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
| 110 | + $out->info('Removed '.$deletedEntries.' shares where the parent did not exist'); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
@@ -32,90 +32,90 @@ |
||
| 32 | 32 | * Repairs shares with invalid data |
| 33 | 33 | */ |
| 34 | 34 | class RepairInvalidShares implements IRepairStep { |
| 35 | - public const CHUNK_SIZE = 200; |
|
| 36 | - |
|
| 37 | - /** @var \OCP\IConfig */ |
|
| 38 | - protected $config; |
|
| 39 | - |
|
| 40 | - /** @var \OCP\IDBConnection */ |
|
| 41 | - protected $connection; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param \OCP\IConfig $config |
|
| 45 | - * @param \OCP\IDBConnection $connection |
|
| 46 | - */ |
|
| 47 | - public function __construct($config, $connection) { |
|
| 48 | - $this->connection = $connection; |
|
| 49 | - $this->config = $config; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function getName() { |
|
| 53 | - return 'Repair invalid shares'; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Adjust file share permissions |
|
| 58 | - * @suppress SqlInjectionChecker |
|
| 59 | - */ |
|
| 60 | - private function adjustFileSharePermissions(IOutput $out) { |
|
| 61 | - $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
| 62 | - $builder = $this->connection->getQueryBuilder(); |
|
| 63 | - |
|
| 64 | - $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
| 65 | - $builder |
|
| 66 | - ->update('share') |
|
| 67 | - ->set('permissions', $permsFunc) |
|
| 68 | - ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
| 69 | - ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
| 70 | - |
|
| 71 | - $updatedEntries = $builder->execute(); |
|
| 72 | - if ($updatedEntries > 0) { |
|
| 73 | - $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Remove shares where the parent share does not exist anymore |
|
| 79 | - */ |
|
| 80 | - private function removeSharesNonExistingParent(IOutput $out) { |
|
| 81 | - $deletedEntries = 0; |
|
| 82 | - |
|
| 83 | - $query = $this->connection->getQueryBuilder(); |
|
| 84 | - $query->select('s1.parent') |
|
| 85 | - ->from('share', 's1') |
|
| 86 | - ->where($query->expr()->isNotNull('s1.parent')) |
|
| 87 | - ->andWhere($query->expr()->isNull('s2.id')) |
|
| 88 | - ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
| 89 | - ->groupBy('s1.parent') |
|
| 90 | - ->setMaxResults(self::CHUNK_SIZE); |
|
| 91 | - |
|
| 92 | - $deleteQuery = $this->connection->getQueryBuilder(); |
|
| 93 | - $deleteQuery->delete('share') |
|
| 94 | - ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
| 95 | - |
|
| 96 | - $deletedInLastChunk = self::CHUNK_SIZE; |
|
| 97 | - while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
| 98 | - $deletedInLastChunk = 0; |
|
| 99 | - $result = $query->execute(); |
|
| 100 | - while ($row = $result->fetch()) { |
|
| 101 | - $deletedInLastChunk++; |
|
| 102 | - $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
| 103 | - ->execute(); |
|
| 104 | - } |
|
| 105 | - $result->closeCursor(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if ($deletedEntries) { |
|
| 109 | - $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function run(IOutput $out) { |
|
| 114 | - $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 115 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
| 116 | - $this->adjustFileSharePermissions($out); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $this->removeSharesNonExistingParent($out); |
|
| 120 | - } |
|
| 35 | + public const CHUNK_SIZE = 200; |
|
| 36 | + |
|
| 37 | + /** @var \OCP\IConfig */ |
|
| 38 | + protected $config; |
|
| 39 | + |
|
| 40 | + /** @var \OCP\IDBConnection */ |
|
| 41 | + protected $connection; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param \OCP\IConfig $config |
|
| 45 | + * @param \OCP\IDBConnection $connection |
|
| 46 | + */ |
|
| 47 | + public function __construct($config, $connection) { |
|
| 48 | + $this->connection = $connection; |
|
| 49 | + $this->config = $config; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function getName() { |
|
| 53 | + return 'Repair invalid shares'; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Adjust file share permissions |
|
| 58 | + * @suppress SqlInjectionChecker |
|
| 59 | + */ |
|
| 60 | + private function adjustFileSharePermissions(IOutput $out) { |
|
| 61 | + $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE; |
|
| 62 | + $builder = $this->connection->getQueryBuilder(); |
|
| 63 | + |
|
| 64 | + $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask); |
|
| 65 | + $builder |
|
| 66 | + ->update('share') |
|
| 67 | + ->set('permissions', $permsFunc) |
|
| 68 | + ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file'))) |
|
| 69 | + ->andWhere($builder->expr()->neq('permissions', $permsFunc)); |
|
| 70 | + |
|
| 71 | + $updatedEntries = $builder->execute(); |
|
| 72 | + if ($updatedEntries > 0) { |
|
| 73 | + $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares'); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Remove shares where the parent share does not exist anymore |
|
| 79 | + */ |
|
| 80 | + private function removeSharesNonExistingParent(IOutput $out) { |
|
| 81 | + $deletedEntries = 0; |
|
| 82 | + |
|
| 83 | + $query = $this->connection->getQueryBuilder(); |
|
| 84 | + $query->select('s1.parent') |
|
| 85 | + ->from('share', 's1') |
|
| 86 | + ->where($query->expr()->isNotNull('s1.parent')) |
|
| 87 | + ->andWhere($query->expr()->isNull('s2.id')) |
|
| 88 | + ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) |
|
| 89 | + ->groupBy('s1.parent') |
|
| 90 | + ->setMaxResults(self::CHUNK_SIZE); |
|
| 91 | + |
|
| 92 | + $deleteQuery = $this->connection->getQueryBuilder(); |
|
| 93 | + $deleteQuery->delete('share') |
|
| 94 | + ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent'))); |
|
| 95 | + |
|
| 96 | + $deletedInLastChunk = self::CHUNK_SIZE; |
|
| 97 | + while ($deletedInLastChunk === self::CHUNK_SIZE) { |
|
| 98 | + $deletedInLastChunk = 0; |
|
| 99 | + $result = $query->execute(); |
|
| 100 | + while ($row = $result->fetch()) { |
|
| 101 | + $deletedInLastChunk++; |
|
| 102 | + $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) |
|
| 103 | + ->execute(); |
|
| 104 | + } |
|
| 105 | + $result->closeCursor(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if ($deletedEntries) { |
|
| 109 | + $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist'); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function run(IOutput $out) { |
|
| 114 | + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 115 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) { |
|
| 116 | + $this->adjustFileSharePermissions($out); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $this->removeSharesNonExistingParent($out); |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -23,18 +23,18 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | return [ |
| 26 | - 'routes' => [ |
|
| 27 | - ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'], |
|
| 28 | - ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'], |
|
| 29 | - ], |
|
| 30 | - 'ocs' => [ |
|
| 31 | - ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'], |
|
| 32 | - ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'], |
|
| 33 | - ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'], |
|
| 34 | - ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'], |
|
| 35 | - ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'], |
|
| 36 | - ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'], |
|
| 37 | - ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'], |
|
| 38 | - ['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'], |
|
| 39 | - ], |
|
| 26 | + 'routes' => [ |
|
| 27 | + ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'], |
|
| 28 | + ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'], |
|
| 29 | + ], |
|
| 30 | + 'ocs' => [ |
|
| 31 | + ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'], |
|
| 32 | + ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'], |
|
| 33 | + ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'], |
|
| 34 | + ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'], |
|
| 35 | + ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'], |
|
| 36 | + ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'], |
|
| 37 | + ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'], |
|
| 38 | + ['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'], |
|
| 39 | + ], |
|
| 40 | 40 | ]; |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | // no php execution timeout for webdav |
| 23 | 23 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
| 24 | - @set_time_limit(0); |
|
| 24 | + @set_time_limit(0); |
|
| 25 | 25 | } |
| 26 | 26 | ignore_user_abort(true); |
| 27 | 27 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | if ($provider === null) { |
| 217 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
| 217 | + throw new ProviderException('No provider with id .'.$id.' found.'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | return $provider; |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | |
| 243 | 243 | if ($provider === null) { |
| 244 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
| 244 | + throw new ProviderException('No share provider for share type '.$shareType); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | return $provider; |
@@ -49,273 +49,273 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | class ProviderFactory implements IProviderFactory { |
| 51 | 51 | |
| 52 | - /** @var IServerContainer */ |
|
| 53 | - private $serverContainer; |
|
| 54 | - /** @var DefaultShareProvider */ |
|
| 55 | - private $defaultProvider = null; |
|
| 56 | - /** @var FederatedShareProvider */ |
|
| 57 | - private $federatedProvider = null; |
|
| 58 | - /** @var ShareByMailProvider */ |
|
| 59 | - private $shareByMailProvider; |
|
| 60 | - /** @var \OCA\Circles\ShareByCircleProvider */ |
|
| 61 | - private $shareByCircleProvider = null; |
|
| 62 | - /** @var bool */ |
|
| 63 | - private $circlesAreNotAvailable = false; |
|
| 64 | - /** @var \OCA\Talk\Share\RoomShareProvider */ |
|
| 65 | - private $roomShareProvider = null; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * IProviderFactory constructor. |
|
| 69 | - * |
|
| 70 | - * @param IServerContainer $serverContainer |
|
| 71 | - */ |
|
| 72 | - public function __construct(IServerContainer $serverContainer) { |
|
| 73 | - $this->serverContainer = $serverContainer; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Create the default share provider. |
|
| 78 | - * |
|
| 79 | - * @return DefaultShareProvider |
|
| 80 | - */ |
|
| 81 | - protected function defaultShareProvider() { |
|
| 82 | - if ($this->defaultProvider === null) { |
|
| 83 | - $this->defaultProvider = new DefaultShareProvider( |
|
| 84 | - $this->serverContainer->getDatabaseConnection(), |
|
| 85 | - $this->serverContainer->getUserManager(), |
|
| 86 | - $this->serverContainer->getGroupManager(), |
|
| 87 | - $this->serverContainer->getLazyRootFolder(), |
|
| 88 | - $this->serverContainer->getMailer(), |
|
| 89 | - $this->serverContainer->query(Defaults::class), |
|
| 90 | - $this->serverContainer->getL10NFactory(), |
|
| 91 | - $this->serverContainer->getURLGenerator(), |
|
| 92 | - $this->serverContainer->getConfig() |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return $this->defaultProvider; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Create the federated share provider |
|
| 101 | - * |
|
| 102 | - * @return FederatedShareProvider |
|
| 103 | - */ |
|
| 104 | - protected function federatedShareProvider() { |
|
| 105 | - if ($this->federatedProvider === null) { |
|
| 106 | - /* |
|
| 52 | + /** @var IServerContainer */ |
|
| 53 | + private $serverContainer; |
|
| 54 | + /** @var DefaultShareProvider */ |
|
| 55 | + private $defaultProvider = null; |
|
| 56 | + /** @var FederatedShareProvider */ |
|
| 57 | + private $federatedProvider = null; |
|
| 58 | + /** @var ShareByMailProvider */ |
|
| 59 | + private $shareByMailProvider; |
|
| 60 | + /** @var \OCA\Circles\ShareByCircleProvider */ |
|
| 61 | + private $shareByCircleProvider = null; |
|
| 62 | + /** @var bool */ |
|
| 63 | + private $circlesAreNotAvailable = false; |
|
| 64 | + /** @var \OCA\Talk\Share\RoomShareProvider */ |
|
| 65 | + private $roomShareProvider = null; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * IProviderFactory constructor. |
|
| 69 | + * |
|
| 70 | + * @param IServerContainer $serverContainer |
|
| 71 | + */ |
|
| 72 | + public function __construct(IServerContainer $serverContainer) { |
|
| 73 | + $this->serverContainer = $serverContainer; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Create the default share provider. |
|
| 78 | + * |
|
| 79 | + * @return DefaultShareProvider |
|
| 80 | + */ |
|
| 81 | + protected function defaultShareProvider() { |
|
| 82 | + if ($this->defaultProvider === null) { |
|
| 83 | + $this->defaultProvider = new DefaultShareProvider( |
|
| 84 | + $this->serverContainer->getDatabaseConnection(), |
|
| 85 | + $this->serverContainer->getUserManager(), |
|
| 86 | + $this->serverContainer->getGroupManager(), |
|
| 87 | + $this->serverContainer->getLazyRootFolder(), |
|
| 88 | + $this->serverContainer->getMailer(), |
|
| 89 | + $this->serverContainer->query(Defaults::class), |
|
| 90 | + $this->serverContainer->getL10NFactory(), |
|
| 91 | + $this->serverContainer->getURLGenerator(), |
|
| 92 | + $this->serverContainer->getConfig() |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return $this->defaultProvider; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Create the federated share provider |
|
| 101 | + * |
|
| 102 | + * @return FederatedShareProvider |
|
| 103 | + */ |
|
| 104 | + protected function federatedShareProvider() { |
|
| 105 | + if ($this->federatedProvider === null) { |
|
| 106 | + /* |
|
| 107 | 107 | * Check if the app is enabled |
| 108 | 108 | */ |
| 109 | - $appManager = $this->serverContainer->getAppManager(); |
|
| 110 | - if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 111 | - return null; |
|
| 112 | - } |
|
| 109 | + $appManager = $this->serverContainer->getAppManager(); |
|
| 110 | + if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 111 | + return null; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /* |
|
| 114 | + /* |
|
| 115 | 115 | * TODO: add factory to federated sharing app |
| 116 | 116 | */ |
| 117 | - $l = $this->serverContainer->getL10N('federatedfilesharing'); |
|
| 118 | - $addressHandler = new AddressHandler( |
|
| 119 | - $this->serverContainer->getURLGenerator(), |
|
| 120 | - $l, |
|
| 121 | - $this->serverContainer->getCloudIdManager() |
|
| 122 | - ); |
|
| 123 | - $notifications = new Notifications( |
|
| 124 | - $addressHandler, |
|
| 125 | - $this->serverContainer->getHTTPClientService(), |
|
| 126 | - $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), |
|
| 127 | - $this->serverContainer->getJobList(), |
|
| 128 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 129 | - \OC::$server->getCloudFederationFactory() |
|
| 130 | - ); |
|
| 131 | - $tokenHandler = new TokenHandler( |
|
| 132 | - $this->serverContainer->getSecureRandom() |
|
| 133 | - ); |
|
| 134 | - |
|
| 135 | - $this->federatedProvider = new FederatedShareProvider( |
|
| 136 | - $this->serverContainer->getDatabaseConnection(), |
|
| 137 | - $addressHandler, |
|
| 138 | - $notifications, |
|
| 139 | - $tokenHandler, |
|
| 140 | - $l, |
|
| 141 | - $this->serverContainer->getLogger(), |
|
| 142 | - $this->serverContainer->getLazyRootFolder(), |
|
| 143 | - $this->serverContainer->getConfig(), |
|
| 144 | - $this->serverContainer->getUserManager(), |
|
| 145 | - $this->serverContainer->getCloudIdManager(), |
|
| 146 | - $this->serverContainer->getGlobalScaleConfig(), |
|
| 147 | - $this->serverContainer->getCloudFederationProviderManager() |
|
| 148 | - ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $this->federatedProvider; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Create the federated share provider |
|
| 156 | - * |
|
| 157 | - * @return ShareByMailProvider |
|
| 158 | - */ |
|
| 159 | - protected function getShareByMailProvider() { |
|
| 160 | - if ($this->shareByMailProvider === null) { |
|
| 161 | - /* |
|
| 117 | + $l = $this->serverContainer->getL10N('federatedfilesharing'); |
|
| 118 | + $addressHandler = new AddressHandler( |
|
| 119 | + $this->serverContainer->getURLGenerator(), |
|
| 120 | + $l, |
|
| 121 | + $this->serverContainer->getCloudIdManager() |
|
| 122 | + ); |
|
| 123 | + $notifications = new Notifications( |
|
| 124 | + $addressHandler, |
|
| 125 | + $this->serverContainer->getHTTPClientService(), |
|
| 126 | + $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), |
|
| 127 | + $this->serverContainer->getJobList(), |
|
| 128 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 129 | + \OC::$server->getCloudFederationFactory() |
|
| 130 | + ); |
|
| 131 | + $tokenHandler = new TokenHandler( |
|
| 132 | + $this->serverContainer->getSecureRandom() |
|
| 133 | + ); |
|
| 134 | + |
|
| 135 | + $this->federatedProvider = new FederatedShareProvider( |
|
| 136 | + $this->serverContainer->getDatabaseConnection(), |
|
| 137 | + $addressHandler, |
|
| 138 | + $notifications, |
|
| 139 | + $tokenHandler, |
|
| 140 | + $l, |
|
| 141 | + $this->serverContainer->getLogger(), |
|
| 142 | + $this->serverContainer->getLazyRootFolder(), |
|
| 143 | + $this->serverContainer->getConfig(), |
|
| 144 | + $this->serverContainer->getUserManager(), |
|
| 145 | + $this->serverContainer->getCloudIdManager(), |
|
| 146 | + $this->serverContainer->getGlobalScaleConfig(), |
|
| 147 | + $this->serverContainer->getCloudFederationProviderManager() |
|
| 148 | + ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $this->federatedProvider; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Create the federated share provider |
|
| 156 | + * |
|
| 157 | + * @return ShareByMailProvider |
|
| 158 | + */ |
|
| 159 | + protected function getShareByMailProvider() { |
|
| 160 | + if ($this->shareByMailProvider === null) { |
|
| 161 | + /* |
|
| 162 | 162 | * Check if the app is enabled |
| 163 | 163 | */ |
| 164 | - $appManager = $this->serverContainer->getAppManager(); |
|
| 165 | - if (!$appManager->isEnabledForUser('sharebymail')) { |
|
| 166 | - return null; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
| 170 | - |
|
| 171 | - $this->shareByMailProvider = new ShareByMailProvider( |
|
| 172 | - $this->serverContainer->getDatabaseConnection(), |
|
| 173 | - $this->serverContainer->getSecureRandom(), |
|
| 174 | - $this->serverContainer->getUserManager(), |
|
| 175 | - $this->serverContainer->getLazyRootFolder(), |
|
| 176 | - $this->serverContainer->getL10N('sharebymail'), |
|
| 177 | - $this->serverContainer->getLogger(), |
|
| 178 | - $this->serverContainer->getMailer(), |
|
| 179 | - $this->serverContainer->getURLGenerator(), |
|
| 180 | - $this->serverContainer->getActivityManager(), |
|
| 181 | - $settingsManager, |
|
| 182 | - $this->serverContainer->query(Defaults::class), |
|
| 183 | - $this->serverContainer->getHasher(), |
|
| 184 | - $this->serverContainer->query(CapabilitiesManager::class) |
|
| 185 | - ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $this->shareByMailProvider; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Create the circle share provider |
|
| 194 | - * |
|
| 195 | - * @return FederatedShareProvider |
|
| 196 | - * |
|
| 197 | - * @suppress PhanUndeclaredClassMethod |
|
| 198 | - */ |
|
| 199 | - protected function getShareByCircleProvider() { |
|
| 200 | - if ($this->circlesAreNotAvailable) { |
|
| 201 | - return null; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || |
|
| 205 | - !class_exists('\OCA\Circles\ShareByCircleProvider') |
|
| 206 | - ) { |
|
| 207 | - $this->circlesAreNotAvailable = true; |
|
| 208 | - return null; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if ($this->shareByCircleProvider === null) { |
|
| 212 | - $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
| 213 | - $this->serverContainer->getDatabaseConnection(), |
|
| 214 | - $this->serverContainer->getSecureRandom(), |
|
| 215 | - $this->serverContainer->getUserManager(), |
|
| 216 | - $this->serverContainer->getLazyRootFolder(), |
|
| 217 | - $this->serverContainer->getL10N('circles'), |
|
| 218 | - $this->serverContainer->getLogger(), |
|
| 219 | - $this->serverContainer->getURLGenerator() |
|
| 220 | - ); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $this->shareByCircleProvider; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Create the room share provider |
|
| 228 | - * |
|
| 229 | - * @return RoomShareProvider |
|
| 230 | - */ |
|
| 231 | - protected function getRoomShareProvider() { |
|
| 232 | - if ($this->roomShareProvider === null) { |
|
| 233 | - /* |
|
| 164 | + $appManager = $this->serverContainer->getAppManager(); |
|
| 165 | + if (!$appManager->isEnabledForUser('sharebymail')) { |
|
| 166 | + return null; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
| 170 | + |
|
| 171 | + $this->shareByMailProvider = new ShareByMailProvider( |
|
| 172 | + $this->serverContainer->getDatabaseConnection(), |
|
| 173 | + $this->serverContainer->getSecureRandom(), |
|
| 174 | + $this->serverContainer->getUserManager(), |
|
| 175 | + $this->serverContainer->getLazyRootFolder(), |
|
| 176 | + $this->serverContainer->getL10N('sharebymail'), |
|
| 177 | + $this->serverContainer->getLogger(), |
|
| 178 | + $this->serverContainer->getMailer(), |
|
| 179 | + $this->serverContainer->getURLGenerator(), |
|
| 180 | + $this->serverContainer->getActivityManager(), |
|
| 181 | + $settingsManager, |
|
| 182 | + $this->serverContainer->query(Defaults::class), |
|
| 183 | + $this->serverContainer->getHasher(), |
|
| 184 | + $this->serverContainer->query(CapabilitiesManager::class) |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $this->shareByMailProvider; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Create the circle share provider |
|
| 194 | + * |
|
| 195 | + * @return FederatedShareProvider |
|
| 196 | + * |
|
| 197 | + * @suppress PhanUndeclaredClassMethod |
|
| 198 | + */ |
|
| 199 | + protected function getShareByCircleProvider() { |
|
| 200 | + if ($this->circlesAreNotAvailable) { |
|
| 201 | + return null; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || |
|
| 205 | + !class_exists('\OCA\Circles\ShareByCircleProvider') |
|
| 206 | + ) { |
|
| 207 | + $this->circlesAreNotAvailable = true; |
|
| 208 | + return null; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if ($this->shareByCircleProvider === null) { |
|
| 212 | + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
| 213 | + $this->serverContainer->getDatabaseConnection(), |
|
| 214 | + $this->serverContainer->getSecureRandom(), |
|
| 215 | + $this->serverContainer->getUserManager(), |
|
| 216 | + $this->serverContainer->getLazyRootFolder(), |
|
| 217 | + $this->serverContainer->getL10N('circles'), |
|
| 218 | + $this->serverContainer->getLogger(), |
|
| 219 | + $this->serverContainer->getURLGenerator() |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $this->shareByCircleProvider; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Create the room share provider |
|
| 228 | + * |
|
| 229 | + * @return RoomShareProvider |
|
| 230 | + */ |
|
| 231 | + protected function getRoomShareProvider() { |
|
| 232 | + if ($this->roomShareProvider === null) { |
|
| 233 | + /* |
|
| 234 | 234 | * Check if the app is enabled |
| 235 | 235 | */ |
| 236 | - $appManager = $this->serverContainer->getAppManager(); |
|
| 237 | - if (!$appManager->isEnabledForUser('spreed')) { |
|
| 238 | - return null; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - try { |
|
| 242 | - $this->roomShareProvider = $this->serverContainer->query('\OCA\Talk\Share\RoomShareProvider'); |
|
| 243 | - } catch (\OCP\AppFramework\QueryException $e) { |
|
| 244 | - return null; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - return $this->roomShareProvider; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @inheritdoc |
|
| 253 | - */ |
|
| 254 | - public function getProvider($id) { |
|
| 255 | - $provider = null; |
|
| 256 | - if ($id === 'ocinternal') { |
|
| 257 | - $provider = $this->defaultShareProvider(); |
|
| 258 | - } elseif ($id === 'ocFederatedSharing') { |
|
| 259 | - $provider = $this->federatedShareProvider(); |
|
| 260 | - } elseif ($id === 'ocMailShare') { |
|
| 261 | - $provider = $this->getShareByMailProvider(); |
|
| 262 | - } elseif ($id === 'ocCircleShare') { |
|
| 263 | - $provider = $this->getShareByCircleProvider(); |
|
| 264 | - } elseif ($id === 'ocRoomShare') { |
|
| 265 | - $provider = $this->getRoomShareProvider(); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - if ($provider === null) { |
|
| 269 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return $provider; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @inheritdoc |
|
| 277 | - */ |
|
| 278 | - public function getProviderForType($shareType) { |
|
| 279 | - $provider = null; |
|
| 280 | - |
|
| 281 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
| 282 | - $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
| 283 | - $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
| 284 | - ) { |
|
| 285 | - $provider = $this->defaultShareProvider(); |
|
| 286 | - } elseif ($shareType === \OCP\Share::SHARE_TYPE_REMOTE || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
| 287 | - $provider = $this->federatedShareProvider(); |
|
| 288 | - } elseif ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 289 | - $provider = $this->getShareByMailProvider(); |
|
| 290 | - } elseif ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 291 | - $provider = $this->getShareByCircleProvider(); |
|
| 292 | - } elseif ($shareType === \OCP\Share::SHARE_TYPE_ROOM) { |
|
| 293 | - $provider = $this->getRoomShareProvider(); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - if ($provider === null) { |
|
| 298 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - return $provider; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - public function getAllProviders() { |
|
| 305 | - $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
| 306 | - $shareByMail = $this->getShareByMailProvider(); |
|
| 307 | - if ($shareByMail !== null) { |
|
| 308 | - $shares[] = $shareByMail; |
|
| 309 | - } |
|
| 310 | - $shareByCircle = $this->getShareByCircleProvider(); |
|
| 311 | - if ($shareByCircle !== null) { |
|
| 312 | - $shares[] = $shareByCircle; |
|
| 313 | - } |
|
| 314 | - $roomShare = $this->getRoomShareProvider(); |
|
| 315 | - if ($roomShare !== null) { |
|
| 316 | - $shares[] = $roomShare; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return $shares; |
|
| 320 | - } |
|
| 236 | + $appManager = $this->serverContainer->getAppManager(); |
|
| 237 | + if (!$appManager->isEnabledForUser('spreed')) { |
|
| 238 | + return null; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + try { |
|
| 242 | + $this->roomShareProvider = $this->serverContainer->query('\OCA\Talk\Share\RoomShareProvider'); |
|
| 243 | + } catch (\OCP\AppFramework\QueryException $e) { |
|
| 244 | + return null; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + return $this->roomShareProvider; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @inheritdoc |
|
| 253 | + */ |
|
| 254 | + public function getProvider($id) { |
|
| 255 | + $provider = null; |
|
| 256 | + if ($id === 'ocinternal') { |
|
| 257 | + $provider = $this->defaultShareProvider(); |
|
| 258 | + } elseif ($id === 'ocFederatedSharing') { |
|
| 259 | + $provider = $this->federatedShareProvider(); |
|
| 260 | + } elseif ($id === 'ocMailShare') { |
|
| 261 | + $provider = $this->getShareByMailProvider(); |
|
| 262 | + } elseif ($id === 'ocCircleShare') { |
|
| 263 | + $provider = $this->getShareByCircleProvider(); |
|
| 264 | + } elseif ($id === 'ocRoomShare') { |
|
| 265 | + $provider = $this->getRoomShareProvider(); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + if ($provider === null) { |
|
| 269 | + throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return $provider; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @inheritdoc |
|
| 277 | + */ |
|
| 278 | + public function getProviderForType($shareType) { |
|
| 279 | + $provider = null; |
|
| 280 | + |
|
| 281 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
| 282 | + $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
| 283 | + $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
| 284 | + ) { |
|
| 285 | + $provider = $this->defaultShareProvider(); |
|
| 286 | + } elseif ($shareType === \OCP\Share::SHARE_TYPE_REMOTE || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
| 287 | + $provider = $this->federatedShareProvider(); |
|
| 288 | + } elseif ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 289 | + $provider = $this->getShareByMailProvider(); |
|
| 290 | + } elseif ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 291 | + $provider = $this->getShareByCircleProvider(); |
|
| 292 | + } elseif ($shareType === \OCP\Share::SHARE_TYPE_ROOM) { |
|
| 293 | + $provider = $this->getRoomShareProvider(); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + if ($provider === null) { |
|
| 298 | + throw new ProviderException('No share provider for share type ' . $shareType); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + return $provider; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + public function getAllProviders() { |
|
| 305 | + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
| 306 | + $shareByMail = $this->getShareByMailProvider(); |
|
| 307 | + if ($shareByMail !== null) { |
|
| 308 | + $shares[] = $shareByMail; |
|
| 309 | + } |
|
| 310 | + $shareByCircle = $this->getShareByCircleProvider(); |
|
| 311 | + if ($shareByCircle !== null) { |
|
| 312 | + $shares[] = $shareByCircle; |
|
| 313 | + } |
|
| 314 | + $roomShare = $this->getRoomShareProvider(); |
|
| 315 | + if ($roomShare !== null) { |
|
| 316 | + $shares[] = $roomShare; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return $shares; |
|
| 320 | + } |
|
| 321 | 321 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | // register hooks |
| 29 | 29 | \OCA\Files_Trashbin\Trashbin::registerHooks(); |
| 30 | 30 | |
| 31 | -\OCA\Files\App::getNavigationManager()->add(function () { |
|
| 31 | +\OCA\Files\App::getNavigationManager()->add(function() { |
|
| 32 | 32 | $l = \OC::$server->getL10N('files_trashbin'); |
| 33 | 33 | return [ |
| 34 | 34 | 'id' => 'trashbin', |
@@ -29,13 +29,13 @@ |
||
| 29 | 29 | \OCA\Files_Trashbin\Trashbin::registerHooks(); |
| 30 | 30 | |
| 31 | 31 | \OCA\Files\App::getNavigationManager()->add(function () { |
| 32 | - $l = \OC::$server->getL10N('files_trashbin'); |
|
| 33 | - return [ |
|
| 34 | - 'id' => 'trashbin', |
|
| 35 | - 'appname' => 'files_trashbin', |
|
| 36 | - 'script' => 'list.php', |
|
| 37 | - 'order' => 50, |
|
| 38 | - 'name' => $l->t('Deleted files'), |
|
| 39 | - 'classes' => 'pinned', |
|
| 40 | - ]; |
|
| 32 | + $l = \OC::$server->getL10N('files_trashbin'); |
|
| 33 | + return [ |
|
| 34 | + 'id' => 'trashbin', |
|
| 35 | + 'appname' => 'files_trashbin', |
|
| 36 | + 'script' => 'list.php', |
|
| 37 | + 'order' => 50, |
|
| 38 | + 'name' => $l->t('Deleted files'), |
|
| 39 | + 'classes' => 'pinned', |
|
| 40 | + ]; |
|
| 41 | 41 | }); |
@@ -119,9 +119,9 @@ |
||
| 119 | 119 | $elements = explode(' ', $fullName); |
| 120 | 120 | $result = ['', '', '', '', '']; |
| 121 | 121 | if (count($elements) > 2) { |
| 122 | - $result[0] = implode(' ', array_slice($elements, count($elements)-1)); |
|
| 122 | + $result[0] = implode(' ', array_slice($elements, count($elements) - 1)); |
|
| 123 | 123 | $result[1] = $elements[0]; |
| 124 | - $result[2] = implode(' ', array_slice($elements, 1, count($elements)-2)); |
|
| 124 | + $result[2] = implode(' ', array_slice($elements, 1, count($elements) - 2)); |
|
| 125 | 125 | } elseif (count($elements) === 2) { |
| 126 | 126 | $result[0] = $elements[1]; |
| 127 | 127 | $result[1] = $elements[0]; |
@@ -33,119 +33,119 @@ |
||
| 33 | 33 | |
| 34 | 34 | class Converter { |
| 35 | 35 | |
| 36 | - /** @var AccountManager */ |
|
| 37 | - private $accountManager; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Converter constructor. |
|
| 41 | - * |
|
| 42 | - * @param AccountManager $accountManager |
|
| 43 | - */ |
|
| 44 | - public function __construct(AccountManager $accountManager) { |
|
| 45 | - $this->accountManager = $accountManager; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param IUser $user |
|
| 50 | - * @return VCard|null |
|
| 51 | - */ |
|
| 52 | - public function createCardFromUser(IUser $user) { |
|
| 53 | - $userData = $this->accountManager->getUser($user); |
|
| 54 | - |
|
| 55 | - $uid = $user->getUID(); |
|
| 56 | - $cloudId = $user->getCloudId(); |
|
| 57 | - $image = $this->getAvatarImage($user); |
|
| 58 | - |
|
| 59 | - $vCard = new VCard(); |
|
| 60 | - $vCard->VERSION = '3.0'; |
|
| 61 | - $vCard->UID = $uid; |
|
| 62 | - |
|
| 63 | - $publish = false; |
|
| 64 | - |
|
| 65 | - if ($image !== null && isset($userData[AccountManager::PROPERTY_AVATAR])) { |
|
| 66 | - $userData[AccountManager::PROPERTY_AVATAR]['value'] = true; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - foreach ($userData as $property => $value) { |
|
| 70 | - $shareWithTrustedServers = |
|
| 71 | - $value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY || |
|
| 72 | - $value['scope'] === AccountManager::VISIBILITY_PUBLIC; |
|
| 73 | - |
|
| 74 | - $emptyValue = !isset($value['value']) || $value['value'] === ''; |
|
| 75 | - |
|
| 76 | - if ($shareWithTrustedServers && !$emptyValue) { |
|
| 77 | - $publish = true; |
|
| 78 | - switch ($property) { |
|
| 79 | - case AccountManager::PROPERTY_DISPLAYNAME: |
|
| 80 | - $vCard->add(new Text($vCard, 'FN', $value['value'])); |
|
| 81 | - $vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value']))); |
|
| 82 | - break; |
|
| 83 | - case AccountManager::PROPERTY_AVATAR: |
|
| 84 | - if ($image !== null) { |
|
| 85 | - $vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]); |
|
| 86 | - } |
|
| 87 | - break; |
|
| 88 | - case AccountManager::PROPERTY_EMAIL: |
|
| 89 | - $vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER'])); |
|
| 90 | - break; |
|
| 91 | - case AccountManager::PROPERTY_WEBSITE: |
|
| 92 | - $vCard->add(new Text($vCard, 'URL', $value['value'])); |
|
| 93 | - break; |
|
| 94 | - case AccountManager::PROPERTY_PHONE: |
|
| 95 | - $vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER'])); |
|
| 96 | - break; |
|
| 97 | - case AccountManager::PROPERTY_ADDRESS: |
|
| 98 | - $vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER'])); |
|
| 99 | - break; |
|
| 100 | - case AccountManager::PROPERTY_TWITTER: |
|
| 101 | - $vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER'])); |
|
| 102 | - break; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ($publish && !empty($cloudId)) { |
|
| 108 | - $vCard->add(new Text($vCard, 'CLOUD', $cloudId)); |
|
| 109 | - $vCard->validate(); |
|
| 110 | - return $vCard; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return null; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param string $fullName |
|
| 118 | - * @return string[] |
|
| 119 | - */ |
|
| 120 | - public function splitFullName($fullName) { |
|
| 121 | - // Very basic western style parsing. I'm not gonna implement |
|
| 122 | - // https://github.com/android/platform_packages_providers_contactsprovider/blob/master/src/com/android/providers/contacts/NameSplitter.java ;) |
|
| 123 | - |
|
| 124 | - $elements = explode(' ', $fullName); |
|
| 125 | - $result = ['', '', '', '', '']; |
|
| 126 | - if (count($elements) > 2) { |
|
| 127 | - $result[0] = implode(' ', array_slice($elements, count($elements)-1)); |
|
| 128 | - $result[1] = $elements[0]; |
|
| 129 | - $result[2] = implode(' ', array_slice($elements, 1, count($elements)-2)); |
|
| 130 | - } elseif (count($elements) === 2) { |
|
| 131 | - $result[0] = $elements[1]; |
|
| 132 | - $result[1] = $elements[0]; |
|
| 133 | - } else { |
|
| 134 | - $result[0] = $elements[0]; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $result; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param IUser $user |
|
| 142 | - * @return null|IImage |
|
| 143 | - */ |
|
| 144 | - private function getAvatarImage(IUser $user) { |
|
| 145 | - try { |
|
| 146 | - return $user->getAvatarImage(-1); |
|
| 147 | - } catch (\Exception $ex) { |
|
| 148 | - return null; |
|
| 149 | - } |
|
| 150 | - } |
|
| 36 | + /** @var AccountManager */ |
|
| 37 | + private $accountManager; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Converter constructor. |
|
| 41 | + * |
|
| 42 | + * @param AccountManager $accountManager |
|
| 43 | + */ |
|
| 44 | + public function __construct(AccountManager $accountManager) { |
|
| 45 | + $this->accountManager = $accountManager; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param IUser $user |
|
| 50 | + * @return VCard|null |
|
| 51 | + */ |
|
| 52 | + public function createCardFromUser(IUser $user) { |
|
| 53 | + $userData = $this->accountManager->getUser($user); |
|
| 54 | + |
|
| 55 | + $uid = $user->getUID(); |
|
| 56 | + $cloudId = $user->getCloudId(); |
|
| 57 | + $image = $this->getAvatarImage($user); |
|
| 58 | + |
|
| 59 | + $vCard = new VCard(); |
|
| 60 | + $vCard->VERSION = '3.0'; |
|
| 61 | + $vCard->UID = $uid; |
|
| 62 | + |
|
| 63 | + $publish = false; |
|
| 64 | + |
|
| 65 | + if ($image !== null && isset($userData[AccountManager::PROPERTY_AVATAR])) { |
|
| 66 | + $userData[AccountManager::PROPERTY_AVATAR]['value'] = true; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + foreach ($userData as $property => $value) { |
|
| 70 | + $shareWithTrustedServers = |
|
| 71 | + $value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY || |
|
| 72 | + $value['scope'] === AccountManager::VISIBILITY_PUBLIC; |
|
| 73 | + |
|
| 74 | + $emptyValue = !isset($value['value']) || $value['value'] === ''; |
|
| 75 | + |
|
| 76 | + if ($shareWithTrustedServers && !$emptyValue) { |
|
| 77 | + $publish = true; |
|
| 78 | + switch ($property) { |
|
| 79 | + case AccountManager::PROPERTY_DISPLAYNAME: |
|
| 80 | + $vCard->add(new Text($vCard, 'FN', $value['value'])); |
|
| 81 | + $vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value']))); |
|
| 82 | + break; |
|
| 83 | + case AccountManager::PROPERTY_AVATAR: |
|
| 84 | + if ($image !== null) { |
|
| 85 | + $vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]); |
|
| 86 | + } |
|
| 87 | + break; |
|
| 88 | + case AccountManager::PROPERTY_EMAIL: |
|
| 89 | + $vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER'])); |
|
| 90 | + break; |
|
| 91 | + case AccountManager::PROPERTY_WEBSITE: |
|
| 92 | + $vCard->add(new Text($vCard, 'URL', $value['value'])); |
|
| 93 | + break; |
|
| 94 | + case AccountManager::PROPERTY_PHONE: |
|
| 95 | + $vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER'])); |
|
| 96 | + break; |
|
| 97 | + case AccountManager::PROPERTY_ADDRESS: |
|
| 98 | + $vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER'])); |
|
| 99 | + break; |
|
| 100 | + case AccountManager::PROPERTY_TWITTER: |
|
| 101 | + $vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER'])); |
|
| 102 | + break; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ($publish && !empty($cloudId)) { |
|
| 108 | + $vCard->add(new Text($vCard, 'CLOUD', $cloudId)); |
|
| 109 | + $vCard->validate(); |
|
| 110 | + return $vCard; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return null; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param string $fullName |
|
| 118 | + * @return string[] |
|
| 119 | + */ |
|
| 120 | + public function splitFullName($fullName) { |
|
| 121 | + // Very basic western style parsing. I'm not gonna implement |
|
| 122 | + // https://github.com/android/platform_packages_providers_contactsprovider/blob/master/src/com/android/providers/contacts/NameSplitter.java ;) |
|
| 123 | + |
|
| 124 | + $elements = explode(' ', $fullName); |
|
| 125 | + $result = ['', '', '', '', '']; |
|
| 126 | + if (count($elements) > 2) { |
|
| 127 | + $result[0] = implode(' ', array_slice($elements, count($elements)-1)); |
|
| 128 | + $result[1] = $elements[0]; |
|
| 129 | + $result[2] = implode(' ', array_slice($elements, 1, count($elements)-2)); |
|
| 130 | + } elseif (count($elements) === 2) { |
|
| 131 | + $result[0] = $elements[1]; |
|
| 132 | + $result[1] = $elements[0]; |
|
| 133 | + } else { |
|
| 134 | + $result[0] = $elements[0]; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $result; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param IUser $user |
|
| 142 | + * @return null|IImage |
|
| 143 | + */ |
|
| 144 | + private function getAvatarImage(IUser $user) { |
|
| 145 | + try { |
|
| 146 | + return $user->getAvatarImage(-1); |
|
| 147 | + } catch (\Exception $ex) { |
|
| 148 | + return null; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -37,57 +37,57 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class ConsoleOutput implements IOutput { |
| 39 | 39 | |
| 40 | - /** @var OutputInterface */ |
|
| 41 | - private $output; |
|
| 40 | + /** @var OutputInterface */ |
|
| 41 | + private $output; |
|
| 42 | 42 | |
| 43 | - /** @var ProgressBar */ |
|
| 44 | - private $progressBar; |
|
| 43 | + /** @var ProgressBar */ |
|
| 44 | + private $progressBar; |
|
| 45 | 45 | |
| 46 | - public function __construct(OutputInterface $output) { |
|
| 47 | - $this->output = $output; |
|
| 48 | - } |
|
| 46 | + public function __construct(OutputInterface $output) { |
|
| 47 | + $this->output = $output; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $message |
|
| 52 | - */ |
|
| 53 | - public function info($message) { |
|
| 54 | - $this->output->writeln("<info>$message</info>"); |
|
| 55 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string $message |
|
| 52 | + */ |
|
| 53 | + public function info($message) { |
|
| 54 | + $this->output->writeln("<info>$message</info>"); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param string $message |
|
| 59 | - */ |
|
| 60 | - public function warning($message) { |
|
| 61 | - $this->output->writeln("<comment>$message</comment>"); |
|
| 62 | - } |
|
| 57 | + /** |
|
| 58 | + * @param string $message |
|
| 59 | + */ |
|
| 60 | + public function warning($message) { |
|
| 61 | + $this->output->writeln("<comment>$message</comment>"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param int $max |
|
| 66 | - */ |
|
| 67 | - public function startProgress($max = 0) { |
|
| 68 | - if (!is_null($this->progressBar)) { |
|
| 69 | - $this->progressBar->finish(); |
|
| 70 | - } |
|
| 71 | - $this->progressBar = new ProgressBar($this->output); |
|
| 72 | - $this->progressBar->start($max); |
|
| 73 | - } |
|
| 64 | + /** |
|
| 65 | + * @param int $max |
|
| 66 | + */ |
|
| 67 | + public function startProgress($max = 0) { |
|
| 68 | + if (!is_null($this->progressBar)) { |
|
| 69 | + $this->progressBar->finish(); |
|
| 70 | + } |
|
| 71 | + $this->progressBar = new ProgressBar($this->output); |
|
| 72 | + $this->progressBar->start($max); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param int $step |
|
| 77 | - * @param string $description |
|
| 78 | - */ |
|
| 79 | - public function advance($step = 1, $description = '') { |
|
| 80 | - if (!is_null($this->progressBar)) { |
|
| 81 | - $this->progressBar = new ProgressBar($this->output); |
|
| 82 | - $this->progressBar->start(); |
|
| 83 | - } |
|
| 84 | - $this->progressBar->advance($step); |
|
| 85 | - } |
|
| 75 | + /** |
|
| 76 | + * @param int $step |
|
| 77 | + * @param string $description |
|
| 78 | + */ |
|
| 79 | + public function advance($step = 1, $description = '') { |
|
| 80 | + if (!is_null($this->progressBar)) { |
|
| 81 | + $this->progressBar = new ProgressBar($this->output); |
|
| 82 | + $this->progressBar->start(); |
|
| 83 | + } |
|
| 84 | + $this->progressBar->advance($step); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function finishProgress() { |
|
| 88 | - if (is_null($this->progressBar)) { |
|
| 89 | - return; |
|
| 90 | - } |
|
| 91 | - $this->progressBar->finish(); |
|
| 92 | - } |
|
| 87 | + public function finishProgress() { |
|
| 88 | + if (is_null($this->progressBar)) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + $this->progressBar->finish(); |
|
| 92 | + } |
|
| 93 | 93 | } |