mirror of
https://gh.wpcy.net/https://github.com/aspirepress/AspireCloud.git
synced 2026-07-17 11:37:03 +08:00
* refactor: use Bag transformers for (Plugin|Theme)HotTagsResponse * refactor: replace more static constructors with Transforms * zap: rm unused ThemeUpdateCheckTranslationCollection (whew) VO * refactor: inline ThemeUpdateData::fromModelCollection * refactor: embaggify QueryPluginsRequest * refactor: Bag up PluginInformationRequest * refactor: throw PluginUpdateRequest into the Bag * test: move phpstan.neon -> phpstan.dist.neon * refactor: tighten up update check request types * test: use more realistic plugin filenames in update check tests * refactor: use single query for plugin update check * refactor: convert plugin updates to Bag (i'm out of "bag" neologisms) * refactor: use ThemeResponse VO for theme info requests * refactor: commit baggravated assault on ThemeCollection/ThemeResource ;) * refactor: bag up the rest of the Resource types * tweak: slipstream in dependabot upgrade
44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Plugins;
|
|
|
|
use App\Models\WpOrg\Plugin;
|
|
use App\Values\WpOrg\Plugins\PluginUpdateCheckRequest;
|
|
use App\Values\WpOrg\Plugins\PluginUpdateCheckResponse;
|
|
use App\Values\WpOrg\Plugins\PluginUpdateData;
|
|
|
|
class PluginUpdateService
|
|
{
|
|
public function checkForUpdates(PluginUpdateCheckRequest $req): PluginUpdateCheckResponse
|
|
{
|
|
$bySlug = collect($req->plugins)
|
|
->mapWithKeys(
|
|
fn($pluginData, $pluginFile) => [$this->extractSlug($pluginFile) => [$pluginFile, $pluginData]],
|
|
);
|
|
|
|
$isUpdated = fn($plugin) => version_compare($plugin->version, $bySlug[$plugin->slug][1]['Version'] ?? '', '>');
|
|
|
|
$mkUpdate = function ($plugin) use ($bySlug) {
|
|
$file = $bySlug[$plugin->slug][0];
|
|
return [$file => PluginUpdateData::from($plugin)->with(plugin: $file)];
|
|
};
|
|
|
|
[$updates, $no_updates] = Plugin::query()
|
|
->whereIn('slug', $bySlug->keys())
|
|
->get()
|
|
->partition($isUpdated)
|
|
->map(fn($collection) => $collection->mapWithKeys($mkUpdate));
|
|
|
|
return PluginUpdateCheckResponse::from(plugins: $updates, no_update: $no_updates, translations: collect([]));
|
|
}
|
|
|
|
/**
|
|
* Extract the plugin slug from the plugin file path
|
|
*/
|
|
private function extractSlug(string $pluginFile): string
|
|
{
|
|
return str_contains($pluginFile, '/')
|
|
? explode('/', $pluginFile)[0]
|
|
: pathinfo($pluginFile, PATHINFO_FILENAME);
|
|
}
|
|
}
|