Umfragen
update_db.php
Go to the documentation of this file.
1 <?php
2 /*
3  * update_db#.php
4  *
5  * Copyright 2013 Johannes <jojo@jojo-42>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  *
22  *
23  */
24 
25 require_once("config.php");
26 require_once("inc/db.class.php");
27 require_once("inc/auth.class.php");
28 require_once("inc/poll.class.php");
29 require_once("inc/tools.php");
30 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
31 
32 try {
33  $dbh = new PDO("mysql:dbname=".DB_DATABASE.";host=".DB_HOST, DB_USER, DB_PASS,
34  array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
35 } catch (PDOException $e) {
36  die( 'Connection failed: ' . $e->getMessage());
37 }
38 
40 
41 
42 echo "<pre>";
43 
44 /*
45 $sqh = $dbh->query("SHOW TABLES FROM `umfragen`");
46 $rows = $sqh->fetchAll(PDO::FETCH_ASSOC);
47 $tables = array();
48 foreach($rows as $r){
49  $tables[] = $r["Tables_in_umfragen"];
50 }
51 //var_dump($tables);
52 foreach($tables as $table){
53 
54 
55  if( is_numeric($table) ){
56  echo "<h1>{$table}</h1>";
57  $sql = "ALTER TABLE `umfragen`.`$table` ADD `parent` int( 11 ) NOT NULL DEFAULT '-1'";
58  echo "<p>".$sql."</p>";
59  $dbh->exec($sql);
60 
61  $sql = "SELECT ID,name FROM `umfragen`.`$table` WHERE `typ`='radioButtonList' OR `typ`='checkBoxList'";
62  $sqh = $dbh->query($sql);
63  $rows = $sqh->fetchAll( PDO::FETCH_ASSOC );
64  foreach( $rows as $row){
65  $sql = "UPDATE `umfragen`.`$table` SET `parent`= {$row["ID"]} WHERE `is_child` = '1' AND `name`={$row["name"]}";
66  echo "<p>".$sql."</p>";
67  $dbh->exec($sql);
68  }
69  }
70 
71 
72  if( substr($table,-1*strlen("_results") ) == "_results"){
73  echo $table.PHP_EOL;
74  echo "/\/\/\/\/\/".PHP_EOL;
75  $sql = "ALTER TABLE `$table` ADD `name` varchar( 256 ) NOT NULL ";
76  echo $sql.PHP_EOL;
77  $dbh->exec($sql);
78 
79  $sql = "ALTER TABLE `$table` ADD `group` varchar( 256 ) NOT NULL ";
80  echo $sql.PHP_EOL;
81  $dbh->exec($sql);
82 
83 
84  }
85 
86 }
87 
88 $sqh = $dbh->query("SELECT * from `umfragen`.`umfragen`");
89 $poll_info_arrays = $sqh->fetchAll(PDO::FETCH_ASSOC);
90 $polls = array();
91 
92 foreach($poll_info_arrays as $poll_array){
93  $p = new poll();
94  $p->load_from_id($db,$poll_array["ID"]);
95  $polls[] = $p;
96 }
97 
98 //var_dump($polls);
99 
100 foreach( $polls as $poll ){
101  foreach( $poll->widget_list as $widget ){
102  if( $widget instanceof container ){
103  foreach( $widget->option_list as $option ){
104  $option->serialize_config();
105  $db->update_widget_field($option , "config" , $option->config);
106  }
107  }
108  $widget->unserialize_config();
109  $widget->serialize_config();
110  $db->update_widget_field($widget , "config" , $widget->config);
111 
112  }
113 }
114 
115 
116 $dbh->exec("ALTER TABLE `umfragen` ADD `active_since` DATETIME NOT NULL AFTER `timeout`");
117 */
118 /*
119 $dbh->exec("ALTER TABLE `umfragen` ADD `hashID` VARCHAR( 32 ) NOT NULL AFTER `ID`");
120 $dbh->exec("ALTER TABLE `umfragen` ADD `noDisplay` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `status`");
121 
122 $polls_arr = $db->get_all_polls_array();
123 
124 foreach( $polls_arr as $p ){
125  $pp = new poll();
126  $pp->load_from_id($db,$p["ID"]);
127 
128  echo "Processing {$pp->name} ...".PHP_EOL;
129  $hash = $pp->make_id_hash();
130  echo " hash is $hash".PHP_EOL;
131  $sql = "UPDATE `umfragen` SET `hashID` = '$hash' WHERE `ID`={$pp->ID}";
132  echo " SQL IS: $sql".PHP_EOL;
133  $count = $dbh->exec($sql);
134  echo " $count row(s) modified".PHP_EOL.PHP_EOL;
135 }
136 
137 */
138 
139 /*$sql "CREATE TABLE IF NOT EXISTS `user_config` (
140  `user` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
141  `polls_visited` longtext COLLATE utf8_unicode_ci NOT NULL
142 );";
143 echo $sql;
144 $dbh->exec($sql);
145 */
146 
147 
148 
149 $sqh = $dbh->query("SHOW TABLES FROM `umfragen`");
150 $rows = $sqh->fetchAll(PDO::FETCH_ASSOC);
151 $tables = array();
152 foreach($rows as $r){
153  $tables[] = $r["Tables_in_umfragen"];
154 }
155 //var_dump($tables);
156 foreach($tables as $table){
157 
158 
159  /*if( is_numeric($table) ){
160  echo "<h1>{$table}</h1>";
161  $sql = "ALTER TABLE `umfragen`.`$table` ADD `parent` int( 11 ) NOT NULL DEFAULT '-1'";
162  echo "<p>".$sql."</p>";
163  $dbh->exec($sql);
164 
165  $sql = "SELECT ID,name FROM `umfragen`.`$table` WHERE `typ`='radioButtonList' OR `typ`='checkBoxList'";
166  $sqh = $dbh->query($sql);
167  $rows = $sqh->fetchAll( PDO::FETCH_ASSOC );
168  foreach( $rows as $row){
169  $sql = "UPDATE `umfragen`.`$table` SET `parent`= {$row["ID"]} WHERE `is_child` = '1' AND `name`={$row["name"]}";
170  echo "<p>".$sql."</p>";
171  $dbh->exec($sql);
172  }
173  }*/
174 
175 
176  if( substr($table,-1*strlen("_results") ) == "_results"){
177  echo "<h1>".$table."</h1>".PHP_EOL;
178 
179  $sql = "ALTER TABLE `$table` ADD `Nachname` varchar( 256 ) NOT NULL AFTER `name`";
180  echo $sql.PHP_EOL;
181  $dbh->exec($sql);
182 
183  $sql = "ALTER TABLE `$table` ADD `Vorname` varchar( 256 ) NOT NULL AFTER `name`";
184  echo $sql.PHP_EOL;
185  $dbh->exec($sql);
186 
187  $sqh = $dbh->query("SELECT * FROM `{$table}`");
188  $rows = $sqh->fetchAll(PDO::FETCH_ASSOC);
189  foreach( $rows as $row ){
190  if( ($row["user"] !== "") ){
191  $inf = $au->info($row["user"]);
192  if( (isset($inf["surName"])) AND (isset($inf["givenName"])) AND ($inf["surName"] != "") AND ($inf["givenName"] != "") ){
193  echo $row["user"]." -> ".$inf["fullName"].PHP_EOL;
194  $sqh = $dbh->prepare("UPDATE `$table` SET `Vorname` = :givenName , `Nachname` = :surName WHERE `user` = '{$row["user"]}'");
195  $sqh->execute( array(":givenName"=>$inf["givenName"], ":surName"=>$inf["surName"]) );
196  }
197  }
198  }
199 
200  }
201 
202 }
203 
204 
205 
206 
207 echo "</pre>";
208 
209 
210 ?>