-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.php
73 lines (64 loc) · 1.32 KB
/
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
<?php
/**
* @copyright Copyright (C) 2013 Don Gilbert. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* Class plgSystemJstatsInstallerScript
*/
class plgSystemJstatsInstallerScript
{
/**
* Enable the plugin and set default params.
*
* @param $type
* @param $parent
*/
public function postflight($type, $parent)
{
$this->removeCacheFile();
if ($type !== 'update')
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$data = json_encode(array(
'unique_id' => $this->generateUniqueId()
));
// Enable and set a unique id
$query
->update('#__extensions')
->set('params = ' . $db->quote($data))
->set('enabled = 1')
->where('name = "plg_system_jstats"');
$db->setQuery($query)->execute();
}
}
public function uninstall($parent)
{
$this->removeCacheFile();
}
/**
* Remove the cache file on uninstall and upgrade.
*
* @since 1.0
*/
protected function removeCacheFile()
{
$cacheFile = JPATH_ROOT . '/cache/jstats.php';
if (is_readable($cacheFile))
{
unlink($cacheFile);
}
}
/**
* Generates a unique key to reduce stats duplication.
*
* @return string
*
* @since 1.0
*/
protected function generateUniqueId()
{
return md5(JFactory::getConfig()->get('secret') . time());
}
}