Skip to content

Commit 67a64d7

Browse files
committed
implement extraction logic
1 parent d4a8193 commit 67a64d7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

app/Jobs/UpdateSite.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\RemoteSite\Responses\PrepareUpdate;
1010
use Illuminate\Contracts\Queue\ShouldQueue;
1111
use Illuminate\Foundation\Queue\Queueable;
12+
use Illuminate\Support\Facades\App;
1213
use Illuminate\Support\Facades\Log;
1314

1415
class UpdateSite implements ShouldQueue
@@ -74,6 +75,45 @@ public function handle(): void
7475

7576
protected function performExtraction(PrepareUpdate $prepareResult): void
7677
{
78+
$connection = App::make(Connection::class, [
79+
$this->site->url,
80+
$prepareResult->password
81+
]);
82+
83+
// Ping server
84+
$pingResult = $connection->performExtractionRequest(["task" => "ping"]);
85+
86+
if (empty($pingResult["message"]) || $pingResult["message"] === 'Invalid login') {
87+
throw new \Exception(
88+
"Invalid ping response for site: " . $this->site->id
89+
);
90+
}
91+
92+
// Start extraction
93+
$stepResult = $connection->performExtractionRequest(["task" => "startExtract"]);
94+
95+
// Run actual core update
96+
while (array_key_exists("done", $stepResult) && $stepResult["done"] !== true) {
97+
if ($stepResult["status"] !== true) {
98+
throw new \Exception(
99+
"Invalid extract response for site: " . $this->site->id
100+
);
101+
}
102+
103+
// Make next backup step
104+
$stepResult = $connection->performExtractionRequest(
105+
[
106+
"task" => "stepExtract",
107+
"instance" => $stepResult["instance"]
108+
]
109+
);
110+
}
77111

112+
// Clean up restore
113+
$connection->performExtractionRequest(
114+
[
115+
"task" => "finalizeUpdate"
116+
]
117+
);
78118
}
79119
}

0 commit comments

Comments
 (0)