Skip to content
Snippets Groups Projects
Commit 387eeacc authored by VESSILLER's avatar VESSILLER
Browse files

NEW modification structure archive et revision taches planifiees

parent 574c2c05
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
<name>Bulletins</name>
<summary>Dématérialisation des bulletins de paie</summary>
<description><![CDATA[Dématérialisation des bulletins de paie]]></description>
<version>3.1.1</version>
<version>3.1.2</version>
<licence>agpl</licence>
<author mail="support@open-dsi.fr" >Open-DSI</author>
<namespace>Dematpayslip</namespace>
......
......@@ -195,7 +195,7 @@ class ArchiveProcess extends TimedJob {
$this->_timeZone = new DateTimeZone($timeZoneName);
// run once by interval
//$taskDefaultInterval = 120;
//$taskDefaultInterval = 60;
$taskDefaultInterval = 3600 * 4; // 4h
$taskInterval = intval($this->_config->getAppValue($this->_appName,$this->_appName . '_archive_cron_interval', $taskDefaultInterval));
//print __METHOD__ . ' : time_zone_name=' . $timeZoneName . ', cron_interval=' . $taskInterval . "\n";
......@@ -256,18 +256,17 @@ class ArchiveProcess extends TimedJob {
if ($result < 0) {
$msgErrorList = $dematpayslipArchive->getMsgList('error');
$this->_log('Error : ' . explode("\r\n", $msgErrorList), self::LOG_ERROR);
foreach ($msgErrorList as $msgError) {
$this->_log('Error : ' . $msgError, self::LOG_ERROR);
}
$processMsgList['error'][] = $dematpayslipArchive;
$dematpayslipArchive->setError(1);
$this->_dematpayslipArchiveMapper->update($dematpayslipArchive);
} else {
$msgSuccessList = $dematpayslipArchive->getMsgList('success');
if (!empty($msgSuccessList)) {
$this->_log('Success : ' . explode("\r\n", $msgSuccessList), self::LOG_SUCCESS);
foreach ($msgSuccessList as $msgSuccess) {
$this->_log('Success : ' . $msgSuccess, self::LOG_SUCCESS);
}
$processMsgList['success'][] = $dematpayslipArchive;
$dematpayslipArchive->setError(0);
$dematpayslipArchive->setOrientationProgress(DematpayslipArchive::OPERATION_FINISHED);
$this->_dematpayslipArchiveMapper->update($dematpayslipArchive);
}
}
}
......
......@@ -281,12 +281,9 @@ class IndexationProcess extends TimedJob {
$result = $process->indexation($processMsgList);
if ($result < 0) {
$this->_log('Indexation process : Error : ', self::LOG_ERROR);
$msgList = $process->getMsgList();
if (!empty($msgList['error'])) {
foreach ($msgList['error'] as $msgError) {
$this->_log("\n" . $msgError, self::LOG_ERROR);
}
$msgErrorList = $process->getMsgList('error');
foreach ($msgErrorList as $msgError) {
$this->_log('Error : ' . $msgError, self::LOG_ERROR);
}
} else {
$nbError = count($processMsgList['error']);
......
......@@ -318,8 +318,8 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
* @param IDBConnection $dbConnection Database connection
* @param IL10N $l10n Lang
* @param IRootFolder $rootFolder Root folder
* @param DematpayslipArchiveMapper $dematpayslipArchiveMapper Archive table mapper
* @param DematpayslipUserMapper $dematpayslipUserMapper User table mapper
* @param DematpayslipArchiveMapper $dematpayslipArchiveMapper Archive mapper
* @param DematpayslipUserMapper $dematpayslipUserMapper User mapper
* @param DateTimeZone $dateTimeZone [=null] Date time zone
* @return int <0 if errors else >0 on success
*/
......@@ -335,7 +335,7 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
try {
// Demat config
$dematAppDataDir = $config->getAppValue($appName, 'app_data_dir', 'dematpayslip');
$appDataDir = $config->getAppValue($appName, 'app_data_dir', 'dematpayslip');
$userId = $config->getAppValue($appName, 'user_id', 'demat');
// Pastell API config
......@@ -361,7 +361,7 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
}
if ($canModifyArchive === false) {
$this->_msgList['error'][] = $l10n->t('L\'archive "' . $this->getFilePath() . '" a déjà été créée.');
$this->_msgList['warning'][] = $l10n->t('L\'archive "' . $this->getFilePath() . '" a déjà été créée.');
} else {
// 1. create document
if (empty($this->getPastellIdDocument())) {
......@@ -373,7 +373,7 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
$this->setPastellLastAction($responseData['last_action']['action']);
$this->setStatus(self::STATUS_CREATED);
$this->setStatusTime($nowDateTime->getTimestamp());
$this->update($this);
$dematpayslipArchiveMapper->update($this);
}
// 2. set document title
if ($this->getStatus() == self::STATUS_CREATED) {
......@@ -384,16 +384,26 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
$this->setPastellLastAction($responseData['content']['last_action']['action']);
$this->setStatus(self::STATUS_TITLED);
$this->setStatusTime($nowDateTime->getTimestamp());
$this->update($this);
$dematpayslipArchiveMapper->update($this);
}
// 3. send document file
if ($this->getStatus() == self::STATUS_TITLED) {
$nowDateTime = new DateTime('now', $dateTimeZone);
$fileId = $this->getIdFile();
//$filePath = Filesystem::getPath($fileId);
//$file = Filesystem::getFileInfo($filePath);
$fileNode = $rootFolder->getById($fileId)[0];
if ($fileNode instanceof File) {
$filePath = $this->getFilePath();
$fileNode = null;
try {
$fileNodeExists = $rootFolder->nodeExists($filePath);
if ($fileNodeExists) {
//$fileNode = $rootFolder->getById($fileId)[0];
$fileNode = $rootFolder->get($filePath);
} else {
$this->_msgList['error'][] = $l10n->t('Le fichier a envoyer en archive "' . $filePath . '" [id = ' . $fileId . '] n\'a pas été trouvé [status=' . $this->getStatus() .'].');
}
} catch (Exception $e) {
$this->_msgList['error'][] = $l10n->t('Impossible de récupérer le fichier a envoyer en archive "' . $filePath . '" [status=' . $this->getStatus() .'].');
}
if (!empty($fileNode) && $fileNode instanceof File) {
$fileName = $fileNode->getName();
$fileContent = $fileNode->getContent();
$responseData = $pastellAPI->postEntityDocumentFile($pastellConfigFlow->getIdE(), $this->getPastellIdDocument(), 'document', 0, $fileName, $fileContent);
......@@ -401,6 +411,8 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
$this->setStatus(self::STATUS_FILE_SENT);
$this->setStatusTime($nowDateTime->getTimestamp());
$dematpayslipArchiveMapper->update($this);
} else {
$this->_msgList['error'][] = $l10n->t('Mauvais fichier a envoyer en archive "' . $filePath . '" [status=' . $this->getStatus() .'].');
}
}
// 4. send to SAE
......@@ -428,17 +440,14 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
);
$jsonFileName = 'sae_config.json';
//$tmpJsonFilePath = tempnam(sys_get_temp_dir(), 'sae');
$userFolder = $rootFolder->getUserFolder($userId);
$dematAppDataTmpPath = $userFolder->getPath() . DIRECTORY_SEPARATOR . $dematAppDataDir;
$tmpJsonFilePath = tempnam($dematAppDataTmpPath, 'sae');
if (!$tmpJsonFilePath) {
$this->_msgList['error'][] = $l10n->t('Impossible de créer le nom du fichier temporaire "' . $dematAppDataTmpPath . '" [status=' . $this->getStatus() .'].');
$appDataTmpPath = $userFolder->getPath() . DIRECTORY_SEPARATOR . $appDataDir . DIRECTORY_SEPARATOR . DematpayslipProcess::$appTmpDirName;
$saeConfigFilePath = $appDataTmpPath . DIRECTORY_SEPARATOR . uniqid('sae');
if (!$saeConfigFilePath) {
$this->_msgList['error'][] = $l10n->t('Impossible de créer le nom du fichier temporaire "' . $appDataTmpPath . '" [status=' . $this->getStatus() .'].');
} else {
//$result = Filesystem::fopen($tmpJsonFilePath, 'w+');
try {
//$jsonFileContent = Filesystem::file_get_contents($tmpJsonFilePath);
$tmpJsonFile = $rootFolder->newFile($tmpJsonFilePath, json_encode($saeConfigArr));
$tmpJsonFile = $rootFolder->newFile($saeConfigFilePath, json_encode($saeConfigArr));
$nowDateTime = new DateTime('now', $dateTimeZone);
$responseData = $pastellAPI->postEntityDocumentExternalData($pastellConfigFlow->getIdE(), $this->getPastellIdDocument(), 'sae_config', array(
'file_name' => $jsonFileName,
......@@ -447,9 +456,10 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
$this->setPastellLastAction($responseData['content']['last_action']['action']);
$this->setStatus(self::STATUS_METADATA_SENT);
$this->setStatusTime($nowDateTime->getTimestamp());
$this->update($this);
$dematpayslipArchiveMapper->update($this);
$tmpJsonFile->delete();
} catch (Exception $e) {
$this->_msgList['error'][] = $l10n->t('Impossible d\'écrire dans le fichier temporaire "' . $tmpJsonFilePath . '" [status=' . $this->getStatus() .'].');
$this->_msgList['error'][] = $l10n->t('Impossible d\'écrire dans le fichier temporaire "' . $saeConfigFilePath . '" [status=' . $this->getStatus() .'].');
}
}
}
......@@ -471,9 +481,13 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
if ($this->getStatus() < self::STATUS_ORIENTATION) {
$this->_msgList['error'][] = $l10n->t('L\'archive "' . $this->getFilePath() . '" n\'a pas été correctement créée [status=' . $this->getStatus() .'].');
$this->setError(1);
} else {
$this->_msgList['success'][] = $l10n->t('L\'archive "' . $this->getFilePath() . '" a été créée.');
$this->setError(0);
$this->setOperationProgress(self::OPERATION_FINISHED);
}
$dematpayslipArchiveMapper->update($this);
}
if (count($this->_msgList['error']) > 0) {
......@@ -482,7 +496,7 @@ class DematpayslipArchive extends Entity implements JsonSerializable {
return 1;
}
} catch (Exception $e) {
$this->_msgList['error'][] = $e->getMessage();
$this->_msgList['error'][] = 'Exception ' . __METHOD__ . ' : error=' . $e->getMessage();
return -1;
}
}
......
This diff is collapsed.
<?php
namespace OCA\Dematpayslip\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
use OCA\Dematpayslip\Db\DematpayslipArchive;
class Version030102Date20210812020000 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$table = $schema->getTable('dematpayslip_archive');
$table->dropIndex('demat_archive_id_file');
$table->addIndex(['id_file'], 'demat_archive_id_file');
return $schema;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment