Created
March 13, 2012 19:42
-
-
Save deviantintegral/2031096 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
db_query("TRUNCATE {kaltura_custom_data}"); | |
$result = db_query("SELECT id FROM {kaltura_full_metadata}"); | |
$count = 0; | |
while ($id = db_result($result)) { | |
$count++; | |
if ($count % 100 == 0) { | |
echo "Imported $count rows.\n"; | |
}; | |
if ($count % 500 == 0) { | |
return; | |
} | |
$custom_data = unserialize(db_result(db_query("SELECT custom_data FROM {kaltura_full_metadata} WHERE id = '%s'", $id))); | |
if (empty($custom_data)) { | |
continue; | |
} | |
db_query("INSERT INTO {kaltura_custom_data} (id) VALUES ('%s')", array($id)); | |
foreach ($custom_data as $key => $value) { | |
if (!db_column_exists("kaltura_custom_data", $key)) { | |
$ret = array(); | |
if (is_int($value)) { | |
$spec = array( | |
'type' => 'int', | |
'not null' => TRUE, | |
); | |
} | |
else { | |
$spec = array( | |
'type' => 'text', | |
'size' => 'medium', | |
); | |
} | |
db_add_field($ret, "kaltura_custom_data", $key, $spec); | |
} | |
is_int($value) ? $placeholder = "%d" : $placeholder = "'%s'"; | |
db_query("UPDATE {kaltura_custom_data} SET %s = $placeholder WHERE id = '%s'", array($key, $value, $id)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment