diff --git a/.gitignore b/.gitignore index 68d9b18a30796dc29252485adb292981585c3ec3..1c765e659bf4f50b70c421e758ecb64ecba6d8c9 100755 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ core/Test/build/ apps/maarch_entreprise/tmp/* /nbproject/private/apps/maarch_entreprise/define_custom.php apps/maarch_entreprise/js/angular/main.bundle.js +modules/convert/batch/scripts/launch_fulltext_letterbox.sh +modules/convert/batch/scripts/launch_convert_letterbox.sh +modules/convert/batch/config/config_only_indexes.xml +modules/convert/batch/tmp/ diff --git a/core/Controllers/DocserverController.php b/core/Controllers/DocserverController.php index d8813ff39e4689fb1301ffcaa7891e141cfdc484..b011be2edcd145afe37197d84f48c3632d2c4198 100755 --- a/core/Controllers/DocserverController.php +++ b/core/Controllers/DocserverController.php @@ -107,7 +107,7 @@ class DocserverController umask(0022); chmod($monthPath, 0770); } else { - return ['errors' => '[createPathOnDocServer] Folder alreay exists, workbatch already exist:' . $pathToDS]; + //return ['errors' => '[createPathOnDocServer] Folder alreay exists, workbatch already exist:' . $pathToDS]; } } diff --git a/core/Controllers/StoreController.php b/core/Controllers/StoreController.php index 521ff4424e52930253eb6f4c958e6564b2e116dd..42aa78df6df0c15586e4c69a0a255c3dcbec658d 100644 --- a/core/Controllers/StoreController.php +++ b/core/Controllers/StoreController.php @@ -99,7 +99,8 @@ class StoreController return ['errors' => '[storeRessourceOnDocserver] FileInfos.tmpDir does not exist']; } if (!file_exists($aArgs['fileInfos']['tmpDir'] . $aArgs['fileInfos']['tmpFileName'])) { - return ['errors' => '[storeRessourceOnDocserver] FileInfos.tmpFileName does not exist']; + return ['errors' => '[storeRessourceOnDocserver] FileInfos.tmpFileName does not exist ' + . $aArgs['fileInfos']['tmpDir'] . $aArgs['fileInfos']['tmpFileName']]; } $aArgs['docserverTypeId'] = empty($aArgs['docserverTypeId']) ? 'DOC' : $aArgs['docserverTypeId']; diff --git a/core/Models/DatabasePDO.php b/core/Models/DatabasePDO.php index 83685fbdeaa4ad637fdaad5aa096237a1bd37f1b..9422820642cb1a4cb4e103d28919da0baabcc2d5 100755 --- a/core/Models/DatabasePDO.php +++ b/core/Models/DatabasePDO.php @@ -35,6 +35,19 @@ class DatabasePDO $path = 'apps/maarch_entreprise/xml/config.xml'; } + if (!file_exists($path)) { + if ( + file_exists($GLOBALS['MaarchDirectory'] + . "custom/{$customId}/apps/maarch_entreprise/xml/config.xml") + ) { + $path = $GLOBALS['MaarchDirectory'] + . "custom/{$customId}/apps/maarch_entreprise/xml/config.xml"; + } else { + $path = $GLOBALS['MaarchDirectory'] + . 'apps/maarch_entreprise/xml/config.xml'; + } + } + $server = ''; $port = ''; $name = ''; diff --git a/modules/convert/Controllers/ProcessConvertController.php b/modules/convert/Controllers/ProcessConvertController.php index f5b63b707d496a51b9d1f7e6f3baa2adc3b5d31e..27276ed007cdaf2878507e24b7d588af8f39648d 100644 --- a/modules/convert/Controllers/ProcessConvertController.php +++ b/modules/convert/Controllers/ProcessConvertController.php @@ -131,7 +131,7 @@ class ProcessConvertController } $res = ResModel::getById(['resId' => $resId, 'resTable' => $args['resTable']]); - + if ($res['res_id'] <> '') { $resourcePath = ResDocserverModel::getSourceResourcePath( [ @@ -182,7 +182,6 @@ class ProcessConvertController 'error' => '', ); } - if ($resultOfConversion['status'] <> '0') { ProcessConvertModel::manageErrorOnDb( ['resTable' => $resTable, 'resId' => $resId, 'result' => '-1'] @@ -194,7 +193,7 @@ class ProcessConvertController $storeResult = StoreController::storeResourceOnDocServer([ 'collId' => $collId, 'fileInfos' => [ - 'tmpDir' => CoreConfigModel::getTmpPath(), + 'tmpDir' => $tmpDir, 'size' => filesize($fileNameOnTmp), 'format' => 'PDF', 'tmpFileName' => pathinfo($fileNameOnTmp, PATHINFO_FILENAME) . '.pdf', @@ -202,7 +201,6 @@ class ProcessConvertController 'docserverTypeId' => 'CONVERT' ]); - if (empty($storeResult)) { $returnArray = array( 'status' => '1', @@ -216,6 +214,19 @@ class ProcessConvertController return $returnArray; } + if (!empty($storeResult['errors'])) { + $returnArray = array( + 'status' => '1', + 'value' => '', + 'error' => $storeResult['errors'] . ' error for convert:' + . $fileNameOnTmp, + ); + ProcessConvertModel::manageErrorOnDb( + ['resTable' => $resTable, 'resId' => $resId, 'result' => '-1'] + ); + return $returnArray; + } + $targetDs = DocserverModel::getById(['id' => $storeResult['docserver_id']]); // LogsController::info(['message'=>'avant update', 'code'=>19, ]); diff --git a/modules/convert/Controllers/ProcessFulltextController.php b/modules/convert/Controllers/ProcessFulltextController.php index 3d39152c58efae9114c73641f97a9f4eab21cf9d..54a3a3bf514e2228741a0d6e723339839a53d7a7 100644 --- a/modules/convert/Controllers/ProcessFulltextController.php +++ b/modules/convert/Controllers/ProcessFulltextController.php @@ -43,19 +43,19 @@ class ProcessFulltextController public function __construct($pdftotext = 'pdftotext') { - // Storing text in lucpreene index + // Storing text in lucene index set_include_path('apps/maarch_entreprise/tools/' . PATH_SEPARATOR . get_include_path() ); - if(!@include('Zend/Search/Lucene.php')) { + //if(!@include('Zend/Search/Lucene.php')) { set_include_path($GLOBALS['MaarchDirectory'] . 'apps/maarch_entreprise/tools/' . PATH_SEPARATOR . get_include_path() ); require_once("Zend/Search/Lucene.php"); - } + //} $this->pdftotext = $pdftotext; } @@ -256,7 +256,7 @@ class ProcessFulltextController $storeResult = StoreController::storeResourceOnDocServer([ 'collId' => $collId, 'fileInfos' => [ - 'tmpDir' => CoreConfigModel::getTmpPath(), + 'tmpDir' => $tmpDir, 'size' => filesize($fileNameOnTmp), 'format' => 'TXT', 'tmpFileName' => pathinfo($fileNameOnTmp, PATHINFO_FILENAME) . '.txt', diff --git a/modules/convert/Controllers/ProcessManageConvertController.php b/modules/convert/Controllers/ProcessManageConvertController.php index 4d8964681b90ff901e60443e140baff5a96ff719..0c0afa889f2565a9d719af1886222c7614f3ad6a 100644 --- a/modules/convert/Controllers/ProcessManageConvertController.php +++ b/modules/convert/Controllers/ProcessManageConvertController.php @@ -188,8 +188,10 @@ class ProcessManageConvertController 'path_to_lucene' => $path_to_lucene ); } - $ProcessConvertService = new ProcessFulltextController(); - $resultOfConversion = $ProcessConvertService->fulltext($params); + $ProcessConvertServiceFulltext = new ProcessFulltextController(); + + $resultOfConversion = $ProcessConvertServiceFulltext->fulltext($params); + if ($resultOfConversion['status'] <> '0') { $returnArray = array( 'status' => '1', diff --git a/modules/convert/Controllers/ProcessThumbnailsController.php b/modules/convert/Controllers/ProcessThumbnailsController.php index c5c9b23b43e183b6c9360fc497169f49eeb6308e..39a4545e0fdb49b886d5dfbd8c3ca73f8f935f61 100644 --- a/modules/convert/Controllers/ProcessThumbnailsController.php +++ b/modules/convert/Controllers/ProcessThumbnailsController.php @@ -199,7 +199,7 @@ class ProcessThumbnailsController $storeResult = StoreController::storeResourceOnDocServer([ 'collId' => $collId, 'fileInfos' => [ - 'tmpDir' => CoreConfigModel::getTmpPath(), + 'tmpDir' => $tmpDir, 'size' => filesize($fileNameOnTmp), 'format' => 'PNG', 'tmpFileName' => pathinfo($fileNameOnTmp, PATHINFO_FILENAME) . '.png', diff --git a/modules/convert/Test/ProcessConvertTest.php b/modules/convert/Test/ProcessConvertTest.php index c25c0dcc3e38cd6cda86ad86ecb6707084e2b812..301729d109adbe399a24d6131eb5986cf1c5f7d6 100644 --- a/modules/convert/Test/ProcessConvertTest.php +++ b/modules/convert/Test/ProcessConvertTest.php @@ -22,23 +22,13 @@ class ProcessConvertTest extends TestCase ] ); - $path = $_SESSION['config']['tmppath'] . '/test/'; + $samplePath = 'modules/convert/Test/Samples/'; - if (!is_dir($path)) { - mkdir($path); - } - - $fileSource = 'test_source.txt'; - - if (file_exists($path . $fileSource)) { - unlink($path . $fileSource); - } - - $fp = fopen($path . $fileSource, 'a'); - fwrite($fp, 'a unit test for PHP CONVERSION lorem ipsum...'); - fclose($fp); + //SAMPLE TXT + $fileSource = 'test.txt'; + $fileFormat = 'txt'; - $fileContent = file_get_contents($path . $fileSource, FILE_BINARY); + $fileContent = file_get_contents($samplePath . $fileSource, FILE_BINARY); $encodedFile = base64_encode($fileContent); //echo $encodedFile . PHP_EOL;exit; @@ -48,7 +38,7 @@ class ProcessConvertTest extends TestCase $data, array( 'column' => 'subject', - 'value' => 'UNIT TEST from slim', + 'value' => 'UNIT TEST CONVERT from slim', 'type' => 'string', ) ); @@ -85,7 +75,7 @@ class ProcessConvertTest extends TestCase 'data' => $data, 'collId' => 'letterbox_coll', 'table' => 'res_letterbox', - 'fileFormat' => 'txt', + 'fileFormat' => $fileFormat, 'status' => 'new', ]; diff --git a/modules/convert/Test/ProcessManageConvertTest.php b/modules/convert/Test/ProcessManageConvertTest.php index 470e953f990a6b55362e5295a0b389e1f1a45bb3..106657787f8e15e0cd1ce9fd81c40709484f3f14 100644 --- a/modules/convert/Test/ProcessManageConvertTest.php +++ b/modules/convert/Test/ProcessManageConvertTest.php @@ -22,23 +22,205 @@ class ManageProcessConvertTest extends TestCase ] ); - $path = $_SESSION['config']['tmppath'] . '/test/'; + $samplePath = 'modules/convert/Test/Samples/'; - if (!is_dir($path)) { - mkdir($path); - } + //SAMPLE TXT + $fileSource = 'test.txt'; + $fileFormat = 'txt'; - $fileSource = 'test_source.txt'; + $fileContent = file_get_contents($samplePath . $fileSource, FILE_BINARY); + $encodedFile = base64_encode($fileContent); + //echo $encodedFile . PHP_EOL;exit; + + $data = []; + + array_push( + $data, + array( + 'column' => 'subject', + 'value' => 'UNIT TEST CONVERT ALL from slim with ' . $fileFormat . ' file', + 'type' => 'string', + ) + ); + + array_push( + $data, + array( + 'column' => 'type_id', + 'value' => 110, + 'type' => 'integer', + ) + ); + + array_push( + $data, + array( + 'column' => 'custom_t1', + 'value' => 'TEST', + 'type' => 'string', + ) + ); + + array_push( + $data, + array( + 'column' => 'custom_t10', + 'value' => 'lgi@maarch.org', + 'type' => 'string', + ) + ); + + $aArgs = [ + 'encodedFile' => $encodedFile, + 'data' => $data, + 'collId' => 'letterbox_coll', + 'table' => 'res_letterbox', + 'fileFormat' => $fileFormat, + 'status' => 'new', + ]; + + $request = \Slim\Http\Request::createFromEnvironment($environment); + $response = new \Slim\Http\Response(); + $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + $response = $action->create($fullRequest, $response); + $responseBody = json_decode((string)$response->getBody()); + + $resIdTxt = $responseBody->resId; + + //SAMPLE PDF + $fileSource = 'test.pdf'; + $fileFormat = 'pdf'; + + $fileContent = file_get_contents($samplePath . $fileSource, FILE_BINARY); + $encodedFile = base64_encode($fileContent); + //echo $encodedFile . PHP_EOL;exit; + + $data = []; + + array_push( + $data, + array( + 'column' => 'subject', + 'value' => 'UNIT TEST CONVERT ALL from slim with ' . $fileFormat . ' file', + 'type' => 'string', + ) + ); + + array_push( + $data, + array( + 'column' => 'type_id', + 'value' => 110, + 'type' => 'integer', + ) + ); + + array_push( + $data, + array( + 'column' => 'custom_t1', + 'value' => 'TEST', + 'type' => 'string', + ) + ); + + array_push( + $data, + array( + 'column' => 'custom_t10', + 'value' => 'lgi@maarch.org', + 'type' => 'string', + ) + ); + + $aArgs = [ + 'encodedFile' => $encodedFile, + 'data' => $data, + 'collId' => 'letterbox_coll', + 'table' => 'res_letterbox', + 'fileFormat' => $fileFormat, + 'status' => 'new', + ]; + + $request = \Slim\Http\Request::createFromEnvironment($environment); + $response = new \Slim\Http\Response(); + $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + $response = $action->create($fullRequest, $response); + $responseBody = json_decode((string)$response->getBody()); + + $resIdPdf = $responseBody->resId; + + //SAMPLE ODT + $fileSource = 'test.odt'; + $fileFormat = 'odt'; + + $fileContent = file_get_contents($samplePath . $fileSource, FILE_BINARY); + $encodedFile = base64_encode($fileContent); + //echo $encodedFile . PHP_EOL;exit; - if (file_exists($path . $fileSource)) { - unlink($path . $fileSource); - } + $data = []; - $fp = fopen($path . $fileSource, 'a'); - fwrite($fp, 'a unit test for PHP CONVERSION lorem ipsum...'); - fclose($fp); + array_push( + $data, + array( + 'column' => 'subject', + 'value' => 'UNIT TEST CONVERT ALL from slim with ' . $fileFormat . ' file', + 'type' => 'string', + ) + ); - $fileContent = file_get_contents($path . $fileSource, FILE_BINARY); + array_push( + $data, + array( + 'column' => 'type_id', + 'value' => 110, + 'type' => 'integer', + ) + ); + + array_push( + $data, + array( + 'column' => 'custom_t1', + 'value' => 'TEST', + 'type' => 'string', + ) + ); + + array_push( + $data, + array( + 'column' => 'custom_t10', + 'value' => 'lgi@maarch.org', + 'type' => 'string', + ) + ); + + $aArgs = [ + 'encodedFile' => $encodedFile, + 'data' => $data, + 'collId' => 'letterbox_coll', + 'table' => 'res_letterbox', + 'fileFormat' => $fileFormat, + 'status' => 'new', + ]; + + $request = \Slim\Http\Request::createFromEnvironment($environment); + $response = new \Slim\Http\Response(); + $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + $response = $action->create($fullRequest, $response); + $responseBody = json_decode((string)$response->getBody()); + + $resIdOdt = $responseBody->resId; + + //SAMPLE HTML + $fileSource = 'test.html'; + $fileFormat = 'html'; + + $fileContent = file_get_contents($samplePath . $fileSource, FILE_BINARY); $encodedFile = base64_encode($fileContent); //echo $encodedFile . PHP_EOL;exit; @@ -48,7 +230,7 @@ class ManageProcessConvertTest extends TestCase $data, array( 'column' => 'subject', - 'value' => 'UNIT TEST from slim', + 'value' => 'UNIT TEST CONVERT ALL from slim with ' . $fileFormat . ' file', 'type' => 'string', ) ); @@ -85,7 +267,7 @@ class ManageProcessConvertTest extends TestCase 'data' => $data, 'collId' => 'letterbox_coll', 'table' => 'res_letterbox', - 'fileFormat' => 'txt', + 'fileFormat' => $fileFormat, 'status' => 'new', ]; @@ -96,13 +278,77 @@ class ManageProcessConvertTest extends TestCase $response = $action->create($fullRequest, $response); $responseBody = json_decode((string)$response->getBody()); - $resId = $responseBody->resId; + $resIdHtml = $responseBody->resId; + + /***************************************************************************/ + + //test TXT + $request = \Slim\Http\Request::createFromEnvironment($environment); + $action = new \Convert\Controllers\ProcessManageConvertController(); + + $aArgs = [ + 'collId' => 'letterbox_coll', + 'resTable' => 'res_letterbox', + 'adrTable' => 'adr_letterbox', + 'resId' => $resIdTxt, + 'tmpDir' => $_SESSION['config']['tmppath'], + 'createZendIndex' => true + ]; + + $response = new \Slim\Http\Response(); + $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + $response = $action->create($fullRequest, $response); + $responseBody = json_decode((string)$response->getBody()); + $status = $responseBody->status; + + $this->assertEquals('0', $status); + + //test PDF + $request = \Slim\Http\Request::createFromEnvironment($environment); + $action = new \Convert\Controllers\ProcessManageConvertController(); + + $aArgs = [ + 'collId' => 'letterbox_coll', + 'resTable' => 'res_letterbox', + 'adrTable' => 'adr_letterbox', + 'resId' => $resIdPdf, + 'tmpDir' => $_SESSION['config']['tmppath'], + 'createZendIndex' => true + ]; + + $response = new \Slim\Http\Response(); + $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + $response = $action->create($fullRequest, $response); + $responseBody = json_decode((string)$response->getBody()); + $status = $responseBody->status; + + $this->assertEquals('0', $status); + + //test ODT + $request = \Slim\Http\Request::createFromEnvironment($environment); + $action = new \Convert\Controllers\ProcessManageConvertController(); + + $aArgs = [ + 'collId' => 'letterbox_coll', + 'resTable' => 'res_letterbox', + 'adrTable' => 'adr_letterbox', + 'resId' => $resIdOdt, + 'tmpDir' => $_SESSION['config']['tmppath'], + 'createZendIndex' => true + ]; + + $response = new \Slim\Http\Response(); + $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); + + $response = $action->create($fullRequest, $response); + $responseBody = json_decode((string)$response->getBody()); + $status = $responseBody->status; - if (!defined("_RES_ID_TEST_CONVERT")) { - define("_RES_ID_TEST_CONVERT", $resId); - } + $this->assertEquals('0', $status); - //real test + //test HTML $request = \Slim\Http\Request::createFromEnvironment($environment); $action = new \Convert\Controllers\ProcessManageConvertController(); @@ -110,7 +356,7 @@ class ManageProcessConvertTest extends TestCase 'collId' => 'letterbox_coll', 'resTable' => 'res_letterbox', 'adrTable' => 'adr_letterbox', - 'resId' => _RES_ID_TEST_CONVERT, + 'resId' => $resIdHtml, 'tmpDir' => $_SESSION['config']['tmppath'], 'createZendIndex' => true ]; diff --git a/modules/convert/Test/Samples/test.html b/modules/convert/Test/Samples/test.html new file mode 100644 index 0000000000000000000000000000000000000000..974952b211c429304d9dd8d28c22e6a0eb9a1209 --- /dev/null +++ b/modules/convert/Test/Samples/test.html @@ -0,0 +1,8 @@ +<html><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"></head> + <!--<body id="validation_page" + onload="javascript:moveTo(0,0);"> + <div id="template_content" style="width:100%;">--> + <body><p style="text-align: center;" data-mce-style="text-align: center;"><span style="font-size: small; text-decoration: underline;" data-mce-style="font-size: small; text-decoration: underline;">ENREGISTREMENT DEMANDE Allo Mairie - DIVERS</span></p><p style="text-align: center;" data-mce-style="text-align: center;"> </p><table style="border: 1pt solid #000000; width: 800px; background-color: #40a497;" data-mce-style="border: 1pt solid #000000; width: 800px; background-color: #40a497;" cellpadding="5" cellspacing="1" border="1"><tbody><tr><td style="width: 200px;" data-mce-style="width: 200px;">DECLARATION DU BESOIN</td><td>DATE: 17-11-2015</td><td>HEURE: 18:01:46</td></tr></tbody></table><table style="border: 1pt solid #000000; width: 800px;" data-mce-style="border: 1pt solid #000000; width: 800px;" cellpadding="5" cellspacing="1" border="1"><tbody><tr><td style="width: 200px; background-color: #40a497;" data-mce-style="width: 200px; background-color: #40a497;">OBJET</td><td style="background-color: #bef3ec;" data-mce-style="background-color: #bef3ec;"> laurent</td></tr><tr><td style="width: 200px; background-color: #40a497;" data-mce-style="width: 200px; background-color: #40a497;">DATE ET HEURE ESTIMEES DU DECLENCHEMENT</td><td> </td></tr><tr><td style="width: 200px; background-color: #40a497;" data-mce-style="width: 200px; background-color: #40a497;">IMPLANTATION / LOCALISATION</td><td style="background-color: #bef3ec;" data-mce-style="background-color: #bef3ec;"> montest</td></tr><tr><td style="width: 200px; background-color: #40a497;" data-mce-style="width: 200px; background-color: #40a497;">DESCRIPTION</td><td> </td></tr><tr><td style="width: 200px; background-color: #40a497;" data-mce-style="width: 200px; background-color: #40a497;">ETENDUE DU PROBLEME</td><td style="background-color: #bef3ec;" data-mce-style="background-color: #bef3ec;"> </td></tr><tr><td style="width: 200px; background-color: #40a497;" data-mce-style="width: 200px; background-color: #40a497;">NATURE DU DESAGREMENT</td><td> </td></tr><tr><td style="width: 200px; background-color: #40a497;" data-mce-style="width: 200px; background-color: #40a497;">DELAIS DE TRAITEMENT SOUHAITE</td><td style="background-color: #bef3ec;" data-mce-style="background-color: #bef3ec;"> </td></tr><tr><td style="width: 200px; background-color: #40a497;" data-mce-style="width: 200px; background-color: #40a497;">AUTRES OBSERVATIONS</td><td> </td></tr></tbody></table><p><br data-mce-bogus="1"></p> <!--</div> + </body> + </html>--> + </body></html> \ No newline at end of file diff --git a/modules/convert/Test/Samples/test.odt b/modules/convert/Test/Samples/test.odt new file mode 100644 index 0000000000000000000000000000000000000000..3038c23914d8df78dbda22d8437ab599bf36509b Binary files /dev/null and b/modules/convert/Test/Samples/test.odt differ diff --git a/modules/convert/Test/Samples/test.pdf b/modules/convert/Test/Samples/test.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f698ff53d41575b222e6778f87f9e9fd8da4f2b1 Binary files /dev/null and b/modules/convert/Test/Samples/test.pdf differ diff --git a/modules/convert/Test/Samples/test.txt b/modules/convert/Test/Samples/test.txt new file mode 100644 index 0000000000000000000000000000000000000000..322dd17d9e0c31454494e3ccac534ada7a156000 --- /dev/null +++ b/modules/convert/Test/Samples/test.txt @@ -0,0 +1 @@ +a unit test for PHP CONVERSION lorem ipsum... \ No newline at end of file diff --git a/modules/convert/batch/LoggerLog4php.php b/modules/convert/batch/LoggerLog4php.php index 5859a92f31f19d495f57e40a68d2ac6f65cda317..22eb7fab0ec1991a89d935a48175b59b5a55f4d2 100644 --- a/modules/convert/batch/LoggerLog4php.php +++ b/modules/convert/batch/LoggerLog4php.php @@ -1,5 +1,12 @@ <?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. + * + */ + /** Logger class * * @author Laurent Giovannoni <dev@maarch.org> diff --git a/modules/convert/batch/batch_tools.php b/modules/convert/batch/batch_tools.php index e5abba1c524f9a67cff99270dd296dd954e49983..8b55200228fc7c1a9a0a28a0511a9ed4d1fa0f73 100644 --- a/modules/convert/batch/batch_tools.php +++ b/modules/convert/batch/batch_tools.php @@ -1,22 +1,10 @@ <?php -/* - * Copyright 2008-2016 Maarch - * - * This file is part of Maarch Framework. - * - * Maarch Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Maarch Framework is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. +/** + * 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. * - * You should have received a copy of the GNU General Public License - * along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. */ /** diff --git a/modules/convert/batch/config/config.xml b/modules/convert/batch/config/config.xml index 3416184920d9818d1da2acc25142cd0abe50518e..ea4fbc747590b133d6759a22dac074512be23ab4 100644 --- a/modules/convert/batch/config/config.xml +++ b/modules/convert/batch/config/config.xml @@ -2,11 +2,11 @@ <ROOT> <CONFIG> <Lang>fr</Lang> <!-- fr, en--> - <MaarchDirectory>/var/www/html/oem_V2/</MaarchDirectory> - <TmpDirectory>/var/www/html/oem_V2/modules/convert/batch/tmp/</TmpDirectory> + <MaarchDirectory>/var/www/html/MaarchCourrier/</MaarchDirectory> + <TmpDirectory>/var/www/html/MaarchCourrier/modules/convert/batch/tmp/</TmpDirectory> <LogLevel>INFO</LogLevel> <!-- DEBUG, INFO, NOTICE, WARNING, ERROR--> <DisplayedLogLevel>INFO</DisplayedLogLevel> <!-- DEBUG, INFO, NOTICE, WARNING, ERROR--> - <StackSizeLimit>50</StackSizeLimit> + <StackSizeLimit>1000</StackSizeLimit> <ApacheUserAndGroup>lgi:lgi</ApacheUserAndGroup> <UnoconvPath>unoconv</UnoconvPath> <!-- only for Windows --> <OpenOfficePath>soffice</OpenOfficePath> <!-- only for Windows --> @@ -31,7 +31,7 @@ <databaseserver>127.0.0.1</databaseserver> <databaseserverport>5432</databaseserverport> <databasetype>POSTGRESQL</databasetype> - <databasename>sipol_v2</databasename> + <databasename>MaarchCourrier</databasename> <databaseuser>maarch</databaseuser> <databasepassword>maarch</databasepassword> </CONFIG_BASE> @@ -50,44 +50,16 @@ <path_to_lucene_index>/opt/maarch/docservers/indexes/attachments_coll/</path_to_lucene_index> </COLLECTION> <COLLECTION> - <Id>attachments_version_coll</Id> + <Id>version_attachments_coll</Id> <Table>res_version_attachments</Table> <View>res_version_attachments</View> <Adr>adr_attachments_version</Adr> - <path_to_lucene_index>/opt/maarch/docservers/indexes/attachments_version_coll/</path_to_lucene_index> - </COLLECTION> - <COLLECTION> - <Id>calendar_coll</Id> - <Table>calendar_event_attachments</Table> - <View>calendar_event_attachments</View> - <Adr>calendar_event_adr_attachments</Adr> - <path_to_lucene_index>/opt/maarch/docservers/indexes/calendar_coll/</path_to_lucene_index> - </COLLECTION> - <COLLECTION> - <Id>folder_coll</Id> - <Table>res_folder</Table> - <View>res_folder</View> - <Adr>adr_folder</Adr> - <path_to_lucene_index>/opt/maarch/docservers/indexes/folder_coll/</path_to_lucene_index> - </COLLECTION> - <COLLECTION> - <Id>chrono_coll</Id> - <Table>res_chrono</Table> - <View>res_chrono</View> - <Adr>adr_chrono</Adr> - <path_to_lucene_index>/opt/maarch/docservers/indexes/chrono_coll/</path_to_lucene_index> - </COLLECTION> - <COLLECTION> - <Id>reprise_coll</Id> - <Table>res_reprise</Table> - <View>res_reprise</View> - <Adr>adr_reprise</Adr> - <path_to_lucene_index>/opt/maarch/docservers/indexes/reprise_coll/</path_to_lucene_index> + <path_to_lucene_index>/opt/maarch/docservers/indexes/version_attachments_coll/</path_to_lucene_index> </COLLECTION> <LOG4PHP> <enabled>true</enabled> <Log4PhpLogger>loggerTechnique</Log4PhpLogger> <Log4PhpBusinessCode>Convert</Log4PhpBusinessCode> - <Log4PhpConfigPath>/var/www/html/oem_V2/apps/maarch_entreprise/xml/log4php.xml</Log4PhpConfigPath> + <Log4PhpConfigPath>/var/www/html/MaarchCourrier/apps/maarch_entreprise/xml/log4php.xml</Log4PhpConfigPath> </LOG4PHP> -</ROOT> +</ROOT> \ No newline at end of file diff --git a/modules/convert/batch/fill_stack.php b/modules/convert/batch/fill_stack.php index 47ebbe5f654a6669d3cc06aa71b0f505f4a2fb06..b7ae35bf5ee0e03f169f163ed70595d7728cab8c 100644 --- a/modules/convert/batch/fill_stack.php +++ b/modules/convert/batch/fill_stack.php @@ -1,22 +1,10 @@ <?php -/* - * Copyright 2008-2016 Maarch - * - * This file is part of Maarch Framework. - * - * Maarch Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Maarch Framework is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. +/** + * 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. * - * You should have received a copy of the GNU General Public License - * along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. */ /** @@ -84,14 +72,22 @@ while ($state <> 'END') { /* Checking if the stack is full */ /**********************************************************************/ case 'CONTROL_STACK' : - $query = "select * from convert_stack " + //ONLY FOR TEST + $query = "truncate table convert_stack"; + $stmt = Bt_doQuery( + $GLOBALS['db'], + $query + ); + + $query = "select count(1) as cpt from convert_stack " . " where coll_id = ? and regex = ?"; $stmt = Bt_doQuery( $GLOBALS['db'], $query, array($GLOBALS['collection'], $GLOBALS['regExResId']) ); - if ($stmt->rowCount() > 0) { + $resultCpt = $stmt->fetchObject(); + if ($resultCpt->cpt > 0) { Bt_exitBatch(107, 'stack is full for collection:' . $GLOBALS['collection'] . ', regex:' . $GLOBALS['regExResId'] @@ -132,8 +128,9 @@ while ($state <> 'END') { ); $stmt = Bt_doQuery($GLOBALS['db'], $query); $resourcesArray = array(); + $stmtCpt = $stmt; - if ($stmt->rowCount() > 0) { + if ($stmtCpt->fetchObject()->res_id > 0) { while ($resoucesRecordset = $stmt->fetchObject()) { array_push( $resourcesArray, @@ -189,7 +186,8 @@ while ($state <> 'END') { $query ); $resourcesArray = array(); - if ($stmt->rowCount() > 0) { + $stmtCpt = $stmt; + if ($stmtCpt->fetchObject()->res_id > 0) { while ($resoucesRecordset = $stmt->fetchObject()) { array_push( $resourcesArray, diff --git a/modules/convert/batch/load_fill_stack.php b/modules/convert/batch/load_fill_stack.php index 559abc01086b4150e9b7d9ba66b6b4e4a3e16ce5..3721e3515a0e0fb22a8c98dd3e8a3a2ece853e24 100644 --- a/modules/convert/batch/load_fill_stack.php +++ b/modules/convert/batch/load_fill_stack.php @@ -1,22 +1,10 @@ <?php -/* - * Copyright 2008-2016 Maarch - * - * This file is part of Maarch Framework. - * - * Maarch Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Maarch Framework is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. +/** + * 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. * - * You should have received a copy of the GNU General Public License - * along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. */ /** @@ -297,6 +285,7 @@ unset($xmlconfig); // Include library try { + Bt_myInclude($GLOBALS['MaarchDirectory'] . 'vendor/autoload.php'); Bt_myInclude($GLOBALS['MaarchDirectory'] . 'core/class/class_functions.php'); Bt_myInclude($GLOBALS['MaarchDirectory'] . 'core/class/class_db.php'); Bt_myInclude($GLOBALS['MaarchDirectory'] . 'core/class/class_db_pdo.php'); @@ -305,7 +294,7 @@ try { Bt_myInclude($GLOBALS['MaarchDirectory'] . 'core/class/docservers_controler.php'); Bt_myInclude($GLOBALS['MaarchDirectory'] . 'core/docservers_tools.php'); Bt_myInclude($GLOBALS['MaarchDirectory'] . 'core/class/docserver_types_controler.php'); - Bt_myInclude($GLOBALS['MaarchDirectory'] . 'modules/convert/services/ManageConvert.php'); + //Bt_myInclude($GLOBALS['MaarchDirectory'] . 'modules/convert/services/ManageConvert.php'); } catch (IncludeFileError $e) { $GLOBALS['logger']->write( 'Problem with the php include path:' @@ -314,24 +303,27 @@ try { exit(111); } if (!is_dir($GLOBALS['tmpDirectoryRoot'])) { - $GLOBALS['logger']->write( - 'Problem with the tmp dir:' . $GLOBALS['tmpDirectory'], 'ERROR', 17 - ); - exit(17); + mkdir($GLOBALS['tmpDirectoryRoot']); + // echo PHP_EOL.'tmpDirectoryRoot '.$GLOBALS['tmpDirectoryRoot'].PHP_EOL; + // $GLOBALS['logger']->write( + // 'Problem with the tmp dir:' . $GLOBALS['tmpDirectoryRoot'], 'ERROR', 17 + // ); + // exit(17); } $coreTools = new core_tools(); $coreTools->load_lang($lang, $GLOBALS['MaarchDirectory'], $MaarchApps); session_start(); $_SESSION['modules_loaded'] = array(); +$_SESSION['user']['UserId'] = 'BOT_CONVERT'; $GLOBALS['func'] = new functions(); $GLOBALS['db'] = new Database($GLOBALS['configFile']); $GLOBALS['db2'] = new Database($GLOBALS['configFile']); $GLOBALS['db3'] = new Database($GLOBALS['configFile']); $GLOBALS['dbLog'] = new Database($GLOBALS['configFile']); $GLOBALS['docserverControler'] = new docservers_controler(); -$GLOBALS['processConvert'] = new Convert_ManageConvert_Service($GLOBALS['openOfficePath']); -$GLOBALS['processIndexes'] = new Convert_ProcessFulltext_Service(); +$GLOBALS['processConvert'] = new \Convert\Controllers\ProcessManageConvertController($GLOBALS['openOfficePath']); +$GLOBALS['processIndexes'] = new \Convert\Controllers\ProcessFulltextController(); $configFileName = basename($GLOBALS['configFile'], '.xml'); $GLOBALS['errorLckFile'] = $GLOBALS['batchDirectory'] . '/' diff --git a/modules/convert/batch/process_stack.php b/modules/convert/batch/process_stack.php index 969d610b8b3b0df9f6133d289cba9fa9bb6884a3..c5d46ecbf4536a054f6d17fd4d600c17b68ad7c1 100644 --- a/modules/convert/batch/process_stack.php +++ b/modules/convert/batch/process_stack.php @@ -1,22 +1,10 @@ <?php -/* - * Copyright 2008-2016 Maarch - * - * This file is part of Maarch Framework. - * - * Maarch Framework is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Maarch Framework is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. +/** + * 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. * - * You should have received a copy of the GNU General Public License - * along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. */ /** @@ -122,7 +110,8 @@ while ($GLOBALS['state'] <> "END") { $query, array($GLOBALS['collection']) ); - if ($stmt->rowCount() == 0) { + $stmtCpt = $stmt; + if ($stmtCpt->fetchObject()->docserver_id == '') { Bt_exitBatch(13, 'Docserver not found'); break; } else { @@ -151,7 +140,8 @@ while ($GLOBALS['state'] <> "END") { $GLOBALS['wb'] ) ); - if ($stmt->rowCount() == 0) { + $stackRecordset = $stmt->fetchObject(); + if (!($stackRecordset->res_id)) { if ($GLOBALS['OnlyIndexes']) { $GLOBALS['processIndexes']->commitZendIndex($GLOBALS['zendIndex']); } @@ -159,7 +149,6 @@ while ($GLOBALS['state'] <> "END") { $GLOBALS['logger']->write('No more records to process', 'INFO'); break; } else { - $stackRecordset = $stmt->fetchObject(); $currentRecordInStack = array(); $currentRecordInStack = $GLOBALS['func']->object2array( $stackRecordset @@ -197,7 +186,7 @@ while ($GLOBALS['state'] <> "END") { 'resId' => $currentRecordInStack['res_id'], 'tmpDir' => $GLOBALS['tmpDirectory'], 'path_to_lucene' => $GLOBALS['path_to_lucene'], - //'zendIndex' => $GLOBALS['zendIndex'] + //'createZendIndex' => false ) ); } diff --git a/modules/convert/batch/verif_index.php b/modules/convert/batch/verif_index.php index 6333e5a42321017b91ea1e8040d0fe0cae4eb4e0..203f6be90d0c7f2884e99de8a3de9f97f34b3fd3 100644 --- a/modules/convert/batch/verif_index.php +++ b/modules/convert/batch/verif_index.php @@ -1,5 +1,12 @@ <?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. + * + */ + date_default_timezone_set('Europe/Paris'); // load the config and prepare to process diff --git a/modules/convert/services/ManageConvert.php b/modules/convert/services/ManageConvert.php deleted file mode 100644 index 37bde281c5ea3f7934912ec18164f63f9fd110b5..0000000000000000000000000000000000000000 --- a/modules/convert/services/ManageConvert.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/* -* Copyright 2008-2016 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief Manage convert class -* -* <ul> -* <li>Services to Manage the convertion of resources</li> -* </ul> -* -* @file -* @author Laurent Giovannoni <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup convert -*/ - - -require_once 'modules/convert/services/ManageConvertAbstract.php'; - -class Convert_ManageConvert_Service extends Convert_ManageConvertAbstract_Service { - - -} diff --git a/modules/convert/services/ManageConvertAbstract.php b/modules/convert/services/ManageConvertAbstract.php deleted file mode 100644 index fc0980e5cdeaf2dac35a65fa659d6b09615612f6..0000000000000000000000000000000000000000 --- a/modules/convert/services/ManageConvertAbstract.php +++ /dev/null @@ -1,164 +0,0 @@ -<?php - -/* -* Copyright 2008-2016 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief Manage convert class -* -* <ul> -* <li>Services to Manage the convertion of resources</li> -* </ul> -* -* @file -* @author Laurent Giovannoni <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup convert -*/ - -require_once 'core/services/Abstract.php'; -require_once 'core/class/class_functions.php'; -require_once 'core/class/class_db_pdo.php'; -require_once 'core/class/class_db.php'; -require_once 'core/docservers_tools.php'; -require_once 'core/class/docservers_controler.php'; -require_once 'core/services/ManageDocservers.php'; -require_once 'modules/convert/services/ProcessConvert.php'; -require_once 'modules/convert/services/ProcessThumbnails.php'; -require_once 'modules/convert/services/ProcessFulltext.php'; - -class Convert_ManageConvertAbstract_Service extends Core_Abstract_Service { - - /** - * Ask for conversion in all mode - * - * @param string $collId collection - * @param string $resTable resource table - * @param string $adrTable adr table - * @param long $resId res_id - * @param string $tmpDir path to tmp - * @throws Exception Check des valeurs d'entrées - * @return array $returnArray the result - */ - public function convertAll(array $args=[]) - { - $timestart = microtime(true); - // Prés-requis : - $this->checkRequired($args, ['collId','resTable','adrTable','resId',]); - $this->checkNumeric($args, ['resId',]); - $this->checkString($args, ['collId','resTable','adrTable',]); - - // Variabilisation : - $returnArray = array(); - $collId = $args['collId']; - $resTable = $args['resTable']; - $adrTable = $args['adrTable']; - $resId = $args['resId']; - - - if (!isset($args['tmpDir']) || $args['tmpDir'] == '') { - $tmpDir = $_SESSION['config']['tmppath']; - } else { - $tmpDir = $args['tmpDir']; - } - - $path_to_lucene = ''; - if (isset($args['path_to_lucene']) && !empty($args['path_to_lucene'])){ - $path_to_lucene = $args['path_to_lucene']; - } - - $params = array( - 'collId' => $collId, - 'resTable' => $resTable, - 'adrTable' => $adrTable, - 'resId' => $resId, - 'tmpDir' => $tmpDir, - 'path_to_lucene' => $path_to_lucene - ); - - //CONV - $ProcessConvertService = new Convert_ProcessConvert_Service(); - $resultOfConversion = $ProcessConvertService->convert($params); - - if ($resultOfConversion['status'] <> '0') { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'CONV:' . $resultOfConversion['error'], - ); - return $returnArray; - } - - //TNL - $ProcessConvertService = new Convert_ProcessThumbnails_Service(); - $resultOfConversion = $ProcessConvertService->thumbnails($params); - if ($resultOfConversion['status'] <> '0') { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'TNL:' . $resultOfConversion['error'], - ); - return $returnArray; - } - - //FULLTEXT - if (!empty($args['zendIndex'])) { - $zendIndex = $args['zendIndex']; - $params = array( - 'collId' => $collId, - 'resTable' => $resTable, - 'adrTable' => $adrTable, - 'resId' => $resId, - 'tmpDir' => $tmpDir, - 'path_to_lucene' => $path_to_lucene, - 'zendIndex' => $zendIndex - ); - } else { - $params = array( - 'collId' => $collId, - 'resTable' => $resTable, - 'adrTable' => $adrTable, - 'resId' => $resId, - 'tmpDir' => $tmpDir, - 'path_to_lucene' => $path_to_lucene - ); - } - $ProcessConvertService = new Convert_ProcessFulltext_Service(); - $resultOfConversion = $ProcessConvertService->fulltext($params); - if ($resultOfConversion['status'] <> '0') { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'TXT:' . $resultOfConversion['error'], - ); - Core_Logs_Service::executionTimeLog($timestart, '', 'debug', '[TIMER] Convert_ManageConvertAbstract_Service::convertAll aucun contenu a indexer dans fulltext'); - return $returnArray; - } - - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - Core_Logs_Service::executionTimeLog($timestart, '', 'debug', '[TIMER] Convert_ManageConvertAbstract_Service::convertAll'); - return $returnArray; - } - -} diff --git a/modules/convert/services/ProcessConvert.php b/modules/convert/services/ProcessConvert.php deleted file mode 100644 index 6cde4c768237ae5e961a88037cad129c4ed0c22b..0000000000000000000000000000000000000000 --- a/modules/convert/services/ProcessConvert.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/* -* Copyright 2008-2016 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief process convert class -* -* <ul> -* <li>Services to process the convertion of resources</li> -* </ul> -* -* @file -* @author Laurent Giovannoni <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup convert -*/ - - -require_once 'modules/convert/services/ProcessConvertAbstract.php'; - -class Convert_ProcessConvert_Service extends Convert_ProcessConvertAbstract_Service { - - -} diff --git a/modules/convert/services/ProcessConvertAbstract.php b/modules/convert/services/ProcessConvertAbstract.php deleted file mode 100644 index d5c079ed4fd800340467063ac26ffb53c95095ed..0000000000000000000000000000000000000000 --- a/modules/convert/services/ProcessConvertAbstract.php +++ /dev/null @@ -1,592 +0,0 @@ -<?php - -/* -* Copyright 2008-2016 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief process convert class -* -* <ul> -* <li>Services to process the convertion of resources</li> -* </ul> -* -* @file -* @author Laurent Giovannoni <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup convert -*/ - - -require_once 'core/services/Abstract.php'; -require_once 'core/class/class_functions.php'; -require_once 'core/class/class_db_pdo.php'; -require_once 'core/class/class_db.php'; -require_once 'core/docservers_tools.php'; -require_once 'core/class/docservers_controler.php'; -require_once 'core/services/ManageDocservers.php'; - -class Convert_ProcessConvertAbstract_Service extends Core_Abstract_Service { - - protected $libreOfficeExecutable; - - //public function __construct($libreOfficeExecutable = 'cloudooo') - public function __construct($libreOfficeExecutable = 'soffice') - //public function __construct($libreOfficeExecutable = 'unoconv') - { - $this->libreOfficeExecutable = $libreOfficeExecutable; - } - - /** - * Ask for conversion - * - * @param string $collId collection - * @param string $resTable resource table - * @param string $adrTable adr table - * @param long $resId res_id - * @param string $tmpDir path to tmp - * @param array $tgtfmt array of target format - * @return array $returnArray the result - */ - public function convert(array $args=[]) - { - $timestart = microtime(true); - // Core_Logs_Service::info(['message'=>'debut convert', 'code'=>111, ]); - $returnArray = array(); - if (empty($args['collId'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'collId empty', - ); - return $returnArray; - } else { - $collId = $args['collId']; - } - if (empty($args['resTable'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'resTable empty', - ); - return $returnArray; - } else { - $resTable = $args['resTable']; - } - if (empty($args['adrTable'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'adrTable empty', - ); - return $returnArray; - } else { - $adrTable = $args['adrTable']; - } - if (empty($args['resId'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'resId empty', - ); - return $returnArray; - } else { - $resId = $args['resId']; - } - - if (!isset($args['tmpDir']) || $args['tmpDir'] == '') { - $tmpDir = $_SESSION['config']['tmppath']; - } else { - $tmpDir = $args['tmpDir']; - } - - $dbConv = new Database($GLOBALS['configFile']); - - //retrieve path of the resource - $stmtConv = $dbConv->query("select * from " . $resTable - . " where res_id = ?", array($resId) - ); - $line = $stmtConv->fetchObject(); - $ManageDocservers = new Core_ManageDocservers_Service(); - if ($line->res_id <> '') { - $resourcePath = $ManageDocservers->getSourceResourcePath( - $resTable, - $adrTable, - $line->res_id, - 'DOC' - ); - } - if (!file_exists($resourcePath)) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'file not exists : ' . $resourcePath, - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //copy the resource on tmp directory - $fileNameOnTmp = $tmpDir . rand() . rand(); - if (!copy($resourcePath, $fileNameOnTmp)) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'copy on tmp failed', - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //now do the conversion ! - if (strtoupper($line->format) <> 'PDF') { - $resultOfConversion = $this->launchConvert( - $fileNameOnTmp, - 'pdf', - $tmpDir, - pathinfo($resourcePath, PATHINFO_EXTENSION) - ); - } else { - //echo $fileNameOnTmp; - copy($fileNameOnTmp, $fileNameOnTmp . '.pdf'); - $resultOfConversion = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - } - - if ($resultOfConversion['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $resultOfConversion; - } - //find the target docserver - $targetDs = $ManageDocservers->findTargetDs($collId); - if (empty($targetDs)) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'Ds of collection not found:' . $collId, - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //copy the result on docserver - // Core_Logs_Service::info(['message'=>'avant cp ds', 'code'=>1112, ]); - $resultCopyDs = $ManageDocservers->copyResOnDS($fileNameOnTmp . '.pdf', $targetDs); - if ($resultCopyDs['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $resultCopyDs; - } - // Core_Logs_Service::info(['message'=>'avant update', 'code'=>19, ]); - //update the database - $resultOfUpDb = $this->updateDatabase( - $collId, - $resTable, - $adrTable, - $resId, - $targetDs, - $resultCopyDs['value']['destinationDir'], - $resultCopyDs['value']['fileDestinationName'] - ); - // Core_Logs_Service::info(['message'=>var_export($resultOfUpDb, true), 'code'=>111111, ]); - // Core_Logs_Service::info(['message'=>$collId, 'code'=>2, ]); - // Core_Logs_Service::info(['message'=>$resTable, 'code'=>3, ]); - // Core_Logs_Service::info(['message'=>$adrTable, 'code'=>4, ]); - // Core_Logs_Service::info(['message'=>$resId, 'code'=>5, ]); - // Core_Logs_Service::info(['message'=>'apres res_id', 'code'=>6, ]); - // Core_Logs_Service::info(['message'=>$targetDs, 'code'=>6, ]); - // Core_Logs_Service::info(['message'=>var_export($resultCopyDs, true), 'code'=>7, ]); - - if ($resultOfUpDb['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $resultOfUpDb; - } - - unlink($fileNameOnTmp); - unlink($fileNameOnTmp . '.pdf'); - - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - Core_Logs_Service::executionTimeLog($timestart, '', 'debug', '[TIMER] Convert_ProcessConvertAbstract_Service::convert'); - return $returnArray; - } - - /** - * Launch the conversion - * - * @param string $srcfile source file - * @param string $tgtfmt target format - * @param string $tgtdir target dir - * @param string $srcfmt source format - * @return array $returnArray the result - */ - public function launchConvert( - $srcfile, - $tgtfmt, - $tgtdir=false, - $srcfmt=null - ) { - $timestart=microtime(true); - - $processHtml = false; - $executable=''; - - Core_Logs_Service::info(['message'=>'[TIMER] Debut Convert_ProcessConvertAbstract_Service::launchConvert']); - if (strtoupper($srcfmt) == 'MAARCH' || strtoupper($srcfmt) == 'HTML') { - $processHtml = true; - Core_Logs_Service::info(['message'=>'[TIMER] srcfmt ' . $srcfmt]); - copy($srcfile, str_ireplace('.maarch', '.', $srcfile) . '.html'); - if (file_exists('/usr/bin/mywkhtmltopdf')) { - $command = "mywkhtmltopdf " - . escapeshellarg(str_ireplace('.maarch', '.', $srcfile) . '.html') . " " - . escapeshellarg($tgtdir . basename(str_ireplace('.maarch', '.', $srcfile)) . '.pdf'); - } else { - $envVar = "export DISPLAY=FRPAROEMINT:0.0 ; "; - $command = $envVar . "wkhtmltopdf " - . escapeshellarg(str_ireplace('.maarch', '.', $srcfile) . '.html') . " " - . escapeshellarg($tgtdir . basename(str_ireplace('.maarch', '.', $srcfile)) . '.pdf'); - } - $executable='wkhtmltopdf'; - } else { - $executable='soffice'; - Core_Logs_Service::info(['message'=>'[TIMER] let LO do it ' . $this->libreOfficeExecutable]); - if ($this->libreOfficeExecutable == "cloudooo") { - $serverAddress = "http://192.168.21.40:8011"; - $tokens = array(); - require_once 'apps/maarch_entreprise/tools/phpxmlrpc/lib/xmlrpc.inc'; - require_once 'apps/maarch_entreprise/tools/phpxmlrpc/lib/xmlrpcs.inc'; - require_once 'apps/maarch_entreprise/tools/phpxmlrpc/lib/xmlrpc_wrappers.inc'; - $fileContent = file_get_contents($srcfile, FILE_BINARY); - $encodedContent = base64_encode($fileContent); - $params = array(); - array_push($params, new PhpXmlRpc\Value($encodedContent)); - array_push($params, new PhpXmlRpc\Value($srcfmt)); - array_push($params, new PhpXmlRpc\Value($tgtfmt)); - array_push($params, new PhpXmlRpc\Value(false)); - $v = new PhpXmlRpc\Value($params, "array"); - } elseif ($this->libreOfficeExecutable == "unoconv") { - $tokens = array('"' . $this->libreOfficeExecutable . '"'); - $tokens[] = "-f"; - $tokens[] = $tgtfmt; - $tokens[] = '-o "' . $srcfile . '.' . $tgtfmt . '"'; - $tokens[] = '"' . $srcfile . '"'; - } else { - $tokens = array('"' . $this->libreOfficeExecutable . '"'); - $tokens[] = "--headless"; - $tokens[] = "--convert-to"; - $tokens[] = $tgtfmt; - $tokens[] = '"' . $srcfile . '"'; - if (!$tgtdir) { - $tgtdir = dirname($srcfile); - } - $tokens[] = '--outdir "' . $tgtdir . '"'; - } - - if (!$srcfmt) { - $tokens[] = $srcfmt; - } - - $command = implode(' ', $tokens); - - $output = array(); - $return = null; - $this->errors = array(); - } - //echo $command . '<br />';exit; - if ($this->libreOfficeExecutable == "cloudooo" && !$processHtml) { - Core_Logs_Service::info(['message'=>'[TIMER] commande : cloudooo url ' . $serverAddress]); - Core_Logs_Service::info(['message'=>'[TIMER] Debut Convert_ProcessConvertAbstract_Service::launchConvert__exec']); - $req = new PhpXmlRpc\Request('convertFile', $v); - //Core_Logs_Service::info(['message'=>'[TIMER] commande : cloudooo url ' . $serverAddress]); - Core_Logs_Service::info(['message'=>'[TIMER] Fin Convert_ProcessConvertAbstract_Service::launchConvert__exec']); - $client = new PhpXmlRpc\Client($serverAddress); - $resp = $client->send($req); - if (!$resp->faultCode()) { - $encoder = new PhpXmlRpc\Encoder(); - $value = $encoder->decode($resp->value()); - $theFile = fopen($srcfile . '.' . $tgtfmt, 'w+'); - fwrite($theFile, base64_decode($value)); - fclose($theFile); - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - } else { - //print "An error occurred: "; - //print "Code: " . htmlspecialchars($resp->faultCode()) - // . " Reason: '" . htmlspecialchars($resp->faultString()) . "'\n"; - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => "Code: " . htmlspecialchars($resp->faultCode()) - . " Reason: '" . htmlspecialchars($resp->faultString()), - ); - } - } else { - $timestart_command = microtime(true); - exec("timeout -k 5m 3m " . $command, $output, $return); - Core_Logs_Service::debug(['message'=>'[TIMER] commande : ' . $command]); - Core_Logs_Service::executionTimeLog($timestart_command, '', 'info', '[TIMER] ' . $executable . ' - Convert_ProcessConvertAbstract_Service::launchConvert__exec'); - if ($return === 0) { - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - } else { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => $return . $output, - ); - } - } - if (strtoupper($srcfmt) == 'MAARCH' || strtoupper($srcfmt) == 'HTML') { - $returnArray = array(); - unlink(str_ireplace('.maarch', '.', $srcfile) . '.html'); - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - } - Core_Logs_Service::executionTimeLog($timestart, '', 'info', '[TIMER] Fin Convert_ProcessConvertAbstract_Service::launchConvert'); - return $returnArray; - } - - /** - * Updating the database with the location information of the document on the - * new docserver - * @param string $collId collection - * @param string $resTable res table - * @param string $adrTable adr table - * @param bigint $resId Id of the resource to process - * @param docserver $docserver docserver object - * @param string $path location of the resource on the docserver - * @param string $fileName file name of the resource on the docserver - * @return array $returnArray the result - */ - private function updateDatabase( - $collId, - $resTable, - $adrTable, - $resId, - $docserver, - $path, - $fileName - ) { - try { - $docserver->path_template = str_replace( - DIRECTORY_SEPARATOR, - '#', - $docserver->path_template - ); - $path = str_replace($docserver->path_template, '', $path); - $dbConv = new Database($GLOBALS['configFile']); - $query = "update convert_stack set status = 'P' where " - . " coll_id = ? and res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $collId, - $resId - ) - ); - - $query = "select * from " . $adrTable - . " where res_id = ? order by adr_priority"; - $stmt = $dbConv->query($query, array($resId)); - if ($stmt->rowCount() == 0) { - $query = "select docserver_id, path, filename, offset_doc, fingerprint" - . " from " . $resTable . " where res_id = ?"; - $stmt = $dbConv->query($query, array($resId)); - $recordset = $stmt->fetchObject(); - // Core_Logs_Service::info(['message'=>$recordset, 'code'=>8, ]); - $resDocserverId = $recordset->docserver_id; - $resPath = $recordset->path; - $resFilename = $recordset->filename; - $resOffsetDoc = $recordset->offset_doc; - $fingerprintInit = $recordset->fingerprint; - $query = "select adr_priority_number from docservers " - . " where docserver_id = ?"; - $stmt = $dbConv->query($query, array($resDocserverId)); - $recordset = $stmt->fetchObject(); - $query = "insert into " . $adrTable . " (res_id, " - . "docserver_id, path, filename, offset_doc, fingerprint, " - . "adr_priority) values (?, ?, ?, ?, ?, ?, ?)"; - $stmt = $dbConv->query( - $query, - array( - $resId, - $resDocserverId, - $resPath, - $resFilename, - $resOffsetDoc, - $fingerprintInit, - $recordset->adr_priority_number - ) - ); - } - - $query = "select * from " . $adrTable - . " where res_id = ? and adr_type = 'CONV'"; - $stmt = $dbConv->query($query, array($resId)); - if ($stmt->rowCount() == 0) { - $query = "insert into " . $adrTable . " (res_id, docserver_id, " - . "path, filename, offset_doc, fingerprint, adr_priority, adr_type) values (" - . "?, ?, ?, ?, ?, ?, ?, ?)"; - $stmt = $dbConv->query( - $query, - array( - $resId, - $docserver->docserver_id, - $path, - $fileName, - $offsetDoc, - $fingerprint, - $docserver->adr_priority_number, - 'CONV' - ) - ); - } else { - $query = "update " . $adrTable . " set docserver_id = ?, " - . " path = ?, filename = ?, offset_doc = ?, fingerprint = ?, adr_priority = ?" - . " where res_id = ? and adr_type = ? "; - $stmt = $dbConv->query( - $query, - array( - $docserver->docserver_id, - $path, - $fileName, - $offsetDoc, - $fingerprint, - $docserver->adr_priority_number, - $resId, - 'CONV' - ) - ); - } - if ($_SESSION['user']['UserId'] <> '') { - $user = $_SESSION['user']['UserId']; - } else { - $user = 'CONVERT_BOT'; - } - $query = "insert into history (table_name, record_id, " - . "event_type, user_id, event_date, info, id_module) values (" - . "?, ?, 'ADD', '" . $user . "', " - . $dbConv->current_datetime() - . ", ?, 'convert')"; - $stmt = $dbConv->query( - $query, - array( - $resTable, - $resId, - "process convert done" - ) - ); - - $queryCpt = "select coalesce(custom_t9, '0') as custom_t9 from " . $resTable - . " where res_id = ?"; - $stmtCpt = $dbConv->query($queryCpt, array($resId)); - $rsCpt = $stmtCpt->fetchObject(); - $cptConvert = $rsCpt->custom_t9 + 1; - - $query = "update " . $resTable - . " set convert_result = '1', is_multi_docservers = 'Y', custom_t9 = '" . $cptConvert . "' where " - . " res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $resId - ) - ); - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - return $returnArray; - } catch (Exception $e) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => $e->getMessage(), - ); - return $returnArray; - } - } - - /** - * Updating the database with the error code - * @param string $resTable res table - * @param bigint $resId Id of the resource to process - * @param string $result error code - * @return nothing - */ - private function manageErrorOnDb( - $resTable, - $resId, - $result - ) { - $dbConv = new Database($GLOBALS['configFile']); - $query = "update " . $resTable - . " set convert_result = ? where " - . " res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $result, - $resId - ) - ); - } - - /** - * Test if the record is already processed by convert module - * @param string $resTable res table - * @param bigint $resId Id of the resource to process - * @return boolean - */ - public function isAlreadyProcessedByConvert( - $resTable, - $resId - ) { - $dbConv = new Database($GLOBALS['configFile']); - $query = "select convert_result from " . $resTable - . " where res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $resId - ) - ); - $rs = $stmt->fetchObject(); - if ( - empty($rs->convert_result) || - $rs->convert_result == '0' - ) { - return false; - } else { - return true; - } - } -} diff --git a/modules/convert/services/ProcessFulltext.php b/modules/convert/services/ProcessFulltext.php deleted file mode 100644 index 8911aab6863da64caee87971f19f9e052e3d0f14..0000000000000000000000000000000000000000 --- a/modules/convert/services/ProcessFulltext.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/* -* Copyright 2008-2016 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief process fulltext class -* -* <ul> -* <li>Services to process the fulltext of resources</li> -* </ul> -* -* @file -* @author Laurent Giovannoni <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup convert -*/ - - -require_once 'modules/convert/services/ProcessFulltextAbstract.php'; - -class Convert_ProcessFulltext_Service extends Convert_ProcessFulltextAbstract_Service { - - -} diff --git a/modules/convert/services/ProcessFulltextAbstract.php b/modules/convert/services/ProcessFulltextAbstract.php deleted file mode 100644 index 3a7e7f8cfa2817b62766c1cdd3eb146cf16a6188..0000000000000000000000000000000000000000 --- a/modules/convert/services/ProcessFulltextAbstract.php +++ /dev/null @@ -1,740 +0,0 @@ -<?php - -/* -* Copyright 2008-2016 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief process fulltext class -* -* <ul> -* <li>Services to process the fulltext of resources</li> -* </ul> -* -* @file -* @author Laurent Giovannoni <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup convert -*/ - -require_once 'core/services/Abstract.php'; -require_once 'core/class/class_functions.php'; -require_once 'core/class/class_db_pdo.php'; -require_once 'core/class/class_db.php'; -require_once 'core/docservers_tools.php'; -require_once 'core/class/docservers_controler.php'; -require_once 'core/services/ManageDocservers.php'; - -// Storing text in lucene index -set_include_path('apps/maarch_entreprise/tools/' - . PATH_SEPARATOR . get_include_path() -); - -if(!@include('Zend/Search/Lucene.php')) { - set_include_path($GLOBALS['MaarchDirectory'].'apps/maarch_entreprise/tools/' - . PATH_SEPARATOR . get_include_path() - ); - if(!@include('Zend/Search/Lucene.php')) { - set_include_path('/var/www/oem/apps/maarch_entreprise/tools/' - . PATH_SEPARATOR . get_include_path() - ); - } - require_once("Zend/Search/Lucene.php"); -} - -//include_once('html2text/html2text.php'); - -class Convert_ProcessFulltextAbstract_Service extends Core_Abstract_Service { - - protected $pdftotext; - - public function __construct($pdftotext = 'pdftotext') - { - $this->pdftotext = $pdftotext; - } - - /** - * Ask for fulltext - * - * @param string $collId collection - * @param string $resTable resource table - * @param string $adrTable adr table - * @param long $resId res_id - * @param string $tmpDir path to tmp - * @param array $tgtfmt array of target format - * @return array $returnArray the result - */ - public function fulltext(array $args=[]) - { - $timestart = microtime(true); - $returnArray = array(); - if (empty($args['collId'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'collId empty for fulltext', - ); - return $returnArray; - } else { - $collId = $args['collId']; - } - // if (empty($args['batchMode'])) { - // $batchMode = false; - // } else { - // $batchMode = $args['batchMode']; - // } - if (empty($args['resTable'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'resTable empty for fulltext', - ); - return $returnArray; - } else { - $resTable = $args['resTable']; - } - if (empty($args['adrTable'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'adrTable empty for fulltext', - ); - return $returnArray; - } else { - $adrTable = $args['adrTable']; - } - if (empty($args['resId'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'resId empty for fulltext', - ); - return $returnArray; - } else { - $resId = $args['resId']; - } - - if (!isset($args['tmpDir']) || $args['tmpDir'] == '') { - $tmpDir = $_SESSION['config']['tmppath']; - } else { - $tmpDir = $args['tmpDir']; - } - - if(isset($args['path_to_lucene']) && !empty($args['path_to_lucene'])){ - $indexFileDirectory = $args['path_to_lucene']; - } else { - $countColl = count($_SESSION['collections']); - for ($i=0;$i<$countColl;$i++) { - if ($_SESSION['collections'][$i]['id'] == $collId) { - $indexFileDirectory - = $_SESSION['collections'][$i]['path_to_lucene_index']; - } - } - } - - $dbConv = new Database($GLOBALS['configFile']); - - //retrieve path of the resource - $stmtConv = $dbConv->query("select * from " . $resTable - . " where res_id = ?", array($resId) - ); - $line = $stmtConv->fetchObject(); - $ManageDocservers = new Core_ManageDocservers_Service(); - if ($line->res_id <> '') { - $resourcePath = $ManageDocservers->getSourceResourcePath( - $resTable, - $adrTable, - $line->res_id, - 'CONV' - ); - } - if (!file_exists($resourcePath)) { - $returnArray = array( - 'status' => '2', - 'value' => '', - 'error' => 'file not already converted in pdf for fulltext. path :' - . $resourcePath . ", adrType : CONV, adr_table : " . $adrTable, - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //copy the resource on tmp directory - $fileNameOnTmp = $tmpDir . rand() . rand(); - if (!copy($resourcePath, $fileNameOnTmp)) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'copy on tmp failed for fulltext. Copy ' . $resourcePath . ' to ' . $fileNameOnTmp, - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //now do the fulltext ! - if (!empty($args['zendIndex'])) { - $resultOfConversion = $this->launchFulltext( - $fileNameOnTmp, - $resId, - $indexFileDirectory, - $tmpDir, - $args['zendIndex'] - ); - } else { - $resultOfConversion = $this->launchFulltext( - $fileNameOnTmp, - $resId, - $indexFileDirectory, - $tmpDir - ); - } - - - if ($resultOfConversion['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - Core_Logs_Service::executionTimeLog($timestart, '', 'debug', '[TIMER] Convert_ProcessFulltextAbstract_Service::fulltext aucunContenuAIndexer'); - return $resultOfConversion; - } - //find the target docserver - $targetDs = $ManageDocservers->findTargetDs($collId, 'FULLTEXT'); - if (empty($targetDs)) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'Ds of collection and ds type not found for fulltext:' - . $collId . ' FULLTEXT', - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //copy the result on docserver - $resultCopyDs = $ManageDocservers->copyResOnDS($fileNameOnTmp . '.txt', $targetDs); - if ($resultCopyDs['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $resultCopyDs; - } - //update the database - $resultOfUpDb = $this->updateDatabase( - $collId, - $resTable, - $adrTable, - $resId, - $targetDs, - $resultCopyDs['value']['destinationDir'], - $resultCopyDs['value']['fileDestinationName'], - $args['zendIndex'] - ); - if ($resultOfUpDb['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $resultOfUpDb; - } - - unlink($fileNameOnTmp); - unlink($fileNameOnTmp . '.txt'); - - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - Core_Logs_Service::executionTimeLog($timestart, '', 'debug', '[TIMER] Convert_ProcessFulltextAbstract_Service::fulltext'); - return $returnArray; - } - - /** - * Launch the fulltext process - * - * @param string $srcfile source file - * @param string $tgtdir target dir - * @param string $srcfmt source format - * @return array $returnArray the result - */ - private function launchFulltext( - $srcfile, - $resId, - $indexFileDirectory, - $tgtdir=false, - $zendIndex='' - ) { - if (!empty($zendIndex)) { - $return = $this->prepareIndexFullTextPdf( - $srcfile, - $tgtdir, - $indexFileDirectory, - $resId, - $zendIndex - ); - } else { - $return = $this->prepareIndexFullTextPdf( - $srcfile, - $tgtdir, - $indexFileDirectory, - $resId - ); - } - - if ($return === 0) { - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - return $returnArray; - } else { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => $return . $output, - ); - return $returnArray; - } - } - - /** - * Read a txt file - * @param $file string path of the file to read - * @return string contents of the file - */ - private function readFileF($file) - { - $result = ""; - if (is_file($file)) { - $fp = fopen($file, "r"); - $result = fread($fp, filesize($file)); - fclose($fp); - } - return $result; - } - - private function prepareIndexFullTextPdf($pathToFile, $tmpDir, $indexFileDirectory, $resId, $zendIndex) - { - $timestart = microtime(true); - if (is_file($pathToFile)) { - $tmpFile = $tmpDir . basename($pathToFile) . ".txt"; - // if ($_ENV['osname'] == "WINDOWS") { - // $resultExtraction = exec(escapeshellarg($_ENV['maarch_tools_path'] . "pdftotext" - // . DIRECTORY_SEPARATOR . $_ENV['pdftotext']) . " " - // . escapeshellarg($pathToFile) . " " . escapeshellarg($tmpFile) - // ); - // } elseif ($_ENV['osname'] == "UNIX") { - // $resultExtraction = exec("pdftotext -enc UTF-8 " . escapeshellarg($pathToFile) - // . " " . escapeshellarg($tmpFile) - // ); - $timestart_fulltext = microtime(true); - $resultExtraction = exec("pdftotext " . escapeshellarg($pathToFile) - . " " . escapeshellarg($tmpFile) - ); - Core_Logs_Service::executionTimeLog($timestart_fulltext, '', 'debug', '[TIMER] Convert_ProcessFulltextAbstract_Service::prepareIndexFullTextPdf__exec'); - //} - // echo "pdftotext " . escapeshellarg($pathToFile) - // . " " . escapeshellarg($tmpFile) . '<br/><br/><br/>'; - $fileContent = trim($this->readFileF($tmpFile)); - //echo $fileContent . '<br />'; - //exit; - //echo $tmpFile . '<br />'; - //echo $indexFileDirectory . '<br />'; - //echo $resId . '<br />'; - if (!empty($zendIndex)) { - $result = $this->launchIndexFullTextWithZendIndex( - $fileContent, - $indexFileDirectory, - $resId, - $zendIndex - ); - } else { - // TODO : will be done only by the batch convert in OnlyIndexes mode - //$result = $this->launchIndexFullText($fileContent, $indexFileDirectory, $resId); - $result = 0; - } - - } else { - $result = 'file not found ' . $pathToFile; - } - Core_Logs_Service::executionTimeLog($timestart, '', 'debug', '[TIMER] Convert_ProcessFulltextAbstract_Service::prepareIndexFullTextPdf'); - return $result; - } - - /** - * Return zend index object for batch mode - * @param $indexFileDirectory string directory of the lucene index - * @return zend index object - */ - public function createZendIndexObject($tempIndexFileDirectory, $numberOfIndexes = 1000) - { - //echo 'createZendIndexObject : ' . $numberOfIndexes . PHP_EOL; - $func = new functions(); - $indexFileDirectory = (string) $tempIndexFileDirectory; - // with version 1.12, we need a string, not an XML element - - if (!is_dir($indexFileDirectory)) { - $index = Zend_Search_Lucene::create($indexFileDirectory); - } else { - if ($func->isDirEmpty($indexFileDirectory)) { - $index = Zend_Search_Lucene::create($indexFileDirectory); - } else { - $index = Zend_Search_Lucene::open($indexFileDirectory); - } - } - $index->setFormatVersion(Zend_Search_Lucene::FORMAT_2_3); - // we set the lucene format to 2.3 - Zend_Search_Lucene_Analysis_Analyzer::setDefault( - new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive() - ); - - //$index->MaxBufferedDocs(); - $index->setMaxBufferedDocs($numberOfIndexes); - - return $index; - } - - /** - * Commit the zend index at the end of the batch - * @return nothing - */ - public function commitZendIndex($index) - { - //echo 'the commit' . PHP_EOL; - $index->commit(); - } - - /** - * Retrieve the text of a pdftext and launch the lucene engine - * @param $pathToFile string path of the file to index - * @param $indexFileDirectory string directory of the lucene index - * @param $id integer id of the document to index - * @return integer user exit code is stored in fulltext_result column of the - * document in "res_x" - */ - private function launchIndexFullText($fileContent, $tempIndexFileDirectory, $Id) - { - // $IndexFileDirectory is replace by tempIndexFileDirectory - $func = new functions(); - $fileContent = $func->normalize($fileContent); - $fileContent = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $fileContent); - $indexFileDirectory = (string) $tempIndexFileDirectory; - // with version 1.12, we need a string, not an XML element - $result = -1; - if (strlen($fileContent) > 2) { - if (!is_dir($indexFileDirectory)) { - //$_ENV['logger']->write($indexFileDirectory . " not exists !", "ERROR", 2); - $index = Zend_Search_Lucene::create($indexFileDirectory); - } else { - if ($func->isDirEmpty($indexFileDirectory)) { - //$_ENV['logger']->write($indexFileDirectory . " empty !"); - $index = Zend_Search_Lucene::create($indexFileDirectory); - } else { - $index = Zend_Search_Lucene::open($indexFileDirectory); - } - } - $index->setFormatVersion(Zend_Search_Lucene::FORMAT_2_3); - // we set the lucene format to 2.3 - Zend_Search_Lucene_Analysis_Analyzer::setDefault( - new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive() - ); - // we need utf8 for accents - $term = new Zend_Search_Lucene_Index_Term($Id, 'Id'); - foreach ($index->termDocs($term) as $id) { - $index->delete($id); - } - //echo $fileContent; - $doc = new Zend_Search_Lucene_Document(); - $doc->addField(Zend_Search_Lucene_Field::UnIndexed('Id', (integer) $Id)); - $doc->addField(Zend_Search_Lucene_Field::UnStored( - 'contents', $fileContent) - ); - //$func->show_array($doc); - $index->addDocument($doc); - $index->commit(); - //$func->show_array($index); - //$index->optimize(); - $result = 0; - } else { - $result = 1; - } - return $result; - } - - /** - * Retrieve the text of a pdftext and launch the lucene engine - * @param $pathToFile string path of the file to index - * @param $indexFileDirectory string directory of the lucene index - * @param $id integer id of the document to index - * @return integer user exit code is stored in fulltext_result column of the - * document in "res_x" - */ - private function launchIndexFullTextWithZendIndex($fileContent, $tempIndexFileDirectory, $Id, $index) - { - //echo 'launchIndexFullTextWithZendIndex' . PHP_EOL; - // $IndexFileDirectory is replace by tempIndexFileDirectory - $func = new functions(); - $fileContent = $func->normalize($fileContent); - $fileContent = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $fileContent); - - // with version 1.12, we need a string, not an XML element - $result = -1; - if (strlen($fileContent) > 2) { - try { - // we need utf8 for accents - $term = new Zend_Search_Lucene_Index_Term($Id, 'Id'); - foreach ($index->termDocs($term) as $id) { - $index->delete($id); - } - //echo $fileContent; - $doc = new Zend_Search_Lucene_Document(); - $doc->addField(Zend_Search_Lucene_Field::UnIndexed('Id', (integer) $Id)); - $doc->addField(Zend_Search_Lucene_Field::UnStored( - 'contents', $fileContent) - ); - //$func->show_array($doc); - $index->addDocument($doc); - //$index->commit(); - //$func->show_array($index); - //$index->optimize(); - $result = 0; - } catch (Exception $e) { - $result = $e->getMessage(); - } - - } else if (strlen($fileContent) >= 0){ - $result = 0; - } - return $result; - } - - /** - * Updating the database with the location information of the document on the - * new docserver - * @param string $collId collection - * @param string $resTable res table - * @param string $adrTable adr table - * @param bigint $resId Id of the resource to process - * @param docserver $docserver docserver object - * @param string $path location of the resource on the docserver - * @param string $fileName file name of the resource on the docserver - * @return array $returnArray the result - */ - private function updateDatabase( - $collId, - $resTable, - $adrTable, - $resId, - $docserver, - $path, - $fileName, - $zendIndex = '' - ) { - try { - $docserver->path_template = str_replace( - DIRECTORY_SEPARATOR, - '#', - $docserver->path_template - ); - $path = str_replace($docserver->path_template, '', $path); - $dbConv = new Database($GLOBALS['configFile']); - $query = "update convert_stack set status = 'P' where " - . " coll_id = ? and res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $collId, - $resId - ) - ); - - $query = "select * from " . $adrTable - . " where res_id = ? order by adr_priority"; - $stmt = $dbConv->query($query, array($resId)); - if ($stmt->rowCount() == 0) { - $query = "select docserver_id, path, filename, offset_doc, fingerprint" - . " from " . $resTable . " where res_id = ?"; - $stmt = $dbConv->query($query, array($resId)); - $recordset = $stmt->fetchObject(); - $resDocserverId = $recordset->docserver_id; - $resPath = $recordset->path; - $resFilename = $recordset->filename; - $resOffsetDoc = $recordset->offset_doc; - $fingerprintInit = $recordset->fingerprint; - $query = "select adr_priority_number from docservers " - . " where docserver_id = ?"; - $stmt = $dbConv->query($query, array($resDocserverId)); - $recordset = $stmt->fetchObject(); - $query = "insert into " . $adrTable . " (res_id, " - . "docserver_id, path, filename, offset_doc, fingerprint, " - . "adr_priority) values (?, ?, ?, ?, ?, ?, ?)"; - $stmt = $dbConv->query( - $query, - array( - $resId, - $resDocserverId, - $resPath, - $resFilename, - $resOffsetDoc, - $fingerprintInit, - $recordset->adr_priority_number - ) - ); - } - - $query = "select * from " . $adrTable - . " where res_id = ? and adr_type = 'TXT'"; - $stmt = $dbConv->query($query, array($resId)); - if ($stmt->rowCount() == 0) { - $query = "insert into " . $adrTable . " (res_id, docserver_id, " - . "path, filename, offset_doc, fingerprint, adr_priority, adr_type) values (" - . "?, ?, ?, ?, ?, ?, ?, ?)"; - $stmt = $dbConv->query( - $query, - array( - $resId, - $docserver->docserver_id, - $path, - $fileName, - $offsetDoc, - $fingerprint, - $docserver->adr_priority_number, - 'TXT' - ) - ); - } else { - $query = "update " . $adrTable . " set docserver_id = ?, " - . " path = ?, filename = ?, offset_doc = ?, fingerprint = ?, adr_priority = ?" - . " where res_id = ? and adr_type = ? "; - $stmt = $dbConv->query( - $query, - array( - $docserver->docserver_id, - $path, - $fileName, - $offsetDoc, - $fingerprint, - $docserver->adr_priority_number, - $resId, - 'TXT' - ) - ); - } - if ($_SESSION['user']['UserId'] <> '') { - $user = $_SESSION['user']['UserId']; - } else { - $user = 'CONVERT_BOT'; - } - $query = "insert into history (table_name, record_id, " - . "event_type, user_id, event_date, info, id_module) values (" - . "?, ?, 'ADD', '" . $user . "', " - . $dbConv->current_datetime() - . ", ?, 'convert')"; - $stmt = $dbConv->query( - $query, - array( - $resTable, - $resId, - "process fulltext done" - ) - ); - - $queryCpt = "select coalesce(custom_t15, '0') as custom_t15 from " . $resTable - . " where res_id = ?"; - $stmtCpt = $dbConv->query($queryCpt, array($resId)); - $rsCpt = $stmtCpt->fetchObject(); - $cptFullText = $rsCpt->custom_t15 + 1; - - if (!empty($zendIndex)) { - $query = "update " . $resTable - . " set fulltext_result = '1', is_multi_docservers = 'Y', custom_t15 = '" . $cptFullText . "' where " - . " res_id = ?"; - } else { - $query = "update " . $resTable - . " set fulltext_result = '0', is_multi_docservers = 'Y', custom_t15 = '" . $cptFullText . "' where " - . " res_id = ?"; - } - $stmt = $dbConv->query( - $query, - array( - $resId - ) - ); - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - return $returnArray; - } catch (Exception $e) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => $e->getMessage(), - ); - return $returnArray; - } - } - - /** - * Updating the database with the error code - * @param string $resTable res table - * @param bigint $resId Id of the resource to process - * @param string $result error code - * @return nothing - */ - private function manageErrorOnDb( - $resTable, - $resId, - $result - ) { - $dbConv = new Database($GLOBALS['configFile']); - - $queryCpt = "select coalesce(custom_t15, '0') as custom_t15 from " . $resTable - . " where res_id = ?"; - $stmtCpt = $dbConv->query($queryCpt, array($resId)); - $rsCpt = $stmtCpt->fetchObject(); - $cptFullText = $rsCpt->custom_t15 + 1; - - $query = "update " . $resTable - . " set fulltext_result = ?, custom_t15 = '" . $cptFullText . "' where " - . " res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $result, - $resId - ) - ); - } - - public static function optimizeLuceneIndex(array $args=[]){ - $timestart = microtime(true); - // Prés-requis : - self::checkRequired($args, ['collId']); - self::checkString($args, ['collId']); - - $collId = $args['collId']; - - $countColl = count($_SESSION['collections']); - for ($i=0;$i<$countColl;$i++) { - if ($_SESSION['collections'][$i]['id'] == $collId) { - $path_to_lucene = $_SESSION['collections'][$i]['path_to_lucene_index']; - } - } - - if(!empty($path_to_lucene)){ - exec('php '.$_SESSION['config']['corepath'].'modules/convert/optimizeLuceneIndex.php '.$path_to_lucene.' '.$_SESSION['config']['corepath'].' > /dev/null 2>&1 &'); - } - Core_Logs_Service::executionTimeLog($timestart, '', 'debug', '[TIMER] Convert_ProcessFulltextAbstract_Service::optimizeLuceneIndex'); - return true; - } - -} diff --git a/modules/convert/services/ProcessThumbnails.php b/modules/convert/services/ProcessThumbnails.php deleted file mode 100644 index 17f4b754bd76ad1d9e390dfa15da4a2ea76157ae..0000000000000000000000000000000000000000 --- a/modules/convert/services/ProcessThumbnails.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/* -* Copyright 2008-2016 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief process thumbnails class -* -* <ul> -* <li>Services to process the thumbnails of resources</li> -* </ul> -* -* @file -* @author Laurent Giovannoni <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup convert -*/ - - -require_once 'modules/convert/services/ProcessThumbnailsAbstract.php'; - -class Convert_ProcessThumbnails_Service extends Convert_ProcessThumbnailsAbstract_Service { - - -} diff --git a/modules/convert/services/ProcessThumbnailsAbstract.php b/modules/convert/services/ProcessThumbnailsAbstract.php deleted file mode 100644 index 0ac20cf65c48d37365b4ce7ba6c1728fa2831ab8..0000000000000000000000000000000000000000 --- a/modules/convert/services/ProcessThumbnailsAbstract.php +++ /dev/null @@ -1,501 +0,0 @@ -<?php - -/* -* Copyright 2008-2016 Maarch -* -* This file is part of Maarch Framework. -* -* Maarch Framework is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* Maarch Framework is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Maarch Framework. If not, see <http://www.gnu.org/licenses/>. -*/ - -/** -* @brief process thumbnails class -* -* <ul> -* <li>Services to process the thumbnails of resources</li> -* </ul> -* -* @file -* @author Laurent Giovannoni <dev@maarch.org> -* @date $date$ -* @version $Revision$ -* @ingroup convert -*/ - - -require_once 'core/services/Abstract.php'; -require_once 'core/class/class_functions.php'; -require_once 'core/class/class_db_pdo.php'; -require_once 'core/class/class_db.php'; -require_once 'core/docservers_tools.php'; -require_once 'core/class/docservers_controler.php'; -require_once 'core/services/ManageDocservers.php'; - -class Convert_ProcessThumbnailsAbstract_Service extends Core_Abstract_Service { - - protected $tnlExecutable; - - public function __construct($tnlExecutable = 'convert') - { - $this->tnlExecutable = $tnlExecutable; - } - - /** - * Ask for thumbnails - * - * @param string $collId collection - * @param string $resTable resource table - * @param string $adrTable adr table - * @param long $resId res_id - * @param string $tmpDir path to tmp - * @param array $tgtfmt array of target format - * @return array $returnArray the result - */ - public function thumbnails(array $args=[]) - { - $timestart = microtime(true); - $returnArray = array(); - if (empty($args['collId'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'collId empty for thumbnails', - ); - return $returnArray; - } else { - $collId = $args['collId']; - } - if (empty($args['resTable'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'resTable empty for thumbnails', - ); - return $returnArray; - } else { - $resTable = $args['resTable']; - } - if (empty($args['adrTable'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'adrTable empty for thumbnails', - ); - return $returnArray; - } else { - $adrTable = $args['adrTable']; - } - if (empty($args['resId'])) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'resId empty for thumbnails', - ); - return $returnArray; - } else { - $resId = $args['resId']; - } - - if (!isset($args['tmpDir']) || $args['tmpDir'] == '') { - $tmpDir = $_SESSION['config']['tmppath']; - } else { - $tmpDir = $args['tmpDir']; - } - - $dbConv = new Database($GLOBALS['configFile']); - - //retrieve path of the resource - $stmtConv = $dbConv->query("select * from " . $resTable - . " where res_id = ?", array($resId) - ); - $line = $stmtConv->fetchObject(); - $ManageDocservers = new Core_ManageDocservers_Service(); - if ($args['fileSource'] <> '' && file_exists($args['fileSource'])) { - $resourcePath = $args['fileSource']; - } else { - if ($line->res_id <> '') { - $adrType = 'CONV'; - if ( - strtoupper($line->format) == 'HTML' || - strtoupper($line->format) == 'MAARCH' - ) { - $adrType = 'DOC'; - } - $resourcePath = $ManageDocservers->getSourceResourcePath( - $resTable, - $adrTable, - $line->res_id, - $adrType - ); - } - } - - if (!file_exists($resourcePath)) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'file not already converted in pdf for thumbnails. Path : ' - . $resourcePath . ", adrType : " . $adrType, - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //copy the resource on tmp directory - $fileNameOnTmp = $tmpDir . rand() . rand(); - if (!copy($resourcePath, $fileNameOnTmp)) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'copy on tmp failed for thumbnails. Copy ' . $resourcePath . ' to ' . $fileNameOnTmp, - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //now do the thumbnails ! - $resultOfConversion = $this->launchThumbnails( - $fileNameOnTmp, - $tmpDir, - pathinfo($resourcePath, PATHINFO_EXTENSION) - ); - if ($resultOfConversion['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $resultOfConversion; - } - //find the target docserver - $targetDs = $ManageDocservers->findTargetDs($collId, 'TNL'); - if (empty($targetDs)) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => 'Ds of collection and ds type not found for thumbnails:' - . $collId . ' TNL', - ); - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $returnArray; - } - //copy the result on docserver - $resultCopyDs = $ManageDocservers->copyResOnDS($fileNameOnTmp . '.png', $targetDs); - if ($resultCopyDs['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $resultCopyDs; - } - //update the database - $resultOfUpDb = $this->updateDatabase( - $collId, - $resTable, - $adrTable, - $resId, - $targetDs, - $resultCopyDs['value']['destinationDir'], - $resultCopyDs['value']['fileDestinationName'] - ); - if ($resultOfUpDb['status'] <> '0') { - $this->manageErrorOnDb($resTable, $resId, '-1'); - return $resultOfUpDb; - } - - unlink($fileNameOnTmp); - unlink($fileNameOnTmp . '.png'); - - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - Core_Logs_Service::executionTimeLog($timestart, '', 'info', '[TIMER] Convert_ProcessThumbnailsAbstract_Service::thumbnails'); - return $returnArray; - } - - /** - * Launch the thumbnails process - * - * @param string $srcfile source file - * @param string $tgtdir target dir - * @param string $srcfmt source format - * @return array $returnArray the result - */ - private function launchThumbnails( - $srcfile, - $tgtdir=false, - $srcfmt - ) { - $timestart = microtime(true); - if (!$tgtdir) { - $tgtdir = dirname($srcfile); - } - - $output = array(); - $return = null; - $this->errors = array(); - - //wkhtmltoimage must be installed with compiled sources - if (strtoupper($srcfmt) == 'MAARCH' || strtoupper($srcfmt) == 'HTML') { - copy($srcfile, str_ireplace('.maarch', '.', $srcfile) . '.html'); - if (file_exists('/usr/bin/mywkhtmltoimage')) { - $command = "mywkhtmltoimage --width 164 --height 105 --quality 100 --zoom 0.2 " - . escapeshellarg(str_ireplace('.maarch', '.', $srcfile) . '.html') . " " - . escapeshellarg($tgtdir . basename(str_ireplace('.maarch', '.', $srcfile)) . '.png'); - } else { - $envVar = "export DISPLAY=FRPAROEMINT:0.0 ; "; - $command = $envVar . "wkhtmltoimage --width 164 --height 105 --quality 100 --zoom 0.2 " - . escapeshellarg(str_ireplace('.maarch', '.', $srcfile) . '.html') . " " - . escapeshellarg($tgtdir . basename(str_ireplace('.maarch', '.', $srcfile)) . '.png'); - } - } else { - $command = "convert -thumbnail 200x300 -background white -alpha remove " - . escapeshellarg($srcfile) . "[0] " - . escapeshellarg($tgtdir . basename($srcfile) . '.png'); - } - //echo $command . PHP_EOL;exit; - $timestart_command = microtime(true); - exec($command, $output, $return); - Core_Logs_Service::debug(['message'=>'[TIMER] Commande : ' . $command]); - Core_Logs_Service::executionTimeLog($timestart_command, '', 'debug', '[TIMER] Convert_ProcessThumbnailsAbstract_Service::launchThumbnails__exec'); - - if ($return === 0) { - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - } else { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => $return . $output, - ); - } - if (strtoupper($srcfmt) == 'MAARCH' || strtoupper($srcfmt) == 'HTML') { - $returnArray = array(); - unlink(str_ireplace('.maarch', '.', $srcfile) . '.html'); - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - } - Core_Logs_Service::executionTimeLog($timestart, '', 'debug', '[TIMER] Convert_ProcessThumbnailsAbstract_Service::launchThumbnails'); - return $returnArray; - } - - /** - * Updating the database with the location information of the document on the - * new docserver - * @param string $collId collection - * @param string $resTable res table - * @param string $adrTable adr table - * @param bigint $resId Id of the resource to process - * @param docserver $docserver docserver object - * @param string $path location of the resource on the docserver - * @param string $fileName file name of the resource on the docserver - * @return array $returnArray the result - */ - private function updateDatabase( - $collId, - $resTable, - $adrTable, - $resId, - $docserver, - $path, - $fileName - ) { - try { - $docserver->path_template = str_replace( - DIRECTORY_SEPARATOR, - '#', - $docserver->path_template - ); - $path = str_replace($docserver->path_template, '', $path); - $dbConv = new Database($GLOBALS['configFile']); - $query = "update convert_stack set status = 'P' where " - . " coll_id = ? and res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $collId, - $resId - ) - ); - - $query = "select * from " . $adrTable - . " where res_id = ? order by adr_priority"; - $stmt = $dbConv->query($query, array($resId)); - if ($stmt->rowCount() == 0) { - $query = "select docserver_id, path, filename, offset_doc, fingerprint" - . " from " . $resTable . " where res_id = ?"; - $stmt = $dbConv->query($query, array($resId)); - $recordset = $stmt->fetchObject(); - $resDocserverId = $recordset->docserver_id; - $resPath = $recordset->path; - $resFilename = $recordset->filename; - $resOffsetDoc = $recordset->offset_doc; - $fingerprintInit = $recordset->fingerprint; - $query = "select adr_priority_number from docservers " - . " where docserver_id = ?"; - $stmt = $dbConv->query($query, array($resDocserverId)); - $recordset = $stmt->fetchObject(); - $query = "insert into " . $adrTable . " (res_id, " - . "docserver_id, path, filename, offset_doc, fingerprint, " - . "adr_priority) values (?, ?, ?, ?, ?, ?, ?)"; - $stmt = $dbConv->query( - $query, - array( - $resId, - $resDocserverId, - $resPath, - $resFilename, - $resOffsetDoc, - $fingerprintInit, - $recordset->adr_priority_number - ) - ); - } - - $query = "select * from " . $adrTable - . " where res_id = ? and adr_type = 'TNL'"; - $stmt = $dbConv->query($query, array($resId)); - if ($stmt->rowCount() == 0) { - $query = "insert into " . $adrTable . " (res_id, docserver_id, " - . "path, filename, offset_doc, fingerprint, adr_priority, adr_type) values (" - . "?, ?, ?, ?, ?, ?, ?, ?)"; - $stmt = $dbConv->query( - $query, - array( - $resId, - $docserver->docserver_id, - $path, - $fileName, - $offsetDoc, - $fingerprint, - $docserver->adr_priority_number, - 'TNL' - ) - ); - } else { - $query = "update " . $adrTable . " set docserver_id = ?, " - . " path = ?, filename = ?, offset_doc = ?, fingerprint = ?, adr_priority = ?" - . " where res_id = ? and adr_type = ? "; - $stmt = $dbConv->query( - $query, - array( - $docserver->docserver_id, - $path, - $fileName, - $offsetDoc, - $fingerprint, - $docserver->adr_priority_number, - $resId, - 'TNL' - ) - ); - } - if ($_SESSION['user']['UserId'] <> '') { - $user = $_SESSION['user']['UserId']; - } else { - $user = 'CONVERT_BOT'; - } - $query = "insert into history (table_name, record_id, " - . "event_type, user_id, event_date, info, id_module) values (" - . "?, ?, 'ADD', '" . $user . "', " - . $dbConv->current_datetime() - . ", ?, 'convert')"; - $stmt = $dbConv->query( - $query, - array( - $resTable, - $resId, - "process thumbnails done" - ) - ); - - $query = "update " . $resTable - . " set tnl_result = '1', is_multi_docservers = 'Y' where " - . " res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $resId - ) - ); - $returnArray = array( - 'status' => '0', - 'value' => '', - 'error' => '', - ); - return $returnArray; - } catch (Exception $e) { - $returnArray = array( - 'status' => '1', - 'value' => '', - 'error' => $e->getMessage(), - ); - return $returnArray; - } - } - - /** - * Updating the database with the error code - * @param string $resTable res table - * @param bigint $resId Id of the resource to process - * @param string $result error code - * @return nothing - */ - private function manageErrorOnDb( - $resTable, - $resId, - $result - ) { - $dbConv = new Database($GLOBALS['configFile']); - $query = "update " . $resTable - . " set tnl_result = ? where " - . " res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $result, - $resId - ) - ); - } - - /** - * Test if the record is already processed by convert module - * @param string $resTable res table - * @param bigint $resId Id of the resource to process - * @return boolean - */ - public function isAlreadyProcessedByhumbnails( - $resTable, - $resId - ) { - $dbConv = new Database($GLOBALS['configFile']); - $query = "select tnl_result from " . $resTable - . " where res_id = ?"; - $stmt = $dbConv->query( - $query, - array( - $resId - ) - ); - $rs = $stmt->fetchObject(); - if ( - empty($rs->tnl_result) || - $rs->tnl_result == '0' - ) { - return false; - } else { - return true; - } - } -}