130 lines
4.3 KiB
PHP
130 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace External\VarioBundle\Controller;
|
|
|
|
use External\VarioBundle\SoapClient;
|
|
use External\VarioBundle\Synchronizers\OrderSynchronizer;
|
|
use External\VarioBundle\Util\SynchronizerLocator;
|
|
use KupShop\KupShopBundle\Context\ContextManager;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
class VarioController extends AbstractController
|
|
{
|
|
/**
|
|
* @Route("/_vario/{type}/")
|
|
*/
|
|
public function doSync(Request $request, SynchronizerLocator $locator, $type = null): StreamedResponse
|
|
{
|
|
return new StreamedResponse(function () use ($type, $locator) {
|
|
ini_set('max_execution_time', (60 * 60) * 20);
|
|
ini_set('memory_limit', '2048M');
|
|
|
|
while (ob_get_level()) {
|
|
ob_end_flush();
|
|
}
|
|
|
|
$synchronizer = $locator->getServiceByType($type);
|
|
if (getVal('no_debug')) {
|
|
$synchronizer->setDebug(false);
|
|
}
|
|
$synchronizer->sync();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @Route("/_vario/dump_order/{id_order}/")
|
|
*/
|
|
public function dumpOrder(OrderSynchronizer $synchronizer, ContextManager $contextManager, int $id_order): JsonResponse
|
|
{
|
|
$order = new \Order();
|
|
$order->createFromDB($id_order);
|
|
|
|
$data = $contextManager->activateOrder($order, function () use ($order, $synchronizer) {
|
|
$order->fetchItems();
|
|
|
|
return $synchronizer->createDocumentObject($order);
|
|
});
|
|
|
|
return new JsonResponse($data);
|
|
}
|
|
|
|
/**
|
|
* @Route("/_vario/dump_product/{code}/")
|
|
* @Route("/_vario_dump_product/")
|
|
*/
|
|
public function dumpProductByCode(SoapClient $soapClient, Request $request, ?string $code = null): JsonResponse
|
|
{
|
|
$code = $code ?: $request->query->get('code');
|
|
if (!($product = $soapClient->getProductByCode($code))) {
|
|
throw new NotFoundHttpException('Product not found');
|
|
}
|
|
|
|
return new JsonResponse($product);
|
|
}
|
|
|
|
/**
|
|
* @Route("/_vario/dump_customer/{email}/")
|
|
*/
|
|
public function dumpCustomerByCode(SoapClient $soapClient, string $email): JsonResponse
|
|
{
|
|
if (!($product = $soapClient->getCustomerByEmail($email))) {
|
|
throw new NotFoundHttpException('Customer not found');
|
|
}
|
|
|
|
return new JsonResponse($product);
|
|
}
|
|
|
|
/**
|
|
* @Route("/_vario_queue-status/")
|
|
*/
|
|
public function varioSynchroProcessCount(SoapClient $soapClient, Request $request): JsonResponse
|
|
{
|
|
ini_set('max_execution_time', '3600');
|
|
|
|
$dataSimple = [];
|
|
$data = [];
|
|
if ($result = $soapClient->getClient()->GetSQLData('', 'select tablename, count (id) pocet, min(Created) nejstarsiDatum from variosynchro group by tablename')) {
|
|
$xml = simplexml_load_string($result);
|
|
foreach ($xml->row as $item) {
|
|
$dataSimple[$item->tablename->__toString()] = (int) $item->pocet->__toString();
|
|
$data[$item->tablename->__toString()] = [
|
|
'count' => (int) $item->pocet->__toString(),
|
|
'oldestDate' => $item->nejstarsiDatum->__toString(),
|
|
];
|
|
}
|
|
}
|
|
|
|
if ($request->get('delayed_update')) {
|
|
$data['delayed_eshop_count'] = sqlQueryBuilder()
|
|
->select('count(id_vario)')
|
|
->from('vario_delayed_update')->execute()->fetchOne();
|
|
}
|
|
|
|
if ($request->get('delayed_debug')) {
|
|
$data['delayed_eshop'] = sqlQueryBuilder()
|
|
->select('id_vario')
|
|
->from('vario_delayed_update')->execute()->fetchFirstColumn();
|
|
}
|
|
|
|
if ($request->get('detail')) {
|
|
return new JsonResponse($data);
|
|
}
|
|
|
|
return new JsonResponse((string) array_sum($dataSimple));
|
|
}
|
|
|
|
#[Route('/_vario/fix/orders-mapping/')]
|
|
public function importMissingOrdersMappingAction(OrderSynchronizer $orderSynchronizer): Response
|
|
{
|
|
$count = $orderSynchronizer->importMissingOrdersMapping();
|
|
|
|
return new Response('Fixed: '.$count);
|
|
}
|
|
}
|