- Timestamp:
- May 6, 2008, 3:04:58 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r2325 r2333 278 278 $where_cats = '%s IN('.wordwrap(implode(', ', $ids), 120, "\n").')'; 279 279 } 280 280 281 281 // find all categories where the setted representative is not possible : 282 282 // the picture does not exist … … 395 395 { 396 396 $query = ' 397 398 399 397 INSERT INTO '.$table_name.' 398 ('.implode(',', $dbfields).') 399 VALUES'; 400 400 $first = false; 401 401 } … … 403 403 { 404 404 $query .= ' 405 405 , '; 406 406 } 407 407 … … 453 453 { 454 454 $query = ' 455 456 455 UPDATE '.$tablename.' 456 SET '; 457 457 $is_first = true; 458 458 foreach ($dbfields['update'] as $key) … … 474 474 } 475 475 $query.= ' 476 476 WHERE '; 477 477 478 478 $is_first = true; … … 483 483 $query.= ' AND '; 484 484 } 485 $query.= $key.' = \''.$data[$key].'\''; 485 if ( isset($data[$key]) ) 486 { 487 $query.= $key.' = \''.$data[$key].'\''; 488 } 489 else 490 { 491 $query.= $key.' IS NULL'; 492 } 486 493 $is_first = false; 487 494 } 488 495 $query.= ' 489 496 ;'; 490 497 pwg_query($query); 491 498 } … … 495 502 // creation of the temporary table 496 503 $query = ' 497 504 SHOW FULL COLUMNS FROM '.$tablename.' 498 505 ;'; 499 506 $result = pwg_query($query); … … 506 513 $column = $row['Field']; 507 514 $column.= ' '.$row['Type']; 508 if (!isset($row['Null']) or $row['Null'] == '') 515 516 $nullable = true; 517 if (!isset($row['Null']) or $row['Null'] == '' or $row['Null']=='NO') 509 518 { 510 519 $column.= ' NOT NULL'; 520 $nullable = false; 511 521 } 512 522 if (isset($row['Default'])) 513 523 { 514 524 $column.= " default '".$row['Default']."'"; 525 } 526 elseif ($nullable) 527 { 528 $column.= " default NULL"; 515 529 } 516 530 if (isset($row['Collation']) and $row['Collation'] != 'NULL') … … 528 542 ( 529 543 '.implode(",\n", $columns).', 530 PRIMARY KEY('.implode(',', $dbfields['primary']).')544 UNIQUE KEY the_key ('.implode(',', $dbfields['primary']).') 531 545 ) 532 546 ;'; 547 533 548 pwg_query($query); 534 549 mass_inserts($temporary_tablename, $all_fields, $datas); 535 550 // update of images table by joining with temporary table 536 551 $query = ' 537 538 552 UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2 553 SET '. 539 554 implode( 540 555 "\n , ", … … 544 559 ) 545 560 ).' 546 561 WHERE '. 547 562 implode( 548 563 "\n AND ", … … 555 570 pwg_query($query); 556 571 $query = ' 557 572 DROP TABLE '.$temporary_tablename.' 558 573 ;'; 559 574 pwg_query($query); -
trunk/admin/stats.php
r2299 r2333 116 116 $query = ' 117 117 SELECT 118 year, 119 month, 120 day, 121 hour, 122 max(id) AS max_id, 118 date, 119 HOUR(time) AS hour, 120 MAX(id) AS max_id, 123 121 COUNT(*) AS nb_pages 124 122 FROM '.HISTORY_TABLE.' 125 123 WHERE summarized = \'false\' 126 124 GROUP BY 127 year ASC, 128 month ASC, 129 day ASC, 130 hour ASC 125 date ASC, 126 HOUR(time) ASC 131 127 ;'; 132 128 $result = pwg_query($query); … … 141 137 { 142 138 $time_keys = array( 139 substr($row['date'], 0, 4), //yyyy 140 substr($row['date'], 0, 7), //yyyy-mm 141 substr($row['date'], 0, 10),//yyyy-mm-dd 143 142 sprintf( 144 '%4u', 145 $row['year'] 146 ), 147 sprintf( 148 '%4u.%02u', 149 $row['year'], $row['month'] 150 ), 151 sprintf( 152 '%4u.%02u.%02u', 153 $row['year'], $row['month'], $row['day'] 154 ), 155 sprintf( 156 '%4u.%02u.%02u.%02u', 157 $row['year'], $row['month'], $row['day'], $row['hour'] 143 '%s-%02u', 144 $row['date'], $row['hour'] 158 145 ), 159 146 ); … … 190 177 // +---------------+----------+ 191 178 // | 2005 | 241109 | 192 // | 2005 .08 | 20133 |193 // | 2005 .08.25 | 620 |194 // | 2005 .08.25.21 | 151 |179 // | 2005-08 | 20133 | 180 // | 2005-08-25 | 620 | 181 // | 2005-08-25-21 | 151 | 195 182 // +---------------+----------+ 196 183 197 $existing_time_keys = array();198 199 if (isset($first_time_key))200 {201 list($year, $month, $day, $hour) = explode('.', $first_time_key);202 203 $time_keys = array(204 sprintf('%4u', $year),205 sprintf('%4u.%02u', $year, $month),206 sprintf('%4u.%02u.%02u', $year, $month, $day),207 sprintf('%4u.%02u.%02u.%02u', $year, $month, $day, $hour),208 );209 210 $query = '211 SELECT212 id,213 nb_pages214 FROM '.HISTORY_SUMMARY_TABLE.'215 WHERE id IN (\''.implode("', '", $time_keys).'\')216 ;';217 $result = pwg_query($query);218 while ($row = mysql_fetch_array($result))219 {220 $existing_time_keys[ $row['id'] ] = $row['nb_pages'];221 }222 }223 184 224 185 $updates = array(); 225 186 $inserts = array(); 226 187 227 foreach (array_keys($need_update) as $time_key) 228 { 229 $time_tokens = explode('.', $time_key); 230 231 if (isset($existing_time_keys[$time_key])) 232 { 233 array_push( 234 $updates, 235 array( 236 'id' => $time_key, 237 'nb_pages' => $existing_time_keys[$time_key] + $need_update[$time_key], 188 if (isset($first_time_key)) 189 { 190 list($year, $month, $day, $hour) = explode('-', $first_time_key); 191 192 $query = ' 193 SELECT * 194 FROM '.HISTORY_SUMMARY_TABLE.' 195 WHERE year='.$year.' 196 AND ( month IS NULL 197 OR ( month='.$month.' 198 AND ( day is NULL 199 OR (day='.$day.' 200 AND (hour IS NULL OR hour='.$hour.') 201 ) 238 202 ) 239 ); 240 } 241 else 242 { 243 array_push( 203 ) 204 ) 205 ;'; 206 $result = pwg_query($query); 207 while ($row = mysql_fetch_assoc($result)) 208 { 209 $key = sprintf('%4u', $row['year']); 210 if ( isset($row['month']) ) 211 { 212 $key .= sprintf('-%02u', $row['month']); 213 if ( isset($row['day']) ) 214 { 215 $key .= sprintf('-%02u', $row['day']); 216 if ( isset($row['hour']) ) 217 { 218 $key .= sprintf('-%02u', $row['hour']); 219 } 220 } 221 } 222 223 if (isset($need_update[$key])) 224 { 225 $row['nb_pages'] += $need_update[$key]; 226 array_push($updates, $row); 227 unset($need_update[$key]); 228 } 229 } 230 } 231 232 foreach ($need_update as $time_key => $nb_pages) 233 { 234 $time_tokens = explode('-', $time_key); 235 236 array_push( 244 237 $inserts, 245 238 array( 246 'id' => $time_key,247 239 'year' => $time_tokens[0], 248 240 'month' => @$time_tokens[1], 249 241 'day' => @$time_tokens[2], 250 242 'hour' => @$time_tokens[3], 251 'nb_pages' => $n eed_update[$time_key],243 'nb_pages' => $nb_pages, 252 244 ) 253 245 ); 254 }255 246 } 256 247 … … 260 251 HISTORY_SUMMARY_TABLE, 261 252 array( 262 'primary' => array(' id'),253 'primary' => array('year','month','day','hour'), 263 254 'update' => array('nb_pages'), 264 255 ), -
trunk/include/functions.inc.php
r2313 r2333 570 570 date, 571 571 time, 572 year,573 month,574 day,575 hour,576 572 user_id, 577 573 IP, … … 586 582 CURDATE(), 587 583 CURTIME(), 588 YEAR( CURDATE() ),589 MONTH( CURDATE() ),590 DAYOFMONTH( CURDATE() ),591 HOUR( CURTIME() ),592 584 '.$user['id'].', 593 585 \''.$_SERVER['REMOTE_ADDR'].'\', -
trunk/install/phpwebgallery_structure.sql
r2324 r2333 117 117 `date` date NOT NULL default '0000-00-00', 118 118 `time` time NOT NULL default '00:00:00', 119 `year` smallint(4) NOT NULL default '0',120 `month` tinyint(2) NOT NULL default '0',121 `day` tinyint(2) NOT NULL default '0',122 `hour` tinyint(2) NOT NULL default '0',123 119 `user_id` smallint(5) NOT NULL default '0', 124 120 `IP` varchar(15) NOT NULL default '', … … 139 135 DROP TABLE IF EXISTS `phpwebgallery_history_summary`; 140 136 CREATE TABLE `phpwebgallery_history_summary` ( 141 `id` varchar(13) NOT NULL default '',142 137 `year` smallint(4) NOT NULL default '0', 143 138 `month` tinyint(2) default NULL, … … 145 140 `hour` tinyint(2) default NULL, 146 141 `nb_pages` int(11) default NULL, 147 PRIMARY KEY (`id`)142 UNIQUE KEY history_summary_ymdh (`year`,`month`,`day`,`hour`) 148 143 ) TYPE=MyISAM; 149 144
Note: See TracChangeset
for help on using the changeset viewer.