6
6
use Extiverse \Api \JsonApi \Repositories \ExtensionRepository ;
7
7
use Extiverse \Api \JsonApi \Types \Extension \Extension ;
8
8
use Flarum \Extension \ExtensionManager ;
9
+ use Flarum \Foundation \Application ;
9
10
use Illuminate \Support \Collection ;
10
11
11
12
class UpdatesChecker
@@ -17,6 +18,19 @@ public function __construct(ExtensionManager $extensions)
17
18
$ this ->extensions = $ extensions ;
18
19
}
19
20
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
+
20
34
public function process (): Collection
21
35
{
22
36
return $ this ->extensions ->getExtensions ()
@@ -26,7 +40,7 @@ public function process(): Collection
26
40
})
27
41
->chunk (15 )
28
42
->map (function ($ chunk ) {
29
- $ response = ( new ExtensionRepository )->all (['filter[batch] ' => $ chunk ->implode (', ' )]);
43
+ $ response = $ this -> repository ( )->all (['filter[batch] ' => $ chunk ->implode (', ' )]);
30
44
31
45
return $ response ->getData ();
32
46
})
@@ -50,4 +64,9 @@ protected function needsUpdate(string $currentVersion, string $highestVersion =
50
64
51
65
return Comparator::compare ($ currentVersion , '< ' , $ highestVersion );
52
66
}
67
+
68
+ protected function repository (): ExtensionRepository
69
+ {
70
+ return new ExtensionRepository ;
71
+ }
53
72
}
0 commit comments