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