Skip to content

Commit 138a704

Browse files
authored
Add option to clear or keep the most recent downloaded release. Defaulted to true.
1 parent 62acad6 commit 138a704

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ To initialize the Updater class and start the update process, follow these steps
6161
string|null $admin,
6262
string|null $mailer,
6363
array|null $sourceExclusions = ['path' => [], 'filename' => []],
64-
array|null $releaseExclusions = ['path' => [], 'filename' => []]
64+
array|null $releaseExclusions = ['path' => [], 'filename' => []],
65+
bool $clear = true
6566
);
6667
```
6768

@@ -73,6 +74,7 @@ To initialize the Updater class and start the update process, follow these steps
7374
> `$mailer` (Optional) The email address that the email will be sent from.<br>
7475
> `$sourceExclusions` (Optional) An array of directories or files in the source to be exclude from the update.<br>
7576
> `$releaseExclusions` (Optional) An array of directories or files in the release to exclude from the update.<br>
77+
> `$clear` (Optional) Clear the downloaded file after the update has completed if set to true.
7678
7779
> The exclusions array keys:
7880

src/Updater.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class Updater
2424
private $exclude = [];
2525
private $log = [];
2626
private $status;
27+
private $clear;
2728

2829
/**
2930
* Constructs a new instance of the class and starts the update process for the provided version.
@@ -42,7 +43,7 @@ final class Updater
4243
* 'filename' => an array of release excluded filenames
4344
* @return void
4445
*/
45-
public function __construct(string $username, string $repository, string $token, string $version, string|null $admin = '', string|null $mailer = '', array|null $sourceExclusions = ['path' => [], 'filename' => []], array|null $releaseExclusions = ['path' => [], 'filename' => []])
46+
public function __construct(string $username, string $repository, string $token, string $version, string|null $admin = '', string|null $mailer = '', array|null $sourceExclusions = ['path' => [], 'filename' => []], array|null $releaseExclusions = ['path' => [], 'filename' => []], bool $clear = true)
4647
{
4748
$this->status = $this::STARTED;
4849

@@ -83,6 +84,7 @@ public function __construct(string $username, string $repository, string $token,
8384
$this->admin = $admin;
8485
$this->mailer = $mailer;
8586
$this->exclude = ['source' => $sourceExclusions, 'release' => $releaseExclusions];
87+
$this->clear = $clear;
8688

8789
$this->dir = getcwd();
8890

@@ -305,7 +307,7 @@ private function Download($url = null)
305307
return false;
306308
}
307309
} else {
308-
$download_file = $this->dir . "/update/update.zip";
310+
$download_file = $this->dir . "/update/" . $this->repository . ".zip";
309311
if (file_exists($download_file)) {
310312
$this->log[] = [date("Y-m-d H:i:s"), "Deleting existing zip file. $download_file"];
311313
if (!$this->Delete($download_file)) {
@@ -350,7 +352,7 @@ private function Download($url = null)
350352

351353
private function Extract()
352354
{
353-
$download_file = $this->dir . "/update/update.zip";
355+
$download_file = $this->dir . "/update/" . $this->repository . ".zip";
354356
$extract_path = $this->dir . "/update/extract";
355357
if (file_exists($extract_path)) {
356358
$this->log[] = [date("Y-m-d H:i:s"), "Deleting existing extract folder. $extract_path"];
@@ -483,10 +485,12 @@ private function CleanUp()
483485
$this->log[] = [date("Y-m-d H:i:s"), "Cleanup failed. " . $this->dir . "/update/extract"];
484486
return false;
485487
};
486-
if (file_exists($this->dir . "/update/update.zip") && !$this->Delete($this->dir . "/update/update.zip")) {
487-
$this->log[] = [date("Y-m-d H:i:s"), "Cleanup failed. " . $this->dir . "/update/update.zip"];
488-
return false;
489-
};
488+
if ($this->clear) {
489+
if (file_exists($this->dir . "/update/" . $this->repository . ".zip") && !$this->Delete($this->dir . "/update/" . $this->repository . ".zip")) {
490+
$this->log[] = [date("Y-m-d H:i:s"), "Cleanup failed. " . $this->dir . "/update/" . $this->repository . ".zip"];
491+
return false;
492+
};
493+
}
490494
$this->log[] = [date("Y-m-d H:i:s"), "Cleanup completed."];
491495
return true;
492496
}

0 commit comments

Comments
 (0)