Fix tx template delete query.
This commit is contained in:
parent
f26f7c60af
commit
2dcac57cba
3 changed files with 8 additions and 6 deletions
|
@ -502,7 +502,7 @@
|
||||||
"subscribers.status.unconfirmed": "Unconfirmed",
|
"subscribers.status.unconfirmed": "Unconfirmed",
|
||||||
"subscribers.status.unsubscribed": "Unsubscribed",
|
"subscribers.status.unsubscribed": "Unsubscribed",
|
||||||
"subscribers.subscribersDeleted": "{num} subscriber(s) deleted",
|
"subscribers.subscribersDeleted": "{num} subscriber(s) deleted",
|
||||||
"templates.cantDeleteDefault": "Cannot delete default template",
|
"templates.cantDeleteDefault": "Cannot delete non-existent or default template",
|
||||||
"templates.default": "Default",
|
"templates.default": "Default",
|
||||||
"templates.dummyName": "Dummy campaign",
|
"templates.dummyName": "Dummy campaign",
|
||||||
"templates.dummySubject": "Dummy campaign subject",
|
"templates.dummySubject": "Dummy campaign subject",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/knadh/listmonk/models"
|
"github.com/knadh/listmonk/models"
|
||||||
|
@ -74,8 +75,7 @@ func (c *Core) SetDefaultTemplate(id int) error {
|
||||||
// DeleteTemplate deletes a given template.
|
// DeleteTemplate deletes a given template.
|
||||||
func (c *Core) DeleteTemplate(id int) error {
|
func (c *Core) DeleteTemplate(id int) error {
|
||||||
var delID int
|
var delID int
|
||||||
if err := c.q.DeleteTemplate.Get(&delID, id); err != nil {
|
if err := c.q.DeleteTemplate.Get(&delID, id); err != nil && err != sql.ErrNoRows {
|
||||||
// TODO: Fix this. Deletes but always throws a "no result set" error.
|
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError,
|
return echo.NewHTTPError(http.StatusInternalServerError,
|
||||||
c.i18n.Ts("globals.messages.errorDeleting", "name", "{globals.terms.template}", "error", pqErrMsg(err)))
|
c.i18n.Ts("globals.messages.errorDeleting", "name", "{globals.terms.template}", "error", pqErrMsg(err)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -776,10 +776,12 @@ WITH tpl AS (
|
||||||
DELETE FROM templates WHERE id = $1 AND (SELECT COUNT(id) FROM templates) > 1 AND is_default = false RETURNING id
|
DELETE FROM templates WHERE id = $1 AND (SELECT COUNT(id) FROM templates) > 1 AND is_default = false RETURNING id
|
||||||
),
|
),
|
||||||
def AS (
|
def AS (
|
||||||
SELECT id FROM templates WHERE is_default = true LIMIT 1
|
SELECT id FROM templates WHERE is_default = true AND type='campaign' LIMIT 1
|
||||||
)
|
),
|
||||||
|
up AS (
|
||||||
UPDATE campaigns SET template_id = (SELECT id FROM def) WHERE (SELECT id FROM tpl) > 0 AND template_id = $1
|
UPDATE campaigns SET template_id = (SELECT id FROM def) WHERE (SELECT id FROM tpl) > 0 AND template_id = $1
|
||||||
RETURNING (SELECT id FROM tpl);
|
)
|
||||||
|
SELECT id FROM tpl;
|
||||||
|
|
||||||
|
|
||||||
-- media
|
-- media
|
||||||
|
|
Loading…
Reference in a new issue