0

I am creating a import script, which is importing node into Drupal website from external database.

Node is inserting properly. I have added condition that node exist into Drupal website or not and I am getting the correct nid with this condition.

When I am using node_load to load the existing node, its showing empty result.

I also checked node_load get blank, but did not get any satisfied answer.

Please forgive me if this question is duplicate.

Code Snippets:

$pricelist_query = db_query("select * from abshop_import.abshop_import_price where (result != 'I' and  result != 'O' and result != 'D') or result is NUll limit 0, 50");

$message = '';

while ($pricelist_object = db_fetch_object($pricelist_query)) {

    $product = db_fetch_object(db_query("select * from abshop_import.abshop_import_antibodies where (result != 'I' or result is NUll) and sku_model='%s'", $pricelist_object -> sku_model));

    if (!empty($product)) {

    $product_object = db_fetch_object(db_query("select nid from {content_field_pr_man_prd_numb} where field_pr_man_prd_numb_value='" . $product -> field_pr_man_prd_numb_value . "'"));

        //If product is primary antibodies
        if ($product -> primary_or_secondary == 'P' || $product -> primary_or_secondary == 'p') {

        //If there is no existing product
            if (empty($product_object)) {

                $node = new STDCLASS;
                $node -> type = 'primary_antibodies';

                //setting language of the node
                $node -> language = 'en';

                //setting the author of the node
                $node -> uid = $product -> uid;

            } else {

                $nid = $product_object -> nid;

                $node = node_load($nid, NULL, TRUE);

                print $product_object -> nid . "===>";

                print_r($node);

            }

            $node -> shippable = 1;

            $node -> model = $product -> sku_model;

            //Setting title of the product
            $node -> title = $product -> title;
            //Setting body of the product
            $node -> body = $product -> body_teaser;
            //Setting teaser of the product
            $node -> teaser = $product -> body_teaser;

            $node -> weight = $product -> uc_products_weight;
            $node -> weight_units = $product -> uc_products_weight_units;

        }

        //If product is primary antibodies
        elseif ($product -> primary_or_secondary == 'S' || $product -> primary_or_secondary == 's') {

            //If there is no existing product
            if (empty($product_object)) {

                $node = new STDCLASS;

                $node -> type = 'secondary_antibodies';
                //setting language of the node
                $node -> language = 'en';

                //setting the author of the node
                $node -> uid = $product -> uid;

            } else {

                $nid = $product_object -> nid;

                $node = node_load(array('nid' => $nid), NULL, TRUE);

                print $product_object -> nid . "===>";

                $n = node_load(array('nid' => $nid), NULL, TRUE);
                print_r($n);

            }

            $node -> model = $product -> sku_model;

            $node -> shippable = 1;

            //Setting title of the product
            $node -> title = $product -> title;
            //Setting body of the product
            $node -> body = $product -> body_teaser;
            //Setting teaser of the product
            $node -> teaser = $product -> body_teaser;


            $node -> weight = $product -> uc_products_weight;
            $node -> weight_units = $product -> uc_products_weight_units;

        }

        if ($node = node_submit($node)) {

            print_r($node);
            die ;

            node_save($node);
        }

        node_load(FALSE, NULL, TRUE);

}

}

Thanks in advance.

  • There are several possibilities but chances are you are not correctly creating all the data for your node. One example would be if the node type value you insert isn't defined as a content type. So I would suggest you compare the table rows created by your import process with ones created if you create nodes manually. – Alfred Armstrong Nov 5 '13 at 17:45
  • some code would definitely help :) – Jimajamma Nov 5 '13 at 18:43
  • @Jimajamma, I have updated my question. – Jayendra Kainthola Nov 6 '13 at 1:17
  • thanks. when you do your debug printing, does $nid show a value that does in fact correspond to a valid node because your node_load()s appear correct. – Jimajamma Nov 6 '13 at 1:26
  • @Jimajamma, yes nid showing the correct value, but node_load is not working. I have found another issue that url node/148272/edit is also not working. So, no idea what is happening here. – Jayendra Kainthola Nov 6 '13 at 1:34
1

After perform R&D, I found that uid of the node was not matching with uid in {users} table, which mean there is no existing user which is author of the node.

As I am importing the node from external database and it was importing properly previously, so I did not noticed the same.

Now, when I changed the uid of the node, everything starts working properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.