Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OHRM5X-2100 : Automation Script forLeave holidays testing #1634

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3826a31
OHRM5X-1928: Upgrade app vue dependencies (#1586)
Jan 10, 2023
0b5bf29
OHRM5X-1931: Develop claim - events API (#1587)
DulsaraNethmin Jan 10, 2023
dabac9e
OHRM5X-1932: Refactor claim - event API (#1594)
DulsaraNethmin Jan 13, 2023
4b953a1
OHRM5X-1942: Develop claim - expense type API create operation (#1598)
ManulMax Jan 18, 2023
cad5fe1
OHRM5X-1947: Develop claim - request API create operation (#1599)
ManulMax Jan 24, 2023
12e094d
OHRM5X-1940: Refactor claim - event API (#1600)
DulsaraNethmin Jan 26, 2023
0cea398
OHRM5X-2001: Develop claim - event list screen (#1605)
DulsaraNethmin Feb 1, 2023
3a0eed5
OHRM5X-2001: Make claim - event name non editable (#1606)
DulsaraNethmin Feb 1, 2023
630350d
OHRM5X-1993: Define password policies and required strength (#1604)
ManulMax Feb 2, 2023
4c5e656
OHRM5X-1943: Develop claim - expense type API (#1607)
DulsaraNethmin Feb 8, 2023
fe03835
OHRM5X-1988: Bump core - oxd dependency to v2 (#1602)
Feb 8, 2023
9e5dc6a
OHRM5X-2034: Check auth - minimum required level of password strength…
ManulMax Feb 9, 2023
6af9cbf
OHRM5X-2041: Add auth - enforce weak password screen (#1610)
Feb 9, 2023
74c97f9
OHRM5X-2039: Initiate help plugin (#1613)
devishke-orange Feb 10, 2023
260ddb1
OHRM5X-2045: Develop claim - expense type screens (#1612)
DulsaraNethmin Feb 10, 2023
686036a
OHRM5X-797: Add help icon to app layout (#1609)
Feb 10, 2023
3e828c3
OHRM5X-2063: Add claim - configurations menu items (#1617)
DulsaraNethmin Feb 16, 2023
ffc3298
OHRM5X-2100 : Scripting automation script for leave - holidays
Ravindu-Bhagya Mar 2, 2023
0a63d78
OHRM5X-2100 : after ddoing some changes to code
Ravindu-Bhagya Mar 2, 2023
a2ab330
OHRM5X - 2100 : did some changes
Ravindu-Bhagya Mar 2, 2023
eb5d548
remove one testcase because its failed in github, cant find the reason
Ravindu-Bhagya Mar 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
-->
<project name="OrangeHRM" basedir="." default="dist">

<property name="version" value="5.3"/>
<property name="version" value="5.4"/>
<property name="package.name" value="orangehrm-${version}"/>
<resolvepath propertyName="project.dir" file=".."/>
<resolvepath propertyName="dist.dir" file="dist"/>
Expand Down
253 changes: 253 additions & 0 deletions installer/Migration/V5_4_0/LangStringHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
<?php
/**
* OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
* all the essential functionalities required for any enterprise.
* Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
*
* OrangeHRM 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 2 of the License, or (at your option) any later version.
*
* OrangeHRM 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 this program;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA
*/

namespace OrangeHRM\Installer\Migration\V5_4_0;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use OrangeHRM\Installer\Util\V1\Dto\LangString;
use OrangeHRM\Installer\Util\V1\LanguageHelper;

class LangStringHelper
{
private Connection $connection;
private ?LanguageHelper $languageHelper = null;

/**
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}

/**
* @return Connection
*/
protected function getConnection(): Connection
{
return $this->connection;
}

/**
* @return QueryBuilder
*/
protected function createQueryBuilder(): QueryBuilder
{
return $this->getConnection()->createQueryBuilder();
}

/**
* @return LanguageHelper
*/
public function getLangHelper(): LanguageHelper
{
if (!$this->languageHelper instanceof LanguageHelper) {
$this->languageHelper = new LanguageHelper($this->getConnection());
}
return $this->languageHelper;
}

/**
* @param string $moduleName
* @return int
*/
public function getGroupId(string $moduleName): int
{
$q = $this->createQueryBuilder();
$q->select('module.id')
->from('ohrm_i18n_group', 'module')
->where('module.name = :group')
->setParameter('group', $moduleName);
return $q->executeQuery()->fetchOne();
}

/**
* @param string $groupName
* @return void
*/
public function deleteNonCustomizedLangStrings(string $groupName): void
{
$groupId = $this->getLangHelper()->getGroupIdByName($groupName);
$langStringIds = $this->getLangStringIdsForGroup($groupId);
$qb = $this->createQueryBuilder()
->delete('ohrm_i18n_translate')
->where('ohrm_i18n_translate.customized != 1');
$qb->andWhere($qb->expr()->in('ohrm_i18n_translate.lang_string_id', ':langStringIds'))
->setParameter('langStringIds', $langStringIds, Connection::PARAM_INT_ARRAY)
->executeQuery();

$deleteStrings = $this->getNonCustomizedLangStringIds($groupId);
$qb = $this->createQueryBuilder()
->delete('ohrm_i18n_lang_string');
$qb->andWhere($qb->expr()->in('ohrm_i18n_lang_string.id', ':deleteIds'))
->setParameter('deleteIds', $deleteStrings, Connection::PARAM_INT_ARRAY)
->executeQuery();
}

/**
* @param int $groupId
* @return array
*/
private function getLangStringIdsForGroup(int $groupId): array
{
$q = $this->createQueryBuilder();
$q->select('langString.id')
->from('ohrm_i18n_lang_string', 'langString')
->where('langString.group_id = :module')
->setParameter('module', $groupId);
$results = $q->executeQuery()->fetchAllAssociative();
return array_column($results, 'id');
}

/**
* @param int $groupId
* @return array
*/
private function getNonCustomizedLangStringIds(int $groupId): array
{
$q = $this->createQueryBuilder()
->select('translate.lang_string_id')
->from('ohrm_i18n_lang_string', 'langString')
->leftJoin('langString', 'ohrm_i18n_translate', 'translate', 'langString.id = translate.lang_string_id')
->where('langString.group_id = :module')
->andWhere('translate.customized = 1')
->setParameter('module', $groupId);
$results = $q->executeQuery()->fetchAllAssociative();
$customStrings = array_column($results, 'lang_string_id');
if ($customStrings == null) {
return $this->getLangStringIdsForGroup($groupId);
}

$qb = $this->createQueryBuilder()
->select('langString.id')
->from('ohrm_i18n_lang_string', 'langString');
$qb->andWhere($qb->expr()->notIn('langString.id', ':customStrings'))
->andWhere('langString.group_id = :module')
->setParameter('customStrings', $customStrings, Connection::PARAM_INT_ARRAY)
->setParameter('module', $groupId);
$results = $qb->executeQuery()->fetchAllAssociative();
return array_column($results, 'id');
}

/**
* @param string $groupName
* @return void
*/
public function insertOrUpdateLangStrings(string $groupName)
{
$langStringArray = $this->getLangHelper()->readLangStrings(
realpath(__DIR__ . "/lang-string/$groupName.yaml"),
$groupName
);
foreach ($langStringArray as $langString) {
$langStringId = $this->getLangStringIdByValueAndGroup($langString->getValue());
if (is_null($langStringId)) {
$this->saveLangString($langString);
} else {
$this->updateLangString($langStringId, $langString);
}
}
}

/**
* @param string $langStringValue
* @param int|null $groupId
* @return int|null
*/
public function getLangStringIdByValueAndGroup(string $langStringValue, ?int $groupId = null): ?int
{
$q = $this->createQueryBuilder()
->select('langString.id')
->from('ohrm_i18n_lang_string', 'langString')
->where('langString.value = :source')
->setParameter('source', $langStringValue);
if (!is_null($groupId)) {
$q->andWhere('langString.group_id = :module')
->setParameter('module', $groupId);
}

if (false != $result = $q->executeQuery()->fetchOne()) {
return $result;
}
return null;
}

/**
* @param string $langStringValue
* @param int $groupId
* @return int|null
*/
public function getLangStringIdByUnitIdAndGroup(string $langStringUnitId, int $groupId): ?int
{
$q = $this->createQueryBuilder()
->select('langString.id')
->from('ohrm_i18n_lang_string', 'langString')
->where('langString.unit_id = :unitId')
->andWhere('langString.group_id = :group')
->setParameter('unitId', $langStringUnitId)
->setParameter('group', $groupId);
if (false != $result = $q->executeQuery()->fetchOne()) {
return $result;
}
return null;
}

/**
* @param LangString $langString
* @return void
*/
private function saveLangString(LangString $langString): void
{
$this->createQueryBuilder()
->insert('ohrm_i18n_lang_string')
->values([
'value' => ':string',
'group_id' => ':module',
'unit_id' => ':unitId',
'version' => ':version',
'note' => ':note'
])
->setParameter('string', $langString->getValue())
->setParameter('module', $langString->getGroupId())
->setParameter('unitId', $langString->getUnitId())
->setParameter('version', $langString->getVersion())
->setParameter('note', $langString->getNote())
->executeQuery();
}

/**
* @param int $langStringId
* @param LangString $langString
* @return void
*/
private function updateLangString(int $langStringId, LangString $langString): void
{
// TODO:: have to look into `version` and `note`
$this->createQueryBuilder()
->update('ohrm_i18n_lang_string')
->set('ohrm_i18n_lang_string.unit_id', ':key')
->set('ohrm_i18n_lang_string.group_id', ':groupId')
->where('ohrm_i18n_lang_string.id = :id')
->setParameter('key', $langString->getUnitId())
->setParameter('groupId', $langString->getGroupId())
->setParameter('id', $langStringId)
->executeQuery();
}
}
Loading