packages

package
v0.0.0-...-a2b067c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackfillTrunkRevisions

func BackfillTrunkRevisions(ctx context.Context, db *sql.DB, slugRevisions map[string]int64) (int64, error)

BackfillTrunkRevisions sets trunk_revision for active plugins that don't have one yet. Only updates rows where trunk_revision IS NULL to avoid overwriting newer data.

func BatchUpsertPackages

func BatchUpsertPackages(ctx context.Context, db *sql.DB, pkgs []*Package) error

BatchUpsertPackages inserts or updates full package records in a single transaction.

func BatchUpsertShellPackages

func BatchUpsertShellPackages(ctx context.Context, db *sql.DB, entries []ShellEntry) error

BatchUpsertShellPackages inserts or updates shell package records in a single transaction.

func DeactivatePackage

func DeactivatePackage(ctx context.Context, db *sql.DB, id int64) error

DeactivatePackage sets is_active = 0 for a package.

func FinishStatusCheck

func FinishStatusCheck(ctx context.Context, db *sql.DB, id int64, started time.Time,
	checked, deactivated, reactivated, failed int64, runErr error) error

FinishStatusCheck updates a status_checks row with the final results.

func FinishSyncRun

func FinishSyncRun(ctx context.Context, db *sql.DB, rowID int64, status string, stats map[string]any) error

FinishSyncRun marks a sync run as completed with stats.

func GetMeta

func GetMeta(ctx context.Context, db *sql.DB, key string) (string, error)

GetMeta retrieves a value from site_meta by key. Returns "" if not found.

func MarkPackagesChanged

func MarkPackagesChanged(ctx context.Context, db *sql.DB, pkgType string, slugRevisions map[string]int64) (int64, error)

MarkPackagesChanged sets last_committed = now and trunk_revision for the given slugs of a specific type, so they'll be picked up by GetPackagesNeedingUpdate. slugRevisions maps each slug to its highest SVN revision from the changelog.

func MarkPermanentlyClosed

func MarkPermanentlyClosed(ctx context.Context, db *sql.DB, id int64) error

MarkPermanentlyClosed tombstones a package so it's excluded from discovery and polling entirely. The row is kept (with is_active = 0 and permanently_closed = 1) so SVN discovery dedup still works and audit history via status_check_changes is preserved.

func ReactivatePackage

func ReactivatePackage(ctx context.Context, db *sql.DB, id int64) error

ReactivatePackage sets is_active = 1 for a package.

func RecordStatusCheckChange

func RecordStatusCheckChange(ctx context.Context, db *sql.DB, statusCheckID int64, pkgType, pkgName, action string)

RecordStatusCheckChange inserts a per-package deactivation or reactivation event.

func RefreshSiteStats

func RefreshSiteStats(ctx context.Context, db *sql.DB) error

RefreshSiteStats recomputes the package_stats row from the packages table.

func SetMeta

func SetMeta(ctx context.Context, db *sql.DB, key, value string) error

SetMeta inserts or updates a value in site_meta.

func StartStatusCheck

func StartStatusCheck(ctx context.Context, db *sql.DB, started time.Time) (int64, error)

StartStatusCheck inserts a new status_checks row and returns its ID.

func UpsertPackage

func UpsertPackage(ctx context.Context, db *sql.DB, pkg *Package) error

UpsertPackage inserts or updates a package record by (type, name).

func UpsertShellPackage

func UpsertShellPackage(ctx context.Context, db *sql.DB, pkgType, name string, lastCommitted *time.Time) error

UpsertShellPackage creates a minimal package record (for SVN discovery) or updates last_committed if the new date is more recent.

Types

type Package

