Rev 84 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
21 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * PHP svn functions |
||
5 | * Copyright 2021 Daniel Marschall, ViaThinkSoft |
||
6 | * Revision 2021-12-15 |
||
7 | * |
||
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
9 | * you may not use this file except in compliance with the License. |
||
10 | * You may obtain a copy of the License at |
||
11 | * |
||
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
13 | * |
||
14 | * Unless required by applicable law or agreed to in writing, software |
||
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
17 | * See the License for the specific language governing permissions and |
||
18 | * limitations under the License. |
||
19 | */ |
||
20 | |||
21 | function get_svn_revision($dir='') { |
||
22 | if (!empty($dir)) $dir .= '/'; |
||
23 | if (!is_dir($dir)) return false; |
||
24 | |||
25 | // Try to find out the SVN version using the shell |
||
26 | $output = @shell_exec('svnversion '.escapeshellarg($dir).' 2>&1'); |
||
27 | $match = array(); |
||
28 | if (preg_match('/\d+/', $output, $match)) { |
||
29 | return ($cachedVersion = $match[0]); |
||
30 | } |
||
31 | |||
32 | $output = @shell_exec('svn info '.escapeshellarg($dir).' 2>&1'); |
||
33 | if (preg_match('/Revision:\s*(\d+)/m', $output, $match)) { // do not translate |
||
34 | return ($cachedVersion = $match[1]); |
||
35 | } |
||
36 | |||
37 | // If that failed, try to get the version via access of the database files |
||
38 | if (class_exists('SQLite3')) { |
||
39 | try { |
||
40 | $db = new SQLite3($dir.'.svn/wc.db'); |
||
41 | $results = $db->query('SELECT MIN(revision) AS rev FROM NODES_BASE'); |
||
42 | while ($row = $results->fetchArray()) { |
||
43 | return ($cachedVersion = $row['rev']); |
||
44 | } |
||
45 | $db->close(); |
||
46 | $db = null; |
||
47 | } catch (Exception $e) { |
||
48 | } |
||
49 | } |
||
50 | if (class_exists('PDO')) { |
||
51 | try { |
||
52 | $pdo = new PDO('sqlite:'.$dir.'.svn/wc.db'); |
||
53 | $res = $pdo->query('SELECT MIN(revision) AS rev FROM NODES_BASE'); |
||
54 | $row = $res->fetch(); |
||
55 | if ($row !== false) { |
||
56 | return ($cachedVersion = $row['rev']); |
||
57 | } |
||
58 | $pdo = null; |
||
59 | } catch (Exception $e) { |
||
60 | } |
||
61 | } |
||
62 | |||
63 | // We couldn't get the revision info |
||
64 | return false; |
||
65 | } |
||
66 |