Skip to content
Snippets Groups Projects
Commit e7c88e94 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

Merge branch 'develop' of https://labs.maarch.org/maarch/MaarchCourrier into develop

parents a669d8ca 2b1257c7
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,6 @@ class ResController ...@@ -60,7 +60,6 @@ class ResController
if (empty($aArgs['fileFormat'])) { if (empty($aArgs['fileFormat'])) {
return ['errors' => 'fileFormat ' . _EMPTY]; return ['errors' => 'fileFormat ' . _EMPTY];
<<<<<<< HEAD
} }
if (empty($aArgs['status'])) { if (empty($aArgs['status'])) {
...@@ -74,100 +73,6 @@ class ResController ...@@ -74,100 +73,6 @@ class ResController
$fileFormat = $aArgs['fileFormat']; $fileFormat = $aArgs['fileFormat'];
$status = $aArgs['status']; $status = $aArgs['status'];
try {
$count = count($data);
for ($i=0;$i<$count;$i++) {
$data[$i]['column'] = strtolower($data[$i]['column']);
}
$returnCode = 0;
//copy sended file on tmp
$fileContent = base64_decode($encodedFile);
$random = rand();
$fileName = 'tmp_file_' . $random . '.' . $fileFormat;
$Fnm = $_SESSION['config']['tmppath'] . $fileName;
$inF = fopen($Fnm,"w");
fwrite($inF, $fileContent);
fclose($inF);
//store resource on docserver
$ds = new DocserverController();
$aArgs = [
'collId' => $collId,
'fileInfos' =>
[
'tmpDir' => $_SESSION['config']['tmppath'],
'size' => filesize($Fnm),
'format' => $fileFormat,
'tmpFileName' => $fileName,
]
];
$storeResult = array();
$storeResult = $ds->storeResourceOnDocserver($aArgs);
if (!empty($storeResult['errors'])) {
return ['errors' => $storeResult['errors']];
}
//store resource metadata in database
$aArgs = [
'data' => $data,
'docserverId' => $storeResult['docserver_id'],
'status' => $status,
'fileFormat' => $fileFormat,
];
$data = $this->prepareStorage($aArgs);
unlink($Fnm);
require_once 'core/class/class_resource.php';
$resource = new \resource();
$resId = $resource->load_into_db(
$table,
$storeResult['destination_dir'],
$storeResult['file_destination_name'],
$storeResult['path_template'],
$storeResult['docserver_id'],
$data,
$_SESSION['config']['databasetype'],
true
);
if (!is_numeric($resId)) {
return ['errors' => 'Pb with SQL insertion : ' .$resId];
}
if ($resId == 0) {
$resId = '';
}
return [$resId];
} catch (Exception $e) {
return ['errors' => 'unknown error' . $e->getMessage()];
=======
>>>>>>> lgi-feat-attachments
}
}
<<<<<<< HEAD
=======
if (empty($aArgs['status'])) {
return ['errors' => 'status ' . _EMPTY];
}
$encodedFile = $aArgs['encodedFile'];
$data = $aArgs['data'];
$collId = $aArgs['collId'];
$table = $aArgs['table'];
$fileFormat = $aArgs['fileFormat'];
$status = $aArgs['status'];
try { try {
$count = count($data); $count = count($data);
for ($i=0;$i<$count;$i++) { for ($i=0;$i<$count;$i++) {
...@@ -247,7 +152,6 @@ class ResController ...@@ -247,7 +152,6 @@ class ResController
} }
} }
>>>>>>> lgi-feat-attachments
/** /**
* Prepares storage on database. * Prepares storage on database.
* @param $data array * @param $data array
...@@ -264,220 +168,6 @@ class ResController ...@@ -264,220 +168,6 @@ class ResController
} }
if (empty($aArgs['docserverId'])) { if (empty($aArgs['docserverId'])) {
<<<<<<< HEAD
return ['errors' => 'docserverId ' . _EMPTY];
}
if (empty($aArgs['status'])) {
return ['errors' => 'status ' . _EMPTY];
}
if (empty($aArgs['fileFormat'])) {
return ['errors' => 'fileFormat ' . _EMPTY];
}
$statusFound = false;
$typistFound = false;
$typeIdFound = false;
$toAddressFound = false;
$userPrimaryEntity = false;
$destinationFound = false;
$initiatorFound = false;
$data = $aArgs['data'];
$docserverId = $aArgs['docserverId'];
$status = $aArgs['status'];
$fileFormat = $aArgs['fileFormat'];
$userModel = new UserModel();
$entityModel = new \Entities\Models\EntitiesModel();
$countD = count($data);
for ($i=0;$i<$countD;$i++) {
if (
strtoupper($data[$i]['type']) == 'INTEGER' ||
strtoupper($data[$i]['type']) == 'FLOAT'
) {
if ($data[$i]['value'] == '') {
$data[$i]['value'] = '0';
}
}
if (strtoupper($data[$i]['type']) == 'STRING') {
$data[$i]['value'] = $data[$i]['value'];
$data[$i]['value'] = str_replace(";", "", $data[$i]['value']);
$data[$i]['value'] = str_replace("--", "", $data[$i]['value']);
}
if (strtoupper($data[$i]['column']) == strtoupper('status')) {
$statusFound = true;
}
if (strtoupper($data[$i]['column']) == strtoupper('typist')) {
$typistFound = true;
}
if (strtoupper($data[$i]['column']) == strtoupper('type_id')) {
$typeIdFound = true;
}
if (strtoupper($data[$i]['column']) == strtoupper('custom_t10')) {
$mail = array();
$theString = str_replace(">", "", $data[$i]['value']);
$mail = explode("<", $theString);
$user = $userModel->getByEmail(['mail' => $mail[count($mail) -1]]);
$userIdFound = $user[0]['user_id'];
if (!empty($userIdFound)) {
$toAddressFound = true;
$destUser = $userIdFound;
$entity = $entityModel->getByUserId(['user_id' => $destUser]);
if (!empty($entity[0]['entity_id'])) {
$userEntity = $entity[0]['entity_id'];
$userPrimaryEntity = true;
}
} else {
$entity = $entityModel->getByEmail(['email' => $mail[count($mail) -1]]);
if (!empty($entity[0]['entity_id'])) {
$userPrimaryEntity = true;
}
}
}
}
if (!$typistFound && !$toAddressFound) {
array_push(
$data,
array(
'column' => 'typist',
'value' => 'auto',
'type' => 'string',
)
);
}
if (!$typeIdFound) {
array_push(
$data,
array(
'column' => 'type_id',
'value' => '10',
'type' => 'string',
)
);
}
if (!$statusFound) {
array_push(
$data,
array(
'column' => 'status',
'value' => $status,
'type' => 'string',
)
);
}
if ($toAddressFound) {
array_push(
$data,
array(
'column' => 'dest_user',
'value' => $destUser,
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'typist',
'value' => $destUser,
'type' => 'string',
)
);
}
if ($userPrimaryEntity) {
for ($i=0;$i<count($data);$i++) {
if (strtoupper($data[$i]['column']) == strtoupper('destination')) {
if ($data[$i]['value'] == "") {
$data[$i]['value'] = $userEntity;
}
$destinationFound = true;
break;
}
}
if (!$destinationFound) {
array_push(
$data,
array(
'column' => 'destination',
'value' => $userEntity,
'type' => 'string',
)
);
}
}
if ($userPrimaryEntity) {
for ($i=0;$i<count($data);$i++) {
if (strtoupper($data[$i]['column']) == strtoupper('initiator')) {
if ($data[$i]['value'] == "") {
$data[$i]['value'] = $userEntity;
}
$initiatorFound = true;
break;
}
}
if (!$initiatorFound) {
array_push(
$data,
array(
'column' => 'initiator',
'value' => $userEntity,
'type' => 'string',
)
);
}
}
array_push(
$data,
array(
'column' => 'format',
'value' => $fileFormat,
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'offset_doc',
'value' => '',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'logical_adr',
'value' => '',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'docserver_id',
'value' => $docserverId,
'type' => 'string',
)
);
return $data;
=======
return ['errors' => 'docserverId ' . _EMPTY]; return ['errors' => 'docserverId ' . _EMPTY];
} }
...@@ -858,6 +548,5 @@ class ResController ...@@ -858,6 +548,5 @@ class ResController
); );
return $returnResArray; return $returnResArray;
} }
>>>>>>> lgi-feat-attachments
} }
} }
\ No newline at end of file
...@@ -116,10 +116,8 @@ class ResControllerTest extends PHPUnit_Framework_TestCase ...@@ -116,10 +116,8 @@ class ResControllerTest extends PHPUnit_Framework_TestCase
$response = $action->storeResource($aArgs); $response = $action->storeResource($aArgs);
$this->assertGreaterThanOrEqual(0, $response); $this->assertGreaterThanOrEqual(0, $response[0]);
} }
<<<<<<< HEAD
=======
public function testStoreExtResource() public function testStoreExtResource()
{ {
...@@ -192,5 +190,4 @@ class ResControllerTest extends PHPUnit_Framework_TestCase ...@@ -192,5 +190,4 @@ class ResControllerTest extends PHPUnit_Framework_TestCase
$this->assertGreaterThanOrEqual(0, $response); $this->assertGreaterThanOrEqual(0, $response);
} }
>>>>>>> lgi-feat-attachments
} }
\ No newline at end of file
...@@ -38,11 +38,21 @@ class AttachmentsController ...@@ -38,11 +38,21 @@ class AttachmentsController
return ['errors' => 'encodedFile ' . _EMPTY]; return ['errors' => 'encodedFile ' . _EMPTY];
} }
if (empty($aArgs['data'])) {
return ['errors' => 'data ' . _EMPTY];
}
if (empty($aArgs['collId'])) { if (empty($aArgs['collId'])) {
return ['errors' => 'collId ' . _EMPTY]; return ['errors' => 'collId ' . _EMPTY];
} }
if (empty($aArgs['collIdMaster'])) {
return ['errors' => 'collIdMaster ' . _EMPTY];
}
if (empty($aArgs['table'])) { if (empty($aArgs['table'])) {
return ['errors' => 'table ' . _EMPTY]; return ['errors' => 'table ' . _EMPTY];
...@@ -53,81 +63,213 @@ class AttachmentsController ...@@ -53,81 +63,213 @@ class AttachmentsController
return ['errors' => 'fileFormat ' . _EMPTY]; return ['errors' => 'fileFormat ' . _EMPTY];
} }
if (empty($aArgs['title'])) {
return ['errors' => 'title ' . _EMPTY];
}
$resId = $aArgs['resId']; $resId = $aArgs['resId'];
$encodedFile = $aArgs['encodedFile']; $encodedFile = $aArgs['encodedFile'];
$collId = $aArgs['collId']; $collId = $aArgs['collId'];
$collIdMaster = $aArgs['collIdMaster'];
$table = $aArgs['table']; $table = $aArgs['table'];
$fileFormat = $aArgs['fileFormat']; $fileFormat = $aArgs['fileFormat'];
$title = $aArgs['title'];
if (!empty($aArgs['data'])) { $aArgs = [
'data' => $aArgs['data'],
'collIdMaster' => $collIdMaster,
'resId' => $resId,
];
$returnPrepare = $this->prepareStorage($aArgs);
$aArgs = [
'encodedFile' => $encodedFile,
'data' => $returnPrepare['data'],
'collId' => $collId,
'table' => $table,
'fileFormat' => $fileFormat,
'status' => $returnPrepare['status'],
];
$res = new \Core\Controllers\ResController();
$response = $res->storeResource($aArgs);
//return $response;
if (!is_numeric($response[0])) {
$data = $aArgs['data']; return ['errors' => 'Pb with SQL insertion : ' . $response[0]];
} else { } else {
$data = []; require_once 'core/class/class_history.php';
require_once 'core/class/class_security.php';
$hist = new \history();
$sec = new \security();
$view = $sec->retrieve_view_from_coll_id($collIdMaster);
$hist->add(
$view, $resId, "ADD", 'attachadd',
ucfirst(_DOC_NUM) . $response[0] . ' '
. _NEW_ATTACH_ADDED . ' ' . _TO_MASTER_DOCUMENT
. $resId,
$_SESSION['config']['databasetype'],
'apps'
);
$hist->add(
$table, $response[0], "ADD",'attachadd',
_NEW_ATTACH_ADDED,
$_SESSION['config']['databasetype'],
'attachments'
);
}
if ($response[0] == 0) {
$response[0] = '';
}
return [$response[0]];
}
/**
* Prepares storage on database.
* @param $data array
* @param $resId bigint
* @param $collIdMaster string
* @return $data
*/
public function prepareStorage($aArgs)
{
if (empty($aArgs['data'])) {
return ['errors' => 'data ' . _EMPTY];
}
if (empty($aArgs['resId'])) {
return ['errors' => 'resId ' . _EMPTY];
}
if (empty($aArgs['collIdMaster'])) {
return ['errors' => 'collIdMaster ' . _EMPTY];
}
$statusFound = false;
$typistFound = false;
$typeIdFound = false;
$attachmentTypeFound = false;
$data = $aArgs['data'];
$countD = count($data);
for ($i=0;$i<$countD;$i++) {
if (
strtoupper($data[$i]['type']) == 'INTEGER' ||
strtoupper($data[$i]['type']) == 'FLOAT'
) {
if ($data[$i]['value'] == '') {
$data[$i]['value'] = '0';
}
}
if (strtoupper($data[$i]['type']) == 'STRING') {
$data[$i]['value'] = $data[$i]['value'];
$data[$i]['value'] = str_replace(";", "", $data[$i]['value']);
$data[$i]['value'] = str_replace("--", "", $data[$i]['value']);
}
if (strtoupper($data[$i]['column']) == strtoupper('status')) {
$statusFound = true;
$status = $data[$i]['value'];
}
if (strtoupper($data[$i]['column']) == strtoupper('typist')) {
$typistFound = true;
}
if (strtoupper($data[$i]['column']) == strtoupper('type_id')) {
$typeIdFound = true;
}
if (strtoupper($data[$i]['column']) == strtoupper('attachment_type')) {
$attachmentTypeFound = true;
}
}
if (!$typistFound) {
array_push(
$data,
array(
'column' => 'typist',
'value' => $_SESSION['user']['UserId'],
'type' => 'string',
)
);
}
if (!$typeIdFound) {
array_push(
$data,
array(
'column' => 'type_id',
'value' => 0,
'type' => 'int',
)
);
} }
array_push( if (!$statusFound) {
$data, array_push(
array( $data,
'column' => "typist", array(
'value' => $_SESSION['user']['UserId'], 'column' => 'status',
'type' => "string", 'value' => 'NEW',
) 'type' => 'string',
); )
);
$status = 'NEW';
}
if (!$attachmentTypeFound) {
array_push(
$data,
array(
'column' => 'attachment_type',
'value' => 'response_project',
'type' => 'string',
)
);
}
array_push( //BASICS
$data,
array(
'column' => "title",
'value' => strtolower($title),
'type' => "string",
)
);
array_push( array_push(
$data, $data,
array( array(
'column' => "coll_id", 'column' => "coll_id",
'value' => $collId, 'value' => $aArgs['collIdMaster'],
'type' => "string", 'type' => "string",
) )
); );
array_push( array_push(
$data, $data,
array( array(
'column' => "res_id_master", 'column' => "res_id_master",
'value' => $resId, 'value' => $aArgs['resId'],
'type' => "integer", 'type' => "integer",
) )
); );
array_push( array_push(
$data, $data,
array( array(
'column' => "type_id", 'column' => "relation",
'value' => 0, 'value' => 1,
'type' => "int", 'type' => "integer",
) )
); );
$aArgs = [ $return = [
'encodedFile' => $encodedFile, 'data' => $data,
'data' => $data, 'status' => $status,
'collId' => $collId,
'table' => $table,
'fileFormat' => $fileFormat,
'status' => 'NEW',
]; ];
$res = new \Core\Controllers\ResController(); return $return;
$response = $res->storeResource($aArgs);
print_r($response);exit;
} }
} }
\ No newline at end of file
...@@ -12,6 +12,50 @@ require_once 'core/Test/define.php'; ...@@ -12,6 +12,50 @@ require_once 'core/Test/define.php';
class AttachmentsControllerTest extends PHPUnit_Framework_TestCase class AttachmentsControllerTest extends PHPUnit_Framework_TestCase
{ {
public function testPrepareStorage()
{
$action = new \Attachments\Controllers\AttachmentsController();
$data = [];
array_push(
$data,
array(
'column' => 'title',
'value' => 'test pj',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'attachment_type',
'value' => 'response_project',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'status',
'value' => 'A_TRA',
'type' => 'string',
)
);
$aArgs = [
'data' => $data,
'resId' => 100,
'collIdMaster' => 'letterbox_coll',
];
$response = $action->prepareStorage($aArgs);
$this->assertArrayHasKey('column', $response['data'][0]);
}
public function testStoreAttachmentResource() public function testStoreAttachmentResource()
{ {
$action = new \Attachments\Controllers\AttachmentsController(); $action = new \Attachments\Controllers\AttachmentsController();
...@@ -24,24 +68,54 @@ class AttachmentsControllerTest extends PHPUnit_Framework_TestCase ...@@ -24,24 +68,54 @@ class AttachmentsControllerTest extends PHPUnit_Framework_TestCase
$fileSource = 'test_source.txt'; $fileSource = 'test_source.txt';
$fp = fopen($path . $fileSource, 'a'); $fp = fopen($path . $fileSource, 'w');
fwrite($fp, 'a unit test'); fwrite($fp, 'a unit test');
fclose($fp); fclose($fp);
$fileContent = file_get_contents($path . $fileSource, FILE_BINARY); $fileContent = file_get_contents($path . $fileSource, FILE_BINARY);
$encodedFile = base64_encode($fileContent); $encodedFile = base64_encode($fileContent);
$data = [];
array_push(
$data,
array(
'column' => 'title',
'value' => 'test pj',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'attachment_type',
'value' => 'response_project',
'type' => 'string',
)
);
array_push(
$data,
array(
'column' => 'status',
'value' => 'A_TRA',
'type' => 'string',
)
);
$aArgs = [ $aArgs = [
'resId' => 100, 'resId' => 100,
'encodedFile' => $encodedFile, 'encodedFile' => $encodedFile,
'data' => $data,
'collId' => 'attachments_coll', 'collId' => 'attachments_coll',
'collIdMaster' => 'letterbox_coll',
'table' => 'res_attachments', 'table' => 'res_attachments',
'fileFormat' => 'txt', 'fileFormat' => 'txt',
'title' => 'test pj',
]; ];
$response = $action->storeAttachmentResource($aArgs); $response = $action->storeAttachmentResource($aArgs);
print_r($response);exit;
$this->assertGreaterThanOrEqual(0, $response); $this->assertGreaterThanOrEqual(0, $response[0]);
} }
} }
\ No newline at end of file
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