Commit 684a705f by Frédéric

Test

parent 136bce95
...@@ -102,6 +102,7 @@ class FluxController extends BackendBase ...@@ -102,6 +102,7 @@ class FluxController extends BackendBase
{ {
$flux->setUpdatedAt(new \DateTime()); $flux->setUpdatedAt(new \DateTime());
$this->getRepository(Flux::class)->update($flux); $this->getRepository(Flux::class)->update($flux);
return $this->redirectToRoute('tourinsoft_admin_flux_index'); return $this->redirectToRoute('tourinsoft_admin_flux_index');
} }
......
...@@ -44,6 +44,7 @@ class Synchronisation ...@@ -44,6 +44,7 @@ class Synchronisation
* @throws \Exception * @throws \Exception
*/ */
public function sync() { public function sync() {
$this->application['schema']->update();
$options = $this->config['tourinsoft']; $options = $this->config['tourinsoft'];
$options['key'] = $this->flux->getKey(); $options['key'] = $this->flux->getKey();
...@@ -53,15 +54,17 @@ class Synchronisation ...@@ -53,15 +54,17 @@ class Synchronisation
$arrayStream = $parser->getArrayStream(); $arrayStream = $parser->getArrayStream();
// Write in contenttypes.yml file // Write in contenttypes.yml file
$file = new ContentTypeFile($this->application, $this->flux->getContentType(), $keys, $options); $file = new ContentTypeFile($this->application, $this->flux, $keys, $options);
$file->updateInFile(); $file->updateInFile();
sleep(20);
// Sync database // Sync database
$schema = new Schema($this->application); $schema = new Schema($this->application);
$schema->update(); $schema->update();
// Add data // Add data
$data = new Data($this->application, $this->flux->getContentType(), $arrayStream); $data = new Data($this->application, $this->flux->getCode(), $arrayStream);
$data->insert(); $data->insert();
} }
...@@ -70,7 +73,7 @@ class Synchronisation ...@@ -70,7 +73,7 @@ class Synchronisation
*/ */
public function delete() { public function delete() {
// Write in contenttypes.yml file // Write in contenttypes.yml file
$file = new ContentTypeFile($this->application, $this->flux->getContentType(), []); $file = new ContentTypeFile($this->application, $this->flux, []);
$file->deleteInFile(); $file->deleteInFile();
// Sync database // Sync database
......
...@@ -3,16 +3,13 @@ ...@@ -3,16 +3,13 @@
namespace Bolt\Extension\Appolo\Tourinsoft\Utils; namespace Bolt\Extension\Appolo\Tourinsoft\Utils;
use Bolt\Application; use Bolt\Application;
use Bolt\Extension\Appolo\Tourinsoft\Storage\Entity\Flux;
use Bolt\Filesystem\Handler\YamlFile; use Bolt\Filesystem\Handler\YamlFile;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
class ContentTypeFile class ContentTypeFile
{ {
/** /**
* @var string
*/
private $contentType;
/**
* @var array * @var array
*/ */
private $keys; private $keys;
...@@ -24,24 +21,28 @@ class ContentTypeFile ...@@ -24,24 +21,28 @@ class ContentTypeFile
* @var array * @var array
*/ */
private $options; private $options;
/**
* @var Flux
*/
private $flux;
/** /**
* ContentTypeFile constructor. * ContentTypeFile constructor.
* @param Application $application * @param Application $application
* @param string $contentType * @param Flux $flux
* @param array $keys * @param array $keys
* @param array $options * @param array $options
* @throws \Exception * @throws \Exception
*/ */
public function __construct(Application $application, $contentType = '', array $keys = [], array $options = []) public function __construct(Application $application, Flux $flux, array $keys = [], array $options = [])
{ {
if(empty($contentType)) { if(empty($flux->getCode()) || empty($flux->getContentType())) {
throw new \Exception('Le content type est requis.'); throw new \Exception('Le flux est invalide.');
} }
$this->contentType = $contentType;
$this->keys = $keys; $this->keys = $keys;
$this->application = $application; $this->application = $application;
$this->options = $options; $this->options = $options;
$this->flux = $flux;
} }
/** /**
...@@ -49,9 +50,9 @@ class ContentTypeFile ...@@ -49,9 +50,9 @@ class ContentTypeFile
*/ */
public function updateInFile() { public function updateInFile() {
$data = [ $data = [
$this->contentType => [ $this->flux->getCode() => [
'name' => ucfirst($this->contentType), 'name' => ucfirst($this->flux->getContentType()),
'singular_name' => ucfirst($this->contentType), 'singular_name' => ucfirst($this->flux->getContentType()),
'fields' => $this->getFields() 'fields' => $this->getFields()
] ]
]; ];
...@@ -100,10 +101,10 @@ class ContentTypeFile ...@@ -100,10 +101,10 @@ class ContentTypeFile
$yamlData = $file->parse(); $yamlData = $file->parse();
if($delete) { if($delete) {
unset($yamlData[$this->contentType]); unset($yamlData[$this->flux->getCode()]);
} else { } else {
if(!empty($yamlData[$this->contentType])) { if(!empty($yamlData[$this->flux->getCode()])) {
unset($yamlData[$this->contentType]); unset($yamlData[$this->flux->getCode()]);
} }
$yamlData += $data; $yamlData += $data;
} }
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
namespace Bolt\Extension\Appolo\Tourinsoft\Utils; namespace Bolt\Extension\Appolo\Tourinsoft\Utils;
use Bolt\Application; use Bolt\Application;
use Bolt\Exception\InvalidRepositoryException;
use Bolt\Storage\Entity\Builder; use Bolt\Storage\Entity\Builder;
use Bolt\Storage\EntityManager;
class Data class Data
{ {
...@@ -37,7 +39,7 @@ class Data ...@@ -37,7 +39,7 @@ class Data
* Insert data in database * Insert data in database
*/ */
public function insert() { public function insert() {
$this->deleteData(); // $this->deleteData();
$items = $this->getFormattedItems(); $items = $this->getFormattedItems();
foreach ($items as $k => $item) { foreach ($items as $k => $item) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment