I have a use case where I'm pulling from an Ektron database into a structure where I have:
- Event node type
- Document node type with filefield
- Nodereference field on Document node that links to Even type
Events come from what are classified as Meetings in Ektron. Both Meetings and documents are records on the nge_content table with a content_id. The data is stored in the database to represent a folder structure as seen here, where I have to start at the top level and look at parent_id values, and then get to content_id records for each document. for example, here's a drush callback I wrote to go through and get all of the documents:
function mymodule_import_documents() {
// Get list of groups and their parent folder ids.
$sql = "SELECT folder_id, folder_name FROM {nge_content_folder_tbl} WHERE parent_id = %d AND LENGTH(folder_description) > %d AND folder_name <> '%s'";
// Filter out the test folder.
$sql .= " AND folder_name not in ('%s', '%s')";
// Narrow down to one group for dev purposes.
//$sql .= " AND folder_id = 11761";
$result = db_query($sql, 0, 0, 'Pages', 'Test Folder');
while ($group = db_fetch_object($result)) {
// Get the second level, which will be stuff like Meetings, Other Content, Post Meeting Reports, etc.
$result_level_2 = db_query("SELECT folder_id FROM {nge_content_folder_tbl} WHERE parent_id = %d", $group->folder_id);
// Get the third level, which will be the docs folder, such as MeetingDocs, OtherContentDocs, PMRDocs, etc.
while ($docs_parent_folder = db_fetch_object($result_level_2)) {
$result_level_3 = db_query("SELECT folder_id FROM {nge_content_folder_tbl} WHERE parent_id = %d", $docs_parent_folder->folder_id);
while ($docs_folder_2 = db_fetch_object($result_level_3) ) {
// There might be another directory level below this (for meeting handouts), but if not, the docs are here.
$level_4_folder_id = db_result(db_query("SELECT folder_id FROM {nge_content_folder_tbl} WHERE parent_id = %d", $docs_folder_2->folder_id));
if ($level_4_folder_id) {
//
$result_level_4 = db_query("SELECT * FROM {nge_content} WHERE folder_id = %d", $level_4_folder_id);
while ($docs_folder_3 = db_fetch_object($result_level_4)) {
// Get the list of actual docs from the content table.
$sql_docs = "SELECT c.content_id, c.content_title, c.asset_id, cf.FolderIdPath";
$sql_docs .= " FROM nge_content c INNER JOIN nge_content_folder_tbl cf on c.folder_id = cf.folder_id";
$sql_docs .= " WHERE c.folder_id = %d";
$result_docs = db_query($sql_docs, $docs_folder_3->folder_id );
while ($docs = db_fetch_object($result_docs)) {
$content_path = 'http://www.neugroup.com/assets/0/' . $docs->FolderIdPath . $docs->asset_id . '.pdf';
//$doc = drupal_http_request($content_path);
}
}
}
// There is no folder below this one, so the docs are here.
else {
$test = 'a';
// But first, let's check to see if there are any docs here.
$doc_count = db_result(db_query("SELECT count(*) FROM {nge_content} WHERE folder_id = %d", $docs_folder_2->content_id));
if ($doc_count) {
// We have docs in this directory.
$sql_docs = "SELECT c.content_id, c.content_title, c.asset_id, cf.FolderIdPath";
$sql_docs .= " FROM nge_content c INNER JOIN nge_content_folder_tbl cf on c.folder_id = cf.folder_id";
$sql_docs .= " WHERE c.folder_id = %d";
$result_docs = db_query($sql_docs, $docs_folder_2->folder_id );
while ($docs = db_fetch_object($result_docs)) {
$content_path = 'http://www.neugroup.com/assets/0/' . $docs->FolderIdPath . $docs->asset_id . '.pdf';
//$doc = drupal_http_request($content_path);
}
}
}
}
}
}
}
Not fun. What's even better is that Ektron actually saves the doc with a hex file name and stores that (along with the original file name) in the content table, so I need to rename the file once I get it downloaded.
So the question is, considering all that code I need to go through just to get the associated docs, what is the best way to write my class to a) get the doc, b) rename it, c) import it to the filefield, and d) link the document node to the appropriate meeting node? I already have a migration set up for meeting nodes, so I can make this one dependent on the meeting migration, since they will both use content_id as key values.
Will I need to create a separate class that inherits from MigrateSource, or is there a way to just use the existing MigrateSourceSQL class?
Thanks.
Comments
Comment #1
wonder95 commentedAfter posting this I had an epiphany, so I just modified the drush code above to get everything into a table that has the image data all nice and neat; one record for each image. However, that brings me to another question.
Since I have a full URL, where do I pass it to the field mapping? From what I can see in migrate_example, it looks like it would be something like
since I need to pass the URL to the file field handler. If that's the case, what do I pass to addFieldMapping? The same field? Or do I pass the file_path value in both places?
Thanks.
Comment #2
mikeryanWith the new file migration support, it's simple:
I think in the old version (up through 2.3, and a couple commits beyond) the direct mapping, with the source_path argument set to NULL, would have worked.