/**
  * Removes all path entries and the contents recursively
  * 
  * @param \OCA\secure_container\Db\Path $path Path to delete
  * @param boolean $move Move the entries to the trash instead of delete
  */
 private function deletePathEntry($path, $move)
 {
     // Get all path children and walk down to begin the delete process on deepest level
     $children = $this->pathMapper->findChildren($path->getId());
     foreach ($children as $child) {
         $this->deletePathEntry($child, $move);
     }
     // Delete all entries in this path and finally delete the path itself
     $entries = $this->contentMapper->findAll($path->getId());
     foreach ($entries as $entry) {
         if ($move) {
             $entry->setPath(self::TRASH_PARENT_ID);
             $this->contentMapper->update($entry);
         } else {
             $this->contentMapper->delete($entry);
         }
     }
     $this->pathMapper->delete($path);
 }
	/**
	 * Create and update a SecureContainer path
	 * 
	 * @param string $guid The ID of the path to upgrade - or null for a new one
	 * 
	 * @return JSONResponse
	 * 
	 * @NoAdminRequired
	 */
	public function section($guid) {
		try {
			// Check for a valid post data format
			$data = (object) $this->request->post;
			if (!is_object($data) || !isset($data->name)) {
				throw new \Exception('Invalid data posted for create a new path in SecureContainer.');
			}
			
			// Create or Update the entity.
			if ($this->pathMapper->exists($guid)) {
				$entity = $this->pathMapper->find($guid);
				$entity->setName($data->name);
				$entity->setParent(intval($data->section));
				$entity = $this->pathMapper->update($entity);
			}
			else {
				$entity = new Path();
				$entity->setUid($this->userId);
				$entity->setName($data->name);
				$entity->setParent(intval($data->section));
				$entity = $this->pathMapper->insert($entity);
			}
			
			// Create the response
			$response = $this->getResponseSkeleton('section');
			$this->appendNavigationEvent('update', array(
				'guid' => $entity->getId(),
				'parent' => $entity->getParent(),
				'name' => $entity->getName(),
				), $response);
		} catch (\Exception $ex) {
			return $this->createResponseException($ex, 'section', Http::STATUS_INTERNAL_SERVER_ERROR);
		}
		
		$this->registerResponder('xml', function($value) {
			return new XMLResponse($value);
		});
		return new JSONResponse($response);
	}