(runtimeDelete request.RuntimeDelete)
| 283 | } |
| 284 | |
| 285 | func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error { |
| 286 | runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(runtimeDelete.ID)) |
| 287 | if err != nil { |
| 288 | return err |
| 289 | } |
| 290 | website, _ := websiteRepo.GetFirst(websiteRepo.WithRuntimeID(runtimeDelete.ID)) |
| 291 | if website.ID > 0 { |
| 292 | return buserr.New("ErrDelWithWebsite") |
| 293 | } |
| 294 | if runtime.Resource != constant.ResourceAppstore { |
| 295 | return runtimeRepo.DeleteBy(repo.WithByID(runtimeDelete.ID)) |
| 296 | } |
| 297 | projectDir := runtime.GetPath() |
| 298 | if out, err := compose.Down(runtime.GetComposePath()); err != nil && !runtimeDelete.ForceDelete { |
| 299 | if out != "" { |
| 300 | return errors.New(out) |
| 301 | } |
| 302 | return err |
| 303 | } |
| 304 | if runtime.Type == constant.RuntimePHP { |
| 305 | client, err := docker.NewClient() |
| 306 | if err != nil { |
| 307 | return err |
| 308 | } |
| 309 | defer client.Close() |
| 310 | imageID, err := client.GetImageIDByName(runtime.Image) |
| 311 | if err != nil { |
| 312 | return err |
| 313 | } |
| 314 | if imageID != "" { |
| 315 | if err := client.DeleteImage(imageID); err != nil { |
| 316 | global.LOG.Errorf("delete image id [%s] error %v", imageID, err) |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | if err := files.NewFileOp().DeleteDir(projectDir); err != nil && !runtimeDelete.ForceDelete { |
| 321 | return err |
| 322 | } |
| 323 | return runtimeRepo.DeleteBy(repo.WithByID(runtimeDelete.ID)) |
| 324 | } |
| 325 | |
| 326 | func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) { |
| 327 | runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(id)) |
nothing calls this directly
no test coverage detected