Skip to content
Snippets Groups Projects
Commit f9847660 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #11272 TIME 0:50 delete child models with master model + check if master...

FEAT #11272 TIME 0:50 delete child models with master model + check if master model is private + fix unit tests
parent 219e5b95
No related branches found
No related tags found
No related merge requests found
......@@ -91,12 +91,18 @@ class IndexingModelController
return $response->withStatus(400)->withJson(['errors' => "Mandatory 'subject' field is missing"]);
}
$master = null;
if (Validator::intVal()->notEmpty()->validate($body['master'])) {
$masterModel = IndexingModelModel::getById(['id' => $body['master']]);
if (empty($masterModel)) {
return $response->withStatus(400)->withJson(['errors' => 'Master model not found']);
}
if ($masterModel['private']) {
return $response->withStatus(400)->withJson(['errors' => 'Master model is a private model']);
}
$master = $body['master'];
$fieldsMaster = IndexingModelFieldModel::get(['select' => ['identifier', 'mandatory', 'default_value', 'unit'], 'where' => ['model_id = ?'], 'data' => [$body['master']]]);
foreach ($fieldsMaster as $key => $value) {
$fieldsMaster[$key]['default_value'] = json_decode($value['default_value'], true);
......@@ -140,7 +146,7 @@ class IndexingModelController
'default' => $body['default'],
'owner' => $GLOBALS['id'],
'private' => $body['private'],
'master' => $body['master']
'master' => $master
]);
foreach ($body['fields'] as $field) {
......@@ -321,11 +327,6 @@ class IndexingModelController
if (!empty($childrenModels)) {
foreach ($childrenModels as $child) {
IndexingModelModel::delete([
'where' => ['id = ?'],
'data' => [$child['id']]
]);
IndexingModelFieldModel::delete(['where' => ['model_id = ?'], 'data' => [$child['id']]]);
HistoryController::add([
......@@ -340,8 +341,8 @@ class IndexingModelController
}
IndexingModelModel::delete([
'where' => ['id = ?'],
'data' => [$args['id']]
'where' => ['(id = ? or master = ?)'],
'data' => [$args['id'], $args['id']]
]);
IndexingModelFieldModel::delete(['where' => ['model_id = ?'], 'data' => [$args['id']]]);
......
......@@ -26,7 +26,7 @@ class IndexingModelControllerTest extends TestCase
$args = [
'label' => 'mon model d indexation',
'category' => 'incoming',
'private' => true,
'private' => false,
'fields' => [
[
'identifier' => 'subject',
......@@ -67,7 +67,7 @@ class IndexingModelControllerTest extends TestCase
$this->assertSame('mon model d indexation', $responseBody->indexingModel->label);
$this->assertSame(false, $responseBody->indexingModel->default);
$this->assertSame(true, $responseBody->indexingModel->private);
$this->assertSame(false, $responseBody->indexingModel->private);
$this->assertSame('subject', $responseBody->indexingModel->fields[0]->identifier);
$this->assertSame(true, $responseBody->indexingModel->fields[0]->mandatory);
$this->assertSame('tika', $responseBody->indexingModel->fields[0]->default_value);
......@@ -270,7 +270,7 @@ class IndexingModelControllerTest extends TestCase
$this->assertSame('mon model d indexation modifié', $responseBody->indexingModel->label);
$this->assertSame(false, $responseBody->indexingModel->default);
$this->assertSame(true, $responseBody->indexingModel->private);
$this->assertSame(false, $responseBody->indexingModel->private);
$this->assertSame('subject', $responseBody->indexingModel->fields[0]->identifier);
$this->assertSame(true, $responseBody->indexingModel->fields[0]->mandatory);
$this->assertSame('butter', $responseBody->indexingModel->fields[0]->default_value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment