Skip to content

Commit

Permalink
Merge branch 'boxalino-sdk-php'
Browse files Browse the repository at this point in the history
  • Loading branch information
ychadwick committed Mar 2, 2016
2 parents 506a487 + f22856c commit a8d3633
Show file tree
Hide file tree
Showing 7 changed files with 541 additions and 485 deletions.
17 changes: 8 additions & 9 deletions Command/ExportPropertiesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,8 @@ public function execute(InputInterface $input, OutputInterface $output)
if (!$result) {
return 1;
}
$publish = 'false';

if ($input->getOption('publish')) {
$publish = 'true';
}

$this->publishProperties($publish, $output);
$this->publishProperties($output, $input->getOption('publish'));

return 0;
}
Expand Down Expand Up @@ -99,13 +94,17 @@ protected function exportProperties(OutputInterface $output, $propertiesXml = nu
}

/**
* @param string $publish
* @param OutputInterface $output
* @param bool|false $publish
* @return bool
*/
protected function publishProperties($publish = 'false', OutputInterface $output)
protected function publishProperties(OutputInterface $output, $publish = false)
{
$response = $this->exporter->publishXml($publish);
if($publish){
$response = $this->exporter->publishXmlChanges();
}else{
$response = $this->exporter->checkXmlChanges();
}

if (array_key_exists('error_type_number', $response)) {
$output->writeln(sprintf('<error>Exporter exited with the following message: "%s"</error>', $response['message']));
Expand Down
4 changes: 2 additions & 2 deletions EventListener/ResponseEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function setHttpP13nHelper(HttpP13nHelper $httpP13nHelper)
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$cems = $this->httpP13nService->createCemsCookie($event->getRequest()->cookies->get('cems', null));
$cemv = $this->httpP13nService->createCemvCookie($event->getRequest()->cookies->get('cemv', null));
$cems = $this->httpP13nService->getCemsCookie($event->getRequest());
$cemv = $this->httpP13nService->getCemvCookie($event->getRequest());

$event->getResponse()->headers->setCookie($cems);
$event->getResponse()->headers->setCookie($cemv);
Expand Down
145 changes: 104 additions & 41 deletions Exporter/Exporter.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
namespace Ibrows\BoxalinoBundle\Exporter;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManager;
use Gedmo\Tool\Wrapper\AbstractWrapper;
use com\boxalino\bxclient\v1\BxData;
use Ibrows\BoxalinoBundle\Helper\HttpP13nHelper;
use Ibrows\BoxalinoBundle\Mapper\EntityMap;
use Ibrows\BoxalinoBundle\Mapper\EntityMapperInterface;
use Ibrows\BoxalinoBundle\Mapper\FieldMap;
Expand All @@ -25,27 +24,32 @@
*/
class Exporter
{

/**
*
*/
const URL_XML = 'http://di1.bx-cloud.com/frontend/dbmind/en/dbmind/api/data/source/update';
const URL_XML = '/frontend/dbmind/en/dbmind/api/data/source/update';
/**
*
*/
const URL_XML_DEV = 'http://di1.bx-cloud.com/frontend/dbmind/en/dbmind/api/data/source/update?dev=true';
const URL_XML_DEV = '/frontend/dbmind/en/dbmind/api/data/source/update?dev=true';
/**
*
*/
const URL_XML_PUBLISH = 'http://di1.bx-cloud.com/frontend/dbmind/en/dbmind/api/configuration/publish/owner';
const URL_XML_PUBLISH = '/frontend/dbmind/en/dbmind/api/configuration/publish/owner';
/**
*
*/
const URL_ZIP = 'http://di1.bx-cloud.com/frontend/dbmind/en/dbmind/api/data/push';
const URL_ZIP = '/frontend/dbmind/en/dbmind/api/data/push';
/**
*
*/
const URL_ZIP_DEV = 'http://di1.bx-cloud.com/frontend/dbmind/en/dbmind/api/data/push?dev=true';
const URL_ZIP_DEV = '/frontend/dbmind/en/dbmind/api/data/push?dev=true';

/**
*
*/
const URL_EXECUTE_TASK = '/frontend/dbmind/en/dbmind/files/task/execute';

/**
*
*/
Expand All @@ -72,9 +76,9 @@ class Exporter
const XML_FORMAT = 'CSV';

/**
* @var EntityManager
* @var string
*/
protected $om;
protected $host = 'http://di1.bx-cloud.com';

/**
* @var array
Expand Down Expand Up @@ -171,30 +175,33 @@ class Exporter
*/
protected $exportLogManager;

/**
* @var
*/
protected $bxData;


/**
* Exporter constructor.
* @param ObjectManager $om
* @param HttpP13nHelper $httpP13nHelper
* @param array $entities
* @param $exportDir
* @param $account
* @param $username
* @param $password
* @param null $propertiesXml
* @param bool|true $debugMode
*/
public function __construct(
ObjectManager $om, array $entities, $exportDir, $account, $username,
$password, $propertiesXml = null, $debugMode = true
HttpP13nHelper $httpP13nHelper, array $entities, $exportDir, $propertiesXml = null, $debugMode = false
) {
$this->om = $om;
$this->entities = $entities;
$this->exportDir = $exportDir;
$this->account = $account;
$this->username = $username;
$this->password = $password;
$this->propertiesXml = $propertiesXml;
$this->devIndex = $debugMode;

$this->account = $httpP13nHelper->getClient()->getAccount();
$this->password = $httpP13nHelper->getClient()->getPassword();
$this->username = $httpP13nHelper->getClient()->getUsername();
$this->bxData = new BxData($httpP13nHelper->getClient());

$this->accessor = $accessor = PropertyAccess::createPropertyAccessor();
$this->createExportDirectory($exportDir);
}
Expand Down Expand Up @@ -248,26 +255,16 @@ public function prepareDeltaExport()
$this->prepareExport();
}

/**
*
*/
public function prepareExport()
{
$this->csvFiles = array();
$this->createCSVFiles($this->entities);
$this->createZipFile();
}

/**
* @Todo: check if we will keep this as it is not standard
* @param $name
*/
// public function preparePartialExport($name)
// {
// $this->csvFiles = array();
// $this->exportType = 'partial_';
// if (array_key_exists($name, $this->entities)) {
// $this->createCSVFiles(array($this->entities[$name]));
// $this->createZipFile();
// }
// }

/**
* @param array $entities
Expand Down Expand Up @@ -430,7 +427,7 @@ public function createCsv(EntityMap $entityMap, $results)
*/
protected function getTranslatableValue(TranslatableFieldMap $field, $entity)
{
$wrapped = AbstractWrapper::wrap($entity, $field->getAdapter()->getObjectManager());
$wrapped = Gedmo\Tool\Wrapper\AbstractWrapper::wrap($entity, $field->getAdapter()->getObjectManager());
$data = $field->getAdapter()->findTranslation($wrapped, $field->getLocale(), $field->getPropertyPath(), $field->getTranslatableClass(), $field->getClass());

return $data->getContent();
Expand Down Expand Up @@ -471,13 +468,13 @@ public function createJoinTableCsv($results)
foreach ($entityMap->getFields() as $field) {
if ($field->hasJoinFields()) {
foreach ($field->getJoinFields() as $joinField) {
$row[] = $this->getColumnData($entity, $joinField->getAccessor());
$row[] = $this->getColumnData($entity, $joinField->getPropertyPath());
}
}

if ($field->hasInverseJoinFields()) {
foreach ($field->getInverseJoinFields() as $joinField) {
$row[] = $this->getColumnData($joinEntity, $joinField->getAccessor());
$row[] = $this->getColumnData($joinEntity, $joinField->getPropertyPath());
}
}
}
Expand Down Expand Up @@ -617,7 +614,10 @@ public function pushZip()
'delta' => $this->delta ? 'true' : 'false',
'data' => $this->getCurlFile($this->getZipFile(), 'application/zip'),
);
$response = $this->pushFile($this->devIndex ? self::URL_ZIP_DEV : self::URL_ZIP, $fields);


$url = $this->host . ($this->devIndex ? self::URL_ZIP_DEV : self::URL_ZIP);
$response = $this->pushFile($url, $fields);

return json_decode($response, true);
}
Expand Down Expand Up @@ -694,21 +694,41 @@ public function pushXml()
'xml' => file_get_contents($this->propertiesXml)
);

