@@ -29,103 +29,103 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface IMountPoint { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * get complete path to the mount point |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - * @since 8.0.0 |
|
| 37 | - */ |
|
| 38 | - public function getMountPoint(); |
|
| 32 | + /** |
|
| 33 | + * get complete path to the mount point |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + * @since 8.0.0 |
|
| 37 | + */ |
|
| 38 | + public function getMountPoint(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Set the mountpoint |
|
| 42 | - * |
|
| 43 | - * @param string $mountPoint new mount point |
|
| 44 | - * @since 8.0.0 |
|
| 45 | - */ |
|
| 46 | - public function setMountPoint($mountPoint); |
|
| 40 | + /** |
|
| 41 | + * Set the mountpoint |
|
| 42 | + * |
|
| 43 | + * @param string $mountPoint new mount point |
|
| 44 | + * @since 8.0.0 |
|
| 45 | + */ |
|
| 46 | + public function setMountPoint($mountPoint); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Get the storage that is mounted |
|
| 50 | - * |
|
| 51 | - * @return \OC\Files\Storage\Storage |
|
| 52 | - * @since 8.0.0 |
|
| 53 | - */ |
|
| 54 | - public function getStorage(); |
|
| 48 | + /** |
|
| 49 | + * Get the storage that is mounted |
|
| 50 | + * |
|
| 51 | + * @return \OC\Files\Storage\Storage |
|
| 52 | + * @since 8.0.0 |
|
| 53 | + */ |
|
| 54 | + public function getStorage(); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get the id of the storages |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - * @since 8.0.0 |
|
| 61 | - */ |
|
| 62 | - public function getStorageId(); |
|
| 56 | + /** |
|
| 57 | + * Get the id of the storages |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + * @since 8.0.0 |
|
| 61 | + */ |
|
| 62 | + public function getStorageId(); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Get the id of the storages |
|
| 66 | - * |
|
| 67 | - * @return int |
|
| 68 | - * @since 9.1.0 |
|
| 69 | - */ |
|
| 70 | - public function getNumericStorageId(); |
|
| 64 | + /** |
|
| 65 | + * Get the id of the storages |
|
| 66 | + * |
|
| 67 | + * @return int |
|
| 68 | + * @since 9.1.0 |
|
| 69 | + */ |
|
| 70 | + public function getNumericStorageId(); |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Get the path relative to the mountpoint |
|
| 74 | - * |
|
| 75 | - * @param string $path absolute path to a file or folder |
|
| 76 | - * @return string |
|
| 77 | - * @since 8.0.0 |
|
| 78 | - */ |
|
| 79 | - public function getInternalPath($path); |
|
| 72 | + /** |
|
| 73 | + * Get the path relative to the mountpoint |
|
| 74 | + * |
|
| 75 | + * @param string $path absolute path to a file or folder |
|
| 76 | + * @return string |
|
| 77 | + * @since 8.0.0 |
|
| 78 | + */ |
|
| 79 | + public function getInternalPath($path); |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Apply a storage wrapper to the mounted storage |
|
| 83 | - * |
|
| 84 | - * @param callable $wrapper |
|
| 85 | - * @since 8.0.0 |
|
| 86 | - */ |
|
| 87 | - public function wrapStorage($wrapper); |
|
| 81 | + /** |
|
| 82 | + * Apply a storage wrapper to the mounted storage |
|
| 83 | + * |
|
| 84 | + * @param callable $wrapper |
|
| 85 | + * @since 8.0.0 |
|
| 86 | + */ |
|
| 87 | + public function wrapStorage($wrapper); |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Get a mount option |
|
| 91 | - * |
|
| 92 | - * @param string $name Name of the mount option to get |
|
| 93 | - * @param mixed $default Default value for the mount option |
|
| 94 | - * @return mixed |
|
| 95 | - * @since 8.0.0 |
|
| 96 | - */ |
|
| 97 | - public function getOption($name, $default); |
|
| 89 | + /** |
|
| 90 | + * Get a mount option |
|
| 91 | + * |
|
| 92 | + * @param string $name Name of the mount option to get |
|
| 93 | + * @param mixed $default Default value for the mount option |
|
| 94 | + * @return mixed |
|
| 95 | + * @since 8.0.0 |
|
| 96 | + */ |
|
| 97 | + public function getOption($name, $default); |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get all options for the mount |
|
| 101 | - * |
|
| 102 | - * @return array |
|
| 103 | - * @since 8.1.0 |
|
| 104 | - */ |
|
| 105 | - public function getOptions(); |
|
| 99 | + /** |
|
| 100 | + * Get all options for the mount |
|
| 101 | + * |
|
| 102 | + * @return array |
|
| 103 | + * @since 8.1.0 |
|
| 104 | + */ |
|
| 105 | + public function getOptions(); |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Get the file id of the root of the storage |
|
| 109 | - * |
|
| 110 | - * @return int |
|
| 111 | - * @since 9.1.0 |
|
| 112 | - */ |
|
| 113 | - public function getStorageRootId(); |
|
| 107 | + /** |
|
| 108 | + * Get the file id of the root of the storage |
|
| 109 | + * |
|
| 110 | + * @return int |
|
| 111 | + * @since 9.1.0 |
|
| 112 | + */ |
|
| 113 | + public function getStorageRootId(); |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Get the id of the configured mount |
|
| 117 | - * |
|
| 118 | - * @return int|null mount id or null if not applicable |
|
| 119 | - * @since 9.1.0 |
|
| 120 | - */ |
|
| 121 | - public function getMountId(); |
|
| 115 | + /** |
|
| 116 | + * Get the id of the configured mount |
|
| 117 | + * |
|
| 118 | + * @return int|null mount id or null if not applicable |
|
| 119 | + * @since 9.1.0 |
|
| 120 | + */ |
|
| 121 | + public function getMountId(); |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Get the type of mount point, used to distinguish things like shares and external storages |
|
| 125 | - * in the web interface |
|
| 126 | - * |
|
| 127 | - * @return string |
|
| 128 | - * @since 12.0.0 |
|
| 129 | - */ |
|
| 130 | - public function getMountType(); |
|
| 123 | + /** |
|
| 124 | + * Get the type of mount point, used to distinguish things like shares and external storages |
|
| 125 | + * in the web interface |
|
| 126 | + * |
|
| 127 | + * @return string |
|
| 128 | + * @since 12.0.0 |
|
| 129 | + */ |
|
| 130 | + public function getMountType(); |
|
| 131 | 131 | } |
@@ -31,90 +31,90 @@ |
||
| 31 | 31 | |
| 32 | 32 | class BuildCalendarSearchIndexBackgroundJob extends QueuedJob { |
| 33 | 33 | |
| 34 | - /** @var IDBConnection */ |
|
| 35 | - private $db; |
|
| 36 | - |
|
| 37 | - /** @var CalDavBackend */ |
|
| 38 | - private $calDavBackend; |
|
| 39 | - |
|
| 40 | - /** @var ILogger */ |
|
| 41 | - private $logger; |
|
| 42 | - |
|
| 43 | - /** @var IJobList */ |
|
| 44 | - private $jobList; |
|
| 45 | - |
|
| 46 | - /** @var ITimeFactory */ |
|
| 47 | - private $timeFactory; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param IDBConnection $db |
|
| 51 | - * @param CalDavBackend $calDavBackend |
|
| 52 | - * @param ILogger $logger |
|
| 53 | - * @param IJobList $jobList |
|
| 54 | - * @param ITimeFactory $timeFactory |
|
| 55 | - */ |
|
| 56 | - public function __construct(IDBConnection $db, |
|
| 57 | - CalDavBackend $calDavBackend, |
|
| 58 | - ILogger $logger, |
|
| 59 | - IJobList $jobList, |
|
| 60 | - ITimeFactory $timeFactory) { |
|
| 61 | - $this->db = $db; |
|
| 62 | - $this->calDavBackend = $calDavBackend; |
|
| 63 | - $this->logger = $logger; |
|
| 64 | - $this->jobList = $jobList; |
|
| 65 | - $this->timeFactory = $timeFactory; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function run($arguments) { |
|
| 69 | - $offset = $arguments['offset']; |
|
| 70 | - $stopAt = $arguments['stopAt']; |
|
| 71 | - |
|
| 72 | - $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); |
|
| 73 | - |
|
| 74 | - $offset = $this->buildIndex($offset, $stopAt); |
|
| 75 | - |
|
| 76 | - if ($offset >= $stopAt) { |
|
| 77 | - $this->logger->info('Building calendar index done'); |
|
| 78 | - } else { |
|
| 79 | - $this->jobList->add(self::class, [ |
|
| 80 | - 'offset' => $offset, |
|
| 81 | - 'stopAt' => $stopAt |
|
| 82 | - ]); |
|
| 83 | - $this->logger->info('New building calendar index job scheduled with offset ' . $offset); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param int $offset |
|
| 89 | - * @param int $stopAt |
|
| 90 | - * @return int |
|
| 91 | - */ |
|
| 92 | - private function buildIndex($offset, $stopAt) { |
|
| 93 | - $startTime = $this->timeFactory->getTime(); |
|
| 94 | - |
|
| 95 | - $query = $this->db->getQueryBuilder(); |
|
| 96 | - $query->select(['id', 'calendarid', 'uri', 'calendardata']) |
|
| 97 | - ->from('calendarobjects') |
|
| 98 | - ->where($query->expr()->lte('id', $query->createNamedParameter($stopAt))) |
|
| 99 | - ->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset))) |
|
| 100 | - ->orderBy('id', 'ASC'); |
|
| 101 | - |
|
| 102 | - $stmt = $query->execute(); |
|
| 103 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 104 | - $offset = $row['id']; |
|
| 105 | - |
|
| 106 | - $calendarData = $row['calendardata']; |
|
| 107 | - if (is_resource($calendarData)) { |
|
| 108 | - $calendarData = stream_get_contents($calendarData); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData); |
|
| 112 | - |
|
| 113 | - if (($this->timeFactory->getTime() - $startTime) > 15) { |
|
| 114 | - return $offset; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return $stopAt; |
|
| 119 | - } |
|
| 34 | + /** @var IDBConnection */ |
|
| 35 | + private $db; |
|
| 36 | + |
|
| 37 | + /** @var CalDavBackend */ |
|
| 38 | + private $calDavBackend; |
|
| 39 | + |
|
| 40 | + /** @var ILogger */ |
|
| 41 | + private $logger; |
|
| 42 | + |
|
| 43 | + /** @var IJobList */ |
|
| 44 | + private $jobList; |
|
| 45 | + |
|
| 46 | + /** @var ITimeFactory */ |
|
| 47 | + private $timeFactory; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param IDBConnection $db |
|
| 51 | + * @param CalDavBackend $calDavBackend |
|
| 52 | + * @param ILogger $logger |
|
| 53 | + * @param IJobList $jobList |
|
| 54 | + * @param ITimeFactory $timeFactory |
|
| 55 | + */ |
|
| 56 | + public function __construct(IDBConnection $db, |
|
| 57 | + CalDavBackend $calDavBackend, |
|
| 58 | + ILogger $logger, |
|
| 59 | + IJobList $jobList, |
|
| 60 | + ITimeFactory $timeFactory) { |
|
| 61 | + $this->db = $db; |
|
| 62 | + $this->calDavBackend = $calDavBackend; |
|
| 63 | + $this->logger = $logger; |
|
| 64 | + $this->jobList = $jobList; |
|
| 65 | + $this->timeFactory = $timeFactory; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function run($arguments) { |
|
| 69 | + $offset = $arguments['offset']; |
|
| 70 | + $stopAt = $arguments['stopAt']; |
|
| 71 | + |
|
| 72 | + $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')'); |
|
| 73 | + |
|
| 74 | + $offset = $this->buildIndex($offset, $stopAt); |
|
| 75 | + |
|
| 76 | + if ($offset >= $stopAt) { |
|
| 77 | + $this->logger->info('Building calendar index done'); |
|
| 78 | + } else { |
|
| 79 | + $this->jobList->add(self::class, [ |
|
| 80 | + 'offset' => $offset, |
|
| 81 | + 'stopAt' => $stopAt |
|
| 82 | + ]); |
|
| 83 | + $this->logger->info('New building calendar index job scheduled with offset ' . $offset); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param int $offset |
|
| 89 | + * @param int $stopAt |
|
| 90 | + * @return int |
|
| 91 | + */ |
|
| 92 | + private function buildIndex($offset, $stopAt) { |
|
| 93 | + $startTime = $this->timeFactory->getTime(); |
|
| 94 | + |
|
| 95 | + $query = $this->db->getQueryBuilder(); |
|
| 96 | + $query->select(['id', 'calendarid', 'uri', 'calendardata']) |
|
| 97 | + ->from('calendarobjects') |
|
| 98 | + ->where($query->expr()->lte('id', $query->createNamedParameter($stopAt))) |
|
| 99 | + ->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset))) |
|
| 100 | + ->orderBy('id', 'ASC'); |
|
| 101 | + |
|
| 102 | + $stmt = $query->execute(); |
|
| 103 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
| 104 | + $offset = $row['id']; |
|
| 105 | + |
|
| 106 | + $calendarData = $row['calendardata']; |
|
| 107 | + if (is_resource($calendarData)) { |
|
| 108 | + $calendarData = stream_get_contents($calendarData); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData); |
|
| 112 | + |
|
| 113 | + if (($this->timeFactory->getTime() - $startTime) > 15) { |
|
| 114 | + return $offset; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return $stopAt; |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -43,86 +43,86 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | interface IPreview { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @since 9.2.0 |
|
| 48 | - */ |
|
| 49 | - const EVENT = self::class . ':' . 'PreviewRequested'; |
|
| 46 | + /** |
|
| 47 | + * @since 9.2.0 |
|
| 48 | + */ |
|
| 49 | + const EVENT = self::class . ':' . 'PreviewRequested'; |
|
| 50 | 50 | |
| 51 | - const MODE_FILL = 'fill'; |
|
| 52 | - const MODE_COVER = 'cover'; |
|
| 51 | + const MODE_FILL = 'fill'; |
|
| 52 | + const MODE_COVER = 'cover'; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * In order to improve lazy loading a closure can be registered which will be |
|
| 56 | - * called in case preview providers are actually requested |
|
| 57 | - * |
|
| 58 | - * $callable has to return an instance of \OCP\Preview\IProvider |
|
| 59 | - * |
|
| 60 | - * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
| 61 | - * @param \Closure $callable |
|
| 62 | - * @return void |
|
| 63 | - * @since 8.1.0 |
|
| 64 | - */ |
|
| 65 | - public function registerProvider($mimeTypeRegex, \Closure $callable); |
|
| 54 | + /** |
|
| 55 | + * In order to improve lazy loading a closure can be registered which will be |
|
| 56 | + * called in case preview providers are actually requested |
|
| 57 | + * |
|
| 58 | + * $callable has to return an instance of \OCP\Preview\IProvider |
|
| 59 | + * |
|
| 60 | + * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
| 61 | + * @param \Closure $callable |
|
| 62 | + * @return void |
|
| 63 | + * @since 8.1.0 |
|
| 64 | + */ |
|
| 65 | + public function registerProvider($mimeTypeRegex, \Closure $callable); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Get all providers |
|
| 69 | - * @return array |
|
| 70 | - * @since 8.1.0 |
|
| 71 | - */ |
|
| 72 | - public function getProviders(); |
|
| 67 | + /** |
|
| 68 | + * Get all providers |
|
| 69 | + * @return array |
|
| 70 | + * @since 8.1.0 |
|
| 71 | + */ |
|
| 72 | + public function getProviders(); |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Does the manager have any providers |
|
| 76 | - * @return bool |
|
| 77 | - * @since 8.1.0 |
|
| 78 | - */ |
|
| 79 | - public function hasProviders(); |
|
| 74 | + /** |
|
| 75 | + * Does the manager have any providers |
|
| 76 | + * @return bool |
|
| 77 | + * @since 8.1.0 |
|
| 78 | + */ |
|
| 79 | + public function hasProviders(); |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Return a preview of a file |
|
| 83 | - * @param string $file The path to the file where you want a thumbnail from |
|
| 84 | - * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 85 | - * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 86 | - * @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly |
|
| 87 | - * @return \OCP\IImage |
|
| 88 | - * @since 6.0.0 |
|
| 89 | - * @deprecated 11 Use getPreview |
|
| 90 | - */ |
|
| 91 | - public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false); |
|
| 81 | + /** |
|
| 82 | + * Return a preview of a file |
|
| 83 | + * @param string $file The path to the file where you want a thumbnail from |
|
| 84 | + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 85 | + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 86 | + * @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly |
|
| 87 | + * @return \OCP\IImage |
|
| 88 | + * @since 6.0.0 |
|
| 89 | + * @deprecated 11 Use getPreview |
|
| 90 | + */ |
|
| 91 | + public function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false); |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Returns a preview of a file |
|
| 95 | - * |
|
| 96 | - * The cache is searched first and if nothing usable was found then a preview is |
|
| 97 | - * generated by one of the providers |
|
| 98 | - * |
|
| 99 | - * @param File $file |
|
| 100 | - * @param int $width |
|
| 101 | - * @param int $height |
|
| 102 | - * @param bool $crop |
|
| 103 | - * @param string $mode |
|
| 104 | - * @param string $mimeType To force a given mimetype for the file (files_versions needs this) |
|
| 105 | - * @return ISimpleFile |
|
| 106 | - * @throws NotFoundException |
|
| 107 | - * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 108 | - * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
| 109 | - */ |
|
| 110 | - public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null); |
|
| 93 | + /** |
|
| 94 | + * Returns a preview of a file |
|
| 95 | + * |
|
| 96 | + * The cache is searched first and if nothing usable was found then a preview is |
|
| 97 | + * generated by one of the providers |
|
| 98 | + * |
|
| 99 | + * @param File $file |
|
| 100 | + * @param int $width |
|
| 101 | + * @param int $height |
|
| 102 | + * @param bool $crop |
|
| 103 | + * @param string $mode |
|
| 104 | + * @param string $mimeType To force a given mimetype for the file (files_versions needs this) |
|
| 105 | + * @return ISimpleFile |
|
| 106 | + * @throws NotFoundException |
|
| 107 | + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 108 | + * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
| 109 | + */ |
|
| 110 | + public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null); |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Returns true if the passed mime type is supported |
|
| 114 | - * @param string $mimeType |
|
| 115 | - * @return boolean |
|
| 116 | - * @since 6.0.0 |
|
| 117 | - */ |
|
| 118 | - public function isMimeSupported($mimeType = '*'); |
|
| 112 | + /** |
|
| 113 | + * Returns true if the passed mime type is supported |
|
| 114 | + * @param string $mimeType |
|
| 115 | + * @return boolean |
|
| 116 | + * @since 6.0.0 |
|
| 117 | + */ |
|
| 118 | + public function isMimeSupported($mimeType = '*'); |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Check if a preview can be generated for a file |
|
| 122 | - * |
|
| 123 | - * @param \OCP\Files\FileInfo $file |
|
| 124 | - * @return bool |
|
| 125 | - * @since 8.0.0 |
|
| 126 | - */ |
|
| 127 | - public function isAvailable(\OCP\Files\FileInfo $file); |
|
| 120 | + /** |
|
| 121 | + * Check if a preview can be generated for a file |
|
| 122 | + * |
|
| 123 | + * @param \OCP\Files\FileInfo $file |
|
| 124 | + * @return bool |
|
| 125 | + * @since 8.0.0 |
|
| 126 | + */ |
|
| 127 | + public function isAvailable(\OCP\Files\FileInfo $file); |
|
| 128 | 128 | } |
@@ -42,89 +42,89 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class PublicAuth extends AbstractBasic { |
| 44 | 44 | |
| 45 | - /** @var \OCP\Share\IShare */ |
|
| 46 | - private $share; |
|
| 45 | + /** @var \OCP\Share\IShare */ |
|
| 46 | + private $share; |
|
| 47 | 47 | |
| 48 | - /** @var IManager */ |
|
| 49 | - private $shareManager; |
|
| 48 | + /** @var IManager */ |
|
| 49 | + private $shareManager; |
|
| 50 | 50 | |
| 51 | - /** @var ISession */ |
|
| 52 | - private $session; |
|
| 51 | + /** @var ISession */ |
|
| 52 | + private $session; |
|
| 53 | 53 | |
| 54 | - /** @var IRequest */ |
|
| 55 | - private $request; |
|
| 54 | + /** @var IRequest */ |
|
| 55 | + private $request; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param IRequest $request |
|
| 59 | - * @param IManager $shareManager |
|
| 60 | - * @param ISession $session |
|
| 61 | - */ |
|
| 62 | - public function __construct(IRequest $request, |
|
| 63 | - IManager $shareManager, |
|
| 64 | - ISession $session) { |
|
| 65 | - $this->request = $request; |
|
| 66 | - $this->shareManager = $shareManager; |
|
| 67 | - $this->session = $session; |
|
| 57 | + /** |
|
| 58 | + * @param IRequest $request |
|
| 59 | + * @param IManager $shareManager |
|
| 60 | + * @param ISession $session |
|
| 61 | + */ |
|
| 62 | + public function __construct(IRequest $request, |
|
| 63 | + IManager $shareManager, |
|
| 64 | + ISession $session) { |
|
| 65 | + $this->request = $request; |
|
| 66 | + $this->shareManager = $shareManager; |
|
| 67 | + $this->session = $session; |
|
| 68 | 68 | |
| 69 | - // setup realm |
|
| 70 | - $defaults = new \OCP\Defaults(); |
|
| 71 | - $this->realm = $defaults->getName(); |
|
| 72 | - } |
|
| 69 | + // setup realm |
|
| 70 | + $defaults = new \OCP\Defaults(); |
|
| 71 | + $this->realm = $defaults->getName(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Validates a username and password |
|
| 76 | - * |
|
| 77 | - * This method should return true or false depending on if login |
|
| 78 | - * succeeded. |
|
| 79 | - * |
|
| 80 | - * @param string $username |
|
| 81 | - * @param string $password |
|
| 82 | - * |
|
| 83 | - * @return bool |
|
| 84 | - * @throws \Sabre\DAV\Exception\NotAuthenticated |
|
| 85 | - */ |
|
| 86 | - protected function validateUserPass($username, $password) { |
|
| 87 | - try { |
|
| 88 | - $share = $this->shareManager->getShareByToken($username); |
|
| 89 | - } catch (ShareNotFound $e) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 74 | + /** |
|
| 75 | + * Validates a username and password |
|
| 76 | + * |
|
| 77 | + * This method should return true or false depending on if login |
|
| 78 | + * succeeded. |
|
| 79 | + * |
|
| 80 | + * @param string $username |
|
| 81 | + * @param string $password |
|
| 82 | + * |
|
| 83 | + * @return bool |
|
| 84 | + * @throws \Sabre\DAV\Exception\NotAuthenticated |
|
| 85 | + */ |
|
| 86 | + protected function validateUserPass($username, $password) { |
|
| 87 | + try { |
|
| 88 | + $share = $this->shareManager->getShareByToken($username); |
|
| 89 | + } catch (ShareNotFound $e) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $this->share = $share; |
|
| 93 | + $this->share = $share; |
|
| 94 | 94 | |
| 95 | - \OC_User::setIncognitoMode(true); |
|
| 95 | + \OC_User::setIncognitoMode(true); |
|
| 96 | 96 | |
| 97 | - // check if the share is password protected |
|
| 98 | - if ($share->getPassword() !== null) { |
|
| 99 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 100 | - if ($this->shareManager->checkPassword($share, $password)) { |
|
| 101 | - return true; |
|
| 102 | - } else if ($this->session->exists('public_link_authenticated') |
|
| 103 | - && $this->session->get('public_link_authenticated') === (string)$share->getId()) { |
|
| 104 | - return true; |
|
| 105 | - } else { |
|
| 106 | - if (in_array('XMLHttpRequest', explode(',', $this->request->getHeader('X-Requested-With')))) { |
|
| 107 | - // do not re-authenticate over ajax, use dummy auth name to prevent browser popup |
|
| 108 | - http_response_code(401); |
|
| 109 | - header('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"'); |
|
| 110 | - throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
|
| 111 | - } |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 114 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 115 | - return true; |
|
| 116 | - } else { |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - } else { |
|
| 120 | - return true; |
|
| 121 | - } |
|
| 122 | - } |
|
| 97 | + // check if the share is password protected |
|
| 98 | + if ($share->getPassword() !== null) { |
|
| 99 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 100 | + if ($this->shareManager->checkPassword($share, $password)) { |
|
| 101 | + return true; |
|
| 102 | + } else if ($this->session->exists('public_link_authenticated') |
|
| 103 | + && $this->session->get('public_link_authenticated') === (string)$share->getId()) { |
|
| 104 | + return true; |
|
| 105 | + } else { |
|
| 106 | + if (in_array('XMLHttpRequest', explode(',', $this->request->getHeader('X-Requested-With')))) { |
|
| 107 | + // do not re-authenticate over ajax, use dummy auth name to prevent browser popup |
|
| 108 | + http_response_code(401); |
|
| 109 | + header('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"'); |
|
| 110 | + throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
|
| 111 | + } |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 115 | + return true; |
|
| 116 | + } else { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + } else { |
|
| 120 | + return true; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * @return \OCP\Share\IShare |
|
| 126 | - */ |
|
| 127 | - public function getShare() { |
|
| 128 | - return $this->share; |
|
| 129 | - } |
|
| 124 | + /** |
|
| 125 | + * @return \OCP\Share\IShare |
|
| 126 | + */ |
|
| 127 | + public function getShare() { |
|
| 128 | + return $this->share; |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -32,85 +32,85 @@ |
||
| 32 | 32 | |
| 33 | 33 | class ImageExportPlugin extends ServerPlugin { |
| 34 | 34 | |
| 35 | - /** @var Server */ |
|
| 36 | - protected $server; |
|
| 37 | - /** @var PhotoCache */ |
|
| 38 | - private $cache; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * ImageExportPlugin constructor. |
|
| 42 | - * |
|
| 43 | - * @param PhotoCache $cache |
|
| 44 | - */ |
|
| 45 | - public function __construct(PhotoCache $cache) { |
|
| 46 | - $this->cache = $cache; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Initializes the plugin and registers event handlers |
|
| 51 | - * |
|
| 52 | - * @param Server $server |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function initialize(Server $server) { |
|
| 56 | - $this->server = $server; |
|
| 57 | - $this->server->on('method:GET', [$this, 'httpGet'], 90); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Intercepts GET requests on addressbook urls ending with ?photo. |
|
| 62 | - * |
|
| 63 | - * @param RequestInterface $request |
|
| 64 | - * @param ResponseInterface $response |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - public function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
| 68 | - |
|
| 69 | - $queryParams = $request->getQueryParameters(); |
|
| 70 | - // TODO: in addition to photo we should also add logo some point in time |
|
| 71 | - if (!array_key_exists('photo', $queryParams)) { |
|
| 72 | - return true; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1; |
|
| 76 | - |
|
| 77 | - $path = $request->getPath(); |
|
| 78 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 79 | - |
|
| 80 | - if (!($node instanceof Card)) { |
|
| 81 | - return true; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $this->server->transactionType = 'carddav-image-export'; |
|
| 85 | - |
|
| 86 | - // Checking ACL, if available. |
|
| 87 | - if ($aclPlugin = $this->server->getPlugin('acl')) { |
|
| 88 | - /** @var \Sabre\DAVACL\Plugin $aclPlugin */ |
|
| 89 | - $aclPlugin->checkPrivileges($path, '{DAV:}read'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Fetch addressbook |
|
| 93 | - $addressbookpath = explode('/', $path); |
|
| 94 | - array_pop($addressbookpath); |
|
| 95 | - $addressbookpath = implode('/', $addressbookpath); |
|
| 96 | - /** @var AddressBook $addressbook */ |
|
| 97 | - $addressbook = $this->server->tree->getNodeForPath($addressbookpath); |
|
| 98 | - |
|
| 99 | - $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate'); |
|
| 100 | - $response->setHeader('Etag', $node->getETag() ); |
|
| 101 | - $response->setHeader('Pragma', 'public'); |
|
| 102 | - |
|
| 103 | - try { |
|
| 104 | - $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node); |
|
| 105 | - $response->setHeader('Content-Type', $file->getMimeType()); |
|
| 106 | - $response->setHeader('Content-Disposition', 'attachment'); |
|
| 107 | - $response->setStatus(200); |
|
| 108 | - |
|
| 109 | - $response->setBody($file->getContent()); |
|
| 110 | - } catch (NotFoundException $e) { |
|
| 111 | - $response->setStatus(404); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return false; |
|
| 115 | - } |
|
| 35 | + /** @var Server */ |
|
| 36 | + protected $server; |
|
| 37 | + /** @var PhotoCache */ |
|
| 38 | + private $cache; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * ImageExportPlugin constructor. |
|
| 42 | + * |
|
| 43 | + * @param PhotoCache $cache |
|
| 44 | + */ |
|
| 45 | + public function __construct(PhotoCache $cache) { |
|
| 46 | + $this->cache = $cache; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Initializes the plugin and registers event handlers |
|
| 51 | + * |
|
| 52 | + * @param Server $server |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function initialize(Server $server) { |
|
| 56 | + $this->server = $server; |
|
| 57 | + $this->server->on('method:GET', [$this, 'httpGet'], 90); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Intercepts GET requests on addressbook urls ending with ?photo. |
|
| 62 | + * |
|
| 63 | + * @param RequestInterface $request |
|
| 64 | + * @param ResponseInterface $response |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + public function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
| 68 | + |
|
| 69 | + $queryParams = $request->getQueryParameters(); |
|
| 70 | + // TODO: in addition to photo we should also add logo some point in time |
|
| 71 | + if (!array_key_exists('photo', $queryParams)) { |
|
| 72 | + return true; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1; |
|
| 76 | + |
|
| 77 | + $path = $request->getPath(); |
|
| 78 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 79 | + |
|
| 80 | + if (!($node instanceof Card)) { |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $this->server->transactionType = 'carddav-image-export'; |
|
| 85 | + |
|
| 86 | + // Checking ACL, if available. |
|
| 87 | + if ($aclPlugin = $this->server->getPlugin('acl')) { |
|
| 88 | + /** @var \Sabre\DAVACL\Plugin $aclPlugin */ |
|
| 89 | + $aclPlugin->checkPrivileges($path, '{DAV:}read'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Fetch addressbook |
|
| 93 | + $addressbookpath = explode('/', $path); |
|
| 94 | + array_pop($addressbookpath); |
|
| 95 | + $addressbookpath = implode('/', $addressbookpath); |
|
| 96 | + /** @var AddressBook $addressbook */ |
|
| 97 | + $addressbook = $this->server->tree->getNodeForPath($addressbookpath); |
|
| 98 | + |
|
| 99 | + $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate'); |
|
| 100 | + $response->setHeader('Etag', $node->getETag() ); |
|
| 101 | + $response->setHeader('Pragma', 'public'); |
|
| 102 | + |
|
| 103 | + try { |
|
| 104 | + $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node); |
|
| 105 | + $response->setHeader('Content-Type', $file->getMimeType()); |
|
| 106 | + $response->setHeader('Content-Disposition', 'attachment'); |
|
| 107 | + $response->setStatus(200); |
|
| 108 | + |
|
| 109 | + $response->setBody($file->getContent()); |
|
| 110 | + } catch (NotFoundException $e) { |
|
| 111 | + $response->setStatus(404); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | <?php p($theme->getName()); ?> |
| 42 | 42 | </h1> |
| 43 | 43 | <?php if(\OC::$server->getConfig()->getSystemValue('installed', false) |
| 44 | - && \OC::$server->getConfig()->getAppValue('theming', 'logoMime', false)): ?> |
|
| 44 | + && \OC::$server->getConfig()->getAppValue('theming', 'logoMime', false)): ?> |
|
| 45 | 45 | <img src="<?php p($theme->getLogo()); ?>"/> |
| 46 | 46 | <?php endif; ?> |
| 47 | 47 | </div> |
@@ -40,235 +40,235 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | class Config { |
| 42 | 42 | |
| 43 | - const ENV_PREFIX = 'NC_'; |
|
| 43 | + const ENV_PREFIX = 'NC_'; |
|
| 44 | 44 | |
| 45 | - /** @var array Associative array ($key => $value) */ |
|
| 46 | - protected $cache = array(); |
|
| 47 | - /** @var string */ |
|
| 48 | - protected $configDir; |
|
| 49 | - /** @var string */ |
|
| 50 | - protected $configFilePath; |
|
| 51 | - /** @var string */ |
|
| 52 | - protected $configFileName; |
|
| 45 | + /** @var array Associative array ($key => $value) */ |
|
| 46 | + protected $cache = array(); |
|
| 47 | + /** @var string */ |
|
| 48 | + protected $configDir; |
|
| 49 | + /** @var string */ |
|
| 50 | + protected $configFilePath; |
|
| 51 | + /** @var string */ |
|
| 52 | + protected $configFileName; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param string $configDir Path to the config dir, needs to end with '/' |
|
| 56 | - * @param string $fileName (Optional) Name of the config file. Defaults to config.php |
|
| 57 | - */ |
|
| 58 | - public function __construct($configDir, $fileName = 'config.php') { |
|
| 59 | - $this->configDir = $configDir; |
|
| 60 | - $this->configFilePath = $this->configDir.$fileName; |
|
| 61 | - $this->configFileName = $fileName; |
|
| 62 | - $this->readData(); |
|
| 63 | - } |
|
| 54 | + /** |
|
| 55 | + * @param string $configDir Path to the config dir, needs to end with '/' |
|
| 56 | + * @param string $fileName (Optional) Name of the config file. Defaults to config.php |
|
| 57 | + */ |
|
| 58 | + public function __construct($configDir, $fileName = 'config.php') { |
|
| 59 | + $this->configDir = $configDir; |
|
| 60 | + $this->configFilePath = $this->configDir.$fileName; |
|
| 61 | + $this->configFileName = $fileName; |
|
| 62 | + $this->readData(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Lists all available config keys |
|
| 67 | - * |
|
| 68 | - * Please note that it does not return the values. |
|
| 69 | - * |
|
| 70 | - * @return array an array of key names |
|
| 71 | - */ |
|
| 72 | - public function getKeys() { |
|
| 73 | - return array_keys($this->cache); |
|
| 74 | - } |
|
| 65 | + /** |
|
| 66 | + * Lists all available config keys |
|
| 67 | + * |
|
| 68 | + * Please note that it does not return the values. |
|
| 69 | + * |
|
| 70 | + * @return array an array of key names |
|
| 71 | + */ |
|
| 72 | + public function getKeys() { |
|
| 73 | + return array_keys($this->cache); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Returns a config value |
|
| 78 | - * |
|
| 79 | - * gets its value from an `NC_` prefixed environment variable |
|
| 80 | - * if it doesn't exist from config.php |
|
| 81 | - * if this doesn't exist either, it will return the given `$default` |
|
| 82 | - * |
|
| 83 | - * @param string $key key |
|
| 84 | - * @param mixed $default = null default value |
|
| 85 | - * @return mixed the value or $default |
|
| 86 | - */ |
|
| 87 | - public function getValue($key, $default = null) { |
|
| 88 | - $envValue = getenv(self::ENV_PREFIX . $key); |
|
| 89 | - if ($envValue !== false) { |
|
| 90 | - return $envValue; |
|
| 91 | - } |
|
| 76 | + /** |
|
| 77 | + * Returns a config value |
|
| 78 | + * |
|
| 79 | + * gets its value from an `NC_` prefixed environment variable |
|
| 80 | + * if it doesn't exist from config.php |
|
| 81 | + * if this doesn't exist either, it will return the given `$default` |
|
| 82 | + * |
|
| 83 | + * @param string $key key |
|
| 84 | + * @param mixed $default = null default value |
|
| 85 | + * @return mixed the value or $default |
|
| 86 | + */ |
|
| 87 | + public function getValue($key, $default = null) { |
|
| 88 | + $envValue = getenv(self::ENV_PREFIX . $key); |
|
| 89 | + if ($envValue !== false) { |
|
| 90 | + return $envValue; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - if (isset($this->cache[$key])) { |
|
| 94 | - return $this->cache[$key]; |
|
| 95 | - } |
|
| 93 | + if (isset($this->cache[$key])) { |
|
| 94 | + return $this->cache[$key]; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $default; |
|
| 98 | - } |
|
| 97 | + return $default; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Sets and deletes values and writes the config.php |
|
| 102 | - * |
|
| 103 | - * @param array $configs Associative array with `key => value` pairs |
|
| 104 | - * If value is null, the config key will be deleted |
|
| 105 | - */ |
|
| 106 | - public function setValues(array $configs) { |
|
| 107 | - $needsUpdate = false; |
|
| 108 | - foreach ($configs as $key => $value) { |
|
| 109 | - if ($value !== null) { |
|
| 110 | - $needsUpdate |= $this->set($key, $value); |
|
| 111 | - } else { |
|
| 112 | - $needsUpdate |= $this->delete($key); |
|
| 113 | - } |
|
| 114 | - } |
|
| 100 | + /** |
|
| 101 | + * Sets and deletes values and writes the config.php |
|
| 102 | + * |
|
| 103 | + * @param array $configs Associative array with `key => value` pairs |
|
| 104 | + * If value is null, the config key will be deleted |
|
| 105 | + */ |
|
| 106 | + public function setValues(array $configs) { |
|
| 107 | + $needsUpdate = false; |
|
| 108 | + foreach ($configs as $key => $value) { |
|
| 109 | + if ($value !== null) { |
|
| 110 | + $needsUpdate |= $this->set($key, $value); |
|
| 111 | + } else { |
|
| 112 | + $needsUpdate |= $this->delete($key); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - if ($needsUpdate) { |
|
| 117 | - // Write changes |
|
| 118 | - $this->writeData(); |
|
| 119 | - } |
|
| 120 | - } |
|
| 116 | + if ($needsUpdate) { |
|
| 117 | + // Write changes |
|
| 118 | + $this->writeData(); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Sets the value and writes it to config.php if required |
|
| 124 | - * |
|
| 125 | - * @param string $key key |
|
| 126 | - * @param mixed $value value |
|
| 127 | - */ |
|
| 128 | - public function setValue($key, $value) { |
|
| 129 | - if ($this->set($key, $value)) { |
|
| 130 | - // Write changes |
|
| 131 | - $this->writeData(); |
|
| 132 | - } |
|
| 133 | - } |
|
| 122 | + /** |
|
| 123 | + * Sets the value and writes it to config.php if required |
|
| 124 | + * |
|
| 125 | + * @param string $key key |
|
| 126 | + * @param mixed $value value |
|
| 127 | + */ |
|
| 128 | + public function setValue($key, $value) { |
|
| 129 | + if ($this->set($key, $value)) { |
|
| 130 | + // Write changes |
|
| 131 | + $this->writeData(); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * This function sets the value |
|
| 137 | - * |
|
| 138 | - * @param string $key key |
|
| 139 | - * @param mixed $value value |
|
| 140 | - * @return bool True if the file needs to be updated, false otherwise |
|
| 141 | - */ |
|
| 142 | - protected function set($key, $value) { |
|
| 143 | - if (!isset($this->cache[$key]) || $this->cache[$key] !== $value) { |
|
| 144 | - // Add change |
|
| 145 | - $this->cache[$key] = $value; |
|
| 146 | - return true; |
|
| 147 | - } |
|
| 135 | + /** |
|
| 136 | + * This function sets the value |
|
| 137 | + * |
|
| 138 | + * @param string $key key |
|
| 139 | + * @param mixed $value value |
|
| 140 | + * @return bool True if the file needs to be updated, false otherwise |
|
| 141 | + */ |
|
| 142 | + protected function set($key, $value) { |
|
| 143 | + if (!isset($this->cache[$key]) || $this->cache[$key] !== $value) { |
|
| 144 | + // Add change |
|
| 145 | + $this->cache[$key] = $value; |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return false; |
|
| 150 | - } |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Removes a key from the config and removes it from config.php if required |
|
| 154 | - * @param string $key |
|
| 155 | - */ |
|
| 156 | - public function deleteKey($key) { |
|
| 157 | - if ($this->delete($key)) { |
|
| 158 | - // Write changes |
|
| 159 | - $this->writeData(); |
|
| 160 | - } |
|
| 161 | - } |
|
| 152 | + /** |
|
| 153 | + * Removes a key from the config and removes it from config.php if required |
|
| 154 | + * @param string $key |
|
| 155 | + */ |
|
| 156 | + public function deleteKey($key) { |
|
| 157 | + if ($this->delete($key)) { |
|
| 158 | + // Write changes |
|
| 159 | + $this->writeData(); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * This function removes a key from the config |
|
| 165 | - * |
|
| 166 | - * @param string $key |
|
| 167 | - * @return bool True if the file needs to be updated, false otherwise |
|
| 168 | - */ |
|
| 169 | - protected function delete($key) { |
|
| 170 | - if (isset($this->cache[$key])) { |
|
| 171 | - // Delete key from cache |
|
| 172 | - unset($this->cache[$key]); |
|
| 173 | - return true; |
|
| 174 | - } |
|
| 175 | - return false; |
|
| 176 | - } |
|
| 163 | + /** |
|
| 164 | + * This function removes a key from the config |
|
| 165 | + * |
|
| 166 | + * @param string $key |
|
| 167 | + * @return bool True if the file needs to be updated, false otherwise |
|
| 168 | + */ |
|
| 169 | + protected function delete($key) { |
|
| 170 | + if (isset($this->cache[$key])) { |
|
| 171 | + // Delete key from cache |
|
| 172 | + unset($this->cache[$key]); |
|
| 173 | + return true; |
|
| 174 | + } |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Loads the config file |
|
| 180 | - * |
|
| 181 | - * Reads the config file and saves it to the cache |
|
| 182 | - * |
|
| 183 | - * @throws \Exception If no lock could be acquired or the config file has not been found |
|
| 184 | - */ |
|
| 185 | - private function readData() { |
|
| 186 | - // Default config should always get loaded |
|
| 187 | - $configFiles = array($this->configFilePath); |
|
| 178 | + /** |
|
| 179 | + * Loads the config file |
|
| 180 | + * |
|
| 181 | + * Reads the config file and saves it to the cache |
|
| 182 | + * |
|
| 183 | + * @throws \Exception If no lock could be acquired or the config file has not been found |
|
| 184 | + */ |
|
| 185 | + private function readData() { |
|
| 186 | + // Default config should always get loaded |
|
| 187 | + $configFiles = array($this->configFilePath); |
|
| 188 | 188 | |
| 189 | - // Add all files in the config dir ending with the same file name |
|
| 190 | - $extra = glob($this->configDir.'*.'.$this->configFileName); |
|
| 191 | - if (is_array($extra)) { |
|
| 192 | - natsort($extra); |
|
| 193 | - $configFiles = array_merge($configFiles, $extra); |
|
| 194 | - } |
|
| 189 | + // Add all files in the config dir ending with the same file name |
|
| 190 | + $extra = glob($this->configDir.'*.'.$this->configFileName); |
|
| 191 | + if (is_array($extra)) { |
|
| 192 | + natsort($extra); |
|
| 193 | + $configFiles = array_merge($configFiles, $extra); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - // Include file and merge config |
|
| 197 | - foreach ($configFiles as $file) { |
|
| 198 | - $fileExistsAndIsReadable = file_exists($file) && is_readable($file); |
|
| 199 | - $filePointer = $fileExistsAndIsReadable ? fopen($file, 'r') : false; |
|
| 200 | - if($file === $this->configFilePath && |
|
| 201 | - $filePointer === false) { |
|
| 202 | - // Opening the main config might not be possible, e.g. if the wrong |
|
| 203 | - // permissions are set (likely on a new installation) |
|
| 204 | - continue; |
|
| 205 | - } |
|
| 196 | + // Include file and merge config |
|
| 197 | + foreach ($configFiles as $file) { |
|
| 198 | + $fileExistsAndIsReadable = file_exists($file) && is_readable($file); |
|
| 199 | + $filePointer = $fileExistsAndIsReadable ? fopen($file, 'r') : false; |
|
| 200 | + if($file === $this->configFilePath && |
|
| 201 | + $filePointer === false) { |
|
| 202 | + // Opening the main config might not be possible, e.g. if the wrong |
|
| 203 | + // permissions are set (likely on a new installation) |
|
| 204 | + continue; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - // Try to acquire a file lock |
|
| 208 | - if(!flock($filePointer, LOCK_SH)) { |
|
| 209 | - throw new \Exception(sprintf('Could not acquire a shared lock on the config file %s', $file)); |
|
| 210 | - } |
|
| 207 | + // Try to acquire a file lock |
|
| 208 | + if(!flock($filePointer, LOCK_SH)) { |
|
| 209 | + throw new \Exception(sprintf('Could not acquire a shared lock on the config file %s', $file)); |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - unset($CONFIG); |
|
| 213 | - include $file; |
|
| 214 | - if(isset($CONFIG) && is_array($CONFIG)) { |
|
| 215 | - $this->cache = array_merge($this->cache, $CONFIG); |
|
| 216 | - } |
|
| 212 | + unset($CONFIG); |
|
| 213 | + include $file; |
|
| 214 | + if(isset($CONFIG) && is_array($CONFIG)) { |
|
| 215 | + $this->cache = array_merge($this->cache, $CONFIG); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - // Close the file pointer and release the lock |
|
| 219 | - flock($filePointer, LOCK_UN); |
|
| 220 | - fclose($filePointer); |
|
| 221 | - } |
|
| 222 | - } |
|
| 218 | + // Close the file pointer and release the lock |
|
| 219 | + flock($filePointer, LOCK_UN); |
|
| 220 | + fclose($filePointer); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Writes the config file |
|
| 226 | - * |
|
| 227 | - * Saves the config to the config file. |
|
| 228 | - * |
|
| 229 | - * @throws HintException If the config file cannot be written to |
|
| 230 | - * @throws \Exception If no file lock can be acquired |
|
| 231 | - */ |
|
| 232 | - private function writeData() { |
|
| 233 | - // Create a php file ... |
|
| 234 | - $content = "<?php\n"; |
|
| 235 | - $content .= '$CONFIG = '; |
|
| 236 | - $content .= var_export($this->cache, true); |
|
| 237 | - $content .= ";\n"; |
|
| 224 | + /** |
|
| 225 | + * Writes the config file |
|
| 226 | + * |
|
| 227 | + * Saves the config to the config file. |
|
| 228 | + * |
|
| 229 | + * @throws HintException If the config file cannot be written to |
|
| 230 | + * @throws \Exception If no file lock can be acquired |
|
| 231 | + */ |
|
| 232 | + private function writeData() { |
|
| 233 | + // Create a php file ... |
|
| 234 | + $content = "<?php\n"; |
|
| 235 | + $content .= '$CONFIG = '; |
|
| 236 | + $content .= var_export($this->cache, true); |
|
| 237 | + $content .= ";\n"; |
|
| 238 | 238 | |
| 239 | - touch ($this->configFilePath); |
|
| 240 | - $filePointer = fopen($this->configFilePath, 'r+'); |
|
| 239 | + touch ($this->configFilePath); |
|
| 240 | + $filePointer = fopen($this->configFilePath, 'r+'); |
|
| 241 | 241 | |
| 242 | - // Prevent others not to read the config |
|
| 243 | - chmod($this->configFilePath, 0640); |
|
| 242 | + // Prevent others not to read the config |
|
| 243 | + chmod($this->configFilePath, 0640); |
|
| 244 | 244 | |
| 245 | - // File does not exist, this can happen when doing a fresh install |
|
| 246 | - if(!is_resource ($filePointer)) { |
|
| 247 | - // TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order |
|
| 248 | - // currently this breaks app routes but also could have other side effects especially during setup and exception handling |
|
| 249 | - $url = \OC::$server->getURLGenerator()->linkToDocs('admin-dir_permissions'); |
|
| 250 | - throw new HintException( |
|
| 251 | - "Can't write into config directory!", |
|
| 252 | - 'This can usually be fixed by giving the webserver write access to the config directory. See ' . $url); |
|
| 253 | - } |
|
| 245 | + // File does not exist, this can happen when doing a fresh install |
|
| 246 | + if(!is_resource ($filePointer)) { |
|
| 247 | + // TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order |
|
| 248 | + // currently this breaks app routes but also could have other side effects especially during setup and exception handling |
|
| 249 | + $url = \OC::$server->getURLGenerator()->linkToDocs('admin-dir_permissions'); |
|
| 250 | + throw new HintException( |
|
| 251 | + "Can't write into config directory!", |
|
| 252 | + 'This can usually be fixed by giving the webserver write access to the config directory. See ' . $url); |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // Try to acquire a file lock |
|
| 256 | - if(!flock($filePointer, LOCK_EX)) { |
|
| 257 | - throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath)); |
|
| 258 | - } |
|
| 255 | + // Try to acquire a file lock |
|
| 256 | + if(!flock($filePointer, LOCK_EX)) { |
|
| 257 | + throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath)); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - // Write the config and release the lock |
|
| 261 | - ftruncate ($filePointer, 0); |
|
| 262 | - fwrite($filePointer, $content); |
|
| 263 | - fflush($filePointer); |
|
| 264 | - flock($filePointer, LOCK_UN); |
|
| 265 | - fclose($filePointer); |
|
| 260 | + // Write the config and release the lock |
|
| 261 | + ftruncate ($filePointer, 0); |
|
| 262 | + fwrite($filePointer, $content); |
|
| 263 | + fflush($filePointer); |
|
| 264 | + flock($filePointer, LOCK_UN); |
|
| 265 | + fclose($filePointer); |
|
| 266 | 266 | |
| 267 | - // Try invalidating the opcache just for the file we wrote... |
|
| 268 | - if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) { |
|
| 269 | - // But if that doesn't work, clear the whole cache. |
|
| 270 | - \OC_Util::clearOpcodeCache(); |
|
| 271 | - } |
|
| 272 | - } |
|
| 267 | + // Try invalidating the opcache just for the file we wrote... |
|
| 268 | + if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) { |
|
| 269 | + // But if that doesn't work, clear the whole cache. |
|
| 270 | + \OC_Util::clearOpcodeCache(); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | 273 | } |
| 274 | 274 | |
@@ -25,36 +25,36 @@ |
||
| 25 | 25 | |
| 26 | 26 | class LanguageParseChecker { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $appId |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - public function analyse($appId) { |
|
| 33 | - $appPath = \OC_App::getAppPath($appId); |
|
| 34 | - if ($appPath === false) { |
|
| 35 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (!is_dir($appPath . '/l10n/')) { |
|
| 39 | - return []; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $errors = []; |
|
| 43 | - $directory = new \DirectoryIterator($appPath . '/l10n/'); |
|
| 44 | - |
|
| 45 | - foreach ($directory as $file) { |
|
| 46 | - if ($file->getExtension() !== 'json') { |
|
| 47 | - continue; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - $content = file_get_contents($file->getPathname()); |
|
| 51 | - json_decode($content, true); |
|
| 52 | - |
|
| 53 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 54 | - $errors[] = 'Invalid language file found: l10n/' . $file->getFilename() . ': ' . json_last_error_msg(); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - return $errors; |
|
| 59 | - } |
|
| 28 | + /** |
|
| 29 | + * @param string $appId |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + public function analyse($appId) { |
|
| 33 | + $appPath = \OC_App::getAppPath($appId); |
|
| 34 | + if ($appPath === false) { |
|
| 35 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (!is_dir($appPath . '/l10n/')) { |
|
| 39 | + return []; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $errors = []; |
|
| 43 | + $directory = new \DirectoryIterator($appPath . '/l10n/'); |
|
| 44 | + |
|
| 45 | + foreach ($directory as $file) { |
|
| 46 | + if ($file->getExtension() !== 'json') { |
|
| 47 | + continue; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + $content = file_get_contents($file->getPathname()); |
|
| 51 | + json_decode($content, true); |
|
| 52 | + |
|
| 53 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 54 | + $errors[] = 'Invalid language file found: l10n/' . $file->getFilename() . ': ' . json_last_error_msg(); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + return $errors; |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -22,10 +22,10 @@ |
||
| 22 | 22 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 23 | 23 | |
| 24 | 24 | $dispatcher->addListener('OC\AccountManager::userUpdated', function(\Symfony\Component\EventDispatcher\GenericEvent $event) { |
| 25 | - /** @var \OCP\IUser $user */ |
|
| 26 | - $user = $event->getSubject(); |
|
| 25 | + /** @var \OCP\IUser $user */ |
|
| 26 | + $user = $event->getSubject(); |
|
| 27 | 27 | |
| 28 | - /** @var \OCA\LookupServerConnector\UpdateLookupServer $updateLookupServer */ |
|
| 29 | - $updateLookupServer = \OC::$server->query(\OCA\LookupServerConnector\UpdateLookupServer::class); |
|
| 30 | - $updateLookupServer->userUpdated($user); |
|
| 28 | + /** @var \OCA\LookupServerConnector\UpdateLookupServer $updateLookupServer */ |
|
| 29 | + $updateLookupServer = \OC::$server->query(\OCA\LookupServerConnector\UpdateLookupServer::class); |
|
| 30 | + $updateLookupServer->userUpdated($user); |
|
| 31 | 31 | }); |