17 include_once (
"WHAT/Lib.System.php");
19 function GetDbVersion($dbid, &$tmachine, $usePreviousVersion =
false)
24 $rq = pg_query($dbid,
"select paramv.val, application.name, application.machine from paramv, application where paramv.name='VERSION' and paramv.appid=application.id");
28 for ($i = 0; $i < pg_numrows($rq); $i++) {
29 $row = pg_fetch_array($rq, $i);
30 $tver[$row[
"name"]] = $row[
"val"];
31 $tmachine[$row[
"name"]] = $row[
"machine"];
34 if ($usePreviousVersion) {
39 $rq = pg_query($dbid,
"select paramv.val, application.name, application.machine from paramv, application where paramv.name='PREVIOUS_VERSION' and paramv.appid=application.id");
43 while ($row = pg_fetch_array($rq)) {
44 if (isset($tver[$row[
'name']])) {
45 $tver[$row[
'name']] = $row[
'val'];
57 if (
$dir = @opendir($topdir)) {
58 while ((
$file = readdir(
$dir)) !==
false) {
59 $inifile = $topdir .
"/$file/${file}_init.php";
60 if (@is_file($inifile)) {
62 $fini = fopen($inifile,
"r");
63 while (!feof($fini)) {
64 $line = fgets($fini, 256);
65 if (preg_match(
"/VERSION.*=>[ \t]*\"[ \t]*([0-9\.\-]+)/", $line, $reg)) {
66 if (isset($reg[1])) $tver[
$file] = $reg[1];
85 if (
$dir = @opendir($topdir)) {
86 while ((
$file = readdir(
$dir)) !==
false) {
87 $inifile = $topdir .
"/$file/${file}.app";
88 if (@is_file($inifile)) {
92 if (isset($app_desc)) {
93 if (isset($app_desc[
"iorder"])) $tiorder[
$file] = $app_desc[
"iorder"];
108 return version_compare($v1, $v2);
113 if (preg_match_all(
'/([0-9]+)/', $ver, $matches)) {
114 $matches = ($matches[0]);
116 $c = count($matches);
118 for ($i = 0; $i < (4 -
$c); $i++) {
122 foreach ($matches as $k => $v) $sva.= sprintf(
"%02d", $v);
123 return floatval($sva);
134 $dbid = @pg_connect($dbaccess_core);
137 $err = _(
"cannot access to core database service [service='$pgservice_core']");
138 exec(
"PGSERVICE=\"$pgservice_core\" psql -c '\q'",
$out);
155 $dbid = @pg_connect($dbaccess_core);
158 $err = _(
"cannot access to core database service [service='$pgservice_core']");
159 exec(
"PGSERVICE=\"$pgservice_core\" psql -c '\q'",
$out);
162 $tvdb =
GetDbVersion($dbid, $tmachine, $usePreviousVersion);
166 $ta = array_unique(array_merge(array_keys($tvdb) , array_keys($tvfile)));
167 foreach ($ta as $k => $v) {
168 if (!isset($tvfile[$v])) {
171 if (!isset($tvdb[$v])) {
174 if (($tmachine[$v] !=
"") && (gethostbyname($tmachine[$v]) != gethostbyname($_SERVER[
"HOSTNAME"]))) $chk[$v] =
"?";
175 else if ($tvdb[$v] == $tvfile[$v]) {
177 }
else if ($tvdb[$v] ==
"") {
179 }
else if ($tvfile[$v] ==
"") {
181 }
else if (
vercmp($tvdb[$v], $tvfile[$v]) == 1) {
189 "vfile" => $tvfile[$v],
191 "machine" => $tmachine[$v]
208 $dbid = @pg_connect(
"service='$pgservice_core'");
210 $tvdb =
GetDbVersion($dbid, $tmachine, $usePreviousVersion);
213 foreach ($tiorder as $k => $v) {
214 $tapp[$k][
"iorder"] = $v;
216 uasort($tapp,
"cmpapp");
217 foreach ($tapp as $k => $v) {
219 $pattern = preg_quote($k,
"/");
221 if (
$dir = @opendir(
"$pubdir/$k")) {
222 while ((
$file = readdir(
$dir)) !==
false) {
223 if (preg_match(
"/{$pattern}_(?:migr|premigr)_([0-9\.]+)$/",
$file, $reg)) {
224 if (($tvdb[$k] !=
"") && (
vercmp($tvdb[$k], $reg[1]) < 0)) $migr[] =
"$pubdir/$k/$file";
228 usort($migr,
"cmpmigr");
231 if (!isset($v[
"chk"])) {
234 if (($v[
"chk"] !=
"") && (is_file(
"$pubdir/$k/{$k}_post"))) {
235 if ($v[
"chk"] ==
"I") {
236 $cmd[] =
"$pubdir/$k/{$k}_post " . $v[
"chk"];
241 $cmd[] =
"$pubdir/wsh.php --api=manageApplications --method=init --appname=$k";
242 $cmd[] =
"$pubdir/wsh.php --api=manageApplications --method=update --appname=$k";
246 $cmd[] =
"$pubdir/wsh.php --api=manageApplications --method=update --appname=$k";
250 $cmd[] =
"#$pubdir/wsh.php --api=manageApplications --method=delete --appname=$k";
254 $cmd[] =
"#rpm -Uvh $k-" . $v[
"vdb"];
258 if (($v[
"chk"] !=
"") && (is_file(
"$pubdir/$k/{$k}_post"))) {
259 if ($v[
"chk"] ==
"I") {
260 $cmd[] =
"$pubdir/$k/{$k}_post U";
262 if (($v[
"chk"] !=
"R") && ($v[
"chk"] !=
"?")) {
263 if ($v[
"chk"] ==
"D")
$cmd[] =
"#$pubdir/$k/{$k}_post " . $v[
"chk"];
264 else $cmd[] =
"$pubdir/$k/{$k}_post " . $v[
"chk"];
270 if (
$dir = @opendir(
"$pubdir/$k")) {
271 while ((
$file = readdir(
$dir)) !==
false) {
272 if (preg_match(
"/{$pattern}_(?:pmigr|postmigr)_([0-9\.]+)$/",
$file, $reg)) {
274 if (($tvdb[$k] !=
"") && (
vercmp($tvdb[$k], $reg[1]) < 0)) $migr[] =
"$pubdir/$k/$file";
278 usort($migr,
"cmpmigr");
283 $dump[] =
"PGSERVICE=\"$pgservice_freedom\" pg_dump -D > " .
getTmpDir() .
"/" . uniqid($pgservice_freedom);
285 $dump[] =
"$pubdir/wstop";
286 $dump[] =
"$pubdir/whattext";
288 $tact = array_merge($dump,
$cmd);
290 $tact[] =
"$pubdir/wsh.php --api=cleanContext";
291 $tact[] =
"$pubdir/wstart";
293 if (empty(
$_GET[
'httpdrestart']) || (
$_GET[
'httpdrestart'] !=
'no')) {
294 if (!empty($_SERVER[
'HTTP_HOST'])) $tact[] =
"sudo $pubdir/admin/shttpd";
295 else $tact[] =
"service httpd restart";
301 if (isset(
$a[
"iorder"]) && isset($b[
"iorder"])) {
302 if (
$a[
"iorder"] > $b[
"iorder"])
return 1;
303 else if (
$a[
"iorder"] < $b[
"iorder"])
return -1;
306 if (isset(
$a[
"iorder"]))
return -1;
307 if (isset($b[
"iorder"]))
return 1;
315 preg_match(
"/_(?:p|post|pre)?migr_(?P<version>[0-9\.]+)$/", $migr_a, $v_a);
316 preg_match(
"/_(?:p|post|pre)?migr_(?P<version>[0-9\.]+)$/", $migr_b, $v_b);
318 return version_compare($v_a[
'version'], $v_b[
'version']);
getCheckActions($pubdir, $tapp, &$tact, $usePreviousVersion=false)
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
foreach($argv as $arg) $cmd
GetDbVersion($dbid, &$tmachine, $usePreviousVersion=false)
static getHostIPAddress($hostname="")
getCheckApp($pubdir, &$tapp, $usePreviousVersion=false)
cmpmigr($migr_a, $migr_b)
if($file) if($subject==""&&$file) if($subject=="") $err