This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.php
65 lines (51 loc) · 1.98 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
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Installer\Installer;
class languagehotfixInstallerScript
{
function preflight($type, $parent)
{
// Define the path to the target file in Joomla installation
$targetFile = JPATH_LIBRARIES . '/src/Language/LanguageHelper.php';
// Define the path to your replacement file in your package
$replacementFile = $parent->getParent()->getPath('source') . '/LanguageHelper.php';
// Check if replacement file exists
if (!file_exists($replacementFile)) {
JError::raiseWarning(500, "Replacement LanguageHelper.php not found in the package at: $replacementFile");
return false;
}
// Replace the file
if (!File::copy($replacementFile, $targetFile)) {
JError::raiseWarning(500, "Error replacing LanguageHelper.php from $replacementFile to $targetFile");
return false;
}
// Display a success message with the path information
Factory::getApplication()->enqueueMessage(
"LanguageHelper.php replaced successfully. New file placed at: $targetFile",
'message'
);
// Remove this plugin to leave no trace
$this->uninstallPlugin();
return true;
}
private function uninstallPlugin()
{
$plugins = $this->findThisPlugin();
foreach ($plugins as $plugin) {
Installer::getInstance()->uninstall($plugin->type, $plugin->extension_id);
}
}
private function findThisPlugin()
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select(array('extension_id', 'type'))
->from('#__extensions')
->where($db->quoteName('element') . ' = ' . $db->quote('languagehotfix'))
->where($db->quoteName('type') . ' = ' . $db->quote('file'));
$db->setQuery($query);
return $db->loadObjectList();
}
}