original_string: public function transfer_file_to_path($srcpath, $dstpath, $operation, $webdavclient = null) {
          $this->systemwebdavclient->open();
          $webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer);
  
          $srcpath = ltrim($srcpath, '/');
          $sourcepath = $webdavendpoint['path'] . $srcpath;
          $dstpath = ltrim($dstpath, '/');
          $destinationpath = $webdavendpoint['path'] . $dstpath . '/' . $srcpath;
  
          if ($operation === 'copy') {
              $result = $this->systemwebdavclient->copy_file($sourcepath, $destinationpath, true);
          } else if ($operation === 'move') {
              $result = $webdavclient->move($sourcepath, $destinationpath, false);
              if ($result == 412) {
                  // A file with that name already exists at that target. Find a unique location!
                  $increment = 0; // Will be appended to/inserted into the filename.
                  // Define the pattern that is used to insert the increment to the filename.
                  if (substr_count($srcpath, '.') === 0) {
                      // No file extension; append increment to the (sprintf-escaped) name.
                      $namepattern = str_replace('%', '%%', $destinationpath) . ' (%s)';
                  } else {
                      // Append the increment to the second-to-last component, which is presumably the one before the extension.
                      // Again, the original path is sprintf-escaped.
                      $components = explode('.', str_replace('%', '%%', $destinationpath));
                      $components[count($components) - 2] .= ' (%s)';
                      $namepattern = implode('.', $components);
                  }
              }
              while ($result == 412) {
                  $increment++;
                  $destinationpath = sprintf($namepattern, $increment);
                  $result = $webdavclient->move($sourcepath, $destinationpath, false);
              }
          }
          $this->systemwebdavclient->close();
          if (!($result == 201 || $result == 412)) {
              $details = get_string('contactadminwith', 'repository_nextcloud',
                  'A webdav request to ' . $operation . ' a file failed.');
              throw new request_exception(array('instance' => $this->repositoryname, 'errormessage' => $details));
          }
          return $result;
      }
code: public function transfer_file_to_path($srcpath, $dstpath, $operation, $webdavclient = null) {
          $this->systemwebdavclient->open();
          $webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer);
  
          $srcpath = ltrim($srcpath, '/');
          $sourcepath = $webdavendpoint['path'] . $srcpath;
          $dstpath = ltrim($dstpath, '/');
          $destinationpath = $webdavendpoint['path'] . $dstpath . '/' . $srcpath;
  
          if ($operation === 'copy') {
              $result = $this->systemwebdavclient->copy_file($sourcepath, $destinationpath, true);
          } else if ($operation === 'move') {
              $result = $webdavclient->move($sourcepath, $destinationpath, false);
              if ($result == 412) {
                  // A file with that name already exists at that target. Find a unique location!
                  $increment = 0; // Will be appended to/inserted into the filename.
                  // Define the pattern that is used to insert the increment to the filename.
                  if (substr_count($srcpath, '.') === 0) {
                      // No file extension; append increment to the (sprintf-escaped) name.
                      $namepattern = str_replace('%', '%%', $destinationpath) . ' (%s)';
                  } else {
                      // Append the increment to the second-to-last component, which is presumably the one before the extension.
                      // Again, the original path is sprintf-escaped.
                      $components = explode('.', str_replace('%', '%%', $destinationpath));
                      $components[count($components) - 2] .= ' (%s)';
                      $namepattern = implode('.', $components);
                  }
              }
              while ($result == 412) {
                  $increment++;
                  $destinationpath = sprintf($namepattern, $increment);
                  $result = $webdavclient->move($sourcepath, $destinationpath, false);
              }
          }
          $this->systemwebdavclient->close();
          if (!($result == 201 || $result == 412)) {
              $details = get_string('contactadminwith', 'repository_nextcloud',
                  'A webdav request to ' . $operation . ' a file failed.');
              throw new request_exception(array('instance' => $this->repositoryname, 'errormessage' => $details));
          }
          return $result;
      }
code_tokens: public function transfer_file_to_path ( $ srcpath , $ dstpath , $ operation , $ webdavclient = null ) { $ this -> systemwebdavclient -> open ( ) ; $ webdavendpoint = issuer_management :: parse_endpoint_url ( 'webdav' , $ this -> issuer ) ; $ srcpath = ltrim ( $ srcpath , '/' ) ; $ sourcepath = $ webdavendpoint [ 'path' ] . $ srcpath ; $ dstpath = ltrim ( $ dstpath , '/' ) ; $ destinationpath = $ webdavendpoint [ 'path' ] . $ dstpath . '/' . $ srcpath ; if ( $ operation === 'copy' ) { $ result = $ this -> systemwebdavclient -> copy_file ( $ sourcepath , $ destinationpath , true ) ; } else if ( $ operation === 'move' ) { $ result = $ webdavclient -> move ( $ sourcepath , $ destinationpath , false ) ; if ( $ result == 412 ) { // A file with that name already exists at that target. Find a unique location! $ increment = 0 ; // Will be appended to/inserted into the filename. // Define the pattern that is used to insert the increment to the filename. if ( substr_count ( $ srcpath , '.' ) === 0 ) { // No file extension; append increment to the (sprintf-escaped) name. $ namepattern = str_replace ( '%' , '%%' , $ destinationpath ) . ' (%s)' ; } else { // Append the increment to the second-to-last component, which is presumably the one before the extension. // Again, the original path is sprintf-escaped. $ components = explode ( '.' , str_replace ( '%' , '%%' , $ destinationpath ) ) ; $ components [ count ( $ components ) - 2 ] .= ' (%s)' ; $ namepattern = implode ( '.' , $ components ) ; } } while ( $ result == 412 ) { $ increment ++ ; $ destinationpath = sprintf ( $ namepattern , $ increment ) ; $ result = $ webdavclient -> move ( $ sourcepath , $ destinationpath , false ) ; } } $ this -> systemwebdavclient -> close ( ) ; if ( ! ( $ result == 201 || $ result == 412 ) ) { $ details = get_string ( 'contactadminwith' , 'repository_nextcloud' , 'A webdav request to ' . $ operation . ' a file failed.' ) ; throw new request_exception ( array ( 'instance' => $ this -> repositoryname , 'errormessage' => $ details ) ) ; } return $ result ; }
docstring: Copy or moves a file to a new path.
  @param string $srcpath source path
  @param string $dstpath
  @param string $operation move or copy
  @param  \webdav_client $webdavclient needed when moving files.
  @return String Http-status of the request
  @throws configuration_exception
  @throws \coding_exception
  @throws \moodle_exception
  @throws \repository_nextcloud\request_exception
docstring_tokens: Copy or moves a file to a new path .