-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpkg_joomcck.script.php
80 lines (61 loc) · 2.11 KB
/
pkg_joomcck.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
<?php
/**
* @copyright Copyright (c) 2013-2018 JoomCoder (http://www.joomcoder.com). All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
use Joomla\CMS\Factory;
defined( '_JEXEC' ) or die( 'Restricted access' );
class pkg_joomcckInstallerScript
{
public function preflight($type, $parent)
{
// Do not run on uninstall.
if ($type === 'uninstall')
{
return true;
}
// Prevent users from installing this on Joomla 3
if (version_compare(JVERSION, '3.999.999', 'le'))
{
$msg = "<p>This version of JoomCCK cannot run on Joomla 3. Kindly note that our site's Downloads page clearly indicates which version of our software is compatible with Joomla 3 and which version is compatible with Joomla 4.</p>";
\Joomla\CMS\Log\Log::add($msg, \Joomla\CMS\Log\Log::WARNING, 'jerror');
return false;
}
return true;
}
/**
* Runs right after any installation action is performed on the component.
*
* @param string $type - Type of PostFlight action. Possible values are:
* - * install
* - * update
* - * discover_install
* @param \stdClass $parent - Parent object calling object.
*
* @return void
*/
public function postflight($type, $parent)
{
$app = Factory::getApplication();
// don't enable plugins if action type is update
if ($type == 'update' || $type == 'uninstall') return;
$db = Factory::getDBO();
$manifest = $parent->getManifest();
// Enable Plugins and set Default plugin
$plugins = array();
foreach ($manifest->files->folder as $file) {
$attributes = $file->attributes();
if ($attributes['enable'] && $attributes['type'] == 'plugin' && $attributes['enable'] == '1') {
$plugins[] = $db->quote($attributes['id']);
}
}
$query = 'UPDATE #__extensions'
. ' SET enabled = 1'
. ' WHERE element IN (' . implode(', ', $plugins) . ') AND type =' . $db->q("plugin");
$db->setQuery($query);
if (!$db->execute()) {
$application = Factory::getApplication();
$application->enqueueMessage('Failed to Enable plugins som plugins', 'error');
}
}
}