function feedapi_update_4 in FeedAPI 5
File
- ./
feedapi.install, line 190
Code
function feedapi_update_4() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql("CREATE TABLE {feedapi_stat} (\n id INT(10) unsigned NOT NULL default '0',\n type VARCHAR(64) NOT NULL,\n timestamp INT(11) NOT NULL,\n time VARCHAR(20) NOT NULL,\n value INT(11) NOT NULL,\n INDEX (type, timestamp, time));\n ");
break;
case 'pgsql':
$ret[] = update_sql("CREATE TABLE feedapi_stat (\n id int NOT NULL default '0',\n type VARCHAR(64) NOT NULL,\n timestamp INT NOT NULL,\n time VARCHAR(20) NOT NULL,\n value INT NOT NULL)\n ");
$ret[] = update_sql("CREATE INDEX type_index on feedapi_stat(type)");
$ret[] = update_sql("CREATE INDEX timestamp_index on feedapi_stat(timestamp)");
$ret[] = update_sql("CREATE INDEX time_index on feedapi_stat(time)");
$ret[] = update_sql("CREATE INDEX id_index on feedapi_stat(id)");
break;
}
$result = db_query("SELECT nid, statistics FROM {feedapi}");
while ($stat = db_fetch_array($result)) {
$id = $stat["nid"];
$stat = unserialize($stat['statistics']);
$stat_fields = is_array($stat) ? array_keys($stat) : array();
foreach ($stat_fields as $field) {
$timestamp = time();
$time = date("Y-m-d H:i", $timestamp);
foreach ($stat[$field] as $val) {
$ret[] = update_sql("INSERT INTO {feedapi_stat} (id, value, time, timestamp, type) VALUES (%d, %d, '%s', %d, '%s')", $id, $val, $time, $timestamp, $field);
}
}
}
$ret[] = update_sql("ALTER TABLE {feedapi} DROP COLUMN statistics");
return $ret;
}