@@ -607,6 +607,31 @@ public function copyFromStorage(
607607 return parent ::copyFromStorage ($ sourceStorage , $ sourceInternalPath , $ targetInternalPath );
608608 }
609609
610+ public function moveFromStorage (IStorage $ sourceStorage , $ sourceInternalPath , $ targetInternalPath , ?ICacheEntry $ sourceCacheEntry = null ): bool {
611+ $ sourceCache = $ sourceStorage ->getCache ();
612+ if (!$ sourceCacheEntry ) {
613+ $ sourceCacheEntry = $ sourceCache ->get ($ sourceInternalPath );
614+ }
615+ if ($ sourceCacheEntry ->getMimeType () === FileInfo::MIMETYPE_FOLDER ) {
616+ foreach ($ sourceCache ->getFolderContents ($ sourceInternalPath ) as $ child ) {
617+ $ this ->moveFromStorage ($ sourceStorage , $ child ->getPath (), $ targetInternalPath . '/ ' . $ child ->getName ());
618+ }
619+ $ sourceStorage ->rmdir ($ sourceInternalPath );
620+ } else {
621+ // move the cache entry before the contents so that we have the correct fileid/urn for the target
622+ $ this ->getCache ()->moveFromCache ($ sourceCache , $ sourceInternalPath , $ targetInternalPath );
623+ try {
624+ $ this ->writeStream ($ targetInternalPath , $ sourceStorage ->fopen ($ sourceInternalPath , 'r ' ), $ sourceCacheEntry ->getSize ());
625+ } catch (\Exception $ e ) {
626+ // restore the cache entry
627+ $ sourceCache ->moveFromCache ($ this ->getCache (), $ targetInternalPath , $ sourceInternalPath );
628+ throw $ e ;
629+ }
630+ $ sourceStorage ->unlink ($ sourceInternalPath );
631+ }
632+ return true ;
633+ }
634+
610635 public function copy ($ source , $ target ) {
611636 $ source = $ this ->normalizePath ($ source );
612637 $ target = $ this ->normalizePath ($ target );
0 commit comments