2021-01-13 00:35:30 +01:00
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2021-03-26 19:01:54 +01:00
|
|
|
"github.com/mattermost/focalboard/server/services/store"
|
2021-10-07 13:51:01 +02:00
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
2021-01-13 00:35:30 +01:00
|
|
|
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
|
|
|
)
|
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
func (s *SQLStore) upsertSharing(db sq.BaseRunner, _ store.Container, sharing model.Sharing) error {
|
2021-10-07 13:51:01 +02:00
|
|
|
now := utils.GetMillis()
|
2021-01-13 00:35:30 +01:00
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).
|
2021-04-17 09:06:57 +02:00
|
|
|
Insert(s.tablePrefix+"sharing").
|
2021-01-13 00:35:30 +01:00
|
|
|
Columns(
|
|
|
|
"id",
|
|
|
|
"enabled",
|
|
|
|
"token",
|
|
|
|
"modified_by",
|
|
|
|
"update_at",
|
|
|
|
).
|
|
|
|
Values(
|
|
|
|
sharing.ID,
|
|
|
|
sharing.Enabled,
|
|
|
|
sharing.Token,
|
|
|
|
sharing.ModifiedBy,
|
|
|
|
now,
|
2021-04-22 22:53:01 +02:00
|
|
|
)
|
|
|
|
if s.dbType == mysqlDBType {
|
2021-06-21 11:21:42 +02:00
|
|
|
query = query.Suffix("ON DUPLICATE KEY UPDATE enabled = ?, token = ?, modified_by = ?, update_at = ?",
|
|
|
|
sharing.Enabled, sharing.Token, sharing.ModifiedBy, now)
|
2021-04-22 22:53:01 +02:00
|
|
|
} else {
|
2021-06-21 11:21:42 +02:00
|
|
|
query = query.Suffix(
|
2021-10-22 12:48:53 +02:00
|
|
|
`ON CONFLICT (id)
|
2021-06-21 11:21:42 +02:00
|
|
|
DO UPDATE SET enabled = EXCLUDED.enabled, token = EXCLUDED.token, modified_by = EXCLUDED.modified_by, update_at = EXCLUDED.update_at`,
|
|
|
|
)
|
2021-04-22 22:53:01 +02:00
|
|
|
}
|
2021-01-13 00:35:30 +01:00
|
|
|
|
|
|
|
_, err := query.Exec()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
func (s *SQLStore) getSharing(db sq.BaseRunner, _ store.Container, rootID string) (*model.Sharing, error) {
|
|
|
|
query := s.getQueryBuilder(db).
|
2021-01-13 00:35:30 +01:00
|
|
|
Select(
|
|
|
|
"id",
|
|
|
|
"enabled",
|
|
|
|
"token",
|
|
|
|
"modified_by",
|
|
|
|
"update_at",
|
|
|
|
).
|
2021-04-17 09:06:57 +02:00
|
|
|
From(s.tablePrefix + "sharing").
|
2021-01-13 00:35:30 +01:00
|
|
|
Where(sq.Eq{"id": rootID})
|
|
|
|
row := query.QueryRow()
|
|
|
|
sharing := model.Sharing{}
|
|
|
|
|
|
|
|
err := row.Scan(
|
|
|
|
&sharing.ID,
|
|
|
|
&sharing.Enabled,
|
|
|
|
&sharing.Token,
|
|
|
|
&sharing.ModifiedBy,
|
|
|
|
&sharing.UpdateAt,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &sharing, nil
|
|
|
|
}
|