Add a warning if a storage wrapper was registered outside of the hook
This commit is contained in:
parent
ba0099f73a
commit
f1b6b0799c
|
@ -207,12 +207,30 @@ class Filesystem {
|
||||||
*/
|
*/
|
||||||
private static $loader;
|
private static $loader;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
private static $logWarningWhenAddingStorageWrapper = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $shouldLog
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public static function logWarningWhenAddingStorageWrapper($shouldLog) {
|
||||||
|
self::$logWarningWhenAddingStorageWrapper = (bool) $shouldLog;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $wrapperName
|
* @param string $wrapperName
|
||||||
* @param callable $wrapper
|
* @param callable $wrapper
|
||||||
* @param int $priority
|
* @param int $priority
|
||||||
*/
|
*/
|
||||||
public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50) {
|
public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50) {
|
||||||
|
if (self::$logWarningWhenAddingStorageWrapper) {
|
||||||
|
\OC::$server->getLogger()->warning("Storage wrapper '{wrapper}' was not registered via the 'OC_Filesystem - preSetup' hook which could cause potential problems.", [
|
||||||
|
'wrapper' => $wrapperName,
|
||||||
|
'app' => 'filesystem',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$mounts = self::getMountManager()->getAll();
|
$mounts = self::getMountManager()->getAll();
|
||||||
if (!self::getLoader()->addStorageWrapper($wrapperName, $wrapper, $priority, $mounts)) {
|
if (!self::getLoader()->addStorageWrapper($wrapperName, $wrapper, $priority, $mounts)) {
|
||||||
// do not re-wrap if storage with this name already existed
|
// do not re-wrap if storage with this name already existed
|
||||||
|
|
|
@ -145,6 +145,7 @@ class OC_Util {
|
||||||
|
|
||||||
\OC\Files\Filesystem::initMountManager();
|
\OC\Files\Filesystem::initMountManager();
|
||||||
|
|
||||||
|
\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
|
||||||
\OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
|
\OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
|
||||||
if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) {
|
if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) {
|
||||||
/** @var \OC\Files\Storage\Common $storage */
|
/** @var \OC\Files\Storage\Common $storage */
|
||||||
|
@ -195,6 +196,7 @@ class OC_Util {
|
||||||
});
|
});
|
||||||
|
|
||||||
OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user));
|
OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user));
|
||||||
|
\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true);
|
||||||
|
|
||||||
//check if we are using an object storage
|
//check if we are using an object storage
|
||||||
$objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null);
|
$objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null);
|
||||||
|
|
Loading…
Reference in New Issue