-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventListener.php
78 lines (67 loc) · 1.73 KB
/
EventListener.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
<?php
/**
* This file is a part of free add-on "Forum Rules Accept".
* Developed by HLModerators.
*
* License - MIT.
*/
namespace HLModerators\ForumRulesAccept;
use XF\Entity\AddOn;
use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Manager;
use XF\Mvc\Entity\Structure;
use function count;
use function in_array;
class EventListener
{
const OPTIONAL_ADD_ONS = [
'XFRM' => ['xf_rm_category']
];
const ENTITIES = [
'XF:Forum',
'XFRM:Category'
];
/**
* Extends the entity structure
*
* @param Manager $em
* @param Structure $structure
*/
public static function onEntityStructure(Manager $em, Structure &$structure): void
{
if (!in_array($structure->shortName, self::ENTITIES))
{
return;
}
$structure->columns['hlmod_rules_url'] = ['type' => Entity::STR, 'maxLength' => 255,
'default' => ''];
}
/**
* Listens the add-on installs for creating tables where this is required.
*
* @param \XF\AddOn\AddOn $addOn
* @param AddOn $installedAddOn
* @param array $json
* @param array $stateChanges
*/
public static function onAddOnInstall(\XF\AddOn\AddOn $addOn, AddOn $installedAddOn,
array $json, array &$stateChanges): void
{
$addOnId = $addOn->getAddOnId();
$tables = self::OPTIONAL_ADD_ONS[$addOnId] ?? [];
if (!count($tables))
{
return;
}
/** @var Setup|null $setup */
$setup = $addOn->getSetup();
if (!$setup)
{
return;
}
foreach ($tables as $tableName)
{
$setup->addRulesColumn($tableName);
}
}
}