添加 'installer/Migration/V5_4_0_cn/Migration.php'

This commit is contained in:
zhongjin 2023-05-05 23:16:59 +08:00
parent bc61c22c97
commit c719e6d22e

View File

@ -0,0 +1,231 @@
<?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_cn;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use OrangeHRM\Entity\WorkflowStateMachine;
use OrangeHRM\Installer\Util\V1\AbstractMigration;
class Migration extends AbstractMigration
{
protected ?TranslationHelper $translationHelper = null;
/**
* @inheritDoc
*/
public function up(): void
{
$langCodes = [
'zh_Hans_CN'
];
foreach ($langCodes as $langCode) {
$this->getTranslationHelper()->addTranslations($langCode);
}
$this->updateLangStringVersion($this->getVersion());
}
/**
* @inheritDoc
*/
public function getVersion(): string
{
return '5.4.0';
}
private function updateLangStringVersion(string $version): void
{
$qb = $this->createQueryBuilder()
->update('ohrm_i18n_lang_string', 'lang_string')
->set('lang_string.version', ':version')
->setParameter('version', $version);
$qb->andWhere($qb->expr()->isNull('lang_string.version'))
->executeStatement();
}
private function getLangStringHelper(): LangStringHelper
{
if (is_null($this->langStringHelper)) {
$this->langStringHelper = new LangStringHelper(
$this->getConnection()
);
}
return $this->langStringHelper;
}
/**
* @return TranslationHelper
*/
public function getTranslationHelper(): TranslationHelper
{
if (is_null($this->translationHelper)) {
$this->translationHelper = new TranslationHelper($this->getConnection());
}
return $this->translationHelper;
}
private function insertI18nGroups(): void
{
$this->getConnection()->createQueryBuilder()
->insert('ohrm_i18n_group')
->values([
'name' => ':name',
'title' => ':title',
])
->setParameters([
'name' => 'claim',
'title' => 'Claim',
])
->executeQuery();
}
private function insertMenuItems(
string $menuTitle,
?int $screenId,
?int $parentId,
int $level,
int $orderHint,
int $status,
?string $additionalParams
): void {
$this->getConnection()->createQueryBuilder()
->insert('ohrm_menu_item')
->values([
'menu_title' => ':menu_title',
'screen_id' => ':screen_id',
'parent_id' => ':parent_id',
'level' => ':level',
'order_hint' => ':order_hint',
'status' => ':status',
'additional_params' => ':additional_params',
])
->setParameters([
'menu_title' => $menuTitle,
'screen_id' => $screenId,
'parent_id' => $parentId,
'level' => $level,
'order_hint' => $orderHint,
'status' => $status,
'additional_params' => $additionalParams,
])
->executeQuery();
}
public function getParentId(string $menu_title, ?int $parent_id): int
{
return $this->getConnection()->createQueryBuilder()
->select('id')
->from('ohrm_menu_item')
->where('menu_title = :menu_title')
->setParameter('menu_title', $menu_title)
->andWhere('parent_id = :parent_id')
->setParameter('parent_id', $parent_id)
->executeQuery()
->fetchOne();
}
public function getScreenId(string $name): int
{
return $this->getConnection()->createQueryBuilder()
->select('id')
->from('ohrm_screen')
->where('name = :name')
->setParameter('name', $name)
->executeQuery()
->fetchOne();
}
public function checkClaimExists(): bool
{
return $this->getConnection()->createQueryBuilder()
->select('id')
->from('ohrm_menu_item')
->where('menu_title = :menu_title')
->setParameter('menu_title', 'Claim')
->executeQuery()
->fetchOne();
}
private function cleanClaimScreens(): void
{
$screenNames = [
'Events',
'Expense Types',
'Employee Claim List',
'Assign Claim',
'Submit Claim',
'My Claims List',
'View Claim Module',
'View Create Event',
'View Create Expense'
];
$qb = $this->createQueryBuilder()
->delete('ohrm_screen');
$qb->andWhere($qb->expr()->in('ohrm_screen.name', ':screenName'))
->setParameter('screenName', $screenNames, Connection::PARAM_STR_ARRAY)
->executeQuery();
}
private function insertWorkflowState(
string $state,
string $role,
int $action,
string $resultingState,
int $priority
): void {
$this->createQueryBuilder()
->insert('ohrm_workflow_state_machine')
->values(
[
'workflow' => ':workflow',
'state' => ':state',
'role' => ':role',
'action' => ':action',
'resulting_state' => ':resultingState',
'roles_to_notify' => ':rolesToNotify',
'priority' => ':priority',
]
)
->setParameter('workflow', WorkflowStateMachine::FLOW_CLAIM)
->setParameter('state', $state)
->setParameter('role', $role)
->setParameter('action', $action)
->setParameter('resultingState', $resultingState)
->setParameter('rolesToNotify', '')
->setParameter('priority', $priority)
->executeQuery();
}
private function deleteClaimWorkflowStates(): void
{
$this->createQueryBuilder()
->delete('ohrm_workflow_state_machine')
->where('workflow = :workflow')
->setParameter('workflow', 'CLAIM')
->executeQuery();
}
}