1919use OCP \Migration \IOutput ;
2020use OCP \Migration \IRepairStep ;
2121use OCP \Share \IShare ;
22+ use Psr \Log \LoggerInterface ;
2223
2324/**
2425 * @psalm-type ShareInfo = array{id: string|int, share_type: string, share_with: string, file_source: string, file_target: string}
@@ -41,6 +42,7 @@ public function __construct(
4142 private readonly SetupManager $ setupManager ,
4243 private readonly IUserMountCache $ userMountCache ,
4344 private readonly IRootFolder $ rootFolder ,
45+ private readonly LoggerInterface $ logger ,
4446 ) {
4547 }
4648
@@ -63,6 +65,9 @@ public function run(IOutput $output) {
6365
6466 foreach ($ this ->getProblemShares () as $ shareInfo ) {
6567 $ recipient = $ this ->userManager ->getExistingUser ($ shareInfo ['share_with ' ]);
68+ if (!$ recipient ->isEnabled ()) {
69+ continue ;
70+ }
6671
6772 // since we ordered the share by user, we can reuse the last data until we get to the next user
6873 if ($ lastUser !== $ recipient ->getUID ()) {
@@ -81,20 +86,26 @@ public function run(IOutput $output) {
8186 $ absoluteNewTarget = $ userFolder ->getFullPath ($ newTarget );
8287 $ targetParentNode = $ this ->rootFolder ->get (dirname ($ absoluteNewTarget ));
8388
84- $ absoluteNewTarget = $ this ->shareTargetValidator ->generateUniqueTarget (
85- (int )$ shareInfo ['file_source ' ],
86- $ absoluteNewTarget ,
87- $ targetParentNode ->getMountPoint (),
88- $ userMounts ,
89- );
90- $ newTarget = $ userFolder ->getRelativePath ($ absoluteNewTarget );
91-
92- $ this ->moveShare ((string )$ shareInfo ['id ' ], $ newTarget );
93-
94- $ oldMountPoint = "/ {$ recipient ->getUID ()}/files $ oldTarget/ " ;
95- $ newMountPoint = "/ {$ recipient ->getUID ()}/files $ newTarget/ " ;
96- $ userMounts [$ newMountPoint ] = $ userMounts [$ oldMountPoint ];
97- unset($ userMounts [$ oldMountPoint ]);
89+ try {
90+ $ absoluteNewTarget = $ this ->shareTargetValidator ->generateUniqueTarget (
91+ (int )$ shareInfo ['file_source ' ],
92+ $ absoluteNewTarget ,
93+ $ targetParentNode ->getMountPoint (),
94+ $ userMounts ,
95+ );
96+ $ newTarget = $ userFolder ->getRelativePath ($ absoluteNewTarget );
97+
98+ $ this ->moveShare ((string )$ shareInfo ['id ' ], $ newTarget );
99+
100+ $ oldMountPoint = "/ {$ recipient ->getUID ()}/files $ oldTarget/ " ;
101+ $ newMountPoint = "/ {$ recipient ->getUID ()}/files $ newTarget/ " ;
102+ $ userMounts [$ newMountPoint ] = $ userMounts [$ oldMountPoint ];
103+ unset($ userMounts [$ oldMountPoint ]);
104+ } catch (\Exception $ e ) {
105+ $ msg = 'error cleaning up share target: ' . $ e ->getMessage ();
106+ $ this ->logger ->error ($ msg , ['exception ' => $ e , 'app ' => 'files_sharing ' ]);
107+ $ output ->warning ($ msg );
108+ }
98109
99110 $ output ->advance ();
100111 }
0 commit comments