Fixes from the first round of TEST.md
SEO: a domain property (sc-domain:) covers every subdomain, so the shop, Gitea and forum were counted as the website. What ranks, the morning check, the Monday report, keywords, change candidates and the audit's traffic now read only the website's own host (with or without www). The report keeps pages worth a proposal apart from "Waiting for your yes", explains only moves past the thresholds, and says "places up/down". Also: - Feed summaries drop the posts' scripts and styles. - Spend you log can't be negative. - Test and check buttons can't be clicked twice while they run. - Previews show the site's web fonts and icon sprites. - Backups are read without leaving -wal/-shm files; deleting one removes them, and leftovers are swept at start. - The Overview's setup flags a CRM that Hermes can't reach. - Import now says what came in; adding a prospect that exists says so; prospects can be deleted. - Signal tags and brief addresses keep accented letters (Ü → u). - Page errors start with a capital; clearer messages for bad uploads, CRM retry and cancel, keywords, and the finished audit. - The module you're in stays unfolded in the sidebar. - A picked keyword can be unpicked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -998,3 +998,79 @@ func Search(d *db.DB, words []string, limit int) ([]Company, []Contact, error) {
|
||||
contacts, err := scanContacts(rows)
|
||||
return companies, contacts, err
|
||||
}
|
||||
|
||||
// Delete forgets a company (with its people) or a person added by mistake:
|
||||
// their steps in the funnel and Hunter.io searches go too, and a CRM action
|
||||
// that hasn't been done yet is taken back. A record Hermes already added to
|
||||
// EspoCRM stays there.
|
||||
func Delete(d *db.DB, kind string, id int64) error {
|
||||
tbl, err := table(kind)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tx, err := d.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
var exists int
|
||||
if err := tx.QueryRow(`SELECT count(*) FROM `+tbl+` WHERE id = ?`, id).Scan(&exists); err != nil {
|
||||
return err
|
||||
}
|
||||
if exists == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
contacts := []int64{}
|
||||
if kind == "contact" {
|
||||
contacts = append(contacts, id)
|
||||
} else {
|
||||
rows, err := tx.Query(`SELECT id FROM prospect_contacts WHERE company_id = ?`, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for rows.Next() {
|
||||
var c int64
|
||||
if err := rows.Scan(&c); err != nil {
|
||||
rows.Close()
|
||||
return err
|
||||
}
|
||||
contacts = append(contacts, c)
|
||||
}
|
||||
rows.Close()
|
||||
}
|
||||
subjects := []any{}
|
||||
if kind == "company" {
|
||||
subjects = append(subjects, "company:"+strconv.FormatInt(id, 10))
|
||||
}
|
||||
for _, c := range contacts {
|
||||
subjects = append(subjects, "contact:"+strconv.FormatInt(c, 10))
|
||||
}
|
||||
origins := make([]any, len(subjects))
|
||||
for i, s := range subjects {
|
||||
origins[i] = "prospect-" + s.(string)
|
||||
}
|
||||
in := "(?" + strings.Repeat(", ?", len(subjects)-1) + ")"
|
||||
for _, q := range []struct {
|
||||
sql string
|
||||
args []any
|
||||
}{
|
||||
{`DELETE FROM funnel_events WHERE subject IN ` + in, subjects},
|
||||
{`DELETE FROM enrich_runs WHERE subject IN ` + in, subjects},
|
||||
{`UPDATE crm_actions SET status = 'cancelled' WHERE status IN ('pending', 'failed') AND origin IN ` + in, origins},
|
||||
} {
|
||||
if _, err := tx.Exec(q.sql, q.args...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, c := range contacts {
|
||||
if _, err := tx.Exec(`DELETE FROM prospect_contacts WHERE id = ?`, c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if kind == "company" {
|
||||
if _, err := tx.Exec(`DELETE FROM prospect_companies WHERE id = ?`, id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user