original_string: public function migrate_directory($rootpath, $relpath='/') {
  
          // Check the trailing slash in the $rootpath
          if (substr($rootpath, -1) === '/') {
              debugging('moodle1_file_manager::migrate_directory() expects $rootpath without the trailing slash', DEBUG_DEVELOPER);
              $rootpath = substr($rootpath, 0, strlen($rootpath) - 1);
          }
  
          if (!file_exists($this->basepath.'/'.$rootpath.$relpath)) {
              return array();
          }
  
          $fileids = array();
  
          // make the fake file record for the directory itself
          $filerecord = $this->make_file_record(array('filepath' => $relpath, 'filename' => '.'));
          $this->stash_file($filerecord);
          $fileids[] = $filerecord['id'];
  
          $items = new DirectoryIterator($this->basepath.'/'.$rootpath.$relpath);
  
          foreach ($items as $item) {
  
              if ($item->isDot()) {
                  continue;
              }
  
              if ($item->isLink()) {
                  throw new moodle1_convert_exception('unexpected_symlink');
              }
  
              if ($item->isFile()) {
                  $fileids[] = $this->migrate_file(substr($item->getPathname(), strlen($this->basepath.'/')),
                      $relpath, $item->getFilename(), 0, $item->getCTime(), $item->getMTime());
  
              } else {
                  $dirname = clean_param($item->getFilename(), PARAM_PATH);
  
                  if ($dirname === '') {
                      throw new moodle1_convert_exception('unsupported_chars_in_filename');
                  }
  
                  // migrate subdirectories recursively
                  $fileids = array_merge($fileids, $this->migrate_directory($rootpath, $relpath.$item->getFilename().'/'));
              }
          }
  
          return $fileids;
      }
code: public function migrate_directory($rootpath, $relpath='/') {
  
          // Check the trailing slash in the $rootpath
          if (substr($rootpath, -1) === '/') {
              debugging('moodle1_file_manager::migrate_directory() expects $rootpath without the trailing slash', DEBUG_DEVELOPER);
              $rootpath = substr($rootpath, 0, strlen($rootpath) - 1);
          }
  
          if (!file_exists($this->basepath.'/'.$rootpath.$relpath)) {
              return array();
          }
  
          $fileids = array();
  
          // make the fake file record for the directory itself
          $filerecord = $this->make_file_record(array('filepath' => $relpath, 'filename' => '.'));
          $this->stash_file($filerecord);
          $fileids[] = $filerecord['id'];
  
          $items = new DirectoryIterator($this->basepath.'/'.$rootpath.$relpath);
  
          foreach ($items as $item) {
  
              if ($item->isDot()) {
                  continue;
              }
  
              if ($item->isLink()) {
                  throw new moodle1_convert_exception('unexpected_symlink');
              }
  
              if ($item->isFile()) {
                  $fileids[] = $this->migrate_file(substr($item->getPathname(), strlen($this->basepath.'/')),
                      $relpath, $item->getFilename(), 0, $item->getCTime(), $item->getMTime());
  
              } else {
                  $dirname = clean_param($item->getFilename(), PARAM_PATH);
  
                  if ($dirname === '') {
                      throw new moodle1_convert_exception('unsupported_chars_in_filename');
                  }
  
                  // migrate subdirectories recursively
                  $fileids = array_merge($fileids, $this->migrate_directory($rootpath, $relpath.$item->getFilename().'/'));
              }
          }
  
          return $fileids;
      }
code_tokens: public function migrate_directory ( $ rootpath , $ relpath = '/' ) { // Check the trailing slash in the $rootpath if ( substr ( $ rootpath , - 1 ) === '/' ) { debugging ( 'moodle1_file_manager::migrate_directory() expects $rootpath without the trailing slash' , DEBUG_DEVELOPER ) ; $ rootpath = substr ( $ rootpath , 0 , strlen ( $ rootpath ) - 1 ) ; } if ( ! file_exists ( $ this -> basepath . '/' . $ rootpath . $ relpath ) ) { return array ( ) ; } $ fileids = array ( ) ; // make the fake file record for the directory itself $ filerecord = $ this -> make_file_record ( array ( 'filepath' => $ relpath , 'filename' => '.' ) ) ; $ this -> stash_file ( $ filerecord ) ; $ fileids [ ] = $ filerecord [ 'id' ] ; $ items = new DirectoryIterator ( $ this -> basepath . '/' . $ rootpath . $ relpath ) ; foreach ( $ items as $ item ) { if ( $ item -> isDot ( ) ) { continue ; } if ( $ item -> isLink ( ) ) { throw new moodle1_convert_exception ( 'unexpected_symlink' ) ; } if ( $ item -> isFile ( ) ) { $ fileids [ ] = $ this -> migrate_file ( substr ( $ item -> getPathname ( ) , strlen ( $ this -> basepath . '/' ) ) , $ relpath , $ item -> getFilename ( ) , 0 , $ item -> getCTime ( ) , $ item -> getMTime ( ) ) ; } else { $ dirname = clean_param ( $ item -> getFilename ( ) , PARAM_PATH ) ; if ( $ dirname === '' ) { throw new moodle1_convert_exception ( 'unsupported_chars_in_filename' ) ; } // migrate subdirectories recursively $ fileids = array_merge ( $ fileids , $ this -> migrate_directory ( $ rootpath , $ relpath . $ item -> getFilename ( ) . '/' ) ) ; } } return $ fileids ; }
docstring: Migrates all files in the given directory
  
  @param string $rootpath path within the backup archive to the root directory containing the files {@example 'course_files'}
  @param string $relpath relative path used during the recursion - do not provide when calling this!
  @return array ids of the migrated files, empty array if the $rootpath not found
docstring_tokens: Migrates all files in the given directory