diff --git a/css/admin.css b/css/admin.css index a5d2c766493b64a3cd195b676ddd6b019bfba792..db932faf4f6063254debf5eeca24d0153db1ad8b 100644 --- a/css/admin.css +++ b/css/admin.css @@ -21,6 +21,14 @@ /* * Bootstrap 4.3.1 */ + +.text-danger { + color: red; +} + +/* + * Alert + */ .alert { position: relative; padding: 0.75rem 1.25rem; diff --git a/lib/BackgroundJob/ArchiveProcess.php b/lib/BackgroundJob/ArchiveProcess.php index 22d83e44500f2a7b0a4a43f43b25ae27d116bcbe..0d7953ac06f43d54d1e89d115cb53e783ec50de9 100644 --- a/lib/BackgroundJob/ArchiveProcess.php +++ b/lib/BackgroundJob/ArchiveProcess.php @@ -191,13 +191,12 @@ class ArchiveProcess extends TimedJob { //$timeZoneDefaultName = 'UTC'; $timeZoneDefaultName = 'Europe/Paris'; - $timeZoneName = $this->_config->getAppValue($this->_appName, $this->_appName . '_archive_cron_time_zone', $timeZoneDefaultName); + $timeZoneName = $this->_config->getAppValue($this->_appName, 'archive_cron_time_zone', $timeZoneDefaultName); $this->_timeZone = new DateTimeZone($timeZoneName); // run once by interval - //$taskDefaultInterval = 60; $taskDefaultInterval = 3600 * 4; // 4h - $taskInterval = intval($this->_config->getAppValue($this->_appName,$this->_appName . '_archive_cron_interval', $taskDefaultInterval)); + $taskInterval = intval($this->_config->getAppValue($this->_appName,'archive_cron_interval', $taskDefaultInterval)); //print __METHOD__ . ' : time_zone_name=' . $timeZoneName . ', cron_interval=' . $taskInterval . "\n"; $this->setInterval($taskInterval); } @@ -215,10 +214,9 @@ class ArchiveProcess extends TimedJob { print __METHOD__ . ' : cron run start_time=' . $dateTimeNow->getTimestamp() . ", date=" . $dateTimeNow->format('d/m/Y H:i:s') . "\n"; // log file - $logLevel = $this->_config->getAppValue($this->_appName, $this->_appName . '_archive_cron_log_level', self::LOG_DEBUG); - //$logLevel = $this->_config->getAppValue($this->_appName, $this->_appName . '_archive_cron_log_level', self::LOG_ERROR); - $logMode = $this->_config->getAppValue($this->_appName, $this->_appName . '_archive_cron_log_mode', self::LOG_MODE_FILE); - $logFileName = $this->_config->getAppValue($this->_appName, $this->_appName . '_archive_cron_log_file_name', $this->_appName . '_archive_cron.log'); + $logLevel = $this->_config->getAppValue($this->_appName, 'archive_cron_log_level', self::LOG_ERROR); + $logMode = $this->_config->getAppValue($this->_appName, 'archive_cron_log_mode', self::LOG_MODE_NONE); + $logFileName = $this->_config->getAppValue($this->_appName, 'archive_cron_log_file_name', $this->_appName . '_archive_cron.log'); $logFilePath = $this->_config->getSystemValue('logfile'); if (empty($logFilePath)) { $logDirPath = $this->_config->getSystemValue('datadirectory'); diff --git a/lib/BackgroundJob/IndexationProcess.php b/lib/BackgroundJob/IndexationProcess.php index 9b9144411ad936cb36595770d7f10de79b1e4b3e..de768631eec9111c1851bbc24c40486b7d0c688a 100644 --- a/lib/BackgroundJob/IndexationProcess.php +++ b/lib/BackgroundJob/IndexationProcess.php @@ -217,13 +217,12 @@ class IndexationProcess extends TimedJob { //$timeZoneDefaultName = 'UTC'; $timeZoneDefaultName = 'Europe/Paris'; - $timeZoneName = $this->_config->getAppValue($this->_appName, $this->_appName . '_indexation_cron_time_zone', $timeZoneDefaultName); + $timeZoneName = $this->_config->getAppValue($this->_appName, 'indexation_cron_time_zone', $timeZoneDefaultName); $this->_timeZone = new DateTimeZone($timeZoneName); // run once by interval - //$taskDefaultInterval = 60; $taskDefaultInterval = 3600; // 1h - $taskInterval = intval($this->_config->getAppValue($this->_appName,$this->_appName . '_indexation_cron_interval', $taskDefaultInterval)); + $taskInterval = intval($this->_config->getAppValue($this->_appName,'indexation_cron_interval', $taskDefaultInterval)); //print __METHOD__ . ' : time_zone_name=' . $timeZoneName . ', cron_interval=' . $taskInterval . "\n"; $this->setInterval($taskInterval); } @@ -241,11 +240,9 @@ class IndexationProcess extends TimedJob { print __METHOD__ . ' : cron run start_time=' . $dateTimeNow->getTimestamp() . ", date=" . $dateTimeNow->format('d/m/Y H:i:s') . "\n"; // log file - $logLevel = $this->_config->getAppValue($this->_appName, $this->_appName . '_indexation_cron_log_level', self::LOG_DEBUG); - //$logLevel = $this->_config->getAppValue($this->_appName, $this->_appName . '_indexation_cron_log_level', self::LOG_ERROR); - //$logMode = $this->_config->getAppValue($this->_appName, $this->_appName . '_indexation_cron_log_mode', self::LOG_MODE_SCREEN); - $logMode = $this->_config->getAppValue($this->_appName, $this->_appName . '_indexation_cron_log_mode', self::LOG_MODE_FILE); - $logFileName = $this->_config->getAppValue($this->_appName, $this->_appName . '_indexation_cron_log_file_name', $this->_appName . '_indexation_cron.log'); + $logLevel = $this->_config->getAppValue($this->_appName, 'indexation_cron_log_level', self::LOG_ERROR); + $logMode = $this->_config->getAppValue($this->_appName, 'indexation_cron_log_mode', self::LOG_MODE_NONE); + $logFileName = $this->_config->getAppValue($this->_appName, 'indexation_cron_log_file_name', $this->_appName . '_indexation_cron.log'); $logFilePath = $this->_config->getSystemValue('logfile'); if (empty($logFilePath)) { $logDirPath = $this->_config->getSystemValue('datadirectory'); diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php index 8b178312cd11a03f5de7924148b92c26a9eb887c..e7548e7bc74174ded257cdbc9056ad8cc362f841 100644 --- a/lib/Settings/AdminSettings.php +++ b/lib/Settings/AdminSettings.php @@ -4,6 +4,7 @@ namespace OCA\Dematpayslip\Settings; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IDateTimeFormatter; +use OCP\IDateTimeZone; use OCP\IDBConnection; use OCP\IL10N; use OCP\Share\IManager as IShareManager; @@ -13,23 +14,26 @@ use OCP\Settings\ISettings; use OCP\Files\Folder; +use DateTime; use Exception; + +use OCA\Dematpayslip\BackgroundJob\ArchiveProcess; +use OCA\Dematpayslip\BackgroundJob\IndexationProcess; use OCA\Dematpayslip\Db\DematpayslipUserMapper; -//use OCA\Pastell\PastellAPI; -//use OCA\Pastell\Db\PastellConfig; -//use OCA\Pastell\Db\PastellConfigMapper; -//use OCA\Pastell\Db\PastellConfigFlow; +// Pastell use OCA\Pastell\Db\PastellConfigFlowMapper; class AdminSettings implements ISettings { /** - * @var string App name + * @var string app name */ private $_appName; - /** @var IConfig */ + /** + * @var IConfig config + */ private $_config; /** @@ -37,38 +41,67 @@ class AdminSettings implements ISettings { */ private $_dbConnection; - /** @var IL10N */ - private $l; + /** + * @var IL10N lang + */ + private $_l10n; - /** @var IDateTimeFormatter */ + /** + * @var IDateTimeFormatter + */ private $_dateTimeFormatter; - /** @var IRootFolder */ + /** + * @var IDateTimeZone date time zone + */ + private $_dateTimeZone; + + /** + * @var IRootFolder root folder + */ private $_rootFolder; - /** @var IShareManager */ + /** + * @var IShareManager share manager + */ private $_shareManager; - /** @var IUserManager */ + /** + * @var IUserManager + */ private $_userManager; - /** @var string User Id */ + /** + * @var string user id + */ private $_userId; - /** @var DematpayslipUserMapper */ + /** + * @var DematpayslipUserMapper + */ private $_dematpayslipUserMapper; // dematpayslip config private $_dematpayslipConfigList = array(); /** - * Pastell app exists - * - * @var bool + * @var bool Pastell app exists */ private $_pastellAppExists = false; - /** @var array Message List */ + /** + * @var array Pastell config flow list + */ + private $_pastellConfigFlowList; + + /** + * @var array server config list + */ + private $_serverConfigList; + + /** + * @var array message list + */ private $_msgList = array( 'error' => array(), 'success' => array(), @@ -81,11 +114,130 @@ class AdminSettings implements ISettings { * @return array Params for template */ private function _assignParams() { - // demat config - $this->_dematpayslipConfigList['payslip_dir'] = $this->_config->getAppValue($this->_appName, 'payslip_dir', 'Bulletins'); // Bulletins - $this->_dematpayslipConfigList['user_id'] = $this->_config->getAppValue($this->_appName, 'user_id', 'demat'); // demat user - $this->_dematpayslipConfigList['app_data_dir'] = $this->_config->getAppValue($this->_appName, 'app_data_dir', 'dematpayslip'); // dematpayslip directory of user demat (upload, check, report, etc) - $this->_dematpayslipConfigList['pastell_use'] = $this->_config->getAppValue($this->_appName, 'pastell_use', ''); // uses pastell + // server config + $this->_serverConfigList = array( + 'time_zone_name' => $this->_dateTimeZone->getTimeZone()->getName() + ); + + // Demat config + $this->_dematpayslipConfigList['payslip_dir'] = $this->_config->getAppValue($this->_appName, 'payslip_dir', 'Bulletins'); + $this->_dematpayslipConfigList['user_id'] = $this->_config->getAppValue($this->_appName, 'user_id', 'demat'); + $this->_dematpayslipConfigList['app_data_dir'] = $this->_config->getAppValue($this->_appName, 'app_data_dir', 'dematpayslip'); + $this->_dematpayslipConfigList['indexation_cron_time_zone'] = $this->_config->getAppValue($this->_appName, 'indexation_cron_time_zone', $this->_dateTimeZone->getTimeZone()->getName()); + $this->_dematpayslipConfigList['indexation_cron_interval'] = $this->_config->getAppValue($this->_appName, 'indexation_cron_interval', 3600); + $this->_dematpayslipConfigList['indexation_cron_log_level'] = $this->_config->getAppValue($this->_appName, 'indexation_cron_log_level', IndexationProcess::LOG_ERROR); + $this->_dematpayslipConfigList['indexation_cron_log_mode'] = $this->_config->getAppValue($this->_appName, 'indexation_cron_log_mode', IndexationProcess::LOG_MODE_NONE); + $this->_dematpayslipConfigList['indexation_cron_log_file_name'] = $this->_config->getAppValue($this->_appName, 'indexation_cron_log_file_name', $this->_appName . '_indexation_cron.log'); + $this->_dematpayslipConfigList['archive_cron_time_zone'] = $this->_config->getAppValue($this->_appName, 'archive_cron_time_zone', $this->_dateTimeZone->getTimeZone()->getName()); + $this->_dematpayslipConfigList['archive_cron_interval'] = $this->_config->getAppValue($this->_appName, 'archive_cron_interval', 3600 * 4); + $this->_dematpayslipConfigList['archive_cron_log_level'] = $this->_config->getAppValue($this->_appName, 'archive_cron_log_level', ArchiveProcess::LOG_ERROR); + $this->_dematpayslipConfigList['archive_cron_log_mode'] = $this->_config->getAppValue($this->_appName, 'archive_cron_log_mode', ArchiveProcess::LOG_MODE_NONE); + $this->_dematpayslipConfigList['archive_cron_log_file_name'] = $this->_config->getAppValue($this->_appName, 'archive_cron_log_file_name', $this->_appName . '_archive_cron.log'); + + // indexation job + $indexationJobArr = array(); + $query = $this->_dbConnection->getQueryBuilder(); + $query->select('*') + ->from('jobs') + ->where($query->expr()->eq('class', $query->createNamedParameter('OCA\Dematpayslip\BackgroundJob\IndexationProcess'))); + $querySQL = $query->getSQL(); + $stmt = $query->execute(); + if (!$stmt) { + $this->_msgList['error'][] = 'Error sql=' . $querySQL . ', error=' . $this->_dbConnection->getError(); + } else { + if ($arr = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $lastRun = $arr['last_run']; + $lastRunFormat = ''; + if (!empty($lastRun)) { + $dateTimeLastRun = new DateTime(); + $dateTimeLastRun->setTimezone($this->_dateTimeZone->getTimeZone()); + $dateTimeLastRun->setTimestamp($lastRun); + $lastRunFormat = $dateTimeLastRun->format('d/m/Y H:i'); + } + + $lastChecked = $arr['last_checked']; + $lastCheckedFormat = ''; + if (!empty($lastChecked)) { + $dateTimeLastChecked = new DateTime(); + $dateTimeLastChecked->setTimezone($this->_dateTimeZone->getTimeZone()); + $dateTimeLastChecked->setTimestamp($lastChecked); + $lastCheckedFormat = $dateTimeLastChecked->format('d/m/Y H:i'); + } + + $reservedAt = $arr['reserved_at']; + $reservedAtFormat = ''; + if (!empty($reservedAt)) { + $dateTimeReservedAt = new DateTime(); + $dateTimeReservedAt->setTimezone($this->_dateTimeZone->getTimeZone()); + $dateTimeReservedAt->setTimestamp($reservedAt); + $reservedAtFormat = $dateTimeReservedAt->format('d/m/Y H:i'); + } + + $indexationJobArr = array( + 'id' => $arr['id'], + 'last_run' => $lastRun, + 'last_run_format' => $lastRunFormat, + 'last_checked' => $lastChecked, + 'last_checked_format' => $lastCheckedFormat, + 'reserved_at' => $reservedAt, + 'reserved_at_format' => $reservedAtFormat, + ); + } + } + + // archive job + $archiveJobArr = array(); + $query = $this->_dbConnection->getQueryBuilder(); + $query->select('*') + ->from('jobs') + ->where($query->expr()->eq('class', $query->createNamedParameter('OCA\Dematpayslip\BackgroundJob\ArchiveProcess'))); + $querySQL = $query->getSQL(); + $stmt = $query->execute(); + if (!$stmt) { + $this->_msgList['error'][] = 'Error sql=' . $querySQL . ', error=' . $this->_dbConnection->getError(); + } else { + if ($arr = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $lastRun = $arr['last_run']; + $lastRunFormat = ''; + if (!empty($lastRun)) { + $dateTimeLastRun = new DateTime(); + $dateTimeLastRun->setTimezone($this->_dateTimeZone->getTimeZone()); + $dateTimeLastRun->setTimestamp($lastRun); + $lastRunFormat = $dateTimeLastRun->format('d/m/Y H:i'); + } + + $lastChecked = $arr['last_checked']; + $lastCheckedFormat = ''; + if (!empty($lastChecked)) { + $dateTimeLastChecked = new DateTime(); + $dateTimeLastChecked->setTimezone($this->_dateTimeZone->getTimeZone()); + $dateTimeLastChecked->setTimestamp($lastChecked); + $lastCheckedFormat = $dateTimeLastChecked->format('d/m/Y H:i'); + } + + $reservedAt = $arr['reserved_at']; + $reservedAtFormat = ''; + if (!empty($reservedAt)) { + $dateTimeReservedAt = new DateTime(); + $dateTimeReservedAt->setTimezone($this->_dateTimeZone->getTimeZone()); + $dateTimeReservedAt->setTimestamp($reservedAt); + $reservedAtFormat = $dateTimeReservedAt->format('d/m/Y H:i'); + } + + $archiveJobArr = array( + 'id' => $arr['id'], + 'last_run' => $lastRun, + 'last_run_format' => $lastRunFormat, + 'last_checked' => $lastChecked, + 'last_checked_format' => $lastCheckedFormat, + 'reserved_at' => $reservedAt, + 'reserved_at_format' => $reservedAtFormat, + ); + } + } + + // Pastell config + $this->_dematpayslipConfigList['pastell_use'] = $this->_config->getAppValue($this->_appName, 'pastell_use', ''); $this->_dematpayslipConfigList['pastell_config_f1_id'] = $this->_config->getAppValue($this->_appName, 'pastell_config_f1_id'); // archiving for 5 years $this->_dematpayslipConfigList['pastell_config_f2_id'] = $this->_config->getAppValue($this->_appName, 'pastell_config_f2_id'); // archiving for 50 years @@ -93,17 +245,17 @@ class AdminSettings implements ISettings { $this->_pastellConfigFlowMapper = null; $this->_pastellConfigFlowList = array(); if ($this->_pastellAppExists === true) { - //$pastellUse = intval($this->_dematpayslipConfigList['pastell_use']); - //if ($pastellUse === 1) { - $this->_pastellConfigFlowMapper = new PastellConfigFlowMapper($this->_dbConnection); - $this->_pastellConfigFlowList = $this->_pastellConfigFlowMapper->findAll(); - //} + $this->_pastellConfigFlowMapper = new PastellConfigFlowMapper($this->_dbConnection); + $this->_pastellConfigFlowList = $this->_pastellConfigFlowMapper->findAll(); } return array( 'dematpayslipConfigList' => $this->_dematpayslipConfigList, 'pastellConfigFlowList' => $this->_pastellConfigFlowList, - 'msgList' => $this->_msgList + 'msgList' => $this->_msgList, + 'archiveJobArr' => $archiveJobArr, + 'indexationJobArr' => $indexationJobArr, + 'serverConfigList' => $this->_serverConfigList, ); } @@ -111,7 +263,8 @@ class AdminSettings implements ISettings { * Get payslip share list * * @return array|\OCP\Share\IShare[][] - * @throws \OCP\Files\NotFoundException + * + * @throws Exception */ private function _payslipShareList() { $payslipShareList = array(); @@ -123,7 +276,7 @@ class AdminSettings implements ISettings { try { $userFolder = $this->_rootFolder->getUserFolder($payslipUserId); } catch (Exception $e) { - $this->_msgList['error'][] = $this->l->t('Utilisateur non trouvé') . ' : ' . $payslipUserId . "<br />" . $e->getMessage(); + $this->_msgList['error'][] = $this->_l10n->t('Utilisateur non trouvé') . ' : ' . $payslipUserId . "<br />" . $e->getMessage(); } if (empty($this->_msgList['error'])) { @@ -137,10 +290,9 @@ class AdminSettings implements ISettings { } /** - * Reshare all payslips + * Share again all payslips * - * @throws \OCP\Files\InvalidPathException - * @throws \OCP\Files\NotFoundException + * @throws Exception */ private function _payslipsReshare() { $payslipDir = $this->_config->getAppValue($this->_appName, 'payslip_dir'); @@ -150,7 +302,7 @@ class AdminSettings implements ISettings { try { $userFolder = $this->_rootFolder->getUserFolder($payslipUserId); } catch (Exception $e) { - $this->_msgList['error'][] = $this->l->t('Répertoire utilisateur non trouvé') . ' : ' . $payslipUserId . "<br />" . $e->getMessage(); + $this->_msgList['error'][] = $this->_l10n->t('Répertoire utilisateur non trouvé') . ' : ' . $payslipUserId . "<br />" . $e->getMessage(); } if (empty($this->_msgList['error'])) { @@ -181,14 +333,12 @@ class AdminSettings implements ISettings { if (count($dematpayslipUserList) === 1) { $dematpayslipUser = $dematpayslipUserList[0]; - // s'il l'utilisateur n'a pas desactive la dematerialisation de son bulletin de paie - //if ($dematpayslipUser->getDisabled() != 1) { - // verifier que l'utilisateur existe toujours + // check if user still exists $dematpayslipUserExists = $this->_userManager->userExists($dematpayslipUser->getUserId()); if ($dematpayslipUserExists === true) { - // verifier si le dossier n'est pas deja partage + // check directory not shared yet if (!in_array($payslipMatriculeNode->getId(), $payslipMatriculeShareNodeIdList)) { - // reshare + // share again $payslipMatriculeShare = $this->_shareManager->newShare(); $payslipMatriculeShare->setNode($payslipMatriculeNode); $payslipMatriculeShare->setShareType(\OC\Share\Share::SHARE_TYPE_USER); @@ -198,10 +348,9 @@ class AdminSettings implements ISettings { $payslipMatriculeShare = $this->_shareManager->createShare($payslipMatriculeShare); } } - //} } else { // error - $this->_msgList['error'][] = $this->l->t('Impossible de re-partager le dossier [matricule="' . $matricule . '"] : aucun utilisateur n\'est associé.'); + $this->_msgList['error'][] = $this->_l10n->t('Impossible de re-partager le dossier [matricule="' . $matricule . '"] : aucun utilisateur n\'est associé.'); break; } } @@ -211,10 +360,9 @@ class AdminSettings implements ISettings { } /** - * Unshare all payslips + * Un-share all payslips * - * @throws \OCP\Files\NotFoundException - * @throws \OCP\Share\Exceptions\ShareNotFound + * @throws Exception */ private function _payslipsUnshare() { $payslipShareList = self::_payslipShareList(); @@ -233,8 +381,9 @@ class AdminSettings implements ISettings { * * @param string $AppName App name * @param IConfig $config Config - * @param IL10N $l Lang + * @param IL10N $l10n Lang * @param IDateTimeFormatter $dateTimeFormatter Date formatter + * @param IDateTimeZone $dateTimeZone Date time zone * @param IDBConnection $dbConnection DB connection * @param IRootFolder $rootFolder Root folder * @param IShareManager $shareManager Share manager @@ -244,8 +393,9 @@ class AdminSettings implements ISettings { */ public function __construct($AppName, IConfig $config, - IL10N $l, + IL10N $l10n, IDateTimeFormatter $dateTimeFormatter, + IDateTimeZone $dateTimeZone, IDBConnection $dbConnection, IRootFolder $rootFolder, IShareManager $shareManager, @@ -255,8 +405,9 @@ class AdminSettings implements ISettings { ) { $this->_appName = $AppName; $this->_config = $config; - $this->l = $l; + $this->_l10n = $l10n; $this->_dateTimeFormatter = $dateTimeFormatter; + $this->_dateTimeZone = $dateTimeZone; $this->_dbConnection = $dbConnection; $this->_rootFolder = $rootFolder; $this->_shareManager = $shareManager; @@ -274,9 +425,7 @@ class AdminSettings implements ISettings { * * @return TemplateResponse * - * @throws \OCP\Files\InvalidPathException - * @throws \OCP\Files\NotFoundException - * @throws \OCP\Share\Exceptions\ShareNotFound + * @throws Exception */ public function getForm() { $action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING); @@ -292,6 +441,124 @@ class AdminSettings implements ISettings { $this->_payslipsUnshare(); } elseif ($action === 'payslips_reshare') { $this->_payslipsReshare(); + } elseif ($action === 'indexation_config_cron') { + $cronTimeZone = $this->_dateTimeZone->getTimeZone()->getName(); + $cronInterval = filter_input(INPUT_GET, 'indexation_cron_interval', FILTER_SANITIZE_NUMBER_INT); + $cronLogLevel = filter_input(INPUT_GET, 'indexation_cron_log_level', FILTER_SANITIZE_NUMBER_INT); + $cronLogMode = filter_input(INPUT_GET, 'indexation_cron_log_mode', FILTER_SANITIZE_NUMBER_INT); + $cronLogFileName = filter_input(INPUT_GET, 'indexation_cron_log_file_name', FILTER_SANITIZE_STRING); + + // check values + if (!($cronInterval > 0)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Fréquence" est obligatoire.'); + } + if (!($cronLogLevel >= IndexationProcess::LOG_SUCCESS)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Niveau" est obligatoire.'); + } + if (!($cronLogMode >= IndexationProcess::LOG_MODE_NONE)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Mode" est obligatoire.'); + } + if (empty($cronLogFileName)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Nom de fichier" est obligatoire.'); + } + + if (count($this->_msgList['error']) <= 0) { + $this->_config->setAppValue($this->_appName, 'indexation_cron_time_zone', $cronTimeZone); + $this->_config->setAppValue($this->_appName, 'indexation_cron_interval', $cronInterval); + $this->_config->setAppValue($this->_appName, 'indexation_cron_log_level', $cronLogLevel); + $this->_config->setAppValue($this->_appName, 'indexation_cron_log_mode', $cronLogMode); + $this->_config->setAppValue($this->_appName, 'indexation_cron_log_file_name', $cronLogFileName); + } + } elseif ($action === 'indexation_cron_update') { + $cronId = filter_input(INPUT_GET, 'indexation_cron_id', FILTER_SANITIZE_NUMBER_INT); + $cronRun = filter_input(INPUT_GET, 'indexation_cron_run', FILTER_SANITIZE_NUMBER_INT); + $cronLastRun = filter_input(INPUT_GET, 'indexation_cron_last_run', FILTER_SANITIZE_NUMBER_INT); + + // check values + if (!($cronId > 0)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "ID" est manquant.'); + } + + if (count($this->_msgList['error']) <= 0) { + try { + if ($cronRun == 0) { + // stop + $query = $this->_dbConnection->getQueryBuilder(); + $query->update('jobs') + ->set('reserved_at', $query->createNamedParameter($cronLastRun)) + ->where($query->expr()->eq('id', $query->createNamedParameter($cronId))) + ->execute(); + } elseif ($cronRun == 1) { + // init + $query = $this->_dbConnection->getQueryBuilder(); + $query->update('jobs') + ->set('reserved_at', $query->createNamedParameter(0)) + ->where($query->expr()->eq('id', $query->createNamedParameter($cronId))) + ->execute(); + } + } catch (Exception $e) { + $this->_msgList['error'][] = $this->_l10n->t('Error : ' . $e->getMessage()); + } + } + } elseif ($action === 'archive_config_cron') { + $cronTimeZone = $this->_dateTimeZone->getTimeZone()->getName(); + $cronInterval = filter_input(INPUT_GET, 'archive_cron_interval', FILTER_SANITIZE_NUMBER_INT); + $cronLogLevel = filter_input(INPUT_GET, 'archive_cron_log_level', FILTER_SANITIZE_NUMBER_INT); + $cronLogMode = filter_input(INPUT_GET, 'archive_cron_log_mode', FILTER_SANITIZE_NUMBER_INT); + $cronLogFileName = filter_input(INPUT_GET, 'archive_cron_log_file_name', FILTER_SANITIZE_STRING); + + // check values + if (!($cronInterval > 0)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Fréquence" est obligatoire.'); + } + if (!($cronLogLevel >= ArchiveProcess::LOG_SUCCESS)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Niveau" est obligatoire.'); + } + if (!($cronLogMode >= ArchiveProcess::LOG_MODE_NONE)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Mode" est obligatoire.'); + } + if (empty($cronLogFileName)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Nom de fichier" est obligatoire.'); + } + + if (count($this->_msgList['error']) <= 0) { + $this->_config->setAppValue($this->_appName, 'archive_cron_time_zone', $cronTimeZone); + $this->_config->setAppValue($this->_appName, 'archive_cron_interval', $cronInterval); + $this->_config->setAppValue($this->_appName, 'archive_cron_log_level', $cronLogLevel); + $this->_config->setAppValue($this->_appName, 'archive_cron_log_mode', $cronLogMode); + $this->_config->setAppValue($this->_appName, 'archive_cron_log_file_name', $cronLogFileName); + } + } elseif ($action === 'archive_cron_update') { + $cronId = filter_input(INPUT_GET, 'archive_cron_id', FILTER_SANITIZE_NUMBER_INT); + $cronRun = filter_input(INPUT_GET, 'archive_cron_run', FILTER_SANITIZE_NUMBER_INT); + $cronLastRun = filter_input(INPUT_GET, 'archive_cron_last_run', FILTER_SANITIZE_NUMBER_INT); + + // check values + if (!($cronId > 0)) { + $this->_msgList['error'][] = $this->_l10n->t('Le champ "ID" est manquant.'); + } + + if (count($this->_msgList['error']) <= 0) { + try { + if ($cronRun == 0) { + // stop + $query = $this->_dbConnection->getQueryBuilder(); + $query->update('jobs') + ->set('reserved_at', $query->createNamedParameter($cronLastRun)) + ->where($query->expr()->eq('id', $query->createNamedParameter($cronId))) + ->execute(); + } elseif ($cronRun == 1) { + // init + $query = $this->_dbConnection->getQueryBuilder(); + $query->update('jobs') + ->set('reserved_at', $query->createNamedParameter(0)) + ->where($query->expr()->eq('id', $query->createNamedParameter($cronId))) + ->execute(); + } + } catch (Exception $e) { + $this->_msgList['error'][] = $this->_l10n->t('Error : ' . $e->getMessage()); + } + } } elseif ($action === 'pastell_config') { $pastellUse = filter_input(INPUT_GET, 'pastell_use', FILTER_SANITIZE_NUMBER_INT); $pastellConfigFlow1Id = filter_input(INPUT_GET, 'pastell_config_f1_id', FILTER_SANITIZE_NUMBER_INT); @@ -304,21 +571,21 @@ class AdminSettings implements ISettings { if ($pastellUse == 1 && $configPastellUse == 1) { // check parameters if (!($pastellConfigFlow1Id > 0)) { - $this->_msgList['error'][] = $this->l->t('Le champ "Flux pour archivage sur 5 ans" est manquant.'); + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Flux pour archivage sur 5 ans" est manquant.'); } if (!($pastellConfigFlow2Id > 0)) { - $this->_msgList['error'][] = $this->l->t('Le champ "Flux pour archivage sur 50 ans" est manquant.'); + $this->_msgList['error'][] = $this->_l10n->t('Le champ "Flux pour archivage sur 50 ans" est manquant.'); } } if (count($this->_msgList['error']) <= 0) { $pastellConfigF1Id = $this->_config->getAppValue($this->_appName, 'pastell_config_f1_id'); - // FIX -- Pastell config flow is NULL + // Pastell config flow is NULL if (empty($pastellConfigF1Id)) { $this->_config->deleteAppValue($this->_appName,'pastell_config_f1_id'); } $pastellConfigF2Id = $this->_config->getAppValue($this->_appName, 'pastell_config_f2_id'); - // FIX -- Pastell config flow is NULL + // Pastell config flow is NULL if (empty($pastellConfigF2Id)) { $this->_config->deleteAppValue($this->_appName,'pastell_config_f2_id'); } @@ -329,7 +596,7 @@ class AdminSettings implements ISettings { if (!empty($action)) { if (count($this->_msgList['error']) <= 0) { - $this->_msgList['success'][] = $this->l->t('Opération réussie.'); + $this->_msgList['success'][] = $this->_l10n->t('Opération réussie.'); } } diff --git a/templates/settings/admin.php b/templates/settings/admin.php index 97e89fe3b0b2d926c4147a544cae6d25248238dc..ace0de17e2a32f56c4f4705fad5bf4db67f75985 100644 --- a/templates/settings/admin.php +++ b/templates/settings/admin.php @@ -1,12 +1,17 @@ <?php /** @var array $_ */ /** @var \OCP\IL10N $l */ + use \OCA\Dematpayslip\BackgroundJob\ArchiveProcess; + use \OCA\Dematpayslip\BackgroundJob\IndexationProcess; ?> <?php // assigned $msgList = (isset($_['msgList']) ? $_['msgList'] : array()); $dematpayslipConfigList = (isset($_['dematpayslipConfigList']) ? $_['dematpayslipConfigList'] : array()); $pastellConfigFlowList = (isset($_['pastellConfigFlowList']) ? $_['pastellConfigFlowList'] : array()); + $indexationJobArr = (isset($_['indexationJobArr']) ? $_['indexationJobArr'] : array()); + $archiveJobArr = (isset($_['archiveJobArr']) ? $_['archiveJobArr'] : array()); + $serverConfigList = (isset($_['serverConfigList']) ? $_['serverConfigList'] : array()); // alert messages $htmlAlert = ''; @@ -107,6 +112,222 @@ <button type="submit" class="btn btn-default"><?php p($l->t('Valider')); ?></button> </div> </form> + <br /> + <br /> + <h3><?php p($l->t('Tâche planifiée - Indexation')); ?></h3> + <form name="dematpayslip_indexation_config_cron" method="get"> + <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>" /> + <input type="hidden" name="action" value="indexation_config_cron" /> + <div> + <label for="indexation_cron_time_zone"> + <span><?php p($l->t('Fuseau horaire')); ?> : </span> + </label> + <input type="text" name="indexation_cron_time_zone" value="<?php if (!empty($dematpayslipConfigList['indexation_cron_time_zone'])) { print $dematpayslipConfigList['indexation_cron_time_zone']; } ?>" disabled="disabled" /> + <span>( <?php print $l->t('Serveur') . ' : ' . $serverConfigList['time_zone_name']; ?> )</span> + </div> + <div> + <label for="indexation_cron_interval"> + <span><?php p($l->t('Fréquence')); ?> : </span> + </label> + <input type="number" name="indexation_cron_interval" value="<?php print $dematpayslipConfigList['indexation_cron_interval']; ?>" min="30" step="1" max="86400" /> + <span><?php p($l->t('secondes')); ?></span> + </div> + <div> + <label for="indexation_cron_log_level"> + <span><?php p($l->t('Niveau')); ?> : </span> + </label> + <select name="indexation_cron_log_level"> + <option value="1" <?php if ($dematpayslipConfigList['indexation_cron_log_level']==IndexationProcess::LOG_DEBUG) { print 'selected="selected"'; } ?>><?php p($l->t('Debug')); ?></option> + <option value="2" <?php if ($dematpayslipConfigList['indexation_cron_log_level']==IndexationProcess::LOG_WARNING) { print 'selected="selected"'; } ?>><?php p($l->t('Danger')); ?></option> + <option value="3" <?php if ($dematpayslipConfigList['indexation_cron_log_level']==IndexationProcess::LOG_ERROR) { print 'selected="selected"'; } ?>><?php p($l->t('Erreur')); ?></option> + </select> + </div> + <div> + <label for="indexation_cron_log_mode"> + <span><?php p($l->t('Mode')); ?> : </span> + </label> + <select name="indexation_cron_log_mode"> + <option value="-1" <?php if ($dematpayslipConfigList['indexation_cron_log_mode']==IndexationProcess::LOG_MODE_NONE) { print 'selected="selected"'; } ?>><?php p($l->t('Aucun')); ?></option> + <option value="0" <?php if ($dematpayslipConfigList['indexation_cron_log_mode']==IndexationProcess::LOG_MODE_FILE) { print 'selected="selected"'; } ?>><?php p($l->t('Fichier')); ?></option> + <option value="1" <?php if ($dematpayslipConfigList['indexation_cron_log_mode']==IndexationProcess::LOG_MODE_SCREEN) { print 'selected="selected"'; } ?>><?php p($l->t('Ecran')); ?></option> + </select> + </div> + <div> + <label for="indexation_cron_log_file_name"> + <span><?php p($l->t('Nom du fichier')); ?> : </span> + </label> + <input type="text" name="indexation_cron_log_file_name" value="<?php print $dematpayslipConfigList['indexation_cron_log_file_name']; ?>" /> + </div> + <div> + <button type="submit" class="btn btn-default"><?php p($l->t('Valider')); ?></button> + </div> + </form> + <br /> + <?php + if (!empty($indexationJobArr)) { + if ($indexationJobArr['last_run'] > 0) { + ?> + <form id="indexation_form_cron_update" name="dematpayslip_indexation_cron_update" method="get"> + <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>" /> + <input type="hidden" name="action" value="indexation_cron_update" /> + <input type="hidden" name="indexation_cron_id" value="<?php print $indexationJobArr['id']; ?>" /> + <div> + <label> + <span><?php p($l->t('Dernière exécution')); ?> : <?php print $indexationJobArr['last_run_format']; ?></span> + </label> + <label> + <span> | <?php p($l->t('Dernière vérification')); ?> : <?php print $indexationJobArr['last_checked_format']; ?></span> + </label> + <label> + <?php + if ($indexationJobArr['reserved_at'] > $indexationJobArr['last_run']) { + ?> + <span class="text-danger"> | <?php p($l->t('Lancé')); ?> : <?php print $indexationJobArr['reserved_at_format']; ?></span> + <?php + } elseif ($indexationJobArr['reserved_at'] == 0) { + ?> + <span> | <?php p($l->t('Prêt')); ?></span> + <?php + } else { + ?> + <span class="text-danger"> | <?php p($l->t('Stoppé')); ?></span> + <?php + } + ?> + </label> + <?php + if ($indexationJobArr['reserved_at'] > $indexationJobArr['last_run']) { + ?> +<!-- <input type="hidden" name="indexation_cron_run" value="1" />--> +<!-- <button type="submit" class="btn btn-default">--><?php //p($l->t('Réinitialiser')); ?><!--</button>--> + <?php + } elseif ($indexationJobArr['reserved_at'] == 0) { + ?> + <input type="hidden" name="indexation_cron_run" value="0" /> + <input type="hidden" name="indexation_cron_last_run" value="<?php print $indexationJobArr['last_run']; ?>" /> + <button type="submit" class="btn btn-default"><?php p($l->t('Arrêter')); ?></button> + <?php + } else { + ?> + <input type="hidden" name="indexation_cron_run" value="1" /> + <button type="submit" class="btn btn-default"><?php p($l->t('Démarrer')); ?></button> + <?php + } + ?> + </div> + </form> + <?php + } + } + ?> + <br /> + <br /> + <h3><?php p($l->t('Tâche planifiée - Archivage')); ?></h3> + <form name="dematpayslip_archive_config_cron" method="get"> + <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>" /> + <input type="hidden" name="action" value="archive_config_cron" /> + <div> + <label for="archive_cron_time_zone"> + <span><?php p($l->t('Fuseau horaire')); ?> : </span> + </label> + <input type="text" name="archive_cron_time_zone" value="<?php if (!empty($dematpayslipConfigList['archive_cron_time_zone'])) { print $dematpayslipConfigList['archive_cron_time_zone']; } ?>" disabled="disabled" /> + <span>( <?php print $l->t('Serveur') . ' : ' . $serverConfigList['time_zone_name']; ?> )</span> + </div> + <div> + <label for="archive_cron_interval"> + <span><?php p($l->t('Fréquence')); ?> : </span> + </label> + <input type="number" name="archive_cron_interval" value="<?php print $dematpayslipConfigList['archive_cron_interval']; ?>" min="30" step="1" max="86400" /> + <span><?php p($l->t('secondes')); ?></span> + </div> + <div> + <label for="archive_cron_log_level"> + <span><?php p($l->t('Niveau')); ?> : </span> + </label> + <select name="archive_cron_log_level"> + <option value="1" <?php if ($dematpayslipConfigList['archive_cron_log_level']==ArchiveProcess::LOG_DEBUG) { print 'selected="selected"'; } ?>><?php p($l->t('Debug')); ?></option> + <option value="2" <?php if ($dematpayslipConfigList['archive_cron_log_level']==ArchiveProcess::LOG_WARNING) { print 'selected="selected"'; } ?>><?php p($l->t('Danger')); ?></option> + <option value="3" <?php if ($dematpayslipConfigList['archive_cron_log_level']==ArchiveProcess::LOG_ERROR) { print 'selected="selected"'; } ?>><?php p($l->t('Erreur')); ?></option> + </select> + </div> + <div> + <label for="archive_cron_log_mode"> + <span><?php p($l->t('Mode')); ?> : </span> + </label> + <select name="archive_cron_log_mode"> + <option value="-1" <?php if ($dematpayslipConfigList['archive_cron_log_mode']==ArchiveProcess::LOG_MODE_NONE) { print 'selected="selected"'; } ?>><?php p($l->t('Aucun')); ?></option> + <option value="0" <?php if ($dematpayslipConfigList['archive_cron_log_mode']==ArchiveProcess::LOG_MODE_FILE) { print 'selected="selected"'; } ?>><?php p($l->t('Fichier')); ?></option> + <option value="1" <?php if ($dematpayslipConfigList['archive_cron_log_mode']==ArchiveProcess::LOG_MODE_SCREEN) { print 'selected="selected"'; } ?>><?php p($l->t('Ecran')); ?></option> + </select> + </div> + <div> + <label for="archive_cron_log_file_name"> + <span><?php p($l->t('Nom du fichier')); ?> : </span> + </label> + <input type="text" name="archive_cron_log_file_name" value="<?php print $dematpayslipConfigList['archive_cron_log_file_name']; ?>" /> + </div> + <div> + <button type="submit" class="btn btn-default"><?php p($l->t('Valider')); ?></button> + </div> + </form> + <br /> + <?php + if (!empty($archiveJobArr)) { + if ($archiveJobArr['last_run'] > 0) { + ?> + <form id="archive_form_cron_update" name="dematpayslip_archive_cron_update" method="get"> + <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>" /> + <input type="hidden" name="action" value="archive_cron_update" /> + <input type="hidden" name="archive_cron_id" value="<?php print $archiveJobArr['id']; ?>" /> + <div> + <label> + <span><?php p($l->t('Dernière exécution')); ?> : <?php print $archiveJobArr['last_run_format']; ?></span> + </label> + <label> + <span> | <?php p($l->t('Dernière vérification')); ?> : <?php print $archiveJobArr['last_checked_format']; ?></span> + </label> + <label> + <?php + if ($archiveJobArr['reserved_at'] > $archiveJobArr['last_run']) { + ?> + <span class="text-danger"> | <?php p($l->t('Lancé')); ?> : <?php print $archiveJobArr['reserved_at_format']; ?></span> + <?php + } elseif ($archiveJobArr['reserved_at'] == 0) { + ?> + <span> | <?php p($l->t('Prêt')); ?></span> + <?php + } else { + ?> + <span class="text-danger"> | <?php p($l->t('Stoppé')); ?></span> + <?php + } + ?> + </label> + <?php + if ($archiveJobArr['reserved_at'] > $archiveJobArr['last_run']) { + ?> +<!-- <input type="hidden" name="archive_cron_run" value="1" />--> +<!-- <button type="submit" class="btn btn-default">--><?php //p($l->t('Réinitialiser')); ?><!--</button>--> + <?php + } elseif ($archiveJobArr['reserved_at'] == 0) { + ?> + <input type="hidden" name="archive_cron_run" value="0" /> + <input type="hidden" name="archive_cron_last_run" value="<?php print $archiveJobArr['last_run']; ?>" /> + <button type="submit" class="btn btn-default"><?php p($l->t('Arrêter')); ?></button> + <?php + } else { + ?> + <input type="hidden" name="archive_cron_run" value="1" /> + <button type="submit" class="btn btn-default"><?php p($l->t('Démarrer')); ?></button> + <?php + } + ?> + </div> + </form> + <?php + } + } + ?> </div> <?php if (count($pastellConfigFlowList) > 0) { ?>