-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Torsten Freyda
committed
Mar 5, 2024
1 parent
0e984b1
commit 096b456
Showing
9 changed files
with
497 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* MuckiSearchPlugin plugin | ||
* | ||
* | ||
* @category Muckiware | ||
* @package MuckiSearch | ||
* @copyright Copyright (c) 2023 by Muckiware | ||
* | ||
* @author Muckiware | ||
* | ||
*/ | ||
|
||
namespace MuckiSearchPlugin\Commands; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\Process\Process; | ||
use Shopware\Core\Framework\Context; | ||
|
||
use MuckiSearchPlugin\Services\Settings as PluginSettings; | ||
use MuckiSearchPlugin\Services\SearchTermLog; | ||
|
||
|
||
#[AsCommand('muckiware:search:log:transfer')] | ||
class SearchLogTransfer extends Command | ||
{ | ||
/** | ||
* @var null | ||
*/ | ||
protected $container = null; | ||
|
||
public function __construct( | ||
protected PluginSettings $settings, | ||
protected LoggerInterface $logger, | ||
protected SearchTermLog $searchTermLog | ||
) { | ||
|
||
parent::__construct(self::$defaultName); | ||
} | ||
|
||
public function setContainer(ContainerInterface $container): void | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @return ContainerInterface | ||
*/ | ||
public function getContainer(): ContainerInterface | ||
{ | ||
if (!$this->container) { | ||
throw new \LogicException('Cannot retrieve the container from a non-booted kernel.'); | ||
} | ||
return $this->container; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public function configure(): void | ||
{ | ||
$this->setDescription('Transfer search logs into database'); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
* @throws \Exception | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$serverInfoAsString = $this->searchTermLog->saveSearchLogsIntoDb(); | ||
if($serverInfoAsString) { | ||
|
||
$output->writeln($serverInfoAsString); | ||
return self::SUCCESS; | ||
} | ||
|
||
return self::FAILURE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MuckiSearchPlugin\Entities; | ||
|
||
class SessionSearchRequest | ||
{ | ||
/** | ||
* UUID for a search log | ||
* @var string | ||
*/ | ||
protected string $id; | ||
|
||
protected string $searchTerm; | ||
|
||
protected string $sessionId; | ||
|
||
protected string $languageId; | ||
|
||
protected string $salesChannelId; | ||
|
||
protected int $hits; | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(string $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getSearchTerm(): string | ||
{ | ||
return $this->searchTerm; | ||
} | ||
|
||
public function setSearchTerm(string $searchTerm): void | ||
{ | ||
$this->searchTerm = $searchTerm; | ||
} | ||
|
||
public function getSessionId(): string | ||
{ | ||
return $this->sessionId; | ||
} | ||
|
||
public function setSessionId(string $sessionId): void | ||
{ | ||
$this->sessionId = $sessionId; | ||
} | ||
|
||
public function getLanguageId(): string | ||
{ | ||
return $this->languageId; | ||
} | ||
|
||
public function setLanguageId(string $languageId): void | ||
{ | ||
$this->languageId = $languageId; | ||
} | ||
|
||
public function getSalesChannelId(): string | ||
{ | ||
return $this->salesChannelId; | ||
} | ||
|
||
public function setSalesChannelId(string $salesChannelId): void | ||
{ | ||
$this->salesChannelId = $salesChannelId; | ||
} | ||
|
||
public function getHits(): int | ||
{ | ||
return $this->hits; | ||
} | ||
|
||
public function setHits(int $hits): void | ||
{ | ||
$this->hits = $hits; | ||
} | ||
|
||
public function toSerialize(): string | ||
{ | ||
return serialize(get_object_vars($this)); | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return get_object_vars($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* MuckiSearchPlugin plugin | ||
* | ||
* | ||
* @category Muckiware | ||
* @package MuckiSearch | ||
* @copyright Copyright (c) 2023 by Muckiware | ||
* | ||
* @author Muckiware | ||
* | ||
*/ | ||
|
||
namespace MuckiSearchPlugin\Services; | ||
|
||
use League\Flysystem\FilesystemException; | ||
use League\Flysystem\FilesystemOperator; | ||
use League\Flysystem\FileAttributes; | ||
use Psr\Log\LoggerInterface; | ||
|
||
use MuckiSearchPlugin\Entities\SessionSearchRequest; | ||
|
||
class SearchTermLog | ||
{ | ||
public function __construct( | ||
protected LoggerInterface $logger, | ||
private readonly FilesystemOperator $fileSystemPrivate | ||
){} | ||
|
||
/** | ||
* @throws FilesystemException | ||
*/ | ||
public function saveSearchLogSessionToFile(string $sessionId, string $currentSearchRequests): void | ||
{ | ||
try { | ||
|
||
$this->fileSystemPrivate->delete($sessionId); | ||
$this->fileSystemPrivate->write($sessionId, $currentSearchRequests); | ||
} catch (FilesystemException $e) { | ||
|
||
$this->logger->error('Not possible to write search log file', array('mucki','search')); | ||
$this->logger->error($e->getMessage(), array('mucki','search')); | ||
} | ||
} | ||
|
||
/** | ||
* @throws FilesystemException | ||
*/ | ||
public function saveSearchLogsIntoDb(): bool | ||
{ | ||
$listContents = $this->fileSystemPrivate->listContents('', true)->toArray(); | ||
foreach ($listContents as $listContent) { | ||
|
||
/** @var SessionSearchRequest $searchLogs */ | ||
$searchLogs = $this->getSearchLogsFromFiles($listContent->path()); | ||
$this->writeSearchLogs($searchLogs); | ||
} | ||
return true; | ||
} | ||
|
||
public function writeSearchLogs(SessionSearchRequest $searchLogs): void | ||
{ | ||
$logData = array( | ||
'id' => $searchLogs->getId(), | ||
'salesChannelId' => $searchLogs->getSalesChannelId(), | ||
'searchTerm' => $searchLogs->getSearchTerm(), | ||
'hits' => $searchLogs->getHits() | ||
); | ||
// $this->searchRequestLogsRepository->create([$logData], $event->getContext()); | ||
// | ||
// $versionLogId = $this->searchRequestLogsRepository->createVersion($logId, $event->getContext()); | ||
// $versionContext = $event->getContext()->createWithVersionId($versionLogId); | ||
} | ||
|
||
/** | ||
* @throws FilesystemException | ||
*/ | ||
public function getSearchLogsFromFiles(string $location): array | ||
{ | ||
return unserialize($this->fileSystemPrivate->read($location)); | ||
} | ||
} |
Oops, something went wrong.