Skip to content

Instantly share code, notes, and snippets.

@deviantintegral
Created March 27, 2012 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deviantintegral/2220738 to your computer and use it in GitHub Desktop.
Save deviantintegral/2220738 to your computer and use it in GitHub Desktop.
Exploding kaltura metadata
<?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