ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
4require_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 {
57 global $DIC;
58
59 $lng = $DIC->language();
60
61 if (null !== self::$revision_information) {
63 }
64
65 $info = array();
66
67 if (self::isProbablySubversion17()) {
68 if (extension_loaded('PDO') && extension_loaded('pdo_sqlite')) {
69 try {
70 $wcdb = new PDO('sqlite:' . self::SVN_GET_17_FILE);
71
72 $result = $wcdb->query('SELECT MAX("revision") current_rev FROM "NODES"');
73 if ($result) {
74 foreach ($result as $row) {
75 $revision = $row['current_rev'];
76 if (self::isSvnRevision($revision)) {
77 $info[] = sprintf($lng->txt('svn_revision_current'), $revision);
78 }
79 break;
80 }
81 }
82
83 $result = $wcdb->query('SELECT "changed_revision" last_changed_revision FROM "NODES" ORDER BY changed_revision DESC LIMIT 1');
84 if ($result) {
85 foreach ($result as $row) {
86 $revision = $row['last_changed_revision'];
87 if (self::isSvnRevision($revision)) {
88 $info[] = sprintf($lng->txt('svn_revision_last_change'), $revision);
89 }
90 break;
91 }
92 }
93
94 $result = $wcdb->query('SELECT * FROM REPOSITORY ');
95 if ($result) {
96 foreach ($result as $row) {
97 $info[] = sprintf($lng->txt('svn_root'), $row['root']);
98 }
99 }
100
101 $result = $wcdb->query('SELECT * FROM "NODES" WHERE local_relpath LIKE "%inc.ilias_version.php"');
102 if ($result) {
103 foreach ($result as $row) {
104 $path = dirname(dirname($row['repos_path']));
105 if ($path) {
106 $info[] = sprintf($lng->txt('svn_path'), $path);
107 }
108 }
109 }
110 } catch (Exception $e) {
111 }
112 }
113 } else {
114 if (function_exists('shell_exec') && is_callable('shell_exec')) {
115 $revision = trim(shell_exec('svnversion ' . realpath(getcwd())));
116 if (self::isSvnRevision($revision)) {
117 $info[] = sprintf($lng->txt('svn_revision_current'), $revision);
118 }
119 }
120 if (self::isProbablySubversionLower17()) {
121 $svnfile = file(self::SVN_LT_17_FILE);
122 $revision = $svnfile[3];
123 if (self::isSvnRevision($revision)) {
124 $info[] = sprintf($lng->txt('svn_revision_last_change'), $revision);
125 }
126 }
127 }
128
129 self::$revision_information = $info;
130 }
131
135 public function getInformationAsHtml()
136 {
137 self::detect();
138
139 return implode("<br />", self::$revision_information);
140 }
141}
$result
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
Class ilSubversionInformation.
$info
Definition: index.php:5
$row
global $DIC
Definition: saml.php:7
$lng