mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	Convert old templates title as well as body (#9034)
* Convert old templates title as well as body * Update convert-template.inc.php
This commit is contained in:
		@@ -31,7 +31,7 @@ header('Content-type: application/json');
 | 
			
		||||
if (!Auth::user()->hasGlobalAdmin()) {
 | 
			
		||||
    die(json_encode([
 | 
			
		||||
        'status' => 'error',
 | 
			
		||||
        'message' => 'ERROR: You need to be admin',
 | 
			
		||||
        'message' => 'You need to be admin',
 | 
			
		||||
    ]));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -42,10 +42,16 @@ if (empty($vars['template'])) {
 | 
			
		||||
    ]));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$new = '';
 | 
			
		||||
$new_body = '';
 | 
			
		||||
foreach (explode(PHP_EOL, $vars['template']) as $line) {
 | 
			
		||||
    $new_body .= convert_template($line) . PHP_EOL;
 | 
			
		||||
}
 | 
			
		||||
$new_title = convert_template($vars['title']);
 | 
			
		||||
 | 
			
		||||
function convert_template($line)
 | 
			
		||||
{
 | 
			
		||||
    if (str_contains($line, '{calc')) {
 | 
			
		||||
        $new .= preg_replace(
 | 
			
		||||
        return preg_replace(
 | 
			
		||||
            [
 | 
			
		||||
                '/{calc[ ]*([\w\d\s\%\.\(\)\*\/\-\+\/]+)}/',// Replaces {calc (something*100)}
 | 
			
		||||
                '/%([\w\d]+)\.([\w\d]+)/',// Replaces %something.anything
 | 
			
		||||
@@ -93,13 +99,13 @@ foreach (explode(PHP_EOL, $vars['template']) as $line) {
 | 
			
		||||
            '$key',
 | 
			
		||||
            '$value',
 | 
			
		||||
        ];
 | 
			
		||||
        $new .= preg_replace($find, $replace, $old1);
 | 
			
		||||
        return preg_replace($find, $replace, $old1);
 | 
			
		||||
    }
 | 
			
		||||
    $new .= PHP_EOL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
die(json_encode([
 | 
			
		||||
    'status'  => 'ok',
 | 
			
		||||
    'status'   => 'ok',
 | 
			
		||||
    'message'  => 'Template converted, review and save to update',
 | 
			
		||||
    'template' => $new,
 | 
			
		||||
    'template' => $new_body,
 | 
			
		||||
    'title'    => $new_title,
 | 
			
		||||
]));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user