Ejemplo n.º 1
0
 protected function DELETE($action = '', $data = '')
 {
     if (!in_array($action, ['entity', 'entities', 'uid'])) {
         return $this->httpError(400, 'Bad Request');
     }
     ob_start();
     if (in_array($action, ['entity', 'entities'])) {
         $ents = json_decode($data, true);
         if ($action === 'entity') {
             $ents = [$ents];
         }
         $deleted = [];
         $failures = false;
         foreach ($ents as $delEnt) {
             $guid = (int) $delEnt['guid'];
             $etype = $delEnt['etype'];
             try {
                 if (Nymph::deleteEntityByID($guid, $etype)) {
                     $deleted[] = $guid;
                 } else {
                     $failures = true;
                 }
             } catch (\Exception $e) {
                 $failures = true;
             }
         }
         if (empty($deleted)) {
             if ($failures) {
                 return $this->httpError(400, 'Bad Request');
             } else {
                 return $this->httpError(500, 'Internal Server Error');
             }
         }
         header('HTTP/1.1 200 OK', true, 200);
         header('Content-Type: application/json');
         if ($action === 'entity') {
             echo json_encode($deleted[0]);
         } else {
             echo json_encode($deleted);
         }
     } else {
         if (!Nymph::deleteUID("{$data}")) {
             return $this->httpError(500, 'Internal Server Error');
         }
         header('HTTP/1.1 204 No Content', true, 204);
     }
     ob_end_flush();
     return true;
 }
Ejemplo n.º 2
0
 public function testDeleteUID()
 {
     $this->assertTrue(Nymph::deleteUID('TestUID'));
     $this->assertNull(Nymph::getUID('TestUID'));
 }