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 
4 chdir(dirname(__FILE__));
5 require_once 'common.php';
6 require_once '../library/HTMLPurifier.auto.php';
7 assertCli();
8 
17 $argv = $_SERVER['argv'];
18 if (count($argv) < 3) {
19  echo "Usage: {$argv[0]} OldName NewName\n";
20  exit(1);
21 }
22 
23 chdir('../library/HTMLPurifier/ConfigSchema/schema');
24 
25 $old = $argv[1];
26 $new = $argv[2];
27 
28 if (!file_exists("$old.txt")) {
29  echo "Cannot move undefined configuration directive $old\n";
30  exit(1);
31 }
32 
33 if ($old === $new) {
34  echo "Attempting to move to self, aborting\n";
35  exit(1);
36 }
37 
38 if (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 
49 if (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 
60 if ($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 
84 rename("$old.txt", "$new.txt") || exit(1);
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$new
$builder
Generic schema interchange format that can be converted to a runtime representation (HTMLPurifier_Con...
Definition: Interchange.php:8
$contents
$argv
$n
Definition: RandomTest.php:80
$old
assertCli()
Definition: common.php:3
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
$insert
$interchange