示例#1
0
 /**
  * 
  * Process collections
  * 
  *    collections/{collection}                      |  Delete {collection}
  *    collections/{collection}/{feature}            |  Delete {feature}
  * 
  * @param array $segments
  */
 private function DELETE_collections($segments)
 {
     /*
      * {collection} is mandatory and no modifier is allowed
      */
     if (!isset($segments[1]) || isset($segments[3])) {
         RestoLogUtil::httpError(404);
     }
     $collection = new RestoCollection($segments[1], $this->context, $this->user, array('autoload' => true));
     if (isset($segments[2])) {
         $feature = new RestoFeature($this->context, $this->user, array('featureIdentifier' => $segments[2], 'collection' => $collection));
         if (!$feature->isValid()) {
             RestoLogUtil::httpError(404);
         }
     }
     /*
      * Only owner of a collection can delete it
      */
     if (!$this->user->hasRightsTo(RestoUser::UPDATE, array('collection' => $collection))) {
         RestoLogUtil::httpError(403);
     }
     /**
      * collections/{collection}
      * 
      *  @SWG\Delete(
      *      tags={"collection"},
      *      path="/collections/{collectionId}",
      *      summary="Delete collection",
      *      description="Delete collection {collectionId} if collection is not empty",
      *      operationId="deleteCollection",
      *      produces={"application/json"},
      *      @SWG\Parameter(
      *          name="collectionId",
      *          in="path",
      *          description="Collection identifier",
      *          required=true,
      *          type="string",
      *          @SWG\Items(type="string")
      *      ),
      *      @SWG\Response(
      *          response="200",
      *          description="Acknowledgment on successful collection deletion"
      *      ),
      *      @SWG\Response(
      *          response="404",
      *          description="Collection not found"
      *      ),
      *      @SWG\Response(
      *          response="403",
      *          description="Forbidden"
      *      )
      *  )
      */
     if (!isset($feature)) {
         $collection->removeFromStore();
         /*
          * Store query
          */
         if ($this->context->storeQuery === true) {
             $this->user->storeQuery($this->context->method, 'remove', $collection->name, null, $this->context->query, $this->context->getUrl());
         }
         return RestoLogUtil::success('Collection ' . $collection->name . ' deleted');
     } else {
         $feature->removeFromStore();
         /*
          * Store query
          */
         if ($this->context->storeQuery === true) {
             $this->user->storeQuery($this->context->method, 'remove', $collection->name, $feature->identifier, $this->context->query, $this->context->getUrl());
         }
         return RestoLogUtil::success('Feature ' . $feature->identifier . ' deleted', array('featureIdentifier' => $feature->identifier));
     }
 }
示例#2
0
 public function testRemoveCollection()
 {
     $this->initContext();
     $collection = new RestoCollection('Example', $this->context, $this->admin, array('autoload' => true));
     $collection->removeFromStore();
     $collection = new RestoCollection('Land', $this->context, $this->admin, array('autoload' => true));
     $collection->removeFromStore();
 }