Verified Commit d0644584 authored by Alexandre Morin's avatar Alexandre Morin
Browse files

Fix : resources optimization

parent b3ff654d
......@@ -32,10 +32,9 @@ if ($_REQUEST['reference']) {
foreach ($resIds as $id) {
$res = $checkAcknowledgement->checkAttachment($id);
if ($res == false) {
if ($res === false) {
$status = 1;
$error = $_SESSION['error'];
break;
}
}
$content = $res;
......@@ -46,10 +45,9 @@ if ($_REQUEST['reference']) {
foreach ($resIds as $id) {
$res = $checkReply->checkAttachment($id);
if ($res == false) {
if ($res === false) {
$status = 1;
$error = $_SESSION['error'];
break;
}
}
$content = $res;
......@@ -60,10 +58,9 @@ if ($_REQUEST['reference']) {
foreach ($resIds as $id) {
$res = $purge->purge($id);
if ($res == false) {
if ($res === false) {
$status = 1;
$error = $_SESSION['error'];
break;
}
}
$content = $res;
......@@ -74,10 +71,9 @@ if ($_REQUEST['reference']) {
foreach ($resIds as $id) {
$res = $reset->reset($id);
if ($res == false) {
if ($res === false) {
$status = 1;
$error = $_SESSION['error'];
break;
}
}
$content = $res;
......
......@@ -11,8 +11,8 @@ class CheckAcknowledgement
}
public function checkAttachment($resId) {
$letter = $this->db->getLetter($resId);
if ($letter->status != "SEND_SEDA") {
$status = $this->db->getStatusLetter($resId);
if ($status != "SEND_SEDA") {
$_SESSION['error'] = _ERROR_STATUS_SEDA . $resId;
return false;
}
......
......@@ -70,9 +70,6 @@ class DOMTemplateProcessor
{
parent::__construct($document);
$this->xinclude();
$this->xinclude();
$this->xinclude();
$this->xinclude();
$this->xinclude();
......
......@@ -27,13 +27,73 @@ class RequestSeda
{
private $db;
protected $statement;
public function __construct($db = null)
{
$this->statement = [];
if ($db) {
$this->db = $db;
} else {
$this->db = new Database();
}
$query = "SELECT * FROM seda WHERE reference = ?";
$this->statement['getMessageByReference'] = $this->db->prepare($query);
$query = "SELECT status FROM res_letterbox WHERE res_id = ?";
$this->statement['getStatusLetter'] = $this->db->prepare($query);
$query = "SELECT destination FROM res_letterbox WHERE res_id = ?";
$this->statement['getDestinationLetter'] = $this->db->prepare($query);
$query = "SELECT res_id, contact_id, filename, docserver_id, path, creation_date, modification_date, type_id, doc_date, admission_date, creation_date, exp_contact_id, dest_contact_id, destination, nature_id, type_label, alt_identifier, subject, title
FROM res_view_letterbox
WHERE res_id = ?";
$this->statement['getLetter'] = $this->db->prepare($query);
$query = "SELECT * FROM entities WHERE entity_id = ?";
$this->statement['getEntity'] = $this->db->prepare($query);
$query = "SELECT * FROM notes WHERE identifier = ?";
$this->statement['getNotes'] = $this->db->prepare($query);
$query = "SELECT * FROM sendmail WHERE res_id = ?";
$this->statement['getMails'] = $this->db->prepare($query);
$query = "SELECT * FROM doctypes WHERE type_id = ?";
$this->statement['getDocTypes'] = $this->db->prepare($query);
$query = "SELECT * FROM unit_identifier WHERE res_id = ?";
$this->statement['getUnitIdentifierByResId'] = $this->db->prepare($query);
$query =
"SELECT res_parent,res_child
FROM res_linked
WHERE coll_id = 'letterbox_coll'
AND (res_child = ? OR res_parent = ?)";
$this->statement['getLinks'] = $this->db->prepare($query);
$query = "SELECT * FROM contacts_v2 WHERE contact_id = ?";
$this->statement['getContact'] = $this->db->prepare($query);
$query = "SELECT * FROM docservers WHERE docserver_id = ?";
$this->statement['getDocServer'] = $this->db->prepare($query);
$query = "SELECT * FROM res_attachments WHERE res_id_master = ? AND status != 'DEL'";
$this->statement['getAttachments'] = $this->db->prepare($query);
$query = "SELECT * FROM history WHERE table_name = ? and record_id = ?";
$this->statement['getHistory'] = $this->db->prepare($query);
$query = "INSERT INTO unit_identifier VALUES (?,?,?)";
$this->statement['insertUnitIdentifier'] = $this->db->prepare($query);
$query = "DELETE FROM seda WHERE message_id = ?";
$this->statement['deleteMessage'] = $this->db->prepare($query);
$query = "DELETE FROM unit_identifier WHERE res_id = ?";
$this->statement['deleteUnitIdentifier'] = $this->db->prepare($query);
}
public function getMessageByReference($reference)
......@@ -45,7 +105,7 @@ class RequestSeda
$query = "SELECT * FROM seda WHERE reference = ?";
$smtp = $this->db->query($query, $queryParams);
$message = $smtp->fetchObject();
return $message;
......@@ -90,11 +150,9 @@ class RequestSeda
$queryParams[] = $resId;
$query = "SELECT * FROM unit_identifier WHERE res_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getUnitIdentifierByResId']->execute($queryParams);
$unitIdentifier = $res = $smtp->fetchObject();
$unitIdentifier = $res = $this->statement['getUnitIdentifierByResId']->fetchObject();
return $unitIdentifier;
}
......@@ -105,31 +163,49 @@ class RequestSeda
$queryParams[] = $resId;
$query = "SELECT * FROM res_view_letterbox WHERE res_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getLetter']->execute($queryParams);
$letterbox = $smtp->fetchObject();
$letterbox = $this->statement['getLetter']->fetchObject();
return $letterbox;
}
public function getLinks($resId) {
public function getStatusLetter($resId)
{
$queryParams = [];
$queryParams[] = $resId;
$this->statement['getStatusLetter']->execute($queryParams);
$res = $this->statement['getStatusLetter']->fetchObject();
return $res->status;
}
public function getDestinationLetter($resId)
{
$queryParams = [];
$queryParams[] = $resId;
$query =
"SELECT res_parent,res_child
FROM res_linked
WHERE coll_id = 'letterbox_coll'
AND (res_child = ? OR res_parent = ?)";
$this->statement['getDestinationLetter']->execute($queryParams);
$smtp = $this->db->query($query, $queryParams);
$res = $this->statement['getDestinationLetter']->fetchObject();
return $res->destination;
}
public function getLinks($resId)
{
$queryParams = [];
$queryParams[] = $resId;
$queryParams[] = $resId;
$this->statement['getLinks']->execute($queryParams);
$links = [];
while ($res = $smtp->fetchObject()) {
while ($res = $this->statement['getLinks']->fetchObject()) {
if ($resId == $res->res_parent) {
$links[] = $res->res_child;
} else {
......@@ -164,11 +240,9 @@ class RequestSeda
$queryParams[] = $typeId;
$query = "SELECT * FROM doctypes WHERE type_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getDocTypes']->execute($queryParams);
$docTypes = $smtp->fetchObject();
$docTypes = $this->statement['getDocTypes']->fetchObject();
return $docTypes;
}
......@@ -194,12 +268,10 @@ class RequestSeda
$queryParams[] = $letterboxId;
$query = "SELECT * FROM notes WHERE identifier = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getNotes']->execute($queryParams);
$notes = [];
while ($res = $smtp->fetchObject()) {
while ($res = $this->statement['getEntity']->fetchObject()) {
$notes[] = $res;
}
......@@ -212,12 +284,10 @@ class RequestSeda
$queryParams[] = $letterboxId;
$query = "SELECT * FROM sendmail WHERE res_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getMails']->execute($queryParams);
$mails = [];
while ($res = $smtp->fetchObject()) {
while ($res = $this->statement['getMails']->fetchObject()) {
$mails[] = $res;
}
......@@ -230,11 +300,9 @@ class RequestSeda
$queryParams[] = $entityId;
$query = "SELECT * FROM entities WHERE entity_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getEntity']->execute($queryParams);
$entity = $smtp->fetchObject();
$entity = $this->statement['getEntity']->fetchObject();
return $entity;
}
......@@ -245,11 +313,9 @@ class RequestSeda
$queryParams[] = $contactId;
$query = "SELECT * FROM contacts_v2 WHERE contact_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getContact']->execute($queryParams);
$contact = $smtp->fetchObject();
$contact = $this->statement['getContact']->fetchObject();
return $contact;
}
......@@ -260,11 +326,9 @@ class RequestSeda
$queryParams[] = $docServerId;
$query = "SELECT * FROM docservers WHERE docserver_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getDocServer']->execute($queryParams);
$docServers = $smtp->fetchObject();
$docServers = $this->statement['getDocServer']->fetchObject();
return $docServers;
}
......@@ -275,12 +339,10 @@ class RequestSeda
$queryParams[] = $resIdMaster;
$query = "SELECT * FROM res_attachments WHERE res_id_master = ? AND status != 'DEL'";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getAttachments']->execute($queryParams);
$attachments = [];
while ($res = $smtp->fetchObject()) {
while ($res = $this->statement['getAttachments']->fetchObject()) {
$attachments[] = $res;
}
......@@ -340,12 +402,10 @@ class RequestSeda
$queryParams[] = $tableName;
$queryParams[] = $recordId;
$query = "SELECT * FROM history WHERE table_name = ? and record_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['getHistory']->execute($queryParams);
$history = [];
while ($res = $smtp->fetchObject()) {
while ($res = $this->statement['getHistory']->fetchObject()) {
$history[] = $res;
}
......@@ -613,14 +673,13 @@ class RequestSeda
public function insertUnitIdentifier($messageId, $tableName, $resId)
{
try {
$query = ("INSERT INTO unit_identifier VALUES (?,?,?)");
$queryParams = [];
$queryParams[] = $messageId;
$queryParams[] = $tableName;
$queryParams[] = $resId;
$res = $this->db->query($query, $queryParams);
$this->statement['insertUnitIdentifier']->execute($queryParams);
} catch (Exception $e) {
return false;
}
......@@ -702,9 +761,7 @@ class RequestSeda
$queryParams = [];
$queryParams[] = $messageId;
try {
$query = "DELETE FROM seda WHERE message_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['deleteMessage']->execute($queryParams);
} catch (Exception $e) {
return false;
}
......@@ -718,9 +775,7 @@ class RequestSeda
$queryParams[] = $resId;
try {
$query = "DELETE FROM unit_identifier WHERE res_id = ?";
$smtp = $this->db->query($query, $queryParams);
$this->statement['deleteUnitIdentifier']->execute($queryParams);
} catch (Exception $e) {
return false;
}
......
......@@ -29,6 +29,7 @@ class ArchiveTransfer
private $abstractMessage;
private $externalLink;
private $xml;
protected $entities;
public function __construct()
{
......@@ -62,6 +63,8 @@ class ArchiveTransfer
if ($getXml) {
$this->xml = simplexml_load_file($path);
}
$this->entities = [];
}
public function receive($listResId)
......@@ -343,7 +346,12 @@ class ArchiveTransfer
$messageObject->ArchivalAgreement = new stdClass();
foreach ($_SESSION['user']['entities'] as $entity) {
$entity = $this->db->getEntity($entity['ENTITY_ID']);
$res = array_key_exists($entity['ENTITY_ID'], $this->entities);
if ($res === false) {
$this->entities[$entity['ENTITY_ID']] = $entity = $this->db->getEntity($entity['ENTITY_ID']);
} else {
$entity = $this->entities[$entity['ENTITY_ID']];
}
if ($entity) {
if (!(string) $this->xml->CONFIG->senderOrgRegNumber) {
......@@ -441,38 +449,40 @@ class ArchiveTransfer
}
}
if ($type != 'Note' && $type != 'Email') {
$notes = $this->db->getNotes($object->res_id);
if ($notes) {
$i = 1;
foreach ($notes as $note) {
$note->title = 'Note n° ' . $note->id;
$archiveUnit->ArchiveUnit[] = $this->getArchiveUnit(
"Note",
$note,
null,
$archiveUnitId . '_note_' . $i,
$note->id
);
$i++;
if ($object->res_id) {
if ($type != 'Note' && $type != 'Email') {
$notes = $this->db->getNotes($object->res_id);
if ($notes) {
$i = 1;
foreach ($notes as $note) {
$note->title = 'Note n° ' . $note->id;
$archiveUnit->ArchiveUnit[] = $this->getArchiveUnit(
"Note",
$note,
null,
$archiveUnitId . '_note_' . $i,
$note->id
);
$i++;
}
}
}
}
if ($type != 'Email' && $type != 'Note') {
$emails = $this->db->getMails($object->res_id);
if ($emails) {
$i = 1;
foreach ($emails as $email) {
$email->title = 'Email n° ' . $email->email_id;
$archiveUnit->ArchiveUnit[] = $this->getArchiveUnit(
"Email",
$email,
null,
$archiveUnitId . '_email_' . $i,
$email->email_id
);
$i++;
if ($type != 'Email' && $type != 'Note') {
$emails = $this->db->getMails($object->res_id);
if ($emails) {
$i = 1;
foreach ($emails as $email) {
$email->title = 'Email n° ' . $email->email_id;
$archiveUnit->ArchiveUnit[] = $this->getArchiveUnit(
"Email",
$email,
null,
$archiveUnitId . '_email_' . $i,
$email->email_id
);
$i++;
}
}
}
}
......@@ -509,23 +519,27 @@ class ArchiveTransfer
$content->Addressee = [];
$content->Keyword = [];
$keyword = $addressee = "";
$keyword = $addressee = $entity = "";
if ($object->destination) {
$res = array_key_exists($object->destination, $this->entities);
if ($res === false) {
$this->entities[$object->destination] = $entity = $this->db->getEntity($object->destination);
} else {
$entity = $this->entities[$object->destination];
}
}
if ($object->exp_contact_id) {
$contact = $this->db->getContact($object->exp_contact_id);
$entity = $this->db->getEntity($object->destination);
$keyword = $this->getKeyword($contact);
$addressee = $this->getAddresse($entity, "entity");
} elseif ($object->dest_contact_id) {
$contact = $this->db->getContact($object->dest_contact_id);
$entity = $this->db->getEntity($object->destination);
$addressee = $this->getAddresse($contact);
$keyword = $this->getKeyword($entity, "entity");
} elseif ($object->exp_user_id) {
$user = $this->db->getUserInformation($object->exp_user_id);
$entity = $this->db->getEntity($object->destination);
$keyword = $this->getKeyword($user);
$addressee = $this->getAddresse($entity, "entity");
}
......@@ -587,9 +601,15 @@ class ArchiveTransfer
$reference->ArchiveUnitRefId = 'letterbox_' . $key;
$content->RelatedObjectReference->References[] = $reference;
} else {
$letterbox = $this->db->getLetter($key);
if (isset($letterbox->destination)) {
$entity = $this->db->getEntity($letterbox->destination);
$destination = $this->db->getDestinationLetter($key);
if (isset($destination)) {
$res = array_key_exists($destination, $this->entities);
if ($res === false) {
$this->entities[$destination] = $entity = $this->db->getEntity($destination);
} else {
$entity = $this->entities[$destination];
}
$reference->RepositoryArchiveUnitPID = 'originator:' . $entity->business_id . ':' . $key;
$content->RelatedObjectReference->References[] = $reference;
}
......@@ -601,7 +621,14 @@ class ArchiveTransfer
if (isset($object->destination)) {
$content->OriginatingAgency = new stdClass();
$content->OriginatingAgency->Identifier = new stdClass();
$content->OriginatingAgency->Identifier->value = $this->db->getEntity($object->destination)->business_id;
$res = array_key_exists($object->destination, $this->entities);
if ($res === false) {
$this->entities[$object->destination] = $entity = $this->db->getEntity($object->destination);
} else {
$entity = $this->entities[$object->destination];
}
$content->OriginatingAgency->Identifier->value = $entity->business_id;
if (empty($content->OriginatingAgency->Identifier->value)) {
unset($content->OriginatingAgency);
......@@ -744,7 +771,12 @@ class ArchiveTransfer
private function getEntity($entityId, $param)
{
$entity = $this->db->getEntity($entityId);
$res = array_key_exists($entityId, $this->entities);
if ($res === false) {
$this->entities[$entityId] = $entity = $this->db->getEntity($entityId);
} else {
$entity = $this->entities[$entityId];
}
if (!$entity) {
return false;
......@@ -794,7 +826,12 @@ class ArchiveTransfer
private function getEntityParent($parentId, $param)
{
$entity = $this->db->getEntity($parentId);
$res = array_key_exists($parentId, $this->entities);
if ($res === false) {
$this->entities[$parentId] = $entity = $this->db->getEntity($parentId);
} else {
$entity = $this->entities[$parentId];
}
if (!$entity) {
return false;
......
......@@ -33,9 +33,9 @@ function get_form_txt($values, $path_manage_action, $id_action, $table, $module,
$archiveTransfer = new ArchiveTransfer();
$db = new RequestSeda();
foreach ($values as $value) {
$letter = $db->getLetter($value);
$status = $db->getStatusLetter($value);
if ($letter->status == 'SEND_SEDA') {
if ($status == 'SEND_SEDA') {
$_SESSION['error'] = _ERROR_MESSAGE_ALREADY_SENT . " " . $value;
}
}
......
Supports Markdown
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