Some checks failed
Upgrade Test (4.x) / upgrade_test (map[file:V4_0.sql version:4.0]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_1.sql version:4.1]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_10.sql version:4.10]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_10_1.sql version:4.10.1]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_1_1.sql version:4.1.1]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_1_2.sql version:4.1.2]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_1_2_1.sql version:4.1.2.1]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_2_0_1.sql version:4.2.0.1]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_3.sql version:4.3]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_3_1.sql version:4.3.1]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_3_2.sql version:4.3.2]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_3_3.sql version:4.3.3]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_3_4.sql version:4.3.4]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_3_5.sql version:4.3.5]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_4.sql version:4.4]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_5.sql version:4.5]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_6.sql version:4.6]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_6_0_1.sql version:4.6.0.1]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_7.sql version:4.7]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_8.sql version:4.8]) (push) Has been cancelled
Upgrade Test (4.x) / upgrade_test (map[file:V4_9.sql version:4.9]) (push) Has been cancelled
Build / build (push) Has been cancelled
Cypress / cypress (push) Has been cancelled
Docker Build Test / build (push) Has been cancelled
Lint / lint (push) Has been cancelled
Scheduled Test / db_test (map[admin:mariadb-admin image:mariadb:11.0]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mariadb-admin image:mariadb:11.1]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mariadb-admin image:mariadb:11.2]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mariadb-admin image:mariadb:11.3]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mariadb-admin image:mariadb:11.4]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.0]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.10]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.11]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.1]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.2]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.3]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.4]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.5]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.6]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.7]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.8]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:10.9]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mariadb:5.5]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mysql:5.5]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mysql:5.6]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mysql:5.7]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mysql:8.0]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mysql:8.1]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mysql:8.2]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mysql:8.3]) (push) Has been cancelled
Scheduled Test / db_test (map[admin:mysqladmin image:mysql:8.4]) (push) Has been cancelled
Scheduled Test / php_test (php7.4) (push) Has been cancelled
Scheduled Test / php_test (php8.0) (push) Has been cancelled
Scheduled Test / php_test (php8.1) (push) Has been cancelled
Scheduled Test / php_test (php8.2) (push) Has been cancelled
Scheduled Test / php_test (php8.3) (push) Has been cancelled
Test / test (map[image:mariadb:10.3 name:mariadb103]) (push) Has been cancelled
Test / test (map[image:mysql:5.7 name:mysql57]) (push) Has been cancelled
Test / composer_check (push) Has been cancelled
Test / installation (push) Has been cancelled
237 lines
7.8 KiB
PHP
Executable File
237 lines
7.8 KiB
PHP
Executable File
<?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 3 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 OrangeHRM.
|
|
* If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
namespace OrangeHRM\Installer\Command;
|
|
|
|
use OrangeHRM\Authentication\Dto\UserCredential;
|
|
use OrangeHRM\Authentication\Utility\PasswordStrengthValidation;
|
|
use OrangeHRM\Installer\Exception\InvalidArgumentException;
|
|
use OrangeHRM\Installer\Util\Service\InstallerPasswordStrengthService;
|
|
use OrangeHRM\Installer\Util\SystemCheck;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Question\Question;
|
|
|
|
trait InstallerCommandHelperTrait
|
|
{
|
|
/**
|
|
* @param string $label
|
|
* @param callable|null $validator
|
|
* @return string
|
|
*/
|
|
private function getRequiredField(string $label, ?callable $validator = null): string
|
|
{
|
|
$question = new Question($label . ' ' . self::REQUIRED_TAG);
|
|
$question->setNormalizer(static function ($value) {
|
|
return $value !== null ? trim($value) : null;
|
|
});
|
|
$question->setValidator(function ($answer) use ($validator) {
|
|
$answer = $this->requiredValidator($answer);
|
|
if ($validator === null) {
|
|
return $answer;
|
|
}
|
|
return $validator($answer);
|
|
});
|
|
return $this->getIO()->askQuestion($question);
|
|
}
|
|
|
|
/**
|
|
* @param string|null $answer
|
|
* @return string|null
|
|
*/
|
|
private function requiredValidator(?string $answer): ?string
|
|
{
|
|
if ($answer === null || strlen($answer) === 0) {
|
|
throw new InvalidArgumentException(self::REQUIRED_WARNING);
|
|
}
|
|
return $answer;
|
|
}
|
|
|
|
/**
|
|
* @param string|null $value
|
|
* @return string|null
|
|
*/
|
|
private function databasePortValidator(?string $value): ?string
|
|
{
|
|
if (($value === null || strlen(trim($value)) === 0)
|
|
|| (is_numeric($value) && (int)$value >= 0 && (int)$value <= 65535)) {
|
|
return $value;
|
|
}
|
|
throw new InvalidArgumentException('Enter a valid port number: 0 - 65535');
|
|
}
|
|
|
|
/**
|
|
* @param string|null $value
|
|
* @param string $message
|
|
* @return string|null
|
|
*/
|
|
private function alphanumericValidator(?string $value, string $message): ?string
|
|
{
|
|
if (preg_match('/^[a-zA-Z0-9_]*$/', $value) === 1) {
|
|
return $value;
|
|
}
|
|
throw new InvalidArgumentException($message);
|
|
}
|
|
|
|
/**
|
|
* @param string|null $value
|
|
* @param string $message
|
|
* @return string|null
|
|
*/
|
|
private function emailValidator(?string $value, string $message): ?string
|
|
{
|
|
$match = preg_match(
|
|
"/^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/",
|
|
$value
|
|
);
|
|
if ($match === 1) {
|
|
return $value;
|
|
}
|
|
throw new InvalidArgumentException($message);
|
|
}
|
|
|
|
/**
|
|
* @param string|null $value
|
|
* @param string $message
|
|
* @return string|null
|
|
*/
|
|
private function phoneNumberValidator(?string $value, string $message): ?string
|
|
{
|
|
if (preg_match('/^[0-9+\-\/() ]+$/', $value) === 1) {
|
|
return $value;
|
|
}
|
|
throw new InvalidArgumentException($message);
|
|
}
|
|
|
|
/**
|
|
* @param InputInterface $input
|
|
* @param string $name
|
|
* @return bool
|
|
*/
|
|
private function hasOption(InputInterface $input, string $name): bool
|
|
{
|
|
$value = $input->getOption($name);
|
|
if ($value == null) {
|
|
return false;
|
|
}
|
|
return strlen(trim($value)) > 0;
|
|
}
|
|
|
|
/**
|
|
* @param array $systemCheckResults
|
|
*/
|
|
private function drawSystemCheckTable(array $systemCheckResults): void
|
|
{
|
|
$this->getIO()->title('System Check');
|
|
$this->getIO()->block(
|
|
'In order for your OrangeHRM installation to function properly, please ensure that all of the system check items listed below are green. If any are red, please take the necessary steps to fix them.'
|
|
);
|
|
foreach ($systemCheckResults as $category) {
|
|
$rows = [];
|
|
foreach ($category['checks'] as $check) {
|
|
switch ($check['value']['status']) {
|
|
case SystemCheck::PASSED:
|
|
$style = '<fg=black;bg=green>%s</>';
|
|
break;
|
|
case SystemCheck::BLOCKER:
|
|
$style = '<fg=white;bg=red>%s</>';
|
|
break;
|
|
case SystemCheck::ACCEPTABLE:
|
|
$style = '<fg=black;bg=yellow>%s</>';
|
|
break;
|
|
default:
|
|
$style = '<fg=default;bg=default>%s</>';
|
|
}
|
|
$status = sprintf($style, $check['value']['message']);
|
|
$rows[] = [$check['label'], $status];
|
|
}
|
|
$this->getIO()->table([$category['category']], $rows);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param OutputInterface $output
|
|
* @param string $step
|
|
* @param string $suffix
|
|
* @return ConsoleSectionOutput
|
|
*/
|
|
private function startSection(OutputInterface $output, string $step, string $suffix = ''): ConsoleSectionOutput
|
|
{
|
|
/** @var ConsoleSectionOutput $section */
|
|
$section = $output->section();
|
|
$section->writeln("* $step$suffix");
|
|
return $section;
|
|
}
|
|
|
|
/**
|
|
* @param ConsoleSectionOutput $section
|
|
* @param string $step
|
|
* @param string $suffix
|
|
*/
|
|
private function startStep(ConsoleSectionOutput $section, string $step, string $suffix = ''): void
|
|
{
|
|
$section->overwrite("* <comment>$step</comment>$suffix");
|
|
}
|
|
|
|
/**
|
|
* @param ConsoleSectionOutput $section
|
|
* @param string $step
|
|
* @param string $suffix
|
|
*/
|
|
private function completeStep(ConsoleSectionOutput $section, string $step, string $suffix = ''): void
|
|
{
|
|
$section->overwrite("<fg=green>* $step ✓</>$suffix");
|
|
}
|
|
|
|
/**
|
|
* @param string|null $text
|
|
* @param int $length
|
|
* @return string|null
|
|
*/
|
|
private function validateStrLength(?string $text, int $length): ?string
|
|
{
|
|
if ($text === null || mb_strlen($text) <= $length) {
|
|
return $text;
|
|
}
|
|
throw InvalidArgumentException::shouldNotExceedCharacters($length);
|
|
}
|
|
|
|
/**
|
|
* @param string $value
|
|
* @return string
|
|
* @throws InvalidArgumentException
|
|
*/
|
|
private function validatePassword(string $value): string
|
|
{
|
|
$passwordStrengthValidation = new PasswordStrengthValidation();
|
|
$passwordStrengthService = new InstallerPasswordStrengthService();
|
|
|
|
$credential = new UserCredential('', $value);
|
|
|
|
$passwordStrength = $passwordStrengthValidation->checkPasswordStrength($credential);
|
|
$messages = $passwordStrengthService->checkPasswordPolicies($credential, $passwordStrength);
|
|
|
|
if (count($messages) > 0) {
|
|
throw new InvalidArgumentException($messages[0]);
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
}
|