Skip to content
Snippets Groups Projects
Verified Commit 3891220d authored by Damien's avatar Damien
Browse files

[REFACTORING] Reconciliation out of src

parent 1011dd7a
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
"User\\" : "src/app/user/", "User\\" : "src/app/user/",
"Core\\" : "core/", "Core\\" : "core/",
"Attachments\\" : "modules/attachments/",
"Convert\\" : "modules/convert/", "Convert\\" : "modules/convert/",
"Visa\\" : "modules/visa/" "Visa\\" : "modules/visa/"
} }
......
<?php <?php
namespace Attachments\Controllers;
use Attachment\Models\AttachmentModel;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Respect\Validation\Validator;
use Resource\controllers\ResController;
use Docserver\models\DocserverModel;
use Docserver\models\DocserverTypeModel;
use Docserver\controllers\DocserverToolsController;
use Core\Models\ResModel;
class ReconciliationController{ class ReconciliationController{
public function storeAttachmentResource($aArgs) public function storeAttachmentResource($aArgs)
...@@ -275,26 +264,25 @@ class ReconciliationController{ ...@@ -275,26 +264,25 @@ class ReconciliationController{
$filetmp .= $tmp; $filetmp .= $tmp;
$filetmp .= $filename; $filetmp .= $filename;
$docserver = DocserverModel::getById([ $docserver = \Docserver\models\DocserverModel::getById([
'id' => $docserverId 'id' => $docserverId
]); ]);
$docserverType = DocserverTypeModel::getById([ $docserverType = \Docserver\models\DocserverTypeModel::getById([
'id' => $docserver['docserver_type_id'] 'id' => $docserver['docserver_type_id']
]); ]);
$fingerprint = DocserverToolsController::doFingerprint( if (empty($docserverType['fingerprint_mode']) || $docserverType['fingerprint_mode'] == 'NONE') {
[ $fingerprint = '0';
'path' => $filetmp, } else {
'fingerprintMode' => $docserverType['fingerprint_mode'], $fingerprint = hash_file(strtolower($docserverType['fingerprint_mode']), $filetmp);
] }
);
$filesize = filesize($filetmp); $filesize = filesize($filetmp);
array_push( array_push(
$data, $data,
array( array(
'column' => "fingerprint", 'column' => "fingerprint",
'value' => $fingerprint['fingerprint'], 'value' => $fingerprint,
'type' => "string" 'type' => "string"
) )
); );
...@@ -346,7 +334,7 @@ class ReconciliationController{ ...@@ -346,7 +334,7 @@ class ReconciliationController{
} }
unset($prepareData['res_id']); // NCH01 unset($prepareData['res_id']); // NCH01
AttachmentModel::create($prepareData); \Attachment\Models\AttachmentModel::create($prepareData);
return true; return true;
} }
......
<?php
/**
*​ ​Copyright​ ​Maarch​ since ​2008​ under licence ​GPLv3.
*​ ​See​ LICENCE​.​txt file at the root folder ​for​ more details.
*​ ​This​ file ​is​ part of ​Maarch​ software.
*
*/
namespace Attachments\Models;
class ReconciliationModel extends ReconciliationModelAbstract {
}
\ No newline at end of file
<?php
/**
*​ ​Copyright​ ​Maarch​ since ​2008​ under licence ​GPLv3.
*​ ​See​ LICENCE​.​txt file at the root folder ​for​ more details.
*​ ​This​ file ​is​ part of ​Maarch​ software.
*
*/
namespace Attachments\Models;
use Core\Models\ValidatorModel;
use SrcCore\models\DatabaseModel;
class ReconciliationModelAbstract{
public static function selectReconciliation (array $aArgs = [])
{
ValidatorModel::notEmpty($aArgs, ['where', 'data', 'table']);
$select = [
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => gettype($aArgs['table']) == 'string' ? array($aArgs['table']) : $aArgs['table'],
'where' => $aArgs['where'],
'data' => $aArgs['data'],
];
if (!empty($aArgs['orderBy'])) {
$select['order_by'] = $aArgs['orderBy'];
}
$aReturn = DatabaseModel::select($select);
return $aReturn;
}
public static function updateReconciliation (array $aArgs = [])
{
ValidatorModel::notEmpty($aArgs, ['where', 'data', 'set']);
$aReturn = DatabaseModel::update([
'set' => $aArgs['set'],
'table' => gettype($aArgs['table']) == 'array' ? (string) $aArgs['table'] : $aArgs['table'],
'where' => $aArgs['where'],
'data' => $aArgs['data'],
]);
return $aReturn;
}
}
\ No newline at end of file
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
namespace MaarchTest;
use PHPUnit\Framework\TestCase;
use MaarchTest\DocserverControllerTest;
class ReconciliationControllerTest extends TestCase
{
public function testPrepareStorage()
{
$action = new \Attachments\Controllers\ReconciliationController();
$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,
'resIdMaster' => 100,
'collIdMaster' => 'letterbox_coll',
];
$response = $action->prepareStorage($aArgs);
$this->assertArrayHasKey('column', $response['data'][0]);
}
public function testStoreAttachmentResources(){
$docserverControllerTest = new DocserverControllerTest();
$action = new \Attachments\Controllers\ReconciliationController();
$docserverControllerTest -> testStoreResourceOnDocserver();
$path = $_SESSION['config']['tmppath'] . '/test/';
if (!is_dir($path)) {
mkdir($path);
}
$fileSource = 'test_source.txt';
$fp = fopen($path . $fileSource, 'w');
fwrite($fp, 'a unit test');
fclose($fp);
$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 = [
'resId' => 101,
'resIdMaster' => 100,
'data' => $data,
'collId' => 'attachments_coll',
'collIdMaster' => 'letterbox_coll',
'table' => 'res_attachments',
'fileFormat' => 'txt',
'filename' => $fileSource,
'path' => $path,
'docserverPath' => $path,
'docserverId' => 'FASTHD_MAN'
];
$response = $action->storeAttachmentResource($aArgs);
$this->assertTrue($response);
}
}
\ No newline at end of file
...@@ -6,12 +6,10 @@ ...@@ -6,12 +6,10 @@
* *
*/ */
use \Attachments\Models\ReconciliationModel;
$core = new core_tools(); $core = new core_tools();
$core->test_user(); $core->test_user();
$db = new Database(); $db = new Database();
$reconciliationControler = new \Attachments\Controllers\ReconciliationController(); $reconciliationControler = new ReconciliationController();
$letterboxTable = $_SESSION['tablename']['reconciliation']['letterbox']; $letterboxTable = $_SESSION['tablename']['reconciliation']['letterbox'];
...@@ -35,14 +33,10 @@ foreach($formValues as $tmpTab){ ...@@ -35,14 +33,10 @@ foreach($formValues as $tmpTab){
$_SESSION['modules_loaded']['attachments']['reconciliation']['tabFormValues'] = $tabFormValues; // declare SESSION var, used in remove_letterbox $_SESSION['modules_loaded']['attachments']['reconciliation']['tabFormValues'] = $tabFormValues; // declare SESSION var, used in remove_letterbox
// Retrieve the informations of the newly scanned document (the one to attach as an attachment) // Retrieve the informations of the newly scanned document (the one to attach as an attachment)
$queryChildInfos = ReconciliationModel::selectReconciliation([ $queryChildInfos = \Resource\models\ResModel::getById(['resId' => $childResId]);
'table' => [$letterboxTable],
'where' => ['res_id = (?)'],
'data' => [$childResId]
]);
$aArgs['data'] = array(); $aArgs['data'] = array();
foreach ($queryChildInfos[0] as $key => $value){ foreach ($queryChildInfos as $key => $value){
if($value != '' if($value != ''
&& $key != 'modification_date' && $key != 'modification_date'
&& $key != 'is_frozen' && $key != 'is_frozen'
...@@ -168,14 +162,12 @@ for($i = 0; $i <= count($aArgs['data']); $i++){ ...@@ -168,14 +162,12 @@ for($i = 0; $i <= count($aArgs['data']); $i++){
} }
if($aArgs['data'][$i]['column'] == 'docserver_id'){ if($aArgs['data'][$i]['column'] == 'docserver_id'){
// Retrieve the PATH TEMPLATE // Retrieve the PATH TEMPLATE
$docserverPath = ReconciliationModel::selectReconciliation([ $docserverPath = \Docserver\models\DocserverModel::getById([
'select' => ['path_template'], 'select' => ['path_template'],
'table' => ['docservers'], 'id' => $aArgs['data'][$i]['value']
'where' => ['docserver_id = (?)'],
'data' => [$aArgs['data'][$i]['value']]
]); ]);
$aArgs['docserverPath'] = $docserverPath[0]['path_template']; $aArgs['docserverPath'] = $docserverPath['path_template'];
$aArgs['docserverId'] = $aArgs['data'][$i]['value']; $aArgs['docserverId'] = $aArgs['data'][$i]['value'];
} }
} }
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
* *
*/ */
use Attachments\Models\ReconciliationModel;
$core = new core_tools(); $core = new core_tools();
$core->test_user(); $core->test_user();
...@@ -54,29 +52,22 @@ for ($i = 0; $i < count($_GET['field']); $i++){ ...@@ -54,29 +52,22 @@ for ($i = 0; $i < count($_GET['field']); $i++){
} }
// Get the informations of the current document in case there is more than one response project // Get the informations of the current document in case there is more than one response project
$defaultInfos = ReconciliationModel::selectReconciliation([ $defaultInfos = \Resource\models\ResModel::getById(['resId' => $_SESSION['doc_id'], 'select' => ['subject']]);
'select' => ['subject'],
'where' => ['res_id = (?)'],
'table' => $letterboxTable,
'data' => [$_SESSION['doc_id']]
]);
//If there is one res_id, we get the recipient information, the chrono number and the title //If there is one res_id, we get the recipient information, the chrono number and the title
if(count($_GET['field']) == 1){ if(count($_GET['field']) == 1){
// Check if there is a response project and retrieve the infos about it // Check if there is a response project and retrieve the infos about it
$queryProjectResponse = ReconciliationModel::selectReconciliation([ $queryProjectResponse = \Attachment\Models\AttachmentModel::getOnView([
'select' => ['identifier, title, dest_contact_id, dest_address_id'], 'select' => ['identifier, title, dest_contact_id, dest_address_id'],
'where' => ["res_id_master = (?) AND attachment_type = 'response_project' AND status <> 'DEL'"], 'where' => ["res_id_master = (?) AND attachment_type = 'response_project' AND status <> 'DEL'"],
'table' => $attachmentTable,
'data' => [$_GET['field']] 'data' => [$_GET['field']]
]); ]);
// Get the informations from res_view_letterbox, in order to get the contact infos if there is no project response // Get the informations from res_view_letterbox, in order to get the contact infos if there is no project response
$queryResViewLetterbox = ReconciliationModel::selectReconciliation([ $queryResViewLetterbox = \Resource\models\ResModel::getOnView([
'select' => ['contact_id, address_id'], 'select' => ['contact_id, address_id'],
'where' => ["res_id = (?)"], 'where' => ['res_id = (?)'],
'table' => 'res_view_letterbox',
'data' => [$_GET['field']] 'data' => [$_GET['field']]
]); ]);
...@@ -148,14 +139,14 @@ if(count($_GET['field']) == 1){ ...@@ -148,14 +139,14 @@ if(count($_GET['field']) == 1){
$str = '<select id="listProjectResponse" name="chrono_number_list" onchange="fillHiddenInput(this.options[this.selectedIndex].value)">'; $str = '<select id="listProjectResponse" name="chrono_number_list" onchange="fillHiddenInput(this.options[this.selectedIndex].value)">';
$str .= "<option value=''>" . _CHOOSE_CHRONO_NUMBER . "</option>"; $str .= "<option value=''>" . _CHOOSE_CHRONO_NUMBER . "</option>";
for($i = 0; $i< count($_GET['field']); $i++){ for($i = 0; $i< count($_GET['field']); $i++){
$queryAllProjectReponse = ReconciliationModel::selectReconciliation([ $queryAllProjectReponse = \Attachment\Models\AttachmentModel::getOnView([
'select' => ['title,identifier, dest_contact_id, dest_address_id'], 'select' => ['title,identifier, dest_contact_id, dest_address_id'],
'where' => ["res_id_master = (?) AND attachment_type = 'response_project'"], 'where' => ["res_id_master = (?) AND attachment_type = 'response_project'"],
'table' => $attachmentTable,
'data' => [$_GET['field'][$i]] 'data' => [$_GET['field'][$i]]
]); ]);
// Check if one of the selected document own a response projet, if attach_to_empty parameter is false
// Check if one of the selected document own a response projet, if attach_to_empty parameter is false
if($attach_to_empty == 'false' && !$queryAllProjectReponse){ if($attach_to_empty == 'false' && !$queryAllProjectReponse){
?> ?>
<script type="text/javascript"> <script type="text/javascript">
......
...@@ -7,11 +7,8 @@ ...@@ -7,11 +7,8 @@
*/ */
use \Attachments\Models\ReconciliationModel;
$core = new core_tools(); $core = new core_tools();
$core->test_user(); $core->test_user();
$db = new Database();
// Variable declaration // Variable declaration
$res_id = $_SESSION['doc_id']; $res_id = $_SESSION['doc_id'];
...@@ -22,33 +19,32 @@ $delete_response_project = $_SESSION['modules_loaded']['attachments']['reconcili ...@@ -22,33 +19,32 @@ $delete_response_project = $_SESSION['modules_loaded']['attachments']['reconcili
$close_incoming = $_SESSION['modules_loaded']['attachments']['reconciliation']['close_incoming']; $close_incoming = $_SESSION['modules_loaded']['attachments']['reconciliation']['close_incoming'];
// Modification of the incoming document, as deleted // Modification of the incoming document, as deleted
$delMail = ReconciliationModel::updateReconciliation([ \Resource\models\ResModel::update([
'set' => ['status' => 'DEL'], 'set' => ['status' => 'DEL'],
'where' => ['res_id = (?)'], 'where' => ['res_id = (?)'],
'data' => [$res_id], 'data' => [$res_id]
'table' => $letterboxTable
]); ]);
$tabFormValues = $_SESSION['modules_loaded']['attachments']['reconciliation']['tabFormValues']; $tabFormValues = $_SESSION['modules_loaded']['attachments']['reconciliation']['tabFormValues'];
// Deletion of the response project, with his chrono number and the res_id_master // Deletion of the response project, with his chrono number and the res_id_master
if($delete_response_project == 'true'){ if($delete_response_project == 'true'){
$delProject = ReconciliationModel::updateReconciliation([ \SrcCore\models\DatabaseModel::update([
'set' => ['status' => 'DEL'], 'set' => ['status' => 'DEL'],
'table' => $attachmentTable,
'where' => ["res_id_master = (?) AND identifier = (?) AND status NOT IN ('DEL','TMP') AND attachment_type = 'response_project'"], 'where' => ["res_id_master = (?) AND identifier = (?) AND status NOT IN ('DEL','TMP') AND attachment_type = 'response_project'"],
'data' => [$res_id_master[0], $tabFormValues['chrono_number']], 'data' => [$res_id_master[0], $tabFormValues['chrono_number']],
'table' => $attachmentTable
]); ]);
} }
// End the incoming mail after the reconciliation of the attachment // End the incoming mail after the reconciliation of the attachment
if($close_incoming == 'true' && $tabFormValues['close_incoming_mail'] == 'true'){ if($close_incoming == 'true' && $tabFormValues['close_incoming_mail'] == 'true'){
for($i = 0; $i < count($res_id_master); $i++){ for($i = 0; $i < count($res_id_master); $i++){
$queryClose = ReconciliationModel::updateReconciliation([ \Resource\models\ResModel::update([
'set' => ['status' => 'END'], 'set' => ['status' => 'END'],
'where' => ['res_id = (?)'], 'where' => ['res_id = ?'],
'data' => [$res_id_master[$i]], 'data' => [$res_id_master[$i]]
'table' => $letterboxTable
]); ]);
} }
} }
\ No newline at end of file
...@@ -559,7 +559,7 @@ class ProcessFulltextController ...@@ -559,7 +559,7 @@ class ProcessFulltextController
{ {
//echo 'launchIndexFullTextWithZendIndex' . PHP_EOL; //echo 'launchIndexFullTextWithZendIndex' . PHP_EOL;
// $IndexFileDirectory is replace by tempIndexFileDirectory // $IndexFileDirectory is replace by tempIndexFileDirectory
$fileContent = \Core\Models\TextFormatModel::normalize(['string' => $fileContent]); $fileContent = TextFormatModel::normalize(['string' => $fileContent]);
$fileContent = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $fileContent); $fileContent = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $fileContent);
// with version 1.12, we need a string, not an XML element // with version 1.12, we need a string, not an XML element
......
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
<directory suffix=".php">core/Models</directory> <directory suffix=".php">core/Models</directory>
<directory suffix=".php">modules/visa/Controllers</directory> <directory suffix=".php">modules/visa/Controllers</directory>
<directory suffix=".php">modules/visa/Models</directory> <directory suffix=".php">modules/visa/Models</directory>
<directory suffix=".php">modules/attachments/Controllers</directory>
<directory suffix=".php">modules/attachments/Models</directory>
<directory suffix=".php">modules/convert/Controllers</directory> <directory suffix=".php">modules/convert/Controllers</directory>
<directory suffix=".php">modules/convert/Models</directory> <directory suffix=".php">modules/convert/Models</directory>
</whitelist> </whitelist>
......
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Docserver tools Controller
* @author dev@maarch.org
* @ingroup core
*/
namespace Docserver\controllers;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Respect\Validation\Validator;
use Docserver\models\DocserverModel;
class DocserverToolsController
{
/**
* Compute the path in the docserver for a batch
* @param $docServer docservers path
* @return array Contains 2 items : subdirectory path and error
*/
public function createPathOnDocServer($aArgs)
{
if (empty($aArgs['path'])) {
$datas = [
'errors' => 'path ' . _EMPTY,
];
return $datas;
}
if (!is_dir($aArgs['path'])) {
$datas = [
'errors' => 'path ' . _NOT_EXISTS,
];
return $datas;
}
$pathOnDocserver = $aArgs['path'];
error_reporting(0);
umask(0022);
if (!is_dir($pathOnDocserver . date('Y') . DIRECTORY_SEPARATOR)) {
mkdir($pathOnDocserver . date('Y') . DIRECTORY_SEPARATOR, 0770);
$this->setRights(['path' => $pathOnDocserver . date('Y') . DIRECTORY_SEPARATOR]);
}
if (!is_dir(
$pathOnDocserver . date('Y') . DIRECTORY_SEPARATOR.date('m')
. DIRECTORY_SEPARATOR
)
) {
mkdir(
$pathOnDocserver . date('Y') . DIRECTORY_SEPARATOR.date('m')
. DIRECTORY_SEPARATOR,
0770
);
$this->setRights(
['path' => $pathOnDocserver . date('Y') . DIRECTORY_SEPARATOR.date('m') . DIRECTORY_SEPARATOR]
);
}
if (isset($GLOBALS['wb']) && $GLOBALS['wb'] <> '') {
$path = $pathOnDocserver . date('Y') . DIRECTORY_SEPARATOR.date('m')
. DIRECTORY_SEPARATOR . 'BATCH' . DIRECTORY_SEPARATOR
. $GLOBALS['wb'] . DIRECTORY_SEPARATOR;
if (!is_dir($path)) {
mkdir($path, 0770, true);
$this->setRights(['path' => $path]);
} else {
$datas = [
'errors' => 'Folder alreay exists, workbatch already exist:' . $path,
];
return $datas;
}
} else {
$path = $pathOnDocserver . date('Y') . DIRECTORY_SEPARATOR.date('m')
. DIRECTORY_SEPARATOR;
}
$datas =
[
'createPathOnDocServer' =>
[
'destinationDir' => $path
]
];
return $datas;
}
/**
* Set Rights on resources
* @param string $dest path of the resource
* @return nothing
*/
public function setRights($aArgs)
{
if (empty($aArgs['path'])) {
$datas = [
'errors' => 'path ' . _EMPTY,
];
return $datas;
}
if (!is_dir($aArgs['path'])) {
$datas = [
'errors' => 'path ' . _NOT_EXISTS,
];
return $datas;
}
if (DIRECTORY_SEPARATOR == '/'
&& (isset($GLOBALS['apacheUserAndGroup'])
&& $GLOBALS['apacheUserAndGroup'] <> '')
) {
exec('chown '
. escapeshellarg($GLOBALS['apacheUserAndGroup']) . ' '
. escapeshellarg($aArgs['path']));
}
umask(0022);
chmod($aArgs['path'], 0770);
$datas = [
'setRights' => true,
];
return $datas;
}
/**
* copy doc in a docserver.
* @param string $sourceFilePath collection resource
* @param array $infoFileNameInTargetDocserver infos of the doc to store,
* contains : subdirectory path and new filename
* @param string $docserverSourceFingerprint
* @return array of docserver data for res_x else return error
*/
public function copyOnDocserver($aArgs)
{
if (empty($aArgs['destinationDir'])) {
$datas = [
'errors' => 'destinationDir ' . _EMPTY,
];
return $datas;
}
if (empty($aArgs['fileDestinationName'])) {
$datas = [
'errors' => 'fileDestinationName ' . _EMPTY,
];
return $datas;
}
if (file_exists(($aArgs['destinationDir'] . $aArgs['fileDestinationName']))) {
$datas = [
'errors' => '' . $aArgs['destinationDir']
. $aArgs['fileDestinationName'] . ' ' . _FILE_ALREADY_EXISTS,
];
return $datas;
}
if (empty($aArgs['sourceFilePath'])) {
$datas = [
'errors' => 'sourceFilePath ' . _EMPTY,
];
return $datas;
}
if (!file_exists($aArgs['sourceFilePath'])) {
$datas = [
'errors' => 'sourceFilePath ' . _NOT_EXISTS,
];
return $datas;
}
$destinationDir = $aArgs['destinationDir'];
$fileDestinationName = $aArgs['fileDestinationName'];
$sourceFilePath = str_replace('\\\\', '\\', $aArgs['sourceFilePath']);
$docserverSourceFingerprint = $aArgs['docserverSourceFingerprint'];
error_reporting(0);
if (!is_dir($destinationDir)) {
mkdir($destinationDir, 0770, true);
$aArgs = [
'path'=> $destinationDir
];
$this->setRights($aArgs);
}
if (!copy($sourceFilePath, $destinationDir . $fileDestinationName)) {
$datas = [
'errors' => _DOCSERVER_COPY_ERROR . ' source : ' . $sourceFilePath
. ' dest : ' . $destinationDir . $fileDestinationName
];
return $datas;
}
$aArgs = [
'path'=> $destinationDir . $fileDestinationName
];
$this->setRights($aArgs);
$fingerprintControl = array();
$aArgs = [
'pathInit' => $sourceFilePath,
'pathTarget' => $destinationDir . $fileDestinationName,
'fingerprintMode' => $docserverSourceFingerprint,
];
$fingerprintControl = $this->controlFingerprint($aArgs);
if (!empty($fingerprintControl['errors'])) {
$datas = [
'errors' => $fingerprintControl['errors'],
];
return $datas;
}
//for batch like life cycle
if (isset($GLOBALS['currentStep'])) {
$destinationDir = str_replace(
$GLOBALS['docservers'][$GLOBALS['currentStep']]['docserver']
['path_template'],
'',
$destinationDir
);
}
$destinationDir = str_replace(
DIRECTORY_SEPARATOR,
'#',
$destinationDir
);
$datas = [
'copyOnDocserver' =>
[
'destinationDir' => $destinationDir,
'fileDestinationName' => $fileDestinationName,
'fileSize' => filesize($sourceFilePath),
]
];
if (isset($GLOBALS['TmpDirectory']) && $GLOBALS['TmpDirectory'] <> '') {
$aArgs = [
'path' => $GLOBALS['TmpDirectory'],
'contentOnly' => true,
];
$this->washTmp($aArgs);
}
return $datas;
}
/**
* Compute the fingerprint of a resource
* @param string $path path of the resource
* @param string $fingerprintMode (md5, sha512, ...)
* @return string the fingerprint
*/
public function doFingerprint($aArgs)
{
if (empty($aArgs['path'])) {
$datas = [
'errors' => 'path ' . _EMPTY,
];
return $datas;
}
if (!file_exists($aArgs['path'])) {
$datas = [
'errors' => 'path ' . _NOT_EXISTS,
];
return $datas;
}
if ($aArgs['fingerprintMode'] == 'NONE' ||
$aArgs['fingerprintMode'] == ''
) {
$datas = [
'fingerprint' => '0',
];
return $datas;
} else {
$fingerprint = hash_file(
strtolower($aArgs['fingerprintMode']),
$aArgs['path']
);
$datas = [
'fingerprint' => $fingerprint,
];
return $datas;
}
}
/**
* Control fingerprint between two resources
* @param string $pathInit path of the resource 1
* @param string $pathTarget path of the resource 2
* @param string $fingerprintMode (md5, sha512, ...)
* @return array ok or ko with error
*/
public function controlFingerprint($aArgs)
{
if (empty($aArgs['pathInit'])) {
$datas = [
'errors' => 'pathInit ' . _EMPTY,
];
return $datas;
}
if (!file_exists($aArgs['pathInit'])) {
$datas = [
'errors' => 'pathInit ' . _NOT_EXISTS,
];
return $datas;
}
if (empty($aArgs['pathTarget'])) {
$datas = [
'errors' => 'pathTarget ' . _EMPTY,
];
return $datas;
}
if (!file_exists($aArgs['pathTarget'])) {
$datas = [
'errors' => 'pathTarget ' . _NOT_EXISTS,
];
return $datas;
}
$aArgsSrc = [
'path' => $aArgs['pathInit'],
'fingerprintMode' => $aArgs['fingerprintMode'],
];
$aArgsTarget = [
'path' => $aArgs['pathTarget'],
'fingerprintMode' => $aArgs['fingerprintMode'],
];
if ($this->doFingerprint($aArgsSrc) <> $this->doFingerprint($aArgsTarget)) {
$datas = [
'errors' => PB_WITH_FINGERPRINT_OF_DOCUMENT . ' ' . $aArgs['pathInit']
. ' '. _AND . ' ' . $aArgs['pathTarget'],
];
} else {
$datas = [
'controlFingerprint' => true,
];
}
return $datas;
}
/**
* del tmp files
* @param $path dir to wash
* @param $contentOnly boolean true if only the content
* @return boolean
*/
public function washTmp($aArgs)
{
if (empty($aArgs['path'])) {
$datas = [
'errors' => 'path ' . _EMPTY,
];
return $datas;
}
if (!is_dir($aArgs['path'])) {
$datas = [
'errors' => 'path ' . _NOT_EXISTS,
];
return $datas;
}
if (!is_bool($aArgs['contentOnly'])) {
$datas = [
'errors' => 'contentOnly ' . _NOT . ' ' . _VALID,
];
return $datas;
}
$objects = scandir($aArgs['path']);
foreach ($objects as $object) {
if ($object != '.' && $object != '..') {
if (filetype($aArgs['path'] . DIRECTORY_SEPARATOR . $object) == 'dir') {
$this->washTmp(
['path' => $aArgs['path'] . DIRECTORY_SEPARATOR . $object]
);
} else {
unlink($aArgs['path'] . DIRECTORY_SEPARATOR . $object);
}
}
}
reset($objects);
if (!$aArgs['contentOnly']) {
rmdir($aArgs['path']);
}
$datas = [
'washTmp' => true,
];
return $datas;
}
}
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