Commit 684a705f by Frédéric

Test

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