Skip to content

Commit 6ce5996

Browse files
committed
added ability to read core
1 parent 505f2fd commit 6ce5996

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Flarum/UpdatesChecker.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Extiverse\Api\JsonApi\Repositories\ExtensionRepository;
77
use Extiverse\Api\JsonApi\Types\Extension\Extension;
88
use Flarum\Extension\ExtensionManager;
9+
use Flarum\Foundation\Application;
910
use Illuminate\Support\Collection;
1011

1112
class UpdatesChecker
@@ -17,6 +18,19 @@ public function __construct(ExtensionManager $extensions)
1718
$this->extensions = $extensions;
1819
}
1920

21+
public function core(): Extension
22+
{
23+
$response = $this->repository()->find('flarum$core');
24+
25+
/** @var Extension $core */
26+
$core = $response->getData();
27+
$core->setAttribute('current-version', Application::VERSION);
28+
$core->setAttribute('enabled', true);
29+
$core->setAttribute('needs-update', $this->needsUpdate($core['current-version'], $core['highest-version']));
30+
31+
return $core;
32+
}
33+
2034
public function process(): Collection
2135
{
2236
return $this->extensions->getExtensions()
@@ -26,7 +40,7 @@ public function process(): Collection
2640
})
2741
->chunk(15)
2842
->map(function ($chunk) {
29-
$response = (new ExtensionRepository)->all(['filter[batch]' => $chunk->implode(',')]);
43+
$response = $this->repository()->all(['filter[batch]' => $chunk->implode(',')]);
3044

3145
return $response->getData();
3246
})
@@ -50,4 +64,9 @@ protected function needsUpdate(string $currentVersion, string $highestVersion =
5064

5165
return Comparator::compare($currentVersion, '<', $highestVersion);
5266
}
67+
68+
protected function repository(): ExtensionRepository
69+
{
70+
return new ExtensionRepository;
71+
}
5372
}

0 commit comments

Comments
 (0)