This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZAuthModuleInstaller.php
93 lines (82 loc) · 3.47 KB
/
ZAuthModuleInstaller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types=1);
/*
* This file is part of the Zikula package.
*
* Copyright Zikula - https://ziku.la/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zikula\ZAuthModule;
use Exception;
use Zikula\ExtensionsModule\Installer\AbstractExtensionInstaller;
use Zikula\ZAuthModule\Entity\AuthenticationMappingEntity;
use Zikula\ZAuthModule\Entity\UserVerificationEntity;
class ZAuthModuleInstaller extends AbstractExtensionInstaller
{
private $entities = [
AuthenticationMappingEntity::class,
UserVerificationEntity::class
];
public function install(): bool
{
foreach ($this->entities as $entity) {
try {
$this->schemaTool->create([
$entity
]);
} catch (Exception $exception) {
if (UserVerificationEntity::class !== $entity) {
throw $exception;
}
// silently fail. This is because on core upgrade the UserVerificationEntity already exists from the UsersModule.
}
}
$this->setVars($this->getDefaultModvars());
return true;
}
public function upgrade(string $oldVersion): bool
{
switch ($oldVersion) {
case '1.0.0': // shipped with Core-1.4.3
// remove password reminder
$this->schemaTool->update([
AuthenticationMappingEntity::class
]);
$this->delVar('password_reminder_enabled');
$this->delVar('password_reminder_mandatory');
// no break
case '1.0.1': // shipped with Core-2.0.15
$this->delVar('hash_method');
$this->setVar(ZAuthConstant::MODVAR_REQUIRE_NON_COMPROMISED_PASSWORD, ZAuthConstant::DEFAULT_REQUIRE_UNCOMPROMISED_PASSWORD);
// no break
case '1.0.2':
$this->setVar(ZAuthConstant::MODVAR_ITEMS_PER_PAGE, ZAuthConstant::DEFAULT_ITEMS_PER_PAGE);
}
return true;
}
public function uninstall(): bool
{
// cannot uninstall this extension
return false;
}
/**
* @return array An array of all current module variables, with their default values, suitable for {@link setVars()}
*/
private function getDefaultModvars(): array
{
return [
ZAuthConstant::MODVAR_PASSWORD_MINIMUM_LENGTH => ZAuthConstant::DEFAULT_PASSWORD_MINIMUM_LENGTH,
ZAuthConstant::MODVAR_REQUIRE_NON_COMPROMISED_PASSWORD => ZAuthConstant::DEFAULT_REQUIRE_UNCOMPROMISED_PASSWORD,
ZAuthConstant::MODVAR_PASSWORD_STRENGTH_METER_ENABLED => ZAuthConstant::DEFAULT_PASSWORD_STRENGTH_METER_ENABLED,
ZAuthConstant::MODVAR_EXPIRE_DAYS_CHANGE_EMAIL => ZAuthConstant::DEFAULT_EXPIRE_DAYS_CHANGE_EMAIL,
ZAuthConstant::MODVAR_EXPIRE_DAYS_CHANGE_PASSWORD => ZAuthConstant::DEFAULT_EXPIRE_DAYS_CHANGE_PASSWORD,
ZAuthConstant::MODVAR_EXPIRE_DAYS_REGISTRATION => ZAuthConstant::DEFAULT_EXPIRE_DAYS_REGISTRATION,
ZAuthConstant::MODVAR_EMAIL_VERIFICATION_REQUIRED => ZAuthConstant::DEFAULT_EMAIL_VERIFICATION_REQUIRED,
ZAuthConstant::MODVAR_REGISTRATION_ANTISPAM_ANSWER => '',
ZAuthConstant::MODVAR_REGISTRATION_ANTISPAM_QUESTION => '',
ZAuthConstant::MODVAR_ITEMS_PER_PAGE => ZAuthConstant::DEFAULT_ITEMS_PER_PAGE,
];
}
}