source: trunk/update_notice.php@ 16

Last change on this file since 16 was 7, checked in by gegorbet, 10 years ago

airvata/thrift, us3-listen, update_notice changes

  • Property svn:keywords set to LastChangedDate Author
File size: 5.5 KB
Line 
1<?php
2
3$us3bin = exec( "ls -d ~us3/bin" );
4$us3etc = exec( "ls -d ~us3/etc" );
5include_once "$us3bin/listen-config.php";
6
7// Get the US3 system release string
8$s_url1 = "//bcf2.uthscsa.edu/ultrascan3/trunk/utils";
9$s_url2 = "//bcf2.uthscsa.edu/ultrascan3/trunk/programs/us";
10
11$s_cmd1 = "/usr/bin/svn info svn:$s_url1|grep Revision|cut -d ' ' -f2";
12$s_cmd2 = "/usr/bin/svn info svn:$s_url1|grep Revision|cut -d ' ' -f2";
13
14$s_rev1 = exec( $s_cmd1 );
15$s_rev2 = exec( $s_cmd2 );
16
17$sysrev = $s_rev2;
18if ( $s_rev1 > $s_rev2 )
19 $sysrev = $s_rev1;
20$sysrev = "3.3." . $sysrev;
21
22// Global variables
23$notice_db = "us3_notice";
24$dbhost = "localhost";
25$dbuser = "root";
26//$dbpassw = exec( "cat ~us3/.sec/.pwsq" );
27$dbpassw = exec( "cat ~/.sec/.pwsq" );
28
29// Produce some output temporarily, so cron will send me message
30$now = time();
31echo "Time started: " . date( 'Y-m-d H:i:s', $now ) . "\n";
32
33// Read and parse the local notice file
34
35$n_fname = "$us3etc/us3-notice.xml";
36$fh = fopen( $n_fname, "r" );
37$xml = fread( $fh, filesize( $n_fname ) );
38
39$parser = new XMLReader();
40$parser->xml( $xml );
41
42$notices = array();
43$keys = array();
44
45echo "=====START of PARSE LOOP===== \n";
46while( $parser->read() )
47{
48 $n_type = $parser->nodeType;
49//echo "n_type=$n_type \n";
50
51 if ( $n_type == XMLReader::ELEMENT )
52 {
53 $name = $parser->name;
54//echo "name=$name \n";
55
56 if ( $name == "notice" )
57 {
58 $type = $parser->getAttribute( "type" );
59//echo " type=$type \n";
60 $parser->moveToAttribute( "revision" );
61 $rev = $parser->value;
62//echo " rev=$rev \n";
63 if ( $rev == "latest" )
64 $rev = $sysrev;
65//echo " rev=$rev \n";
66
67 $key = $type . $rev;
68 $notices[ $key ] = array();
69//echo " key=$key \n";
70 }
71 }
72
73 else if ( $n_type == XMLReader::TEXT )
74 {
75 $msg = $parser->readString();
76//echo " msg=+++$msg+++ \n";
77 $len = strlen( $msg );
78
79 if ( $len > 0 )
80 { // Only add if not an empty message
81 $msg = preg_replace( "/\@revision/", $rev, $msg );
82 $msg = preg_replace( "/'/", "\\'", $msg );
83 $notices[ $key ][ 'type' ] = $type;
84 $notices[ $key ][ 'rev' ] = $rev;
85 $notices[ $key ][ 'msg' ] = $msg;
86 $notices[ $key ][ 'act' ] = 'add';
87 $notices[ $key ][ 'id' ] = '0';
88
89 $keys[] = $key;
90 }
91 }
92}
93
94$parser->close();
95echo "=====END of PARSE LOOP===== \n";
96
97// Get data from notice DB. Update the action field to
98// reflect which action is required on each entry:
99// "add" - is only present in file (add to DB);
100// "del" - is only present in DB (delete from DB);
101// "upd" - present in both, but messages differ (update in DB);
102// "none" - present in both and messages identical (no DB update).
103
104$noteLink = mysql_connect( $dbhost, $dbuser, $dbpassw );
105
106if ( ! mysql_select_db( $notice_db, $noteLink ) )
107{
108 echo "Could not select DB $notice_db - " . mysql_error() . "\n";
109 exit();
110}
111
112$query = "SELECT id, type, revision, message FROM notice";
113
114$result = mysql_query( $query, $noteLink )
115 or die( "Query failed : $query<br />" . mysql_error() );
116
117echo "=====START of DB QUERY LOOP===== \n";
118$num_rows = mysql_num_rows( $result );
119
120echo " numrows = $num_rows \n";
121while ( list( $id, $type, $rev, $msg ) = mysql_fetch_array( $result ) )
122{
123 $key = $type . $rev;
124 $msgf = $notices[ $key ][ 'msg' ];
125
126 if ( in_array( $key, $keys ) )
127 { // Entry is in both file and DB
128 $notices[ $key ][ 'id' ] = $id;
129 $notices[ $key ][ 'type' ] = $type;
130 $notices[ $key ][ 'rev' ] = $rev;
131
132 if ( strcmp( $msg, $msgf ) == 0 )
133 { // Messages match, so no update is needed
134 $notices[ $key ][ 'act' ] = 'none';
135 }
136 else
137 { // Messages differ, so DB entry must be updated
138 $notices[ $key ][ 'act' ] = 'upd';
139 $notices[ $key ][ 'msg' ] = $msgf;
140echo " msg = ++$msg++\n";
141echo " msgf = ++$msgf++\n";
142 }
143 }
144
145 else
146 { // Entry is only in DB, so a delete is needed
147 $notices[ $key ] = array();
148 $notices[ $key ][ 'id' ] = $id;
149 $notices[ $key ][ 'type' ] = $type;
150 $notices[ $key ][ 'rev' ] = $rev;
151 $notices[ $key ][ 'act' ] = 'del';
152 $notices[ $key ][ 'msg' ] = $msg;
153 $keys[] = $key;
154 }
155}
156echo "=====END of DB QUERY LOOP===== \n";
157
158echo "=====START of DB Update LOOP===== \n";
159foreach ( $keys as $key )
160{
161 $type = $notices[ $key ][ 'type' ];
162 $rev = $notices[ $key ][ 'rev' ];
163 $act = $notices[ $key ][ 'act' ];
164 $id = $notices[ $key ][ 'id' ];
165 $msg = $notices[ $key ][ 'msg' ];
166 $len = strlen( $msg );
167 echo "-- key=$key --\n";
168 echo " type: $type \n";
169 echo " rev: $rev \n";
170 echo " act: $act \n";
171 echo " id: $id \n";
172// echo " msg: $msg \n";
173 echo " msg: ( $len characters ) \n";
174
175 if ( $act == "add" )
176 { // Must add the entry to the database
177 $query = "INSERT INTO notice " .
178 "SET type='$type', revision='$rev', message='$msg'";
179 }
180 else if ( $act == "del" )
181 { // Must delete the entry from the database
182 $query = "DELETE FROM notice WHERE id='$id'";
183 }
184 else if ( $act == "upd" )
185 { // Must update an existing entry in the database
186 $query = "UPDATE notice " .
187 "SET message='$msg' " .
188 "WHERE id='$id'";
189 }
190 echo " query: [ $query ] \n";
191
192 $result = mysql_query( $query, $noteLink )
193 or die( "Query failed : $query<br />" . mysql_error() );
194
195}
196echo "=====END of DB Update LOOP===== \n";
197
198?>
Note: See TracBrowser for help on using the repository browser.