0); // test if a certain database field exists function field_exists($table, $field) { global $opt; return sql_value("SELECT COUNT(*) FROM `information_schema`.`columns` WHERE `table_schema`='&1' AND `table_name`='&2' AND `column_name`='&3'", 0, $opt['db']['placeholder']['db'], $table, $field) > 0; } // get type of a database field function field_type($table, $field) { global $opt; return strtoupper( sql_value("SELECT `data_type` FROM `information_schema`.`columns` WHERE `table_schema`='&1' AND `table_name`='&2' AND `column_name`='&3'", '', $opt['db']['placeholder']['db'], $table, $field) ); } // Database mutations // - must be consecutively numbered // - should behave well if run multiple times function dbv_100() // expands log date to datetime, to enable time logging { if (field_type('cache_logs','date') != 'DATETIME') sql("ALTER TABLE `cache_logs` CHANGE COLUMN `date` `date` DATETIME NOT NULL"); if (field_type('cache_logs_archived','date') != 'DATETIME') sql("ALTER TABLE `cache_logs_archived` CHANGE COLUMN `date` `date` DATETIME NOT NULL"); } function dbv_101() // add fields for fixing OKAPI issue #232 { if (!field_exists('caches','meta_last_modified')) { // initialize with '0000-00-00 00:00:00' for existing data, that's ok sql("ALTER TABLE `caches` ADD COLUMN `meta_last_modified` DATETIME NOT NULL COMMENT 'via Trigger (cache_logs)' AFTER `listing_last_modified`"); } if (!field_exists('cache_logs','log_last_modified')) { if (field_exists('cache_logs','okapi_syncbase')) $after = 'okapi_syncbase'; else $after = 'last_modified'; sql("ALTER TABLE `cache_logs` ADD COLUMN `log_last_modified` DATETIME NOT NULL COMMENT 'via Trigger (stat_caches, gk_item_waypoint)' AFTER `".$after."`"); sql("UPDATE `cache_logs` SET `log_last_modified` = GREATEST( `last_modified`, IFNULL((SELECT MAX(`last_modified`) FROM `pictures` WHERE `pictures`.`object_type`=1 AND `pictures`.`object_id` = `cache_logs`.`id`),'0') )"); } if (!field_exists('cache_logs_archived','log_last_modified')) { if (field_exists('cache_logs_archived','okapi_syncbase')) $after = 'okapi_syncbase'; else $after = 'last_modified'; sql("ALTER TABLE `cache_logs_archived` ADD COLUMN `log_last_modified` DATETIME NOT NULL AFTER `".$after."`"); sql("UPDATE `cache_logs_archived` SET `log_last_modified` = `last_modified`"); } } function dbv_102() // remove invisible caches from users' hidden stats { sql("INSERT IGNORE INTO `stat_user` (`user_id`) SELECT `user_id` FROM `caches` GROUP BY `user_id`"); sql("UPDATE `stat_user`, (SELECT `user_id`, COUNT(*) AS `count` FROM `caches` INNER JOIN `cache_status` ON `cache_status`.`id`=`caches`.`status` AND `allow_user_view`=1 GROUP BY `user_id`) AS `tblHidden` SET `stat_user`.`hidden`=`tblHidden`.`count` WHERE `stat_user`.`user_id`=`tblHidden`.`user_id`"); sql("CALL sp_refreshall_statpic()"); } ?>