-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpkg_script.php
More file actions
155 lines (127 loc) · 4.53 KB
/
Copy pathpkg_script.php
File metadata and controls
155 lines (127 loc) · 4.53 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
declare(strict_types=1);
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScriptInterface;
use Joomla\Database\DatabaseInterface;
/**
* Instalační skript BALÍČKU pkg_joomleague. Postflight balíčku běží až po
* instalaci všech dětských rozšíření (komponenta, moduly, pluginy), takže se
* v něm dají nově nainstalované pluginy rovnou zapnout.
*/
return new class () implements InstallerScriptInterface {
private const UPDATE_SITE_NAME = 'JoomLeague';
private const UPDATE_SITE_LOCATION = 'https://github.com/klucon/com_joomleague/releases/latest/download/joomleague-update.xml';
/** Vlastní pluginy balíčku, které se po instalaci automaticky zapnou. */
private const PLUGINS = [
['folder' => 'content', 'element' => 'joomleaguematch'],
['folder' => 'content', 'element' => 'joomleagueperson'],
['folder' => 'extension', 'element' => 'joomleagueesport'],
['folder' => 'finder', 'element' => 'joomleague'],
['folder' => 'quickicon', 'element' => 'joomleague'],
];
public function install(InstallerAdapter $adapter): bool
{
return true;
}
public function update(InstallerAdapter $adapter): bool
{
return true;
}
public function uninstall(InstallerAdapter $adapter): bool
{
return true;
}
public function preflight(string $type, InstallerAdapter $adapter): bool
{
return true;
}
public function postflight(string $type, InstallerAdapter $adapter): bool
{
$this->ensureUpdateSite();
// Jen při první instalaci – při update respektujeme volbu uživatele.
if ($type === 'install') {
$this->enablePlugins();
}
return true;
}
private function ensureUpdateSite(): void
{
try {
$db = Factory::getContainer()->get(DatabaseInterface::class);
} catch (\Throwable $exception) {
return;
}
try {
$query = $db->createQuery()
->select($db->quoteName('extension_id'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('package'))
->where($db->quoteName('element') . ' = ' . $db->quote('pkg_joomleague'));
$extensionId = (int) $db->setQuery($query)->loadResult();
if ($extensionId < 1) {
return;
}
$query = $db->createQuery()
->select($db->quoteName('update_site_id'))
->from($db->quoteName('#__update_sites'))
->where($db->quoteName('location') . ' = ' . $db->quote(self::UPDATE_SITE_LOCATION));
$updateSiteId = (int) $db->setQuery($query)->loadResult();
if ($updateSiteId < 1) {
$site = (object) [
'name' => self::UPDATE_SITE_NAME,
'type' => 'extension',
'location' => self::UPDATE_SITE_LOCATION,
'enabled' => 1,
'last_check_timestamp' => 0,
];
$db->insertObject('#__update_sites', $site);
$updateSiteId = (int) $db->insertid();
} else {
$query = $db->createQuery()
->update($db->quoteName('#__update_sites'))
->set($db->quoteName('name') . ' = ' . $db->quote(self::UPDATE_SITE_NAME))
->set($db->quoteName('type') . ' = ' . $db->quote('extension'))
->set($db->quoteName('enabled') . ' = 1')
->where($db->quoteName('update_site_id') . ' = ' . (int) $updateSiteId);
$db->setQuery($query)->execute();
}
$query = $db->createQuery()
->select('COUNT(*)')
->from($db->quoteName('#__update_sites_extensions'))
->where($db->quoteName('update_site_id') . ' = ' . (int) $updateSiteId)
->where($db->quoteName('extension_id') . ' = ' . (int) $extensionId);
if ((int) $db->setQuery($query)->loadResult() < 1) {
$link = (object) [
'update_site_id' => $updateSiteId,
'extension_id' => $extensionId,
];
$db->insertObject('#__update_sites_extensions', $link);
}
} catch (\Throwable $exception) {
// Update site registration must not break package installation.
}
}
private function enablePlugins(): void
{
try {
$db = Factory::getContainer()->get(DatabaseInterface::class);
foreach (self::PLUGINS as $plugin) {
$folder = $plugin['folder'];
$element = $plugin['element'];
$query = $db->createQuery()
->update($db->quoteName('#__extensions'))
->set($db->quoteName('enabled') . ' = 1')
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = :folder')
->where($db->quoteName('element') . ' = :element')
->bind(':folder', $folder)
->bind(':element', $element);
$db->setQuery($query)->execute();
}
} catch (\Throwable $exception) {
// Auto-zapnutí je nice-to-have; případná chyba nesmí shodit instalaci.
}
}
};