mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-12 20:20:41 -05:00
- Updated the SptVersion and ModVersion dependancies to resolve *all* compatible versions and introduced new relationships to pull just the latest compatible version. Had to rewrite a *bunch*, but it should be much more capable now. It can be expensive to resolve these properties when iterated over, so *make sure they're eager loaded using the `with` method when you're building the queries*. - Updated the mod listing Livewire component to save the filter options within the PHP session instead of in browser local storage. *Much* cleaner. - Removed caching from homepage queries to see how they preform on production. Will add back later. - Updated ModVersion factory to create SptVersions if there are none specified. - Probably lots of other changes too... I need to make smaller commits. :(
48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\ModVersion;
|
|
use Composer\Semver\Semver;
|
|
|
|
class DependencyVersionService
|
|
{
|
|
/**
|
|
* Resolve the dependencies for a mod version.
|
|
*/
|
|
public function resolve(ModVersion $modVersion): void
|
|
{
|
|
$dependencies = $this->satisfyConstraint($modVersion);
|
|
$modVersion->resolvedDependencies()->sync($dependencies);
|
|
}
|
|
|
|
/**
|
|
* Satisfies all dependency constraints of a ModVersion.
|
|
*/
|
|
private function satisfyConstraint(ModVersion $modVersion): array
|
|
{
|
|
// Eager load the dependencies and their mod versions.
|
|
$modVersion->load('dependencies.dependentMod.versions');
|
|
|
|
// Iterate over each ModVersion dependency.
|
|
$dependencies = [];
|
|
foreach ($modVersion->dependencies as $dependency) {
|
|
|
|
// Get all dependent mod versions.
|
|
$dependentModVersions = $dependency->dependentMod->versions()->get();
|
|
|
|
// Filter the dependent mod versions to find the ones that satisfy the dependency constraint.
|
|
$matchedVersions = $dependentModVersions->filter(function ($version) use ($dependency) {
|
|
return Semver::satisfies($version->version, $dependency->constraint);
|
|
});
|
|
|
|
// Map the matched versions to the sync data.
|
|
foreach ($matchedVersions as $matchedVersion) {
|
|
$dependencies[$matchedVersion->id] = ['dependency_id' => $dependency->id];
|
|
}
|
|
}
|
|
|
|
return $dependencies;
|
|
}
|
|
}
|