type Package struct {
	ID                      int64
	Type                    string
	Name                    string
	DisplayName             *string
	Description             *string
	Author                  *string
	Homepage                *string
	SlugURL                 *string
	VersionsJSON            string
	Downloads               int64
	ActiveInstalls          int64
	CurrentVersion          *string
	WporgVersion            *string
	Rating                  *float64
	NumRatings              int
	IsActive                bool
	PermanentlyClosed       bool
	LastCommitted           *time.Time
	LastSyncedAt            *time.Time
	LastSyncRunID           *int64
	TrunkRevision           *int64
	ContentHash             *string
	DeployedHash            *string
	ContentChangedAt        *time.Time
	WpPackagesInstallsTotal int
	WpPackagesInstalls30d   int
	LastInstalledAt         *time.Time
	CreatedAt               time.Time
	UpdatedAt               time.Time

	// RawVersions holds the pre-normalization version map from the API.
	// Not persisted directly — normalized into VersionsJSON before storage.
	RawVersions map[string]string `json:"-"`
}

func GetAllPackages

func GetAllPackages(ctx context.Context, db *sql.DB, pkgType string) ([]*Package, error)

GetAllPackages returns all packages, optionally filtered by type.

func GetDeactivatedDeployedPackages

func GetDeactivatedDeployedPackages(ctx context.Context, db *sql.DB) ([]*Package, error)

GetDeactivatedDeployedPackages returns inactive packages that still have a deployed_hash (i.e. their p2 files are still on R2 and need to be deleted).

func GetDirtyPackages

func GetDirtyPackages(ctx context.Context, db *sql.DB) ([]*Package, error)

GetDirtyPackages returns active packages whose content_hash differs from deployed_hash.

func GetPackagesNeedingUpdate

func GetPackagesNeedingUpdate(ctx context.Context, db *sql.DB, opts UpdateQueryOpts) ([]*Package, error)

GetPackagesNeedingUpdate returns packages that should be updated.

func PackageFromAPIData

func PackageFromAPIData(data map[string]any, pkgType string) *Package

PackageFromAPIData maps a WordPress.org API response to a Package struct.

func (*Package) ComposerMeta

func (p *Package) ComposerMeta() composer.PackageMeta

ComposerMeta builds a composer.PackageMeta from a Package's nullable DB fields.

func (*Package) NormalizeAndStoreVersions

func (p *Package) NormalizeAndStoreVersions() (int, error)

NormalizeAndStoreVersions normalizes raw versions and serializes to VersionsJSON. It also sets CurrentVersion to the highest available version. Returns the number of valid versions.

type Seeds

type Seeds struct {
	PopularPlugins []string `yaml:"popular_plugins"`
	PopularThemes  []string `yaml:"popular_themes"`
}

func LoadSeeds

func LoadSeeds(path string) (*Seeds, error)

type ShellEntry

type ShellEntry struct {
	Type          string
	Name          string
	LastCommitted *time.Time
}

ShellEntry holds minimal package data for batch SVN discovery upserts.

type StatusCheck

type StatusCheck struct {
	ID              int64
	StartedAt       string
	FinishedAt      string
	Status          string
	Checked         int64
	Deactivated     int64
	Reactivated     int64
	Failed          int64
	DurationSeconds *int
	ErrorMessage    string
}

StatusCheck represents a row from the status_checks table.

func GetStatusChecks

func GetStatusChecks(ctx context.Context, db *sql.DB, limit int) ([]StatusCheck, error)

GetStatusChecks returns the most recent status check runs.

type StatusCheckChange

type StatusCheckChange struct {
	PackageType string
	PackageName string
	Action      string
}

StatusCheckChange represents a per-package event from a status check run.

func GetStatusCheckChanges

func GetStatusCheckChanges(ctx context.Context, db *sql.DB, statusCheckID int64) ([]StatusCheckChange, error)

GetStatusCheckChanges returns the per-package changes for a given status check.

type SyncRun

type SyncRun struct {
	RowID int64 // sync_runs.id (auto-increment)
	RunID int64 // logical ID assigned to packages.last_sync_run_id
}

SyncRun holds both the logical sync run ID (for package tracking) and the database row ID (for updating sync_runs status).

func AllocateSyncRunID

func AllocateSyncRunID(ctx context.Context, db *sql.DB) (*SyncRun, error)

AllocateSyncRunID atomically allocates a new sync run ID and creates a sync_runs record.

type UpdateQueryOpts

type UpdateQueryOpts struct {
	Type            string
	Name            string
	Names           []string // filter to these slugs only
	Force           bool
	IncludeInactive bool
	Limit           int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL