Skip to content

Commit

Permalink
separate class for url rewrite logger
Browse files Browse the repository at this point in the history
  • Loading branch information
garfix committed Jul 14, 2018
1 parent ac6881d commit df79bbb
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
15 changes: 15 additions & 0 deletions Api/UrlRewriteUpdateLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace BigBridge\ProductImport\Api;


/**
* @author Patrick van Bergen
*/
interface UrlRewriteUpdateLogger
{
/**
* @param string $info
*/
public function info(string $info);
}
5 changes: 2 additions & 3 deletions Api/UrlRewriteUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
* @param array $storeViewCodes
* @throws \Exception
*/
public function updateUrlRewrites(array $storeViewCodes)
public function updateUrlRewrites(array $storeViewCodes, UrlRewriteUpdateLogger $logger)
{
$storeViewIds = $this->metaData->getStoreViewIds($storeViewCodes);
$productIds = $this->information->getProductIds();
Expand All @@ -50,9 +50,8 @@ public function updateUrlRewrites(array $storeViewCodes)
while ($chunkedIds = array_slice($productIds, $i, self::BUNCH_SIZE)) {
$this->urlRewriteStorage->updateRewritesByProductIds($chunkedIds, $storeViewIds);
$i += self::BUNCH_SIZE;
#todo: not here
echo "\r" . $i;

$logger->info($i);
}
}
}
1 change: 1 addition & 0 deletions Console/Command/ProductImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var XmlProductReader $xmlProductReader */
$xmlProductReader = $this->objectManager->create(XmlProductReader::class);
$fileName = $input->getArgument(self::ARGUMENT_FILENAME);

Expand Down
9 changes: 6 additions & 3 deletions Console/Command/ProductUrlRewriteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace BigBridge\ProductImport\Console\Command;

use BigBridge\ProductImport\Api\Information;
use BigBridge\ProductImport\Api\UrlRewriteUpdater;
use Exception;
use Magento\Framework\ObjectManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use BigBridge\ProductImport\Model\Updater\UrlRewriteUpdateCommandLogger;
use BigBridge\ProductImport\Api\Information;
use BigBridge\ProductImport\Api\UrlRewriteUpdater;

/**
* @author Patrick van Bergen
Expand Down Expand Up @@ -65,8 +66,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$storeViewCodes = $information->getNonGlobalStoreViewCodes();
}

$logger = new UrlRewriteUpdateCommandLogger($output);

try {
$urlRewriteUpdater->updateUrlRewrites($storeViewCodes);
$urlRewriteUpdater->updateUrlRewrites($storeViewCodes, $logger);
} catch (Exception $e) {
$output->writeln("<error>" . $e->getMessage() . "</error>");
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
Expand Down
30 changes: 30 additions & 0 deletions Model/Updater/UrlRewriteUpdateCommandLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace BigBridge\ProductImport\Model\Updater;

use BigBridge\ProductImport\Api\UrlRewriteUpdateLogger;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @author Patrick van Bergen
*/
class UrlRewriteUpdateCommandLogger implements UrlRewriteUpdateLogger
{
/**
* @var OutputInterface
*/
protected $output;

public function __construct(OutputInterface $output)
{
$this->output = $output;
}

/**
* @param string $info
*/
public function info(string $info)
{
$this->output->writeln("<info>" . $info . "<info>");
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ This library imports product data into Magento 2 via direct database queries. It
* An Web API service for product import via Post Request with XML
* A tool to update url_rewrites

## Disclaimer
## Warning!

The aim of this library is speed. If you find that Magento 2's product importer is too slow, consider using this library.

However, the library bypasses all of Magento's API's to insert data directly into the database. Possible problems with this approach are:
However, the library bypasses all of Magento's API's to insert data directly into the database. Possible problems you may encounter:

* The library is still new and brings with it its own set of bugs and problems!
* The library creator is not perfectly knowledgeable of all Magento's ins and outs (even though he tries hard to be). It is possible that the data is not entered in exactly the same way that Magento 2 does it.
* The library is still new and brings with it its own set of bugs and problems.
* Magento may change its data structure in the future. The library will have to be updated to follow.
* The library probably does not have all features you need and expect.

Experiment with the library in a safe webshop. Make sure to create a database backup before you start.

Expand Down

0 comments on commit df79bbb

Please sign in to comment.