diff --git a/rest/index.php b/rest/index.php index 8c8160dbfd83757b00afb55e948e92c29bda1a70..65161b7f4638d3e62c5d51f2614a5b8988299cfc 100755 --- a/rest/index.php +++ b/rest/index.php @@ -313,6 +313,7 @@ $app->get('/installer/prerequisites', \SrcCore\controllers\InstallerController:: $app->get('/installer/databaseConnection', \SrcCore\controllers\InstallerController::class . ':checkDatabaseConnection'); $app->post('/installer/custom', \SrcCore\controllers\InstallerController::class . ':createCustom'); $app->post('/installer/database', \SrcCore\controllers\InstallerController::class . ':createDatabase'); +$app->post('/installer/docservers', \SrcCore\controllers\InstallerController::class . ':createDocservers'); //ListInstances $app->put('/listinstances', \Entity\controllers\ListInstanceController::class . ':update'); diff --git a/sql/data_en.sql b/sql/data_en.sql index a9b000301e6bfd9a2cb3fcbbe2c6a25f09036031..9d3d1eb0f2fe4fe05fd774f8deda15d5e7b28abf 100755 --- a/sql/data_en.sql +++ b/sql/data_en.sql @@ -711,37 +711,29 @@ VALUES ('ACKNOWLEDGEMENT_RECEIPTS', 'Acknowledgement Receipts', 'Y'); TRUNCATE TABLE docservers; INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FASTHD_AI', 'DOC', 'Dépôt documentaire issue d''imports de masse', 'Y', 50000000000, 1, '/opt/maarch/docservers/DDS1/ai/', '2011-01-07 13:43:48.696644', 'letterbox_coll'); +VALUES ('FASTHD_AI', 'DOC', 'Dépôt documentaire issue d''imports de masse', 'Y', 50000000000, 1, '/opt/maarch/docservers/ai/', '2011-01-07 13:43:48.696644', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FASTHD_MAN', 'DOC', 'Dépôt documentaire de numérisation manuelle', 'N', 50000000000, 1290730, '/opt/maarch/docservers/DDS1/manual/', '2011-01-13 14:47:49.197164', 'letterbox_coll'); +VALUES ('FASTHD_MAN', 'DOC', 'Dépôt documentaire de numérisation manuelle', 'N', 50000000000, 1290730, '/opt/maarch/docservers/resources/', '2011-01-13 14:47:49.197164', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FASTHD_ATTACH', 'FASTHD', 'Dépôt des pièces jointes', 'N', 50000000000, 1, '/opt/maarch/docservers/DDS1/manual_attachments/', '2011-01-13 14:47:49.197164', 'attachments_coll'); +VALUES ('FASTHD_ATTACH', 'DOC', 'Dépôt des pièces jointes', 'N', 50000000000, 1, '/opt/maarch/docservers/attachments/', '2011-01-13 14:47:49.197164', 'attachments_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FASTHD_ATTACH_VERSION', 'FASTHD', 'Dépôt des pièces jointes versionnées', 'N', 50000000000, 1, '/opt/maarch/docservers/DDS1/manual_attachments_version/', '2011-01-13 14:47:49.197164', 'attachments_version_coll'); +VALUES ('CONVERT_MLB', 'CONVERT', 'Dépôt des formats des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/convert_resources/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('CONVERT_MLB', 'CONVERT', 'Dépôt des formats des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/convert_mlb/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); +VALUES ('CONVERT_ATTACH', 'CONVERT', 'Dépôt des formats des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/convert_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('CONVERT_ATTACH', 'CONVERT', 'Dépôt des formats des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/convert_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); +VALUES ('TNL_MLB', 'TNL', 'Dépôt des maniatures des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/thumbnails_resources/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('CONVERT_ATTACH_VERSION', 'CONVERT', 'Dépôt des formats des pièces jointes versionnées', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/convert_attachments_version/', '2015-03-16 14:47:49.197164', 'attachments_version_coll'); +VALUES ('TNL_ATTACH', 'TNL', 'Dépôt des maniatures des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/thumbnails_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('TNL_MLB', 'TNL', 'Dépôt des maniatures des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/thumbnails_mlb/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); +VALUES ('FULLTEXT_MLB', 'FULLTEXT', 'Dépôt de l''extraction plein texte des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/fulltext_resources/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('TNL_ATTACH', 'TNL', 'Dépôt des maniatures des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/thumbnails_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); +VALUES ('FULLTEXT_ATTACH', 'FULLTEXT', 'Dépôt de l''extraction plein texte des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/fulltext_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('TNL_ATTACH_VERSION', 'TNL', 'Dépôt des maniatures des pièces jointes versionnées', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/thumbnails_attachments_version/', '2015-03-16 14:47:49.197164', 'attachments_version_coll'); +VALUES ('TEMPLATES', 'TEMPLATES', 'Dépôt des modèles de documents', 'N', 50000000000, 71511, '/opt/maarch/docservers/templates/', '2012-04-01 14:49:05.095119', 'templates'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FULLTEXT_MLB', 'FULLTEXT', 'Dépôt de l''extraction plein texte des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/fulltext_mlb/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); +VALUES ('ARCHIVETRANSFER', 'ARCHIVETRANSFER', 'Dépôt des archives numériques', 'N', 50000000000, 1, '/opt/maarch/docservers/archive_transfer/', '2017-01-13 14:47:49.197164', 'archive_transfer_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FULLTEXT_ATTACH', 'FULLTEXT', 'Dépôt de l''extraction plein texte des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/fulltext_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); -INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FULLTEXT_ATTACH_VERSION', 'FULLTEXT', 'Dépôt de l''extraction plein texte des pièces jointes versionnées', 'N', 50000000000, 0, '/opt/maarch/docservers/DDS1/fulltext_attachments_version/', '2015-03-16 14:47:49.197164', 'attachments_version_coll'); -INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('TEMPLATES', 'TEMPLATES', 'Dépôt des modèles de documents', 'N', 50000000000, 71511, '/opt/maarch/docservers/DDS1/templates/', '2012-04-01 14:49:05.095119', 'templates'); -INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('ARCHIVETRANSFER', 'ARCHIVETRANSFER', 'Dépôt des archives numériques', 'N', 50000000000, 1, '/opt/maarch/docservers/DDS1/archive_transfer/', '2017-01-13 14:47:49.197164', 'archive_transfer_coll'); -INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('ACKNOWLEDGEMENT_RECEIPTS', 'ACKNOWLEDGEMENT_RECEIPTS', 'Acknowledgement Receipts', 'N', 50000000000, 0, '/opt/maarch/docservers/acknowledgement_receipts/', '2019-04-19 22:22:22.201904', 'letterbox_coll'); +VALUES ('ACKNOWLEDGEMENT_RECEIPTS', 'ACKNOWLEDGEMENT_RECEIPTS', 'Dépôt des AR', 'N', 50000000000, 0, '/opt/maarch/docservers/acknowledgement_receipts/', '2019-04-19 22:22:22.201904', 'letterbox_coll'); ------------ --SUPERADMIN USER diff --git a/sql/data_fr.sql b/sql/data_fr.sql index 349fc1027e32eef0b3f333cfcf4c6850dc427845..1d99ae44c1adc723dff33c6cd66726dc6b55d3e7 100755 --- a/sql/data_fr.sql +++ b/sql/data_fr.sql @@ -829,19 +829,19 @@ TRUNCATE TABLE docservers; INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) VALUES ('FASTHD_AI', 'DOC', 'Dépôt documentaire issue d''imports de masse', 'Y', 50000000000, 1, '/opt/maarch/docservers/ai/', '2011-01-07 13:43:48.696644', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FASTHD_MAN', 'DOC', 'Dépôt documentaire de numérisation manuelle', 'N', 50000000000, 1290730, '/opt/maarch/docservers/manual/', '2011-01-13 14:47:49.197164', 'letterbox_coll'); +VALUES ('FASTHD_MAN', 'DOC', 'Dépôt documentaire de numérisation manuelle', 'N', 50000000000, 1290730, '/opt/maarch/docservers/resources/', '2011-01-13 14:47:49.197164', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FASTHD_ATTACH', 'DOC', 'Dépôt des pièces jointes', 'N', 50000000000, 1, '/opt/maarch/docservers/manual_attachments/', '2011-01-13 14:47:49.197164', 'attachments_coll'); +VALUES ('FASTHD_ATTACH', 'DOC', 'Dépôt des pièces jointes', 'N', 50000000000, 1, '/opt/maarch/docservers/attachments/', '2011-01-13 14:47:49.197164', 'attachments_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('CONVERT_MLB', 'CONVERT', 'Dépôt des formats des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/convert_mlb/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); +VALUES ('CONVERT_MLB', 'CONVERT', 'Dépôt des formats des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/convert_resources/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) VALUES ('CONVERT_ATTACH', 'CONVERT', 'Dépôt des formats des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/convert_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('TNL_MLB', 'TNL', 'Dépôt des maniatures des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/thumbnails_mlb/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); +VALUES ('TNL_MLB', 'TNL', 'Dépôt des maniatures des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/thumbnails_resources/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) VALUES ('TNL_ATTACH', 'TNL', 'Dépôt des maniatures des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/thumbnails_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) -VALUES ('FULLTEXT_MLB', 'FULLTEXT', 'Dépôt de l''extraction plein texte des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/fulltext_mlb/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); +VALUES ('FULLTEXT_MLB', 'FULLTEXT', 'Dépôt de l''extraction plein texte des documents numérisés', 'N', 50000000000, 0, '/opt/maarch/docservers/fulltext_resources/', '2015-03-16 14:47:49.197164', 'letterbox_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) VALUES ('FULLTEXT_ATTACH', 'FULLTEXT', 'Dépôt de l''extraction plein texte des pièces jointes', 'N', 50000000000, 0, '/opt/maarch/docservers/fulltext_attachments/', '2015-03-16 14:47:49.197164', 'attachments_coll'); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, size_limit_number, actual_size_number, path_template, creation_date, coll_id) diff --git a/src/core/controllers/InstallerController.php b/src/core/controllers/InstallerController.php index 2126852dbc8b31bcf8f4639f9d826ae4b158dc03..caa54704dedc16e86c68209ad646a09ebe8b65c3 100644 --- a/src/core/controllers/InstallerController.php +++ b/src/core/controllers/InstallerController.php @@ -18,6 +18,8 @@ use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; use SrcCore\models\CoreConfigModel; +use SrcCore\models\DatabaseModel; +use SrcCore\models\DatabasePDO; class InstallerController { @@ -125,13 +127,13 @@ class InstallerController { $body = $request->getParsedBody(); - if (!Validator::stringType()->notEmpty()->validate($body['customName'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body customName is empty or not a string']); + if (!Validator::stringType()->notEmpty()->validate($body['customId'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body customId is empty or not a string']); } - if (is_dir("custom/{$body['customName']}")) { + if (is_dir("custom/{$body['customId']}")) { return $response->withStatus(400)->withJson(['errors' => 'Custom with this name already exists']); - } elseif (!@mkdir("custom/{$body['customName']}/apps/maarch_entreprise/xml", 0755, true)) { + } elseif (!@mkdir("custom/{$body['customId']}/apps/maarch_entreprise/xml", 0755, true)) { return $response->withStatus(400)->withJson(['errors' => 'Custom folder creation failed']); } @@ -143,9 +145,9 @@ class InstallerController $customFile = CoreConfigModel::getJsonLoaded(['path' => 'custom/custom.json']); $customFile[] = [ - 'id' => $body['customName'], + 'id' => $body['customId'], 'uri' => null, - 'path' => $body['customName'] + 'path' => $body['customId'] ]; $fp = fopen('custom/custom.json', 'w'); fwrite($fp, json_encode($customFile, JSON_PRETTY_PRINT)); @@ -154,17 +156,17 @@ class InstallerController $jsonFile = [ 'config' => [ 'lang' => $body['lang'] ?? 'fr', - 'applicationName' => $body['customName'], + 'applicationName' => $body['applicationName'] ?? $body['customId'], 'cookieTime' => 10080, 'timezone' => 'Europe/Paris' ], 'database' => [] ]; - $fp = fopen("custom/{$body['customName']}/apps/maarch_entreprise/xml/config.json", 'w'); + $fp = fopen("custom/{$body['customId']}/apps/maarch_entreprise/xml/config.json", 'w'); fwrite($fp, json_encode($jsonFile, JSON_PRETTY_PRINT)); fclose($fp); - $cmd = 'ln -s ' . realpath('.') . "/ {$body['customName']}"; + $cmd = 'ln -s ' . realpath('.') . "/ {$body['customId']}"; exec($cmd); return $response->withStatus(204); @@ -184,8 +186,8 @@ class InstallerController return $response->withStatus(400)->withJson(['errors' => 'Body password is empty or not a string']); } elseif (!Validator::stringType()->notEmpty()->validate($body['name'])) { return $response->withStatus(400)->withJson(['errors' => 'Body name is empty or not a string']); - } elseif (!Validator::stringType()->notEmpty()->validate($body['customName'])) { - return $response->withStatus(400)->withJson(['errors' => 'Body customName is empty or not a string']); + } elseif (!Validator::stringType()->notEmpty()->validate($body['customId'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body customId is empty or not a string']); } if (empty($body['alreadyCreated'])) { @@ -233,7 +235,7 @@ class InstallerController } } - $configFile = CoreConfigModel::getJsonLoaded(['path' => "custom/{$body['customName']}/apps/maarch_entreprise/xml/config.json"]); + $configFile = CoreConfigModel::getJsonLoaded(['path' => "custom/{$body['customId']}/apps/maarch_entreprise/xml/config.json"]); $configFile['database'] = [ [ "server" => $body['server'], @@ -245,10 +247,71 @@ class InstallerController ] ]; - $fp = fopen("custom/{$body['customName']}/apps/maarch_entreprise/xml/config.json", 'w'); + $fp = fopen("custom/{$body['customId']}/apps/maarch_entreprise/xml/config.json", 'w'); fwrite($fp, json_encode($configFile, JSON_PRETTY_PRINT)); fclose($fp); return $response->withStatus(204); } + + public function createDocservers(Request $request, Response $response) + { + $body = $request->getParsedBody(); + + if (!Validator::stringType()->notEmpty()->validate($body['path'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body path is empty or not a string']); + } elseif (!Validator::stringType()->notEmpty()->validate($body['customId'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body customId is empty or not a string']); + } elseif (!is_dir($body['path'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body path does not exist']); + } elseif (!is_writable($body['path'])) { + return $response->withStatus(400)->withJson(['errors' => 'Body path is not writable']); + } + + $body['path'] = rtrim($body['path'], '/'); + $docservers = [ + 'AI' => 'ai', + 'RESOURCES' => 'resources', + 'ATTACHMENTS' => 'attachments', + 'CONVERT_RESOURCES' => 'convert_resources', + 'CONVERT_ATTACH' => 'convert_attachments', + 'TNL_RESOURCES' => 'thumbnails_resources', + 'TNL_ATTACHMENTS' => 'thumbnails_attachments', + 'FULLTEXT_RESOURCES' => 'fulltext_resources', + 'FULLTEXT_ATTACHMENTS' => 'fulltext_attachments', + 'TEMPLATES' => 'templates', + 'ARCHIVETRANSFER' => 'archive_transfer', + 'ACKNOWLEDGEMENT_RECEIPTS' => 'acknowledgement_receipts' + ]; + + foreach ($docservers as $docserver) { + if (!@mkdir("{$body['path']}/{$body['customId']}/{$docserver}", 0755, true)) { + return $response->withStatus(400)->withJson(['errors' => "Docserver folder creation failed for path : {$body['path']}/{$body['customId']}/{$docserver}"]); + } + } + + $templatesPath = "{$body['path']}/{$body['customId']}/templates/0000"; + if (!@mkdir($templatesPath, 0755, true)) { + return $response->withJson(['success' => "Docservers created but templates folder creation failed"]); + } + + $templatesToCopy = scandir('install/templates/0000'); + foreach ($templatesToCopy as $templateToCopy) { + if ($templateToCopy == '.' || $templateToCopy == '..') { + continue; + } + + copy("install/templates/0000/{$templateToCopy}", "{$templatesPath}/{$templateToCopy}"); + } + + DatabasePDO::reset(); + new DatabasePDO(['customId' => $body['customId']]); + DatabaseModel::update([ + 'table' => 'docservers', + 'postSet' => ['path_template' => "replace(path_template, '/opt/maarch/docservers', '{$body['path']}/{$body['customId']}')"], + 'where' => ['1 = 1'] + ]); + + return $response->withStatus(204); + } }