2017-10-11 16:06:51 +00:00
|
|
|
package models
|
|
|
|
|
2017-11-08 09:55:17 +00:00
|
|
|
// DeletePublisherByID deletes a publisher by its ID
|
2018-03-06 11:36:49 +00:00
|
|
|
func DeletePublisherByID(id int64, doer *User) error {
|
2017-11-24 15:27:35 +00:00
|
|
|
// Check if the id is 0
|
|
|
|
if id == 0 {
|
2018-01-24 11:58:00 +00:00
|
|
|
return ErrIDCannotBeZero{}
|
2017-11-24 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 16:06:51 +00:00
|
|
|
// Delete the publisher
|
|
|
|
_, err := x.Id(id).Delete(&Publisher{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set all publisher to 0 on all book with this publisher
|
2017-11-29 15:23:19 +00:00
|
|
|
_, err = x.Table("books").
|
2017-11-30 14:48:03 +00:00
|
|
|
Where("publisher_id = ?", id).
|
|
|
|
Update(map[string]interface{}{"publisher_id": 0})
|
2018-03-06 11:36:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Logging
|
|
|
|
err = logAction(ActionTypePublisherDeleted, doer, id)
|
2017-10-11 16:06:51 +00:00
|
|
|
|
|
|
|
return err
|
2017-11-07 15:35:10 +00:00
|
|
|
}
|