Closed (fixed)
Project:
Asset
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
12 Apr 2008 at 20:29 UTC
Updated:
7 May 2008 at 11:11 UTC
Im working on migrating content from our old db into Drupal. I was able to import content from the old db and create nodes using the script below. The CCK Content Type contains an asset field for images which i was also able to import. But the problem is that when im on the edit page of that node the asset module doesnt pre populate the asset image fields. In addition im able to view the values of those fields when im vieweing using "Dev Load".
Is there a way that I can have asset module display the images on nodes that have been generated automatically by a script ??
Thanks
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
$result = db_query(db_rewrite_sql("select * from dbname.dbtable"));
while($results = db_fetch_object($result))
{
$node = new StdClass();
$node->type = 'cck_content_type';
$node->uid = $user->uid;
$node->status = 1;
$node->promote = 0;
$node->sticky = 0;
$node->title = $results->TITLE;
$node->body = $results->TEXT;
$node->field_story_id[0]['value'] = $results->STORYID;
$node->field_datel[0]['value'] = $results->SUBMITDATE;
$node->field_datel[0]['value'] .= 'T00:00:00';
$node->field_breakpoint[0]['value'] = $results->breakpoint;
$images = db_query("select imagename from dbname.pictures where STORYID = $results->STORYID");
$imageCount = db_num_rows($images);
$i=0;
while($image = db_fetch_object($images))
{
$assetId = db_next_id('{asset}_aid');
$imagename = $image->imagename. '-460.jpg';
$node->field_story_images[$i]['options'] = $imagename;
$node->field_story_images[$i]['caption'] = $imagename;
$asset_type = 'local';
$asset_dirname = 'images';
$asset_extension = 'jpg';
$asset_uid = 1;
db_query("insert into {asset} (aid, type, dirname, extension, filename, uid, status) values (%d, '%s', '%s', '%s', '%s', %d, %d)", $assetId, $asset_type, $asset_dirname, $asset_extension, $imagename, 1, 1);
$i++;
}
node_save($node);
$nid = $node->nid;
}
Comments
Comment #1
janwari commentedgot it working :)
Just needed to add a single line of code
$node->field_story_images[$i]]['aid'] = $assetId;
Comment #2
wmostrey commentedGlad to see you got it working, good job :) You could also have used asset_save() of course.
Comment #3
janwari commentedIf i had to do it using asset_save() how can I do it ?? I searched but wasnt able to find any documentation on asset_save()
Comment #4
wmostrey commentedThat's probably because there isn't any I'm afraid, the asset api or the code in general isn't documented yet. The only way to see how asset_save works, is to look at the code (asset.module).
Comment #5
petermo commentedI have a related migration request... I have imported several hundred assets using Asset Import. I have a content type (called FcaDocument), which has an asset field, and thus want to populate several hundred FcaDocuments each with their appropriate asset. My PHP is not very strong, but I can drive PHPMyAdmin reasonably well, so have a working knowledge of nids and vids and aids. I can easily make a list specifying "FcaDocument with node ID xxxx needs to have asset ID yyyy added to it". Any help much appreciated.
Comment #6
janwari commentedyou could write a script for each FcaDocuments which gets the related asset and adds it to a CCK field.
Comment #7
petermo commentedThanks, can you give me some pointers, on what such a script might look like.... anything similar would be a help.
Comment #8
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #8.0
(not verified) commented