/** * Copy a folder to another folder * * @param Folder $destinationFolder * @return boolean */ public function copy($destinationFolder, $newName = false) { if (\GO::config()->debug) { \GO::debug("Copy folder " . $this->path . " to " . $destinationFolder->path); } if (!$newName) { $newName = $this->name; } $existing = $destinationFolder->hasFolder($newName); if (!$existing) { $copy = $this->duplicate(array("parent_id" => $destinationFolder->id, 'name' => $newName, 'quota_user_id' => null), true, true); //$copy->parent_id=$destinationFolder->id; if (!$copy) { return false; } $destinationFsFolder = $copy->fsFolder->parent(); // $copy->fsFolder->delete(); try { // $copy directory already made but copy() might throw an exception when coping in the source folder if (!$this->fsFolder->copy($destinationFsFolder, $newName)) { return false; } } catch (\Exception $e) { $copy->delete(); throw $e; } } else { $copy = $existing; //if folder exist then merge the folder. } $stmt = $this->folders(); while ($folder = $stmt->fetch()) { if (!$folder->copy($copy)) { return false; } } $stmt = $this->files(); while ($file = $stmt->fetch()) { if (!$file->copy($copy)) { return false; } } return true; }