Commit 7a6b1a98 by Frédéric

Sync contenttypes.yml

parent 66b70ac0
......@@ -48,6 +48,14 @@ class Synchronisation
$keys = $parser->getKeys();
$file = new ContentTypeFile($this->application, $this->flux->getContentType(), $keys);
$file->createOrUpdateFile();
$file->updateInFile();
}
/**
*
*/
public function delete() {
$file = new ContentTypeFile($this->application, $this->flux->getContentType(), []);
$file->deleteInFile();
}
}
\ No newline at end of file
......@@ -39,10 +39,10 @@ class ContentTypeFile
}
/**
* Create or update file
* Update content type in file
*/
public function createOrUpdateFile() {
$yamlData = [
public function updateInFile() {
$data = [
$this->contentType => [
'name' => ucfirst($this->contentType),
'singular_name' => ucfirst($this->contentType),
......@@ -50,9 +50,14 @@ class ContentTypeFile
]
];
/** @var YamlFile $file */
$file = $this->application['filesystem']->getFile(strtolower("extensions_config://contenttypes/$this->contentType.yml"));
$file->dump($yamlData);
$this->updateOrDelete($data, false);
}
/**
* Delete content type in file
*/
public function deleteInFile() {
$this->updateOrDelete([], true);
}
/**
......@@ -74,4 +79,25 @@ class ContentTypeFile
return $fields;
}
/**
* @param array $data
* @param bool $delete
*/
private function updateOrDelete(array $data = [], $delete = false) {
/** @var YamlFile $file */
$file = $this->application['filesystem']->getFile(strtolower('config://contenttypes.yml'));
if($file->exists()) {
$yamlData = $file->parse();
if($delete) {
unset($yamlData[$this->contentType]);
} else {
$yamlData += $data;
}
$file->dump($yamlData, ['inline' => 4]);
}
}
}
\ No newline at end of file
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