db_upgrade.php

Go to the documentation of this file.
00001 <?php
00013 
00014 require_once('sql.php');
00015 require_once('error.php');
00016 require_once('upload.php');
00017 
00018 function main() {
00019 
00020 $db1 = mysql_connect('localhost','semapp', 'Owtsgmi');
00021 mysql_select_db('semapp', $db1);
00022 
00023 $db2 = sql_init();
00024 
00025 ## step 1: users
00026 
00027 $p = array( 'tables' => 'users' );
00028 $users = sql_query('select', $p, $db1);
00029 
00030 #print_r($users);
00031 
00032 
00033 $new_state = array ( 1 => 1, 2 => 3, 3 => 5 );
00034 $new_role = array ( 1 => 3, 2 => 2, 3 => 1 );
00035 $new_degree = array ( 'Prof. Dr.' => 2, 'Dr.' => 4, 'PD Dr.' => 3, '' => 1);
00036 
00037 $p = array( 'table' => 'user');
00038 sql_query('delete', $p, $db2);
00039 
00040 print "Users:\n";
00041 
00042 foreach ($users as $u) {
00043         print($u['surname']) . ", " . $u['forename'] .   "\n" ;
00044 
00045         # translate state, role, etc.
00046 
00047         $u['degree_id'] = $new_degree[$u['title']];
00048         unset($u['title']);
00049 
00050         $u['state_id'] = $new_state[$u['state_id']];
00051 
00052         $u['role_id'] = $new_role[$u['group_id']];
00053         unset($u['group_id']);
00054 
00055         $u['use_alias'] = 0;
00056 
00057         $p = array( 'table' => 'user', 'data' => $u);
00058         sql_query('insert', $p, $db2);
00059 }
00060 
00061 ## step 2 lectures (-> collections)
00062 
00063 $p = array( 'tables' => 'lectures' );
00064 $lectures = sql_query('select', $p, $db1);
00065 
00066 $p = array( 'table' => 'collection');
00067 sql_query('delete', $p, $db2);
00068 
00069 $new_state = array ( 1 => 1, 2 => 3, 3 => 5 );
00070 
00071 print "Lectures:\n";
00072 foreach ($lectures as $l) {
00073         print $l['title'] . "\n";
00074         
00075         $l['state_id'] = $new_state[$l['state_id']];
00076 
00077         $l['expiry_date'] = '2006-10-01';
00078         $l['created'] = $l['last_modified'] = $l['last_state_change'] = '2006-01-01';
00079 
00080         $l['collection_no'] = $l['lecture_no'];
00081         unset($l['lecture_no']);
00082 
00083         $l['location_id'] = 1;
00084 
00085         $p = array( 'table' => 'collection', 'data' => $l);
00086         sql_query('insert', $p, $db2);
00087 }
00088 
00089 ### documents
00090 
00091 $p = array( 'table' => 'document');
00092 sql_query('delete', $p, $db2);
00093 
00094 ## urls
00095 
00096 $p = array( 'tables' => 'urls' );
00097 $urls = sql_query('select', $p, $db1);
00098 
00099 print "URLs:\n";
00100 
00101 foreach ($urls as $d) {
00102 
00103         print $d['title'] . "\n";
00104 
00105         $d['collection_id'] =  $d['lecture_id'];
00106         unset($d['lecture_id']);
00107 
00108         $d['relevance'] =  $d['sort_prio'];
00109         unset($d['sort_prio']);
00110 
00111         unset($d['id']);
00112 
00113         $d['created'] = $d['last_modified'] = $d['last_state_change'] = '2006-01-01';
00114 
00115         $d['doc_type_id'] = 3; ## url
00116 
00117         $d['state_id'] = 3;    ## active 
00118         $d['url_type_id'] = 4; ## weblink 
00119 
00120         $p = array( 'table' => 'document', 'data' => $d);
00121         sql_query('insert', $p, $db2);
00122 }
00123 
00124 $p = array( 'tables' => 'articles' );
00125 $articles = sql_query('select', $p, $db1);
00126 
00127 print "Artikel:\n";
00128 
00129 $new_state = array ( 1 => 1, 2 => 3, 3 => 5 );
00130 
00131 foreach ($articles as $d) {
00132 
00133         print $d['title'] . "\n";
00134 
00135         $d['collection_id'] =  $d['lecture_id'];
00136         unset($d['lecture_id']);
00137 
00138         $d['relevance'] =  $d['sort_prio'];
00139         unset($d['sort_prio']);
00140 
00141         $d['state_id'] = $new_state[$d['state_id']];
00142 
00143         unset($d['id']);
00144 
00145         $contents = file_get_contents($d['url']);
00146         $fn = basename($d['url']);
00147 
00148         unset($d['url']);
00149 
00150         $d['created'] = $d['last_modified'] = $d['last_state_change'] = '2006-01-01';
00151 
00152         $d['doc_type_id'] = 4; ## article
00153         $d['url_type_id'] = 3; ## full text
00154 
00155         $p = array( 'table' => 'document', 'data' => $d);
00156         sql_query('insert', $p, $db2);
00157         
00158         $ans = sql_query('last_id', array(), $db2);
00159         $id = $ans[0]['last_id'];
00160 
00161         print "new_id: $id";
00162 
00163         put_file('article', $id, $fn, $contents);
00164 }
00165 
00166 
00167 $p = array( 'tables' => 'books' );
00168 $books = sql_query('select', $p, $db1);
00169 
00170 print "Buecher:\n";
00171 
00172 $new_state = array ( 1 => 1, 2 => 3, 3 => 5 );
00173 
00174 foreach ($books as $d) {
00175 
00176         print $d['title'] . "\n";
00177 
00178         unset($d['chapter']);
00179 
00180         $d['ppn'] = preg_replace("/^.*ppn\+/", "", $d['opac_url']);
00181         unset($d['opac_url']);
00182 
00183         $d['collection_id'] =  $d['lecture_id'];
00184         unset($d['lecture_id']);
00185 
00186         $d['relevance'] =  $d['sort_prio'];
00187         unset($d['sort_prio']);
00188 
00189         $d['state_id'] = $new_state[$d['state_id']];
00190 
00191         unset($d['id']);
00192 
00193         $contents = file_get_contents($d['url']);
00194         $fn = basename($d['url']);
00195 
00196         unset($d['url']);
00197 
00198         $d['created'] = $d['last_modified'] = $d['last_state_change'] = '2006-01-01';
00199 
00200         $d['doc_type_id'] = 1; ## book
00201         $d['url_type_id'] = 2; ## toc
00202 
00203         $p = array( 'table' => 'document', 'data' => $d);
00204         sql_query('insert', $p, $db2);
00205         
00206         $ans = sql_query('last_id', array(), $db2);
00207         $id = $ans[0]['last_id'];
00208 
00209         print "new_id: $id";
00210 
00211         if ($fn == '') {
00212                 $fn = 'index.html';
00213         }
00214 
00215         if (!empty($contents)) {
00216                 put_file('book', $id, $fn, $contents);
00217         }
00218 }
00219 
00220 }
00221 
00222 main();
00223 ?>

Generated on Fri Jul 14 17:38:55 2006 for semapp by  doxygen 1.4.7