-
Notifications
You must be signed in to change notification settings - Fork 86
/
UpdateAdminLinksWhenCustomAdminPathChanges.php
55 lines (40 loc) · 2.29 KB
/
UpdateAdminLinksWhenCustomAdminPathChanges.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
<?php
/**
* Knowledgebase Author
*
* @package WHMCS
* @copyright Katamaze
* @link https://katamaze.com
* @author Davide Mantenuto <[email protected]>
*/
use WHMCS\Database\Capsule;
use WHMCS\Config\Setting;
define('KtConfigurationCustomAdminPath', $config->customadminpath);
add_hook('AdminAreaPage', 1, function($vars) {
// Custom Admin Path not set. Nothing to do
if (!KtConfigurationCustomAdminPath) {
return;
}
$stored_custom_admin_path = Setting::getValue('KtStoredCustomAdminPath');
// Storing current Custom Admin Path in tblconfigurations table to detect when it changes
if (empty($stored_custom_admin_path)) {
Setting::setValue('KtStoredCustomAdminPath', KtConfigurationCustomAdminPath);
return;
}
// The stored and live version of Custom Admin Path (the one in configuration.php) are the same. Nothing to do
if (KtConfigurationCustomAdminPath == $stored_custom_admin_path) {
return;
}
// If we're here it means Custom Admin Path has been updated so we need to perform a couple of replacements
$system_url = Setting::getValue('SystemURL');
$find = $system_url . '/' . Setting::getValue('KtStoredCustomAdminPath');
$replace = $system_url . '/' . KtConfigurationCustomAdminPath;
Capsule::table('tbladmins')->update([ 'notes' => Capsule::raw('REPLACE(notes, "' . $find . '", "' . $replace . '")') ]);
Capsule::table('tblnotes')->update([ 'note' => Capsule::raw('REPLACE(note, "' . $find . '", "' . $replace . '")') ]);
Capsule::table('tblticketnotes')->update([ 'message' => Capsule::raw('REPLACE(`message`, "' . $find . '", "' . $replace . '")') ]);
Capsule::table('tbltodolist')->update([ 'description' => Capsule::raw('REPLACE(`description`, "' . $find . '", "' . $replace . '")') ]);
// Uncomment if you have Project Management on your system
//Capsule::table('mod_projectmessages')->update([ 'message' => Capsule::raw('REPLACE(`message`, "' . $find . '", "' . $replace . '")') ]);
//Capsule::table('mod_projecttasks')->update([ 'task' => Capsule::raw('REPLACE(`task`, "' . $find . '", "' . $replace . '")'), 'notes' => Capsule::raw('REPLACE(`notes`, "' . $find . '", "' . $replace . '")') ]);
Setting::setValue('KtStoredCustomAdminPath', KtConfigurationCustomAdminPath);
});