@@ -594,6 +594,30 @@ 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+ $ this ->getCache ()->remove ($ targetInternalPath );
614+ throw $ e ;
615+ }
616+ $ sourceStorage ->unlink ($ sourceInternalPath );
617+ }
618+ return true ;
619+ }
620+
597621 public function copy ($ source , $ target ) {
598622 $ source = $ this ->normalizePath ($ source );
599623 $ target = $ this ->normalizePath ($ target );
0 commit comments