/
install.script.php
131 lines (107 loc) · 3.74 KB
/
install.script.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
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
<?php
/**
* Kunena Component
*
* @package Kunena.Installer
*
* @copyright Copyright (C) 2008 - 2023 Kunena Team. All rights reserved.
* @license https://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
**/
defined('_JEXEC') or die();
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Kunena\Forum\Libraries\Forum\KunenaForum;
/**
* Class pkg_kunena_languagesInstallerScript
*
* @since Kunena 6.0
*/
class pkg_kunena_languagesInstallerScript
{
/**
* @param Joomla\CMS\Installer\Adapter\FileAdapter $parent parent
*
* @since Kunena 6.0
*/
public function uninstall($parent)
{
// Remove languages.
$languages = Joomla\CMS\Language\LanguageHelper::getKnownLanguages();
foreach ($languages as $language) {
$this->uninstallLanguage($language['tag'], $language['name']);
}
}
/**
* @param string $type type
* @param Joomla\CMS\Installer\Adapter\FileAdapter $parent parent
*
* @return boolean
*
* @throws Exception
* @since Kunena 6.0
*/
public function preflight($type, $parent)
{
if (!in_array($type, ['install', 'update'])) {
return true;
}
$app = Factory::getApplication();
// Do not install if Kunena doesn't exist.
if (!class_exists('Kunena\Forum\Libraries\Forum\KunenaForum') || !KunenaForum::isCompatible('6.0')) {
$app->enqueueMessage(sprintf('Kunena %s has not been installed, aborting!', '6.0'), 'notice');
return false;
}
/*
if (KunenaForum::isDev())
{
$app->enqueueMessage(sprintf('You have installed Kunena from GitHub, aborting!'), 'notice');
return false;
}*/
// Get list of languages to be installed.
$source = $parent->getParent()->getPath('source') . '/language';
$languages = Joomla\CMS\Language\LanguageHelper::getKnownLanguages();
$files = $parent->manifest->files;
foreach ($languages as $language) {
$name = "com_kunena_{$language['tag']}";
$search = Folder::files($source, $name);
if (empty($search)) {
continue;
}
// Generate <file type="file" client="site" id="fi-FI">com_kunena_fi-FI_v2.0.0-BETA2-DEV2.zip</file>
$file = $files->addChild('file', array_pop($search));
$file->addAttribute('type', 'file');
$file->addAttribute('client', 'site');
$file->addAttribute('id', $name);
echo sprintf('Installing language %s - %s ...', $language['tag'], $language['name']) . '<br />';
}
if (empty($files)) {
$app->enqueueMessage(sprintf('Your site is English only. There\'s no need to install Kunena language pack.'), 'notice');
return false;
}
// Remove old K1.7 style language pack.
$table = Joomla\CMS\Table\Table::getInstance('extension');
$id = $table->find(['type' => 'file', 'element' => "kunena_language_pack"]);
if ($id) {
$installer = new Joomla\CMS\Installer\Installer();
$installer->uninstall('file', $id);
}
return true;
}
/**
* @param $tag
* @param $name
*
* @since Kunena 6.0
*/
public function uninstallLanguage($tag, $name)
{
$table = Joomla\CMS\Table\Table::getInstance('extension');
$id = $table->find(['type' => 'file', 'element' => "com_kunena_{$tag}"]);
if (!$id) {
return;
}
$installer = new Joomla\CMS\Installer\Installer();
$installer->uninstall('file', $id);
}
}