$response = $this->pushFile(self::URL_XML, $fields);
$url = $this->host . self::URL_XML;
$response = $this->pushFile($url, $fields);

return json_decode($response, true);
}

/**
* @return mixed
*/
public function checkXmlChanges() {
return $this->publishXml(false);
}

/**
* @return mixed
*/
public function publishXmlChanges() {
return $this->publishXml(true);
}

/**
* @param string $publish
* @return mixed
*/
public function publishXml($publish = '')
{
$fields = array(
'username' => $this->username,
'password' => $this->password,
'account' => $this->account,
'owner' => $this->owner,
'publish' => $publish
'publish' => ($publish ? 'true' : 'false')
);
$response = $this->pushFile(self::URL_XML_PUBLISH, $fields);
$url = $this->host . self::URL_XML_PUBLISH;
$response = $this->pushFile($url, $fields);

return json_decode($response, true);
}
Expand Down Expand Up @@ -779,4 +799,47 @@ protected function createExportDirectory($exportDir){

return $exportDir;
}


/**
* @param $taskName
* @return string
*/
public function getTaskExecuteUrl($taskName) {
return $this->host . self::URL_EXECUTE_TASK . '?iframeAccount=' . $this->account . '&task_process=' . $taskName;
}

/**
* @param bool|false $isTest
* @param string $taskName
*/
public function publishChoices($isTest = false, $taskName="generate_optimization") {

if($this->devIndex) {
$taskName .= '_dev';
}
if($isTest) {
$taskName .= '_test';
}

$url = $this->getTaskExecuteUrl($taskName);
file_get_contents($url);
}

/**
* @param string $taskName
*/
public function prepareCorpusIndex($taskName="corpus") {
$url = $this->getTaskExecuteUrl($taskName);
file_get_contents($url);
}

/**
* @param $fields
* @param string $taskName
*/
public function prepareAutocompleteIndex($fields, $taskName="autocomplete") {
$url = $this->getTaskExecuteUrl($taskName);
file_get_contents($url);
}
}
Loading

0 comments on commit a8d3633

Please sign in to comment.