Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35131 from owncloud/stable10-configurable-thumbna…
…ils-path [stable10] Allow configuring thumbnails path
- Loading branch information
Showing
6 changed files
with
254 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* @author Vincent Petry <pvince81@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Files\Mount; | ||
|
||
use OCP\Files\Config\IMountProvider; | ||
use OCP\Files\Storage\IStorageFactory; | ||
use OCP\IConfig; | ||
use OCP\IUser; | ||
|
||
/** | ||
* Mount provider for custom preview storages | ||
*/ | ||
class PreviewsMountProvider implements IMountProvider { | ||
/** | ||
* @var IConfig | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* PreviewsMountProvider constructor. | ||
* | ||
* @param IConfig $config | ||
*/ | ||
public function __construct(IConfig $config) { | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Get the previews mount for a user | ||
* | ||
* @param IUser $user | ||
* @param IStorageFactory $loader | ||
* @return \OCP\Files\Mount\IMountPoint[] | ||
*/ | ||
public function getMountsForUser(IUser $user, IStorageFactory $loader) { | ||
$previewsPath = $this->config->getSystemValue('previews_path', ''); | ||
if ($previewsPath !== '') { | ||
$previewsDir = \rtrim($previewsPath, '/') . '/' . $user->getUID(); | ||
if (!\file_exists($previewsDir)) { | ||
\mkdir($previewsDir, 0770, true); | ||
} | ||
|
||
return [ | ||
new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/thumbnails', ['datadir' => $previewsDir], $loader) | ||
]; | ||
} else { | ||
return []; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* @author Vincent Petry <pvince81@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2019, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace Test\Files\Mount; | ||
|
||
use OC\Files\Mount\CacheMountProvider; | ||
use OCP\Files\Storage\IStorageFactory; | ||
use OCP\IConfig; | ||
use OCP\IUser; | ||
use OC\Files\Mount\MountPoint; | ||
|
||
class CacheMountProviderTest extends \Test\TestCase { | ||
|
||
/** @var CacheMountPorivder */ | ||
protected $provider; | ||
|
||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $config; | ||
|
||
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $user; | ||
|
||
/** @var IStorageFactory|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $loader; | ||
|
||
public function setUp() { | ||
parent::setUp(); | ||
|
||
$this->config = $this->createMock(IConfig::class); | ||
$this->user = $this->createMock(IUser::class); | ||
$this->loader = $this->createMock(IStorageFactory::class); | ||
|
||
$this->provider = new CacheMountProvider($this->config); | ||
} | ||
|
||
public function testConfiguredCachePath() { | ||
$tempFolder = \OC::$server->getTempManager()->getTemporaryFolder(); | ||
$this->config->expects($this->once()) | ||
->method('getSystemValue') | ||
->with('cache_path', '') | ||
->willReturn($tempFolder . '/cache'); | ||
|
||
$this->user->expects($this->any())->method('getUID')->willReturn('someuser'); | ||
|
||
$mounts = $this->provider->getMountsForUser($this->user, $this->loader); | ||
|
||
$this->assertCount(1, $mounts); | ||
$mount = $mounts[0]; | ||
|
||
$this->assertInstanceOf(MountPoint::class, $mount); | ||
$this->assertEquals('/someuser/cache/', $mount->getMountPoint()); | ||
|
||
$this->assertTrue(\is_dir($tempFolder . '/cache/someuser')); | ||
|
||
$storageArgs = ['datadir' => $tempFolder . '/cache/someuser']; | ||
|
||
$this->loader->expects($this->once()) | ||
->method('getInstance') | ||
->with($mount, '\OC\Files\Storage\Local', $storageArgs); | ||
|
||
// trigger storage creation which will pass config args above | ||
$mount->getStorage(); | ||
|
||
\rmdir($tempFolder . '/cache/someuser'); | ||
\rmdir($tempFolder . '/cache'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* @author Vincent Petry <pvince81@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2019, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace Test\Files\Mount; | ||
|
||
use OC\Files\Mount\PreviewsMountProvider; | ||
use OCP\Files\Storage\IStorageFactory; | ||
use OCP\IConfig; | ||
use OCP\IUser; | ||
use OC\Files\Mount\MountPoint; | ||
|
||
class PreviewsMountProviderTest extends \Test\TestCase { | ||
|
||
/** @var PreviewsMountPorivder */ | ||
protected $provider; | ||
|
||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $config; | ||
|
||
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $user; | ||
|
||
/** @var IStorageFactory|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $loader; | ||
|
||
public function setUp() { | ||
parent::setUp(); | ||
|
||
$this->config = $this->createMock(IConfig::class); | ||
$this->user = $this->createMock(IUser::class); | ||
$this->loader = $this->createMock(IStorageFactory::class); | ||
|
||
$this->provider = new PreviewsMountProvider($this->config); | ||
} | ||
|
||
public function testConfiguredPreviewsPath() { | ||
$tempFolder = \OC::$server->getTempManager()->getTemporaryFolder(); | ||
$this->config->expects($this->once()) | ||
->method('getSystemValue') | ||
->with('previews_path', '') | ||
->willReturn($tempFolder . '/thumbnails'); | ||
|
||
$this->user->expects($this->any())->method('getUID')->willReturn('someuser'); | ||
|
||
$mounts = $this->provider->getMountsForUser($this->user, $this->loader); | ||
|
||
$this->assertCount(1, $mounts); | ||
$mount = $mounts[0]; | ||
|
||
$this->assertInstanceOf(MountPoint::class, $mount); | ||
$this->assertEquals('/someuser/thumbnails/', $mount->getMountPoint()); | ||
|
||
$this->assertTrue(\is_dir($tempFolder . '/thumbnails/someuser')); | ||
|
||
$storageArgs = ['datadir' => $tempFolder . '/thumbnails/someuser']; | ||
|
||
$this->loader->expects($this->once()) | ||
->method('getInstance') | ||
->with($mount, '\OC\Files\Storage\Local', $storageArgs); | ||
|
||
// trigger storage creation which will pass config args above | ||
$mount->getStorage(); | ||
|
||
\rmdir($tempFolder . '/thumbnails/someuser'); | ||
\rmdir($tempFolder . '/thumbnails'); | ||
} | ||
} |