Skip to content

Commit

Permalink
fix: cs
Browse files Browse the repository at this point in the history
  • Loading branch information
yajra committed May 28, 2024
1 parent aef4bac commit 1897563
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions src/SQLLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Yajra\SQLLoader;

use Exception;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Contracts\Process\ProcessResult;
use Illuminate\Support\Facades\File;
Expand Down Expand Up @@ -144,6 +143,15 @@ public function disk(string $disk): static
return $this;
}

protected function getFile(): string
{
if (! $this->controlFile) {
$this->controlFile = Str::uuid().'.ctl';
}

return $this->controlFile;
}

protected function buildControlFile(): string
{
$template = File::get($this->getStub());
Expand Down Expand Up @@ -188,6 +196,14 @@ protected function buildDiscardFile(): string
return '';
}

protected function buildMethod(): string
{
return in_array($this->method, [
Method::INSERT,
Method::TRUNCATE,
]) ? Method::TRUNCATE->value : $this->method->value;
}

protected function buildInserts(): string
{
$inserts = '';
Expand Down Expand Up @@ -223,6 +239,27 @@ public function getSqlLoaderBinary(): string
return config('sql-loader.sqlldr', 'sqlldr');
}

protected function deleteGeneratedFiles(): void
{
$filesystem = $this->getDisk();
$filesystem->delete($this->getFile());
if ($this->logPath) {
unlink($this->logPath);
}

if ($this->badFile) {
unlink($this->badFile);
}

if ($this->discardFile) {
unlink($this->discardFile);
}

if ($this->controlFile) {
$filesystem->delete($this->controlFile);
}
}

public function as(string $controlFile): static
{
$this->controlFile = $controlFile;
Expand Down Expand Up @@ -292,51 +329,13 @@ public function enclosure(string $enclosure): static
return $this;
}

protected function buildMethod(): string
{
return in_array($this->method, [
Method::INSERT,
Method::TRUNCATE,
]) ? Method::TRUNCATE->value : $this->method->value;
}

public function deleteFilesAfterRun(bool $delete = true): static
{
$this->deleteFiles = $delete;

return $this;
}

protected function getFile(): string
{
if (! $this->controlFile) {
$this->controlFile = Str::uuid().'.ctl';
}

return $this->controlFile;
}

protected function deleteGeneratedFiles(): void
{
$filesystem = $this->getDisk();
$filesystem->delete($this->getFile());
if ($this->logPath) {
unlink($this->logPath);
}

if ($this->badFile) {
unlink($this->badFile);
}

if ($this->discardFile) {
unlink($this->discardFile);
}

if ($this->controlFile) {
$filesystem->delete($this->controlFile);
}
}

public function logs(): string
{
return $this->logs;
Expand Down

0 comments on commit 1897563

Please sign in to comment.