1 | <?php |
||
30 | class Shared_Updater { |
||
31 | |||
32 | /** |
||
33 | * @param array $params |
||
34 | */ |
||
35 | static public function renameHook($params) { |
||
39 | |||
40 | /** |
||
41 | * Fix for https://github.com/owncloud/core/issues/20769 |
||
42 | * |
||
43 | * The owner is allowed to move their files (if they are shared) into a receiving folder |
||
44 | * In this case we need to update the parent of the moved share. Since they are |
||
45 | * effectively handing over ownership of the file the rest of the code needs to know |
||
46 | * they need to build up the reshare tree. |
||
47 | * |
||
48 | * @param string $path |
||
49 | */ |
||
50 | static private function moveShareToShare($path) { |
||
51 | $userFolder = \OC::$server->getUserFolder(); |
||
52 | |||
53 | // If the user folder can't be constructed (e.g. link share) just return. |
||
54 | if ($userFolder === null) { |
||
55 | return; |
||
56 | } |
||
57 | |||
58 | $src = $userFolder->get($path); |
||
59 | |||
60 | $shareManager = \OC::$server->getShareManager(); |
||
61 | |||
62 | $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1); |
||
63 | $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1)); |
||
64 | |||
65 | // If the path we move is not a share we don't care |
||
66 | if (empty($shares)) { |
||
67 | return; |
||
68 | } |
||
69 | |||
70 | // Check if the destination is inside a share |
||
71 | $mountManager = \OC::$server->getMountManager(); |
||
72 | $dstMount = $mountManager->find($src->getPath()); |
||
73 | if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
||
74 | return; |
||
75 | } |
||
76 | |||
77 | $newOwner = $dstMount->getShare()->getShareOwner(); |
||
78 | |||
79 | //Ownership is moved over |
||
80 | foreach ($shares as $share) { |
||
81 | /** @var \OCP\Share\IShare $share */ |
||
82 | $share->setShareOwner($newOwner); |
||
83 | $shareManager->updateShare($share); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * clean up oc_share table from files which are no longer exists |
||
89 | * |
||
90 | * This fixes issues from updates from files_sharing < 0.3.5.6 (ownCloud 4.5) |
||
91 | * It will just be called during the update of the app |
||
92 | */ |
||
93 | static public function fixBrokenSharesOnAppUpdate() { |
||
101 | |||
102 | /** |
||
103 | * rename mount point from the children if the parent was renamed |
||
104 | * |
||
105 | * @param string $oldPath old path relative to data/user/files |
||
106 | * @param string $newPath new path relative to data/user/files |
||
107 | */ |
||
108 | static private function renameChildren($oldPath, $newPath) { |
||
123 | |||
124 | } |
||
125 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: