Skip to content

Commit

Permalink
Исправление ошибки установки (#59)
Browse files Browse the repository at this point in the history
Co-authored-by: Storozhuk Valentine <vstorozhuk@evilcoders.me>
  • Loading branch information
stolentine and Storozhuk Valentine authored Dec 7, 2022
1 parent c2a25a4 commit 358873f
Show file tree
Hide file tree
Showing 31 changed files with 118 additions and 87 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.github export-ignore
/docker export-ignore
/generator export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/Makefile export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml export-ignore
4 changes: 2 additions & 2 deletions src/Downloader/CurlDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function download(string $url, \SplFileInfo $localFile): void
$response = new CurlDownloaderResponse();
for ($i = 0; $i < $this->maxAttempts; ++$i) {
$response = $this->runRequest($url, $options);
if ($response->isOk() && $response->getError() === null) {
if ($response->isOk() && !$response->hasError()) {
break;
}
// в случае ошибки пробуем скачать файл еще раз,
Expand All @@ -69,7 +69,7 @@ public function download(string $url, \SplFileInfo $localFile): void

fclose($options[\CURLOPT_FILE]);

if ($response->getError() !== null) {
if ($response->hasError()) {
$message = sprintf(
"There was an error while downloading '%s': %s.",
$url,
Expand Down
7 changes: 6 additions & 1 deletion src/Downloader/CurlDownloaderResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(?array $rawCurlResponse = null)
$this->statusCode = isset($rawCurlResponse[0]) ? (int) $rawCurlResponse[0] : 0;
$this->isOk = $this->statusCode >= 200 && $this->statusCode < 300;
$this->headers = isset($rawCurlResponse[1]) ? $this->extractHeadersFromContent($rawCurlResponse[1]) : [];
$this->error = isset($rawCurlResponse[2]) ? (string) $rawCurlResponse[2] : null;
$this->error = isset($rawCurlResponse[2]) && !empty($rawCurlResponse[2]) ? (string) $rawCurlResponse[2] : null;
}

public function getStatusCode(): int
Expand All @@ -43,6 +43,11 @@ public function getError(): ?string
return $this->error;
}

public function hasError(): bool
{
return $this->error !== null;
}

/**
* @return array<string, string>
*/
Expand Down
14 changes: 14 additions & 0 deletions src/Pipeline/State/StateParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Liquetsoft\Fias\Component\Pipeline\State;

class StateParameter
{
public const FILES_TO_PROCEED = 'files_to_proceed';
public const FIAS_VERSION = 'fias_version';
public const EXTRACT_TO_FOLDER = 'extract_to';
public const FIAS_INFO = 'fias_info';
public const DOWNLOAD_TO_FILE = 'download_to';
}
5 changes: 3 additions & 2 deletions src/Pipeline/Task/CleanupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Liquetsoft\Fias\Component\Pipeline\Task;

use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Marvin255\FileSystemHelper\FileSystemFactory;
use Marvin255\FileSystemHelper\FileSystemHelperInterface;
use Psr\Log\LogLevel;
Expand All @@ -29,8 +30,8 @@ public function __construct()
public function run(State $state): void
{
$toRemove = [
$state->getParameter(Task::DOWNLOAD_TO_FILE_PARAM),
$state->getParameter(Task::EXTRACT_TO_FOLDER_PARAM),
$state->getParameter(StateParameter::DOWNLOAD_TO_FILE),
$state->getParameter(StateParameter::EXTRACT_TO_FOLDER),
];

$toRemove = array_diff($toRemove, [null]);
Expand Down
3 changes: 2 additions & 1 deletion src/Pipeline/Task/DataAbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Liquetsoft\Fias\Component\Exception\TaskException;
use Liquetsoft\Fias\Component\Exception\XmlException;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Liquetsoft\Fias\Component\Storage\Storage;
use Liquetsoft\Fias\Component\XmlReader\XmlReader;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -65,7 +66,7 @@ abstract protected function processItem(object $item): void;
*/
public function run(State $state): void
{
$allFiles = $state->getParameter(Task::FILES_TO_PROCEED);
$allFiles = $state->getParameter(StateParameter::FILES_TO_PROCEED);
$allFiles = \is_array($allFiles) ? $allFiles : [];

foreach ($allFiles as $file) {
Expand Down
9 changes: 5 additions & 4 deletions src/Pipeline/Task/DownloadTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Liquetsoft\Fias\Component\Exception\TaskException;
use Liquetsoft\Fias\Component\FiasInformer\InformerResponse;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Psr\Log\LogLevel;

/**
Expand All @@ -33,17 +34,17 @@ public function __construct(Downloader $downloader)
*/
public function run(State $state): void
{
$info = $state->getParameter(Task::FIAS_INFO_PARAM);
$info = $state->getParameter(StateParameter::FIAS_INFO);
if (!($info instanceof InformerResponse)) {
throw new TaskException(
"State parameter '" . Task::FIAS_INFO_PARAM . "' must be an '" . InformerResponse::class . "' instance for '" . self::class . "'."
"State parameter '" . StateParameter::FIAS_INFO . "' must be an '" . InformerResponse::class . "' instance for '" . self::class . "'."
);
}

$localFile = $state->getParameter(Task::DOWNLOAD_TO_FILE_PARAM);
$localFile = $state->getParameter(StateParameter::DOWNLOAD_TO_FILE);
if (!($localFile instanceof \SplFileInfo)) {
throw new TaskException(
"State parameter '" . Task::DOWNLOAD_TO_FILE_PARAM . "' must be an '" . \SplFileInfo::class . "' instance for '" . self::class . "'."
"State parameter '" . StateParameter::DOWNLOAD_TO_FILE . "' must be an '" . \SplFileInfo::class . "' instance for '" . self::class . "'."
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Pipeline/Task/InformDeltaTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Liquetsoft\Fias\Component\Exception\TaskException;
use Liquetsoft\Fias\Component\FiasInformer\FiasInformer;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Psr\Log\LogLevel;

/**
Expand All @@ -32,10 +33,10 @@ public function __construct(FiasInformer $informer)
*/
public function run(State $state): void
{
$version = (int) $state->getParameter(Task::FIAS_VERSION_PARAM);
$version = (int) $state->getParameter(StateParameter::FIAS_VERSION);
if (!$version) {
throw new TaskException(
"State parameter '" . Task::FIAS_VERSION_PARAM . "' is required for '" . self::class . "'."
"State parameter '" . StateParameter::FIAS_VERSION . "' is required for '" . self::class . "'."
);
}

Expand All @@ -61,6 +62,6 @@ public function run(State $state): void
);
}

$state->setAndLockParameter(Task::FIAS_INFO_PARAM, $info);
$state->setAndLockParameter(StateParameter::FIAS_INFO, $info);
}
}
3 changes: 2 additions & 1 deletion src/Pipeline/Task/InformFullTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Liquetsoft\Fias\Component\Exception\TaskException;
use Liquetsoft\Fias\Component\FiasInformer\FiasInformer;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Psr\Log\LogLevel;

/**
Expand Down Expand Up @@ -48,6 +49,6 @@ public function run(State $state): void
]
);

$state->setAndLockParameter(Task::FIAS_INFO_PARAM, $info);
$state->setAndLockParameter(StateParameter::FIAS_INFO, $info);
}
}
5 changes: 3 additions & 2 deletions src/Pipeline/Task/PrepareFolderTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Liquetsoft\Fias\Component\Pipeline\Task;

use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Marvin255\FileSystemHelper\FileSystemFactory;
use Marvin255\FileSystemHelper\FileSystemHelperInterface;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function run(State $state): void
$this->log(LogLevel::INFO, "Creating '{$this->folder->getRealPath()}/extracted' folder.");
$this->fs->mkdir($extractToFolder);

$state->setAndLockParameter(Task::DOWNLOAD_TO_FILE_PARAM, $downloadToFile);
$state->setAndLockParameter(Task::EXTRACT_TO_FOLDER_PARAM, $extractToFolder);
$state->setAndLockParameter(StateParameter::DOWNLOAD_TO_FILE, $downloadToFile);
$state->setAndLockParameter(StateParameter::EXTRACT_TO_FOLDER, $extractToFolder);
}
}
3 changes: 2 additions & 1 deletion src/Pipeline/Task/ProcessSwitchTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Liquetsoft\Fias\Component\FilesDispatcher\FilesDispatcher;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Psr\Log\LogLevel;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function __construct(
*/
public function run(State $state): void
{
$rawFiles = $state->getParameter(Task::FILES_TO_PROCEED);
$rawFiles = $state->getParameter(StateParameter::FILES_TO_PROCEED);
$files = [];
if (\is_array($rawFiles)) {
$files = array_map(
Expand Down
5 changes: 3 additions & 2 deletions src/Pipeline/Task/SaveFiasFilesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Liquetsoft\Fias\Component\Pipeline\Task;

use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Marvin255\FileSystemHelper\FileSystemFactory;
use Marvin255\FileSystemHelper\FileSystemHelperInterface;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -33,11 +34,11 @@ public function __construct(?string $moveArchiveTo, ?string $moveExtractedTo)
$this->movePaths = [];

if ($moveArchiveTo !== null) {
$this->movePaths[Task::DOWNLOAD_TO_FILE_PARAM] = $moveArchiveTo;
$this->movePaths[StateParameter::DOWNLOAD_TO_FILE] = $moveArchiveTo;
}

if ($moveExtractedTo !== null) {
$this->movePaths[Task::EXTRACT_TO_FOLDER_PARAM] = $moveExtractedTo;
$this->movePaths[StateParameter::EXTRACT_TO_FOLDER] = $moveExtractedTo;
}

$this->fs = FileSystemFactory::create();
Expand Down
7 changes: 4 additions & 3 deletions src/Pipeline/Task/SelectFilesToProceedTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Liquetsoft\Fias\Component\Exception\TaskException;
use Liquetsoft\Fias\Component\Filter\Filter;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Psr\Log\LogLevel;

class SelectFilesToProceedTask implements LoggableTask, Task
Expand All @@ -32,7 +33,7 @@ public function __construct(EntityManager $entityManager, ?Filter $filter = null
*/
public function run(State $state): void
{
$folderParameter = $state->getParameter(Task::EXTRACT_TO_FOLDER_PARAM);
$folderParameter = $state->getParameter(StateParameter::EXTRACT_TO_FOLDER);
$extractToFolder = $this->checkDirectory($folderParameter);

$this->log(
Expand All @@ -41,7 +42,7 @@ public function run(State $state): void
);

$files = $this->getFilesForProceedFromFolder($extractToFolder);
$state->setAndLockParameter(Task::FILES_TO_PROCEED, $files);
$state->setAndLockParameter(StateParameter::FILES_TO_PROCEED, $files);

$this->log(
LogLevel::INFO,
Expand All @@ -65,7 +66,7 @@ private function checkDirectory($parameterValue): \SplFileInfo
{
if (!($parameterValue instanceof \SplFileInfo)) {
throw new TaskException(
"State parameter '" . Task::EXTRACT_TO_FOLDER_PARAM . "' must be an '" . \SplFileInfo::class . "' instance for '" . self::class . "'."
"State parameter '" . StateParameter::EXTRACT_TO_FOLDER . "' must be an '" . \SplFileInfo::class . "' instance for '" . self::class . "'."
);
}

Expand Down
10 changes: 0 additions & 10 deletions src/Pipeline/Task/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
*/
interface Task
{
public const FIAS_VERSION_PARAM = 'fias_version';

public const FIAS_INFO_PARAM = 'fias_info';

public const DOWNLOAD_TO_FILE_PARAM = 'download_to';

public const EXTRACT_TO_FOLDER_PARAM = 'extract_to';

public const FILES_TO_PROCEED = 'files_to_proceed';

/**
* Запускает задачу на исполнение.
*
Expand Down
9 changes: 5 additions & 4 deletions src/Pipeline/Task/UnpackTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Liquetsoft\Fias\Component\Exception\TaskException;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Liquetsoft\Fias\Component\Unpacker\Unpacker;
use Psr\Log\LogLevel;

Expand All @@ -31,17 +32,17 @@ public function __construct(Unpacker $unpacker)
*/
public function run(State $state): void
{
$source = $state->getParameter(Task::DOWNLOAD_TO_FILE_PARAM);
$source = $state->getParameter(StateParameter::DOWNLOAD_TO_FILE);
if (!($source instanceof \SplFileInfo)) {
throw new TaskException(
"State parameter '" . Task::DOWNLOAD_TO_FILE_PARAM . "' must be an '" . \SplFileInfo::class . "' instance for '" . self::class . "'."
"State parameter '" . StateParameter::DOWNLOAD_TO_FILE . "' must be an '" . \SplFileInfo::class . "' instance for '" . self::class . "'."
);
}

$destination = $state->getParameter(Task::EXTRACT_TO_FOLDER_PARAM);
$destination = $state->getParameter(StateParameter::EXTRACT_TO_FOLDER);
if (!($destination instanceof \SplFileInfo)) {
throw new TaskException(
"State parameter '" . Task::EXTRACT_TO_FOLDER_PARAM . "' must be an '" . \SplFileInfo::class . "' instance for '" . self::class . "'."
"State parameter '" . StateParameter::EXTRACT_TO_FOLDER . "' must be an '" . \SplFileInfo::class . "' instance for '" . self::class . "'."
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Pipeline/Task/VersionGetTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Liquetsoft\Fias\Component\Exception\TaskException;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Liquetsoft\Fias\Component\VersionManager\VersionManager;

/**
Expand Down Expand Up @@ -34,6 +35,6 @@ public function run(State $state): void
throw new TaskException('There is no version of FIAS installed.');
}

$state->setAndLockParameter(Task::FIAS_VERSION_PARAM, $version->getVersion());
$state->setAndLockParameter(StateParameter::FIAS_VERSION, $version->getVersion());
}
}
3 changes: 2 additions & 1 deletion src/Pipeline/Task/VersionSetTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Liquetsoft\Fias\Component\FiasInformer\InformerResponse;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Liquetsoft\Fias\Component\VersionManager\VersionManager;

/**
Expand All @@ -28,7 +29,7 @@ public function __construct(VersionManager $versionManager)
*/
public function run(State $state): void
{
$version = $state->getParameter(Task::FIAS_INFO_PARAM);
$version = $state->getParameter(StateParameter::FIAS_INFO);

if ($version instanceof InformerResponse && $version->hasResult()) {
$this->versionManager->setCurrentVersion($version);
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Downloader/CurlDownloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function testDownload(): void
function (array $options) use ($source) {
if (
!empty($options[\CURLOPT_HEADER])
|| $options[\CURLOPT_URL] === $source
&& \is_resource($options[\CURLOPT_FILE])
&& !empty($options[\CURLOPT_CONNECT_ONLY])
|| ($options[\CURLOPT_URL] === $source
&& \is_resource($options[\CURLOPT_FILE])
&& !empty($options[\CURLOPT_CONNECT_ONLY]))
) {
return [200, '', null];
}
Expand Down
8 changes: 4 additions & 4 deletions tests/src/Pipeline/Task/CleanupTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Liquetsoft\Fias\Component\Tests\Pipeline\Task;

use Liquetsoft\Fias\Component\Pipeline\State\StateParameter;
use Liquetsoft\Fias\Component\Pipeline\Task\CleanupTask;
use Liquetsoft\Fias\Component\Pipeline\Task\Task;
use Liquetsoft\Fias\Component\Tests\BaseCase;

/**
Expand All @@ -32,8 +32,8 @@ public function testRun(): void

$state = $this->createDefaultStateMock(
[
Task::DOWNLOAD_TO_FILE_PARAM => $downloadTo,
Task::EXTRACT_TO_FOLDER_PARAM => $extractTo,
StateParameter::DOWNLOAD_TO_FILE => $downloadTo,
StateParameter::EXTRACT_TO_FOLDER => $extractTo,
]
);

Expand All @@ -56,7 +56,7 @@ public function testRunEmptyFiles(): void

$state = $this->createDefaultStateMock(
[
Task::DOWNLOAD_TO_FILE_PARAM => $downloadTo,
StateParameter::DOWNLOAD_TO_FILE => $downloadTo,
]
);

Expand Down
Loading

0 comments on commit 358873f

Please sign in to comment.