fkooman\RemoteStorage\DocumentStorage::deleteDocument PHP Метод

deleteDocument() публичный Метод

Delete a document and all empty parent directories if there are any.
public deleteDocument ( Path $p )
$p Path the path of a document to delete
    public function deleteDocument(Path $p)
    {
        $documentPath = $this->baseDir . $p->getPath();
        if (false === @unlink($documentPath)) {
            throw new DocumentStorageException('unable to delete file');
        }
        $deletedObjects = array();
        $deletedObjects[] = $p->getPath();
        // delete all empty folders in the tree up to the user root if
        // they are empty
        foreach ($p->getFolderTreeToUserRoot() as $pathItem) {
            if ($this->isEmptyFolder(new Path($pathItem))) {
                $this->deleteFolder(new Path($pathItem));
                $deletedObjects[] = $pathItem;
            }
        }
        return $deletedObjects;
    }

Usage Example

Пример #1
0
 public function deleteDocument(Path $p, array $ifMatch = null)
 {
     if (null !== $ifMatch && !in_array($this->md->getVersion($p), $ifMatch)) {
         throw new PreconditionFailedException('version mismatch');
     }
     $deletedEntities = $this->d->deleteDocument($p);
     foreach ($deletedEntities as $d) {
         $this->md->deleteNode(new Path($d));
     }
     // increment the version from the folder containing the last deleted
     // folder and up to the user root, we cannot conveniently do this from
     // the MetadataStorage class :(
     foreach ($p->getFolderTreeToUserRoot() as $i) {
         if (null !== $this->md->getVersion(new Path($i))) {
             $this->md->updateFolder(new Path($i));
         }
     }
 }