@@ -594,6 +594,31 @@ public function copyFromStorage(
594594 return parent ::copyFromStorage ($ sourceStorage , $ sourceInternalPath , $ targetInternalPath );
595595 }
596596
597+ public function moveFromStorage (IStorage $ sourceStorage , $ sourceInternalPath , $ targetInternalPath , ?ICacheEntry $ sourceCacheEntry = null ): bool {
598+ $ sourceCache = $ sourceStorage ->getCache ();
599+ if (!$ sourceCacheEntry ) {
600+ $ sourceCacheEntry = $ sourceCache ->get ($ sourceInternalPath );
601+ }
602+ if ($ sourceCacheEntry ->getMimeType () === FileInfo::MIMETYPE_FOLDER ) {
603+ foreach ($ sourceCache ->getFolderContents ($ sourceInternalPath ) as $ child ) {
604+ $ this ->moveFromStorage ($ sourceStorage , $ child ->getPath (), $ targetInternalPath . '/ ' . $ child ->getName ());
605+ }
606+ $ sourceStorage ->rmdir ($ sourceInternalPath );
607+ } else {
608+ // move the cache entry before the contents so that we have the correct fileid/urn for the target
609+ $ this ->getCache ()->moveFromCache ($ sourceCache , $ sourceInternalPath , $ targetInternalPath );
610+ try {
611+ $ this ->writeStream ($ targetInternalPath , $ sourceStorage ->fopen ($ sourceInternalPath , 'r ' ), $ sourceCacheEntry ->getSize ());
612+ } catch (\Exception $ e ) {
613+ // restore the cache entry
614+ $ sourceCache ->moveFromCache ($ this ->getCache (), $ targetInternalPath , $ sourceInternalPath );
615+ throw $ e ;
616+ }
617+ $ sourceStorage ->unlink ($ sourceInternalPath );
618+ }
619+ return true ;
620+ }
621+
597622 public function copy ($ source , $ target ) {
598623 $ source = $ this ->normalizePath ($ source );
599624 $ target = $ this ->normalizePath ($ target );
0 commit comments