-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.php
95 lines (78 loc) · 2.62 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* @package RSform!Pro - Postcode API
* @copyright (C) 2018 extensions.perfectwebteam.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerHelper;
use Joomla\CMS\Language\Text;
class plgSystemRSFPPostcodeapiInstallerScript
{
public function preflight($type, $parent) {
if ($type == 'uninstall') {
return true;
}
$app = Factory::getApplication();
try {
if (!file_exists(JPATH_ADMINISTRATOR.'/components/com_rsform/helpers/rsform.php')) {
throw new Exception('Please install the RSForm! Pro component before continuing.');
}
if (!file_exists(JPATH_ADMINISTRATOR.'/components/com_rsform/helpers/assets.php')) {
throw new Exception('Please update RSForm! Pro to at least version 1.51.0 before continuing!');
}
require_once JPATH_ADMINISTRATOR.'/components/com_rsform/helpers/version.php';
$version = new RSFormProVersion;
if (version_compare((string) $version, '1.52.5', '<')) {
throw new Exception('Please update RSForm! Pro to at least version 1.52.5 before continuing!');
}
} catch (Exception $e) {
$app->enqueueMessage($e->getMessage(), 'error');
return false;
}
return true;
}
public function update($parent) {
$this->copyFiles($parent);
$this->runSQL($parent, 'install');
}
public function install($parent) {
$this->copyFiles($parent);
$this->runSQL($parent, 'install');
}
protected function copyFiles($parent) {
jimport('joomla.filesystem.folder');
// Copy /admin files
$src = $parent->getParent()->getPath('source').'/admin';
$dest = JPATH_ADMINISTRATOR.'/components/com_rsform';
if (!JFolder::copy($src, $dest, '', true)) {
throw new Exception('Could not copy to '.str_replace(JPATH_ADMINISTRATOR, '', $dest).', please make sure destination is writable!');
}
}
protected function runSQL($parent, $file) {
$db = Factory::getDbo();
$driver = strtolower($db->name);
$src = $parent->getParent()->getPath('source');
if (strpos($driver, 'mysql') !== false) {
$driver = 'mysql';
}
$sqlfile = $src.'/sql/'.$driver.'/'.$file.'.sql';
if (file_exists($sqlfile)) {
$buffer = file_get_contents($sqlfile);
if ($buffer !== false) {
$queries = InstallerHelper::splitSql($buffer);
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query{0} != '#') {
$db->setQuery($query);
if (!$db->execute()) {
throw new Exception(Text::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
}
}
}
}
}
}
}