mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-23 03:21:35 +02:00
Change ShadowCopyID type from *int64 to sql.NullInt64.
This commit is contained in:
parent
7046bd5e39
commit
799885246a
2 changed files with 9 additions and 2 deletions
|
@ -5,6 +5,7 @@ package moderation
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"slices"
|
||||
|
||||
|
@ -101,7 +102,7 @@ type AbuseReport struct {
|
|||
// Remarks provided by the reporter.
|
||||
Remarks string // TODO: ReporterReparks or Reason
|
||||
// The ID of the corresponding shadow-copied content when exists; otherwise null.
|
||||
ShadowCopyID *int64 `xorm:"DEFAULT NULL"`
|
||||
ShadowCopyID sql.NullInt64 `xorm:"DEFAULT NULL"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ package moderation
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
|
@ -20,6 +21,11 @@ type AbuseReportShadowCopy struct {
|
|||
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
|
||||
}
|
||||
|
||||
// Returns the ID encapsulated in a sql.NullInt64 struct.
|
||||
func (sc AbuseReportShadowCopy) NullableID() sql.NullInt64 {
|
||||
return sql.NullInt64{Int64: sc.ID, Valid: sc.ID > 0}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// RegisterModel will create the table if does not already exist
|
||||
// or any missing columns if the table was previously created.
|
||||
|
@ -69,7 +75,7 @@ func createShadowCopy(ctx context.Context, contentType ReportedContentType, cont
|
|||
"content_type": contentType,
|
||||
"content_id": contentID,
|
||||
// TODO: What should happen if an item is updated multiple times (and the reports already have a shadow copy ID)?
|
||||
}).And(builder.IsNull{"shadow_copy_id"}).Cols("shadow_copy_id").Update(&AbuseReport{ShadowCopyID: &shadowCopy.ID})
|
||||
}).And(builder.IsNull{"shadow_copy_id"}).Update(&AbuseReport{ShadowCopyID: shadowCopy.NullableID()})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not link the shadow copy (%d) to reported content with type %d and ID %d - %w", shadowCopy.ID, contentType, contentID, err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue