forked from JPathRu/proofreader
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.php
More file actions
102 lines (84 loc) · 2.87 KB
/
script.php
File metadata and controls
102 lines (84 loc) · 2.87 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
<?php
/**
* Proofreader
*
* @package Proofreader
* @author Sergey M. Litvinov (smart@joomlatune.com)
* @copyright Copyright (C) 2013-2015 by Sergey M. Litvinov. All rights reserved.
* @copyright Copyright (C) 2005-2007 by Alexandr Balashov. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Language\Text;
use Joomla\Filesystem\File;
class com_proofreaderInstallerScript
{
protected static $minVersion = '4.4.0';
public function preflight($type, $parent)
{
if (!version_compare(JVERSION, self::$minVersion, 'ge'))
{
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_PROOFREADER_ERROR_UNSUPPORTED_JOOMLA_VERSION', self::$minVersion), 'error');
return false;
}
return true;
}
public function postflight($type, $parent)
{
/** @var \Joomla\Database\DatabaseDriver $db */
$db = Factory::getContainer()->get('DatabaseDriver');
$src = $parent->getParent()->getPath('source');
$manifest = $parent->getParent()->manifest;
$plugins = $manifest->xpath('plugins/plugin');
foreach ($plugins as $plugin)
{
$name = (string) $plugin->attributes()->plugin;
$group = (string) $plugin->attributes()->group;
$path = $src . '/plugins/' . $group;
if (is_dir($src . '/plugins/' . $group . '/' . $name))
{
$path = $src . '/plugins/' . $group . '/' . $name;
}
$installer = new Installer;
$installer->install($path);
$query = $db->getQuery(true);
$query->update($db->quoteName('#__extensions'));
$query->set($db->quoteName('enabled') . ' = 1');
$query->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
$query->where($db->quoteName('element') . ' = ' . $db->quote($name));
$query->where($db->quoteName('folder') . ' = ' . $db->quote($group));
$db->setQuery($query);
$db->execute();
}
}
public function uninstall($parent)
{
/** @var \Joomla\Database\DatabaseDriver $db */
$db = Factory::getContainer()->get('DatabaseDriver');
$manifest = $parent->getParent()->manifest;
$plugins = $manifest->xpath('plugins/plugin');
foreach ($plugins as $plugin)
{
$name = (string) $plugin->attributes()->plugin;
$group = (string) $plugin->attributes()->group;
$query = $db->getQuery(true);
$query->select($db->quoteName('extension_id'));
$query->from($db->quoteName('#__extensions'));
$query->where($db->quoteName('type') . ' = ' . $db->Quote('plugin'));
$query->where($db->quoteName('element') . ' = ' . $db->Quote($name));
$query->where($db->quoteName('folder') . ' = ' . $db->Quote($group));
$db->setQuery($query);
$extensions = $db->loadColumn();
if (count($extensions))
{
foreach ($extensions as $id)
{
$installer = new Installer;
$installer->uninstall('plugin', $id);
}
}
}
}
}