Skip to content

Commit ac7d705

Browse files
author
Holger Lösken
committed
Better readme example, make update function fit to contract
1 parent e4d9f24 commit ac7d705

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,16 @@ Route::get('/', function (\Codedge\Updater\UpdaterManager $updater) {
121121
if($updater->source()->isNewVersionAvailable()) {
122122

123123
// Get the current installed version
124-
$updater->source()->getVersionInstalled();
124+
echo $updater->source()->getVersionInstalled();
125125

126126
// Get the new version available
127-
$updater->source()->getVersionAvailable();
127+
$versionAvailable = $updater->source()->getVersionAvailable();
128+
129+
// Create a release
130+
$release = $updater->source()->fetch($versionAvailable);
128131

129132
// Run the update process
130-
$updater->source()->update();
133+
$updater->source()->update($release);
131134

132135
} else {
133136
echo "No new version available.";

src/SourceRepository.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
66
use Codedge\Updater\Models\Release;
7+
use Codedge\Updater\Models\UpdateExecutor;
78
use Codedge\Updater\Traits\SupportPrivateAccessToken;
89
use Codedge\Updater\Traits\UseVersionFile;
910
use Illuminate\Support\Facades\Artisan;
@@ -23,14 +24,20 @@ final class SourceRepository implements SourceRepositoryTypeContract
2324
*/
2425
protected $sourceRepository;
2526

27+
/**
28+
* @var UpdateExecutor
29+
*/
30+
protected $updateExecutor;
31+
2632
/**
2733
* SourceRepository constructor.
2834
*
2935
* @param SourceRepositoryTypeContract $sourceRepository
3036
*/
31-
public function __construct(SourceRepositoryTypeContract $sourceRepository)
37+
public function __construct(SourceRepositoryTypeContract $sourceRepository, UpdateExecutor $updateExecutor)
3238
{
3339
$this->sourceRepository = $sourceRepository;
40+
$this->updateExecutor = $updateExecutor;
3441
}
3542

3643
/**
@@ -48,21 +55,14 @@ public function fetch($version = ''): Release
4855
}
4956

5057
/**
51-
* Perform the actual update process.
58+
* @param Release $release
5259
*
53-
* @param string $version Define the version you want to update to
5460
* @return bool
61+
* @throws \Exception
5562
*/
56-
public function update($version = ''): bool
63+
public function update(Release $release): bool
5764
{
58-
$version = $version ?: $this->getVersionAvailable();
59-
$release = $this->fetch($version);
60-
61-
$this->preUpdateArtisanCommands();
62-
$updateStatus = $this->sourceRepository->update($release);
63-
$this->postUpdateArtisanCommands();
64-
65-
return $updateStatus;
65+
return $this->updateExecutor->run($release);
6666
}
6767

6868
/**

src/SourceRepositoryTypes/GithubRepositoryType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function update(Release $release): bool
7979

8080
protected function useBranchForVersions(): bool
8181
{
82-
return $this->config['use_branch'] !== '';
82+
return !empty($this->config['use_branch']);
8383
}
8484

8585
/**

src/UpdaterManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
88
use Codedge\Updater\Contracts\UpdaterContract;
9+
use Codedge\Updater\Models\UpdateExecutor;
910
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryType;
1011
use Codedge\Updater\SourceRepositoryTypes\HttpRepositoryType;
1112
use Exception;
@@ -78,7 +79,7 @@ public function getDefaultSourceRepository()
7879
*/
7980
public function sourceRepository(SourceRepositoryTypeContract $sourceRepository): SourceRepositoryTypeContract
8081
{
81-
return new SourceRepository($sourceRepository);
82+
return new SourceRepository($sourceRepository, $this->app->make(UpdateExecutor::class));
8283
}
8384

8485
/**

0 commit comments

Comments
 (0)