-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
132 lines (115 loc) · 4.09 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
require_once 'config.php';
require_once 'revisioner.php';
$db = new PDO("mysql:host=" . CONFIG_HOST . ";dbname=" . CONFIG_DATABASE, CONFIG_USERNAME, CONFIG_PASSWORD);
$revisioner = new Revisioner($db);
if (!$revisioner->isRevisionerInstalled()) {
if (isset($_GET['install_revisioner'])) {
$revisioner->installRevisioner();
header('Location: ./'); exit;
}
die("<div style='font: 16px Arial; padding: 20px;'><h1>Revisioner is not installed.</h1> <a href='?install_revisioner'>Install</a> (Only adds schema_version table to your database).</div>");
}
if (isset($_GET['install_all_revisions'])) {
$revisioner->updateAll();
header('Location: ./'); exit;
}
$_all_versions = $revisioner->getAllVersions();
$current_version_id = $revisioner->getCurrentVersion();
$latest_version_id = $revisioner->getLatestVersion();
$_versions = array();
foreach ($_all_versions as $vid => $version_folder) {
$_versions[$vid] = array(
'id' => $vid,
'folder' => $version_folder,
'name' => ucwords(trim(substr($version_folder, strpos($version_folder, '-')), ' -')),
'files' => $revisioner->getVersionFiles($version_folder, TRUE),
'imported' => ($vid > $current_version_id - 5 AND $vid <= $current_version_id),
'pending' => ($vid > $current_version_id),
);
}
?><!DOCTYPE html>
<html>
<head>
<title>Database Revisioner</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" />
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css" />
<style type="text/css">
body {
padding: 50px;
}
.version.imported .version_details {
display: none;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="hero-unit">
<h2>Current Database Schema Version: <?= $current_version_id; ?></h2>
<p>
<?php if ($current_version_id == $latest_version_id) : ?>
Your database is up to date. <br />
Here are latest imported versions.
<?php else : ?>
There are <?= ($latest_version_id - $current_version_id); ?> new revisions. <br />
Here are pending and latest imported versions.
<?php endif; ?>
</p>
</div>
<table class="table versions_table">
<tr>
<th width="40"> </th>
<th width="30" align="center">#</th>
<th>Version</th>
<th width="100">Actions</th>
</tr>
<?php foreach ($_versions as $vid => $_version): ?>
<tr class="version <?=($_version['imported'] ? 'imported success' : 'pending warning')?>">
<?php if ($_version['imported']): ?>
<td><span class="badge badge-success" title="Imported"><i class="icon-ok icon-white"></i></span></td>
<?php else: ?>
<td> </td>
<?php endif; ?>
<td align="center"><?=$vid;?></td>
<td>
<?=$_version['name'];?>
<div class="version_details">
<ul>
<?php foreach ($_version['files'] as $file): ?>
<li>
<h5><?=pathinfo($file, PATHINFO_FILENAME) . '.' . pathinfo($file, PATHINFO_EXTENSION);?></h5>
<pre class="pre-scrollable prettyprint linenums languague-sql"><?php readfile($file); ?></pre>
</li>
<?php endforeach; ?>
</ul>
</div>
</td>
<td>
<a href="javascript:;" class="details_button btn btn-mini">Details</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<br />
<?php if ($current_version_id != $latest_version_id) : ?>
<div>
<a href="?install_all_revisions" class="btn btn-success btn-large">Install Pending Revisions</a>
</div>
<?php endif; ?>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.js"></script>
<script type="text/javascript">
$(function(){
prettyPrint();
$('.versions_table tr.version .details_button').click(function(){
$(this).parents('td').parents('tr').find('.version_details').slideToggle();
});
});
</script>
</body>
</html>