public function getFolderTreeToUserRoot()
{
$p = $this->getFolderPath();
do {
$folderTree[] = $p;
// remove from last "/" to previous "/", e.g.:
// "/foo/bar/baz/" -> "/foo/bar/"
// remove the last "/"
$p = substr($p, 0, strlen($p) - 1);
// remove everything after the now last "/"
$p = substr($p, 0, strrpos($p, '/') + 1);
} while (substr_count($p, '/') > 1);
return $folderTree;
}
/** * Delete a document and all empty parent directories if there are any. * * @param $p the path of a document to delete * @returns an array of all deleted objects */ 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; }