本文整理汇总了PHP中OC\Files\Filesystem::initMountPoints方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::initMountPoints方法的具体用法?PHP Filesystem::initMountPoints怎么用?PHP Filesystem::initMountPoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::initMountPoints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->sourceUser = $input->getArgument('source-user');
$this->destinationUser = $input->getArgument('destination-user');
if (!$this->userManager->userExists($this->sourceUser)) {
$output->writeln("<error>Unknown source user {$this->sourceUser}</error>");
return;
}
if (!$this->userManager->userExists($this->destinationUser)) {
$output->writeln("<error>Unknown destination user {$this->destinationUser}</error>");
return;
}
$date = date('c');
$this->finalTarget = "{$this->destinationUser}/files/transferred from {$this->sourceUser} on {$date}";
// setup filesystem
Filesystem::initMountPoints($this->sourceUser);
Filesystem::initMountPoints($this->destinationUser);
// analyse source folder
$this->analyse($output);
// collect all the shares
$this->collectUsersShares($output);
// transfer the files
$this->transfer($output);
// restore the shares
$this->restoreShares($output);
}
示例2: getSourceCache
/**
* Get the source cache of a shared file or folder
*
* @param string $target Shared target file path
* @return \OC\Files\Cache\Cache
*/
private function getSourceCache($target)
{
if ($target === false || $target === $this->storage->getMountPoint()) {
$target = '';
}
$source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
if (isset($source['path']) && isset($source['fileOwner'])) {
try {
\OC\Files\Filesystem::initMountPoints($source['fileOwner']);
} catch (NoUserException $e) {
\OC::$server->getLogger()->warning('The user \'' . $source['uid_owner'] . '\' of a share can\'t be retrieved.', array('app' => 'files_sharing'));
return false;
}
$mounts = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
if (is_array($mounts) and !empty($mounts)) {
$fullPath = $mounts[0]->getMountPoint() . $source['path'];
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath);
if ($storage) {
$this->files[$target] = $internalPath;
$cache = $storage->getCache();
$this->storageId = $storage->getId();
$this->numericId = $cache->getNumericStorageId();
return $cache;
}
}
}
return false;
}
示例3: checkUpdate
private static function checkUpdate($id)
{
$cacheItem = Cache::getById($id);
if (is_null($cacheItem)) {
return;
}
list($storageId, $internalPath) = $cacheItem;
$mounts = Filesystem::getMountByStorageId($storageId);
if (count($mounts) === 0) {
//if the storage we need isn't mounted on default, try to find a user that has access to the storage
$permissionsCache = new Permissions($storageId);
$users = $permissionsCache->getUsers($id);
if (count($users) === 0) {
return;
}
Filesystem::initMountPoints($users[0]);
$mounts = Filesystem::getMountByStorageId($storageId);
if (count($mounts) === 0) {
return;
}
}
$storage = $mounts[0]->getStorage();
$watcher = new Watcher($storage);
$watcher->checkUpdate($internalPath);
}
示例4: correctFolders
/**
* Correct the parent folders' ETags for all users shared the file at $target
*
* @param string $target
*/
public static function correctFolders($target)
{
$uid = \OCP\User::getUser();
$uidOwner = \OC\Files\Filesystem::getOwner($target);
$info = \OC\Files\Filesystem::getFileInfo($target);
// Correct Shared folders of other users shared with
$users = \OCP\Share::getUsersItemShared('file', $info['fileid'], $uidOwner, true);
if (!empty($users)) {
while (!empty($users)) {
$reshareUsers = array();
foreach ($users as $user) {
if ($user !== $uidOwner) {
$etag = \OC\Files\Filesystem::getETag('');
\OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag);
// Look for reshares
$reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true));
}
}
$users = $reshareUsers;
}
// Correct folders of shared file owner
$target = substr($target, 8);
if ($uidOwner !== $uid && ($source = \OC_Share_Backend_File::getSource($target))) {
\OC\Files\Filesystem::initMountPoints($uidOwner);
$source = '/' . $uidOwner . '/' . $source['path'];
\OC\Files\Cache\Updater::correctFolder($source, $info['mtime']);
}
}
}
示例5: getUidAndFilename
/**
* get the UID of the owner of the file and the path to the file relative to
* owners files folder
*
* @param string $filename
* @return array
* @throws \OC\User\NoUserException
*/
public static function getUidAndFilename($filename)
{
$uid = Filesystem::getOwner($filename);
$userManager = \OC::$server->getUserManager();
// if the user with the UID doesn't exists, e.g. because the UID points
// to a remote user with a federated cloud ID we use the current logged-in
// user. We need a valid local user to create the versions
if (!$userManager->userExists($uid)) {
$uid = User::getUser();
}
Filesystem::initMountPoints($uid);
if ($uid != User::getUser()) {
$info = Filesystem::getFileInfo($filename);
$ownerView = new View('/' . $uid . '/files');
try {
$filename = $ownerView->getPath($info['fileid']);
// make sure that the file name doesn't end with a trailing slash
// can for example happen single files shared across servers
$filename = rtrim($filename, '/');
} catch (NotFoundException $e) {
$filename = null;
}
}
return [$uid, $filename];
}
示例6: generateTarget
/**
* create unique target
* @param string $filePath
* @param string $shareWith
* @param string $exclude
* @return string
*/
public function generateTarget($filePath, $shareWith, $exclude = null)
{
$shareFolder = \OCA\Files_Sharing\Helper::getShareFolder();
$target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath));
// for group shares we return the target right away
if ($shareWith === false) {
return $target;
}
\OC\Files\Filesystem::initMountPoints($shareWith);
$view = new \OC\Files\View('/' . $shareWith . '/files');
if (!$view->is_dir($shareFolder)) {
$dir = '';
$subdirs = explode('/', $shareFolder);
foreach ($subdirs as $subdir) {
$dir = $dir . '/' . $subdir;
if (!$view->is_dir($dir)) {
$view->mkdir($dir);
}
}
}
$excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES);
if (is_array($exclude)) {
$excludeList = array_merge($excludeList, $exclude);
}
return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view);
}
示例7: removeSharedFolder
/**
* update script for the removal of the logical "Shared" folder, we create physical "Shared" folder and
* update the users file_target so that it doesn't make any difference for the user
* @note parameters are just for testing, please ignore them
*/
function removeSharedFolder($mkdirs = true, $chunkSize = 99)
{
$query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $query->execute();
$view = new \OC\Files\View('/');
$users = array();
$shares = array();
//we need to set up user backends
OC_User::useBackend(new OC_User_Database());
OC_Group::useBackend(new OC_Group_Database());
OC_App::loadApps(array('authentication'));
//we need to set up user backends, otherwise creating the shares will fail with "because user does not exist"
while ($row = $result->fetchRow()) {
//collect all user shares
if ((int) $row['share_type'] === 0 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
$users[] = $row['share_with'];
$shares[$row['id']] = $row['file_target'];
} else {
if ((int) $row['share_type'] === 1 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
//collect all group shares
$users = array_merge($users, \OC_group::usersInGroup($row['share_with']));
$shares[$row['id']] = $row['file_target'];
} else {
if ((int) $row['share_type'] === 2) {
$shares[$row['id']] = $row['file_target'];
}
}
}
}
$unique_users = array_unique($users);
if (!empty($unique_users) && !empty($shares)) {
// create folder Shared for each user
if ($mkdirs) {
foreach ($unique_users as $user) {
\OC\Files\Filesystem::initMountPoints($user);
if (!$view->file_exists('/' . $user . '/files/Shared')) {
$view->mkdir('/' . $user . '/files/Shared');
}
}
}
$chunkedShareList = array_chunk($shares, $chunkSize, true);
$connection = \OC_DB::getConnection();
foreach ($chunkedShareList as $subList) {
$statement = "UPDATE `*PREFIX*share` SET `file_target` = CASE `id` ";
//update share table
$ids = implode(',', array_keys($subList));
foreach ($subList as $id => $target) {
$statement .= "WHEN " . $connection->quote($id, \PDO::PARAM_INT) . " THEN " . $connection->quote('/Shared' . $target, \PDO::PARAM_STR);
}
$statement .= ' END WHERE `id` IN (' . $ids . ')';
$query = OCP\DB::prepare($statement);
$query->execute(array());
}
// set config to keep the Shared folder as the default location for new shares
\OCA\Files_Sharing\Helper::setShareFolder('/Shared');
}
}
示例8: testChangeLock
public function testChangeLock()
{
Filesystem::initMountPoints($this->recipientUid);
$recipientView = new View('/' . $this->recipientUid . '/files');
$recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED);
$recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
$recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
$this->assertTrue(true);
}
示例9: __construct
/**
* @param IRequest $request
* @param string $user
* @param string $path
*/
public function __construct(IRequest $request, $user, $path)
{
$this->request = $request;
$this->user = $user;
$this->path = $path;
Filesystem::initMountPoints($user);
$this->view = new View('/' . $user);
if (!$this->view->file_exists($path)) {
$this->setStatus(Http::STATUS_NOT_FOUND);
}
}
示例10: getUidAndFilename
public static function getUidAndFilename($filename)
{
$uid = \OC\Files\Filesystem::getOwner($filename);
\OC\Files\Filesystem::initMountPoints($uid);
if ($uid != \OCP\User::getUser()) {
$info = \OC\Files\Filesystem::getFileInfo($filename);
$ownerView = new \OC\Files\View('/' . $uid . '/files');
$filename = $ownerView->getPath($info['fileid']);
}
return array($uid, $filename);
}
示例11: impl
/**
* @return Directory
*/
private function impl()
{
$rootView = new View();
$user = \OC::$server->getUserSession()->getUser();
Filesystem::initMountPoints($user->getUID());
if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) {
$rootView->mkdir('/' . $user->getUID() . '/uploads');
}
$view = new View('/' . $user->getUID() . '/uploads');
$rootInfo = $view->getFileInfo('');
$impl = new Directory($view, $rootInfo);
return $impl;
}
示例12: getStorage
/**
* Returns the cache storage for the logged in user
* @return \OC\Files\View cache storage
*/
protected function getStorage()
{
if (isset($this->storage)) {
return $this->storage;
}
if (\OC_User::isLoggedIn()) {
\OC\Files\Filesystem::initMountPoints(\OC_User::getUser());
$this->storage = new \OC\Files\View('/' . \OC_User::getUser() . '/cache');
return $this->storage;
} else {
\OC_Log::write('core', 'Can\'t get cache storage, user not logged in', \OC_Log::ERROR);
throw new \OC\ForbiddenException('Can\\t get cache storage, user not logged in');
}
}
示例13: init
private function init()
{
if ($this->initialized) {
return;
}
$this->initialized = true;
try {
Filesystem::initMountPoints($this->newShare->getShareOwner());
$sourcePath = $this->ownerView->getPath($this->newShare->getNodeId());
list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
$this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
} catch (\Exception $e) {
$this->logger->logException($e);
}
}
示例14: getUidAndFilename
/**
* @param string $filename
* @return array
* @throws \OC\User\NoUserException
*/
public static function getUidAndFilename($filename)
{
$uid = \OC\Files\Filesystem::getOwner($filename);
\OC\Files\Filesystem::initMountPoints($uid);
if ($uid != \OCP\User::getUser()) {
$info = \OC\Files\Filesystem::getFileInfo($filename);
$ownerView = new \OC\Files\View('/' . $uid . '/files');
try {
$filename = $ownerView->getPath($info['fileid']);
} catch (NotFoundException $e) {
$filename = null;
}
}
return [$uid, $filename];
}
示例15: generateTarget
/**
* create unique target
* @param string $filePath
* @param string $shareWith
* @param string $exclude
* @return string
*/
public function generateTarget($filePath, $shareWith, $exclude = null)
{
$target = '/' . basename($filePath);
// for group shares we return the target right away
if ($shareWith === false) {
return $target;
}
\OC\Files\Filesystem::initMountPoints($shareWith);
$view = new \OC\Files\View('/' . $shareWith . '/files');
$excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES);
if (is_array($exclude)) {
$excludeList = array_merge($excludeList, $exclude);
}
return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view);
}