API / Minn\Ops / Updates

Updates final class

Minn\Ops\Updates · public/minn/src/Minn/Ops/Updates.php · 456 lines

Update offers for the site's plugins and themes from the directory, asked through the Minn update service (Ops\Directory), which answers with wordpress.org's own offers and serves their packages: the update-check endpoints asked with the installed headers (each plugin's Name, Version and Update URI, so a plugin that updates from elsewhere is never offered the directory's plugin of the same folder name), the answer kept in the minn_updates option (JSON) for twelve hours, and the offers applied by downloading the release archive through the one package unpacker. A plugin or theme the directory does not know keeps its folder untouched and is never offered anything. The per-item auto-update lists are the site's own auto_update_plugins and auto_update_themes options, in the shape the app already reads.

The directory is not the only source. A plugin that hosts itself answers for its own version through the update transient's filter, which is where WordPress reads it too, so Runtime\PluginUpdates asks the runtime the same question and its answer is merged in. Applying such an offer goes through the publisher: a package outside the directory is unpacked only when `upgrader_pre_download` hands back a copy it verified.

Constants and properties

constOPTION = 'minn_updates'
constTTL = 43200
private?array $state
privatereadonly Minn\Content\Site $site

Promoted from the constructor.

privatereadonly Minn\Content\Inventory $inventory

Promoted from the constructor.

privatereadonly Minn\Ops\Packages $packages

Promoted from the constructor.

privatereadonly string $contentDir

Promoted from the constructor.

privatereadonly Minn\Http $http

Promoted from the constructor.

Public

new__construct(Minn\Content\Site $site, Minn\Content\Inventory $inventory, Minn\Ops\Packages $packages, string $contentDir, Minn\Http $http = \Minn\Http::__set_state(array( 'within' => array ( ), 'fake' => NULL, 'refusal' => NULL, )))#
staticforSite(Minn\Content\Site $site, string $contentDir): self#

The updater over a site's wp-content.

methodcheckForWordPress(string $transient, array $fresh): void#

wp_update_plugins and wp_update_themes: the service asked when the stored answer is old (or a fresh one is wanted), and the offers left in the update transients when they are not there already.

methodstate(): array#

The stored answer, refreshed when older than the TTL or absent.

methodrefresh(): array#

Asks the directory now, whatever the cache says, and keeps the answer.

methodcheck(): array#

Asks the directory now and stores the answer.

methodpublish(): void#

The offers in WordPress's update transients, update_plugins and update_themes, in the shape wp_update_plugins and wp_update_themes leave there: where plugins, the facade's update helpers and the upgraders read them. Written after every check and after an update.

methodpluginOffers(): array#

Plugin file => offered version, only where the installed version is older. @return array<string, string>

@return array<string, string>
methodthemeOffers(): array#

Stylesheet => offered version. @return array<string, string>

@return array<string, string>
methodpluginMeta(): array#

Plugin file => slug, icon, directory URL, for every plugin the directory knows. @return array<string, array{slug: string, icon: string, url: string}>

@return array<string, array{slug: string, icon: string, url: string}>
methodthemeOnDirectory(string $stylesheet): bool#

Whether the directory knows this theme.

methodupdatePlugin(string $file): string#

Applies the offer for one plugin file; returns the installed version afterwards.

methodupdateTheme(string $stylesheet): string#

Updates one theme to its offer; the new version.

methodauto(string $type): array#

The auto-update list for plugins or themes, trimmed to what is installed. @return list<string>

@return list<string>
methodenableAuto(string $type, string $asset): array#

Turns auto-updates on or off for one plugin or theme.

@return list<string> the list after the change
methoddisableAuto(string $type, string $asset): array#

Takes one plugin or theme off the auto-update list; the list after.

methodrunAuto(Minn\Ops\AutoUpdates $gate): array#

Applies every offer on the auto-update lists: what was updated, and what was refused with the reason, by plugin file or theme slug.

@return array{done: list<string>, failed: array<string, string>}
methodpluginVersions(): array#

Plugin file => installed version. @return array<string, string>

@return array<string, string>
methodpluginNames(): array#

Plugin file => Plugin Name. @return array<string, string>

@return array<string, string>
methodthemeHeaders(): array#

Stylesheet => style.css headers. @return array<string, array<string, string>>

@return array<string, array<string, string>>

Internals 8

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatelocales(string $filter): array#

The locales a check asks about, as the reference asks: the languages installed (their .mo files, through get_available_languages), then the check's own filter (plugins_update_check_locales, themes_update_check_locales); none for an English-only site.

@return list<string>
privatesupplied(array $stored): array#

What the site's own plugins offer for themselves. A check that runs without a booted runtime (a cron trigger that loads no plugins) asks nobody, so the last answer rides across rather than the offer vanishing until the next request.

$storedarray<string, mixed>the previous state
@return array{plugins: array<string, array<string, mixed>>, no_update: array<string, array<string, mixed>>}
privatesaveAuto(string $type, string $asset, array $list): array#

Stores an auto-update list, kept to assets that exist; the asset being changed must be one of them.

$listlist<string>
@return list<string>
privatepluginHeaders(): array#

Plugin file => the headers the update check sends, in WordPress's keys.

@return array<string, array{Name: string, Version: string, UpdateURI: string}>
privateapply(string $kind, string $item, string $package): void#

Applies one offer through the upgrader (UpgraderRun): the update transients carry the offers first, as they do on WordPress when an update starts. The archive's SHA-256 is kept under "archives" in the state when the package came from the update service, so an audit can ask what code arrived.

privateconsume(string $from, string $to, string $key): void#

An applied offer moves to the current bucket so the next read agrees with the folder, and the offers left go back into the update transients the upgrader cleared, as Minn Admin puts them back on WordPress.

privatemap(mixed $bucket): array#

The directory answers an empty bucket as a list; a map either way.

privatesafeUrl(string $url): string#