diff --git a/install/class/Class_Install.php b/install/class/Class_Install.php index a26bb317a17582e056e4a29a565090c5505ae680..0ca9e1f8dc78942787bb090c726e130fd16ab5bc 100755 --- a/install/class/Class_Install.php +++ b/install/class/Class_Install.php @@ -47,6 +47,7 @@ class Install extends functions private $docservers = array( array('FASTHD_AI', 'ai'), array('FASTHD_MAN', 'manual'), + array('FASTHD_ATTACH', 'manual_attachments'), array('TEMPLATES', 'templates'), array('TNL', 'thumbnails_mlb'), ); diff --git a/modules/attachments/Controllers/AttachmentsController.php b/modules/attachments/Controllers/AttachmentsController.php index 3289d9674771d77978763171c1fc4a959d5969c8..7d20149d5e5ad3c05f53e51f8163de27e6d694fd 100644 --- a/modules/attachments/Controllers/AttachmentsController.php +++ b/modules/attachments/Controllers/AttachmentsController.php @@ -19,250 +19,115 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Respect\Validation\Validator; use Attachments\Models\AttachmentsModel; +use Core\Controllers\ResController; require_once 'modules/attachments/Models/AttachmentsModel.php'; class AttachmentsController { - - public function getList(RequestInterface $request, ResponseInterface $response) + + public function storeAttachmentResource($aArgs) { - $obj = AttachmentsModel::getList(); - - $datas = [ - [ - 'attachments' => $obj, - ] - ]; - - return $response->withJson($datas); - } + if (empty($aArgs['resId'])) { - public function getById(RequestInterface $request, ResponseInterface $response, $aArgs) - { - if (isset($aArgs['id'])) { - $id = $aArgs['id']; - $obj = AttachmentsModel::getById([ - 'id' => $id - ]); - } else { - - return $response - ->withStatus(500) - ->withJson(['errors' => _ID . ' ' . _IS_EMPTY]); + return ['errors' => 'resId ' . _EMPTY]; } - - $datas = [ - [ - 'attachments' => $obj, - ] - ]; - - return $response->withJson($datas); - } - - public function create(RequestInterface $request, ResponseInterface $response, $aArgs) - { - $errors = []; - - $errors = $this->control($request, 'create'); - if (!empty($errors)) { + if (empty($aArgs['encodedFile'])) { - return $response - ->withStatus(500) - ->withJson(['errors' => $errors]); + return ['errors' => 'encodedFile ' . _EMPTY]; } - $aArgs = $request->getQueryParams(); + if (empty($aArgs['collId'])) { - $return = AttachmentsModel::create($aArgs); - - if ($return) { - $id = $aArgs['id']; - $obj = AttachmentsModel::getById([ - 'id' => $id - ]); - } else { - - return $response - ->withStatus(500) - ->withJson(['errors' => _NOT_CREATE]); + return ['errors' => 'collId ' . _EMPTY]; } - $datas = [ - [ - 'status' => $obj, - ] - ]; + if (empty($aArgs['table'])) { - return $response->withJson($datas); - } - - public function update(RequestInterface $request, ResponseInterface $response, $aArgs) - { - $errors = []; - - $errors = $this->control($request, 'update'); - - if (!empty($errors)) { - - return $response - ->withStatus(500) - ->withJson(['errors' => $errors]); + return ['errors' => 'table ' . _EMPTY]; } - $aArgs = $request->getQueryParams(); + if (empty($aArgs['fileFormat'])) { - $return = AttachmentsModel::update($aArgs); + return ['errors' => 'fileFormat ' . _EMPTY]; + } - if ($return) { - $id = $aArgs['id']; - $obj = AttachmentsModel::getById([ - 'id' => $id - ]); - } else { + if (empty($aArgs['title'])) { - return $response - ->withStatus(500) - ->withJson(['errors' => _NOT_UPDATE]); + return ['errors' => 'title ' . _EMPTY]; } - $datas = [ - [ - 'status' => $obj, - ] - ]; + $resId = $aArgs['resId']; + $encodedFile = $aArgs['encodedFile']; + $collId = $aArgs['collId']; + $table = $aArgs['table']; + $fileFormat = $aArgs['fileFormat']; + $title = $aArgs['title']; - return $response->withJson($datas); - } + if (!empty($aArgs['data'])) { - public function delete(RequestInterface $request, ResponseInterface $response, $aArgs) - { - if (isset($aArgs['id'])) { - $id = $aArgs['id']; - $obj = AttachmentsModel::delete([ - 'id' => $id - ]); + $data = $aArgs['data']; } else { - - return $response - ->withStatus(500) - ->withJson(['errors' => _NOT_DELETE]); + $data = []; } - $datas = [ - [ - 'status' => $obj, - ] + array_push( + $data, + array( + 'column' => "typist", + 'value' => $_SESSION['user']['UserId'], + 'type' => "string", + ) + ); + + array_push( + $data, + array( + 'column' => "title", + 'value' => strtolower($title), + 'type' => "string", + ) + ); + array_push( + $data, + array( + 'column' => "coll_id", + 'value' => $collId, + 'type' => "string", + ) + ); + array_push( + $data, + array( + 'column' => "res_id_master", + 'value' => $resId, + 'type' => "integer", + ) + ); + array_push( + $data, + array( + 'column' => "type_id", + 'value' => 0, + 'type' => "int", + ) + ); + + $aArgs = [ + 'encodedFile' => $encodedFile, + 'data' => $data, + 'collId' => $collId, + 'table' => $table, + 'fileFormat' => $fileFormat, + 'status' => 'NEW', ]; - return $response->withJson($datas); - } - - protected function control($request, $mode) - { - $errors = []; - - if($mode == 'update') { - $obj = AttachmentsModel::getById([ - 'id' => $request->getParam('id') - ]); - if (empty($obj)) { - array_push( - $errors, - _ID . ' ' . $request->getParam('id') . ' ' . _NOT_EXISTS - ); - } - } - - if (!Validator::notEmpty()->validate($request->getParam('id'))) { - array_push($errors, _ID . ' ' . _IS_EMPTY); - } elseif($mode == 'create') { - $obj = AttachmentsModel::getById([ - 'id' => $request->getParam('id') - ]); - if (!empty($obj)) { - array_push( - $errors, - _ID . ' ' . $obj[0]['id'] . ' ' . _ALREADY_EXISTS - ); - } - } - - if (!Validator::regex('/^[\w.-]*$/')->validate($request->getParam('id'))) { - array_push($errors, _ID . ' ' . _NOT . ' ' . _VALID); - } - - if (!Validator::notEmpty()->validate($request->getParam('label_status'))) { - array_push($errors, _LABEL_STATUS . ' ' . _IS_EMPTY); - } - - if ( - Validator::notEmpty() - ->validate($request->getParam('is_system')) && - !Validator::contains('Y') - ->validate($request->getParam('is_system')) && - !Validator::contains('N') - ->validate($request->getParam('is_system')) - ) { - array_push($errors, _IS_SYSTEM . ' ' . _NOT . ' ' . _VALID); - } + $res = new \Core\Controllers\ResController(); + $response = $res->storeResource($aArgs); - if ( - Validator::notEmpty() - ->validate($request->getParam('is_folder_status')) && - !Validator::contains('Y') - ->validate($request->getParam('is_folder_status')) && - !Validator::contains('N') - ->validate($request->getParam('is_folder_status')) - ) { - array_push($errors, _IS_FOLDER_STATUS . ' ' . _NOT . ' ' . _VALID); - } - - if ( - Validator::notEmpty() - ->validate($request->getParam('img_filename')) && - (!Validator::regex('/^[\w-.]+$/') - ->validate($request->getParam('img_filename')) || - !Validator::length(null, 255) - ->validate($request->getParam('img_filename'))) - ) { - array_push($errors, _IMG_FILENAME . ' ' . _NOT . ' ' . _VALID); - } - - if ( - Validator::notEmpty() - ->validate($request->getParam('maarch_module')) && - !Validator::length(null, 255) - ->validate($request->getParam('maarch_module')) - ) { - array_push($errors, _MAARCH_MODULE . ' ' . _NOT . ' ' . _VALID); - } - - if ( - Validator::notEmpty() - ->validate($request->getParam('can_be_searched')) && - !Validator::contains('Y') - ->validate($request->getParam('can_be_searched')) && - !Validator::contains('N') - ->validate($request->getParam('can_be_searched')) - ) { - array_push($errors, _CAN_BE_SEARCHED . ' ' . _NOT . ' ' . _VALID); - } - - if ( - Validator::notEmpty() - ->validate($request->getParam('can_be_modified')) && - !Validator::contains('Y') - ->validate($request->getParam('can_be_modified')) && - !Validator::contains('N') - ->validate($request->getParam('can_be_modified')) - ) { - array_push($errors, _CAN_BE_MODIFIED . ' ' . _NOT . ' ' . _VALID); - } + print_r($response);exit; - return $errors; } } \ No newline at end of file diff --git a/modules/attachments/Models/AttachmentsModelAbstract.php b/modules/attachments/Models/AttachmentsModelAbstract.php index fe1b74a357861bd531a9702a26bea17f1a641823..e84d7e84fc58d9701f4eca044ef3b3bc5e1519f6 100644 --- a/modules/attachments/Models/AttachmentsModelAbstract.php +++ b/modules/attachments/Models/AttachmentsModelAbstract.php @@ -14,87 +14,5 @@ require_once 'apps/maarch_entreprise/services/Table.php'; class AttachmentsModelAbstract extends \Apps_Table_Service { - public static function getList() - { - $aReturn = static::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_attachments'], - ]); - - return $aReturn; - } - - public static function getById(array $aArgs = []) - { - static::checkRequired($aArgs, ['id']); - static::checkString($aArgs, ['id']); - - $aReturn = static::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_attachments'], - 'where' => ['res_id = ?'], - 'data' => [$aArgs['id']] - ]); - - return $aReturn; - } - - public static function create(array $aArgs = []) - { - if (empty($aArgs['status'])) { - $aArgs['status'] = 'NEW'; - } - - if (empty($aArgs['creation_date'])) { - $aArgs['creation_date'] = date('c'); - } - - if (empty($aArgs['typist'])) { - $aArgs['typist'] = empty($_SESSION['user']['UserId'])?'auto':$_SESSION['user']['UserId']; - } - - if (empty($aArgs['fingerprint'])) { - throw new \Exception('fingerprint empty'); - } - - if (empty($aArgs['type_id'])) { - $aArgs['type_id'] = 0; - } - - $aArgs['title'] = strtolower($aArgs['title']); - - $aReturn = static::insertInto($aArgs, 'status'); - - return $aReturn; - } - - public static function update(array $aArgs = []) - { - static::checkRequired($aArgs, ['id']); - static::checkString($aArgs, ['id']); - - $where['id'] = $aArgs['id']; - - $aReturn = static::updateTable( - $aArgs, - 'status', - $where - ); - - return $aReturn; - } - - public static function delete(array $aArgs = []) - { - static::checkRequired($aArgs, ['id']); - static::checkString($aArgs, ['id']); - - $aReturn = static::deleteFrom([ - 'table' => 'status', - 'where' => ['id = ?'], - 'data' => [$aArgs['id']] - ]); - - return $aReturn; - } + } diff --git a/sql/160_to_161.sql b/sql/160_to_161.sql index 0f4cf8cceeb5fc9879c604c2ef37277738b8a4a2..a317d15e07abf63df490f07354c5d2a396c5976c 100644 --- a/sql/160_to_161.sql +++ b/sql/160_to_161.sql @@ -164,3 +164,7 @@ ALTER TABLE entities ADD COLUMN transferring_agency character varying(255); ALTER TABLE entities DROP COLUMN IF EXISTS archival_agreement; ALTER TABLE entities ADD COLUMN archival_agreement character varying(255); + +DELETE FROM docservers where docserver_id = 'FASTHD_ATTACH'; +INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, enabled, size_limit_number, actual_size_number, path_template, ext_docserver_info, chain_before, chain_after, creation_date, closing_date, coll_id, priority_number, docserver_location_id, adr_priority_number) +VALUES ('FASTHD_ATTACH', 'FASTHD', 'Fast internal disc bay for attachments', 'N', 'Y', 50000000000, 1, '/opt/maarch/docservers/manual_attachments/', NULL, NULL, NULL, '2011-01-13 14:47:49.197164', NULL, 'attachments_coll', 2, 'NANTERRE', 3); diff --git a/sql/data_fr.sql b/sql/data_fr.sql index 3f6a7242848814e70110ab582b2967cdfc7dc067..242389a824d88724a4ec86f4136a06e0cba83598 100644 --- a/sql/data_fr.sql +++ b/sql/data_fr.sql @@ -752,6 +752,8 @@ INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readon INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, enabled, size_limit_number, actual_size_number, path_template, ext_docserver_info, chain_before, chain_after, creation_date, closing_date, coll_id, priority_number, docserver_location_id, adr_priority_number) VALUES ('TNL', 'TNL', 'Server for thumbnails of documents', 'N', 'Y', 50000000000, 0, '/opt/maarch/docservers/thumbnails_mlb/', NULL, NULL, NULL, '2015-03-16 14:47:49.197164', NULL, 'letterbox_coll', 11, 'NANTERRE', 3); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, enabled, size_limit_number, actual_size_number, path_template, ext_docserver_info, chain_before, chain_after, creation_date, closing_date, coll_id, priority_number, docserver_location_id, adr_priority_number) VALUES ('TEMPLATES', 'TEMPLATES', '[system] Templates', 'N', 'Y', 50000000000, 71511, '/opt/maarch/docservers/templates/', NULL, NULL, NULL, '2012-04-01 14:49:05.095119', NULL, 'templates', 1, 'NANTERRE', 1); INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, enabled, size_limit_number, actual_size_number, path_template, ext_docserver_info, chain_before, chain_after, creation_date, closing_date, coll_id, priority_number, docserver_location_id, adr_priority_number) VALUES ('FASTHD_MAN', 'FASTHD', 'Fast internal disc bay for letterbox mode', 'N', 'Y', 50000000000, 1290730, '/opt/maarch/docservers/manual/', NULL, NULL, NULL, '2011-01-13 14:47:49.197164', NULL, 'letterbox_coll', 10, 'NANTERRE', 2); +INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, enabled, size_limit_number, actual_size_number, path_template, ext_docserver_info, chain_before, chain_after, creation_date, closing_date, coll_id, priority_number, docserver_location_id, adr_priority_number) VALUES ('FASTHD_ATTACH', 'FASTHD', 'Fast internal disc bay for attachments', 'N', 'Y', 50000000000, 1, '/opt/maarch/docservers/manual_attachments/', NULL, NULL, NULL, '2011-01-13 14:47:49.197164', NULL, 'attachments_coll', 2, 'NANTERRE', 3); + ------------ --SUPERADMIN USER ------------