示例#1
0
 public function deleteFile($id)
 {
     if (empty($id)) {
         return Response::json(array('error' => array('message' => "Bad request.", 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     $model = new FileModel();
     $file = $model->find($id);
     if (!$file) {
         return Response::json(array('error' => array('message' => "Bad request.", 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     if (!$model->delete_safe($id)) {
         return Response::json(array('error' => array('message' => $model->errors[0], 'type' => "InvalidParameters", 'code' => 100)), 400);
     } else {
         Response::json(array('result' => $file));
     }
 }
示例#2
0
 /**
  * @name deleteItems
  *
  * Delete gallery item/items by their ids (delete)
  * 
  * @param array|int $ids - Array of IDs or single ID of item/items for delete
  * @return bool - returns TRUE on success or FALSE if there was an error
  * @static
  */
 public static function deleteItems($ids)
 {
     if (empty($ids)) {
         return false;
     }
     try {
         DB::beginTransaction();
         if (!is_array($ids)) {
             $ids = array($ids);
         }
         $file_ids = array();
         foreach ($ids as $id) {
             $gallery_item = GalleryItemDB::find($id);
             if (!$gallery_item) {
                 DB::rollBack();
                 $this->errors[] = 'Invalid Gallery Item ID';
                 return false;
             }
             if ($gallery_item->file_id) {
                 $file_ids[] = $gallery_item->file_id;
             }
             if (!$gallery_item->delete()) {
                 DB::rollBack();
                 $this->errors[] = 'Failed to delete Gallery Item';
                 return false;
             }
         }
         $file_model = new FileModel();
         $file_model->delete_safe($file_ids);
         DB::commit();
         return true;
     } catch (PDOException $e) {
         DB::rollBack();
         $this->errors[] = 'Fatal error' . $e->message;
         return false;
     }
 }
示例#3
0
 /**
  * @name deleteSafe
  *
  * Delete attachment (delete)
  * 
  * @param int $id - ID of attachment that will be deleted
  * @return bool - returns TRUE on success or FALSE if there was an error
  * @static
  */
 public static function deleteSafe($id)
 {
     if (empty($id)) {
         return false;
     }
     try {
         DB::beginTransaction();
         $file_id = false;
         $attachment = self::find($id);
         if (!$attachment) {
             DB::rollBack();
             $this->errors[] = 'Invalid attachment Item ID';
             return false;
         }
         if ($attachment->file_id) {
             $file_id = $attachment->file_id;
         }
         if (!$attachment->delete()) {
             DB::rollBack();
             $this->errors[] = 'Failed to delete attachment';
             return false;
         }
         if ($file_id) {
             $file_model = new FileModel();
             if (!$file_model->delete_safe($file_id)) {
                 DB::rollBack();
                 $this->errors[] = 'Failed to delete Files';
                 return false;
             }
         }
         DB::commit();
         return true;
     } catch (PDOException $e) {
         DB::rollBack();
         $this->errors[] = 'Fatal error' . $e->message;
         return false;
     }
 }