ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
rename-config.php
Go to the documentation of this file.
1#!/usr/bin/php
2<?php
3
4chdir(dirname(__FILE__));
5require_once 'common.php';
6require_once '../library/HTMLPurifier.auto.php';
8
17$argv = $_SERVER['argv'];
18if (count($argv) < 3) {
19 echo "Usage: {$argv[0]} OldName NewName\n";
20 exit(1);
21}
22
23chdir('../library/HTMLPurifier/ConfigSchema/schema');
24
27
28if (!file_exists("$old.txt")) {
29 echo "Cannot move undefined configuration directive $old\n";
30 exit(1);
31}
32
33if ($old === $new) {
34 echo "Attempting to move to self, aborting\n";
35 exit(1);
36}
37
38if (file_exists("$new.txt")) {
39 echo "Cannot move to already defined directive $new\n";
40 exit(1);
41}
42
43$file = "$old.txt";
46$builder->buildFile($interchange, $file);
47$contents = file_get_contents($file);
48
49if (strpos($contents, "\r\n") !== false) {
50 $nl = "\r\n";
51} elseif (strpos($contents, "\r") !== false) {
52 $nl = "\r";
53} else {
54 $nl = "\n";
55}
56
57// replace name with new name
58$contents = str_replace($old, $new, $contents);
59
60if ($interchange->directives[$old]->aliases) {
61 $pos_alias = strpos($contents, 'ALIASES:');
62 $pos_ins = strpos($contents, $nl, $pos_alias);
63 if ($pos_ins === false) $pos_ins = strlen($contents);
64 $contents =
65 substr($contents, 0, $pos_ins) . ", $old" . substr($contents, $pos_ins);
66 file_put_contents($file, $contents);
67} else {
68 $lines = explode($nl, $contents);
69 $insert = false;
70 foreach ($lines as $n => $line) {
71 if (strncmp($line, '--', 2) === 0) {
72 $insert = $n;
73 break;
74 }
75 }
76 if (!$insert) {
77 $lines[] = "ALIASES: $old";
78 } else {
79 array_splice($lines, $insert, 0, "ALIASES: $old");
80 }
81 file_put_contents($file, implode($nl, $lines));
82}
83
84rename("$old.txt", "$new.txt") || exit(1);
$n
Definition: RandomTest.php:80
An exception for terminatinating execution or to throw for unit testing.
Generic schema interchange format that can be converted to a runtime representation (HTMLPurifier_Con...
Definition: Interchange.php:9
assertCli()
Definition: common.php:3
$builder
$new
$old
$contents
$insert
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$argv
$interchange
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']