ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSubversionInformation.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Administration/interfaces/interface.ilVersionControlInformation.php';
5 
11 {
15  const SVN_GET_17_FILE = '.svn/wc.db';
16 
20  const SVN_LT_17_FILE = '.svn/entries';
21 
25  private static $revision_information = null;
26 
31  private static function isSvnRevision($revision)
32  {
33  return (bool)preg_match('/^\d+(:\d+)*[MSP]*$/', $revision);
34  }
35 
39  private static function isProbablySubversion17()
40  {
41  return file_exists(self::SVN_GET_17_FILE) && is_file(self::SVN_GET_17_FILE) && is_readable(self::SVN_GET_17_FILE);
42  }
43 
47  private static function isProbablySubversionLower17()
48  {
49  return file_exists(self::SVN_LT_17_FILE) && is_file(self::SVN_LT_17_FILE) && is_readable(self::SVN_LT_17_FILE);
50  }
51 
55  private static function detect()
56  {
60  global $lng;
61 
62  if(null !== self::$revision_information)
63  {
64  return self::$revision_information;
65  }
66 
67  $info = array();
68 
69  if(self::isProbablySubversion17())
70  {
71  if(extension_loaded('PDO') && extension_loaded('pdo_sqlite'))
72  {
73  try
74  {
75  $wcdb = new PDO('sqlite:' . self::SVN_GET_17_FILE);
76 
77  $result = $wcdb->query('SELECT MAX("revision") current_rev FROM "NODES"');
78  if($result)
79  {
80  foreach($result as $row)
81  {
82  $revision = $row['current_rev'];
83  if(self::isSvnRevision($revision))
84  {
85  $info[] = sprintf($lng->txt('svn_revision_current'), $revision);
86  }
87  break;
88  }
89  }
90 
91  $result = $wcdb->query('SELECT "changed_revision" last_changed_revision FROM "NODES" ORDER BY changed_revision DESC LIMIT 1');
92  if($result)
93  {
94  foreach($result as $row)
95  {
96  $revision = $row['last_changed_revision'];
97  if(self::isSvnRevision($revision))
98  {
99  $info[] = sprintf($lng->txt('svn_revision_last_change'), $revision);
100  }
101  break;
102  }
103  }
104 
105  $result = $wcdb->query('SELECT * FROM REPOSITORY ');
106  if($result)
107  {
108  foreach($result as $row)
109  {
110  $info[] = sprintf($lng->txt('svn_root'), $row['root']);
111  }
112  }
113 
114  $result = $wcdb->query('SELECT * FROM "NODES" WHERE local_relpath LIKE "%inc.ilias_version.php"');
115  if($result)
116  {
117  foreach($result as $row)
118  {
119  $path = dirname(dirname($row['repos_path']));
120  if($path)
121  {
122  $info[] = sprintf($lng->txt('svn_path'), $path);
123  }
124  }
125  }
126  }
127  catch(Exception $e) {}
128  }
129  }
130  else
131  {
132  if(function_exists('shell_exec') && is_callable('shell_exec'))
133  {
134  $revision = trim(shell_exec('svnversion ' . realpath(getcwd())));
135  if(self::isSvnRevision($revision))
136  {
137  $info[] = sprintf($lng->txt('svn_revision_current'), $revision);
138  }
139  }
140  if(self::isProbablySubversionLower17())
141  {
142  $svnfile = file(self::SVN_LT_17_FILE);
143  $revision = $svnfile[3];
144  if(self::isSvnRevision($revision))
145  {
146  $info[] = sprintf($lng->txt('svn_revision_last_change'), $revision);
147  }
148  }
149  }
150 
151  self::$revision_information = $info;
152  }
153 
157  public function getInformationAsHtml()
158  {
159  self::detect();
160 
161  return implode("<br />", self::$revision_information);
162  }
163 }
$path
Definition: aliased.php:25
$result
Class ilVersionControlInformation.
$info
Definition: example_052.php:80
Reload workbook from saved file
Class ilSubversionInformation.
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17