FIles/Node api examples

Regarding the namespace issue as mentioned by @Raudius see also my post. The OC is perfectly valid in the front end.

The documentation I have sent to you are from the public API definition, aka from the OCP namespace. So, these methods are save to use.


To give you an idea of this might be working, I can write you a small snippet. Do not get fooled, I did not test anything and it might simply be wrong.

/** @var ITags */
private $tagger;
/** @var IRootFolder */
private $rootFolder;
/** @var String */
private $userId;

public function __construct(ITag $tagger, IRootFolder $rootFolder, $user_id){
  $this->$tagger = $tagger;
  $this->rootFolder = $rootFolder;
  $this->userId = $user_id;
}

// Method for parsing a single folder
private function parseFolder(Folder $folder): void {
  // No handling of the folders was requested by the OT.
  // That could/would go here.

  foreach ($folder->getDirectoryListing() as $node) {
    if ($node->getType() === FileInfo::TYPE_FOLDER) {
      $this->parseFolder($node);
    } else {
      $this->parseFile($node);
    }
  }
}

// Extract the data of a single file
private function parseFile(File $file){
  // Here we do the stuff with the files.

  // This is rather costly. Maybe you can replace it with something more restricted?
  $stat = $file->stat();

  if (false /* ... */) {
    $file->move("/the/target/path");
  }

  if (false /* ... */){
    // Add tag to file
    $fileId = $file->getId();
    $tag = ...

    $this->tagger->tagAs($fileId, $tag);
    // This will only add new tags. If you want to remove them as well (sync them), you need to do that as well.
  }
}

public function iterateFolder() {
  $userFolder = $this->rootFolder->get($this->userId)->get('files');
  $this->parseFolder($userFolder);
}

References:

You will have to tweak according to your needs.

Does this help you with your problem?

1 Like