Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8744679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:52:47+00:00 2026-06-13T11:52:47+00:00

Ok, trying to process a script, both PHP and JavaScript, where I am moving

  • 0

Ok, trying to process a script, both PHP and JavaScript, where I am moving a particular content type NODE from one reference to another. This is the structure:

I have a PROJECT
Inside each PROJECT are PAGES
Inside each PAGE are CALLOUTS
and Inside each CALLOUT are PRODUCTS.

What I want to do is take a PRODUCT from one CALLOUT to another CALLOUT. I am able to merge these, but now what I want to do is delete the first instance. An example:

I have PRODUCT AAG-794200 that is on PAGE 6 CALLOUT A. I am merging that PRODUCT with PAGE 6 CALLOUT B.

I can get the product to merge, but now I need to remove it from CALLOUT A. Here is my code:

$merge = explode(',', $merge); //Merge SKUs
$mpages = explode(',', $mpages); //Merge Pages
$mcallouts = explode(',', $mcallouts); //Merge Callouts
$mcallout_nid = explode(',', $mcallout_nid);  //Merge Current callout

$length = count($merge);
$e = 0;
while ($e < $length) {
    //Where is the SKU going to?
    $to_callout_letter = strtoupper($mcallouts[$e]);
    $to_page_num = $mpages[$e];
    $sku = $merge[$e];
    $from_callout = $mcallout_nid[$e];

    //Where is the SKU coming from?     
    $other_callout = node_load($from_callout);

    //Need page ID of current callout for project purposes
    $page_nid = $other_callout->field_page[0]['nid'];
    $page = node_load($page_nid);
    //Need the project NID
    $project_nid = $page->field_project[0]['nid'];

    //We need to get the NID of the page we are going to
    $page_nid = db_query('SELECT * FROM content_type_page WHERE field_page_order_value = "%d" and field_project_nid = "%d" ORDER BY vid DESC LIMIT 1', $to_page_num, $project_nid);

    $page_nid_res = db_fetch_array($page_nid);
    $to_page_nid = $page_nid_res['nid'];

    //We need to get the NID of the callout here
    $co_nid = db_query('SELECT * FROM content_type_callout WHERE field_identifier_value = "%s" and field_page_nid = "%d"', $to_callout_letter, $to_page_nid);
    $co_nid_res = db_fetch_array($co_nid);
    $to_callout_letter_nid = $co_nid_res['nid'];


    //Load the present callout the SKU resides on
    $f_callout = node_load($from_callout);

    $callout = node_load($to_callout_letter_nid);
    $long = count($f_callout->field_skus);
    $deletecallout = array();
    foreach($f_callout->field_skus as $skus) {
        $s = 0;
        while ($s < $long) {
            if($skus['nid'] == $sku) {
                $callout->field_skus[] = $skus;
                $s++;
            }
            else {
                $deletecallout[] = $skus;
                $s++;
            }
        }
    }


    foreach($other_callout->field_images as $old_image) {
        $callout->field_images[] = $old_image;
    }
    foreach($other_callout->field_line_art as $old_image) {
        $callout->field_line_art[] = $old_image;
    }
    foreach($other_callout->field_swatches as $old_image) {
        $callout->field_swatches[] = $old_image;
    }

    $callout->field_copy_text[0]['value'] .= $other_callout->field_copy_text[0]['value'];
    $callout->field_notes[0]['value'] .= $other_callout->field_notes[0]['value'];
    $callout->field_image_notes[0]['value'] .= $other_callout->field_image_notes[0]['value'];
    $callout->field_status[0]['value'] = 'In Process';
    node_save($callout);

This causes the PRODUCTS to MERGE, but not delete the original.

Thanks for any help. I know it’s something simple, and it will be a palm-to-face moment.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:52:48+00:00Added an answer on June 13, 2026 at 11:52 am

    I was actually able to solve this myself. @Chris – The brace ended after node_save(callout); I must have missed that when I copied and pasted. However, here is the code I ended up using:

    $merge = explode(',', $merge); //Merge SKUs
    $mpages = explode(',', $mpages); //Merge Pages
    $mcallouts = explode(',', $mcallouts); //Merge Callouts
    $mcallout_nid = explode(',', $mcallout_nid);  //Merge Current callout
    if($merge[0] !== '0') {
        //Store NIDs of Old Callouts to the proper SKU
        $oc_sku = array();
        $oc_sku_e = count($merge);
        $oc_sku_ee = 0;
        while ($oc_sku_ee < $oc_sku_e) {
            $curr_sku = $merge[$oc_sku_ee];
            $curr_oldco = $mcallout_nid[$oc_sku_ee];
            $oc_sku[$curr_sku] = $curr_oldco;
            $oc_sku_ee++;
        }
    
        //Convert page numbers to page_nids
        $pc = count($mpages); //How many pages are we getting
        $pc_e = 0;
        while($pc_e < $pc) {
            $nid = $mpages[$pc_e];
            $sql = db_query('SELECT * FROM content_type_page WHERE field_page_order_value = "%d" AND field_project_nid = "%d" ORDER BY vid DESC LIMIT 1', $nid, $project_nid);
            $res = db_fetch_array($sql);
            if($res) {
                $npage_arr[] = $res['nid'];
            } else {  //If there is no page, we need to create it here.
                $node = new StdClass();
                $node->type = 'page';
                $node->title = 'Page ' . $nid . ' of ' . $project->title;
                $node->field_project[0]['nid'] = $project_nid;
                $node->field_page_order[0]['value'] = $nid;
                $node = node_submit($node);
                node_save($node);
                $npage_arr[] = $node->nid;
            }
        $pc_e++;
        }
    
    
        // Convert callout letters to callout_nids
        $coc = count($mcallouts);
        $coc_e = 0;
        while($coc_e < $coc) {
            $cnid = strtoupper($mcallouts[$coc_e]);
            $pnid = $npage_arr[$coc_e];
            $page_node = node_load($pnid);
            $sql = db_query('SELECT * FROM content_type_callout WHERE field_identifier_value = "%s" AND field_page_nid = "%d" ORDER BY vid DESC LIMIT 1', $cnid, $pnid);
            $res = db_fetch_array($sql);
            if($res) {
                $cpage_arr[] = $res['nid'];
            } else { //If there is no callout that exists, we need to make it here.
                $callout_node = new stdClass();
                $callout_node->type = 'callout';
                $callout_node->field_page[0]['nid'] = $pnid;
                $callout_node->field_identifier[0]['value'] = $cnid;
                $callout_node->field_sequence[0]['value'] = 0;
                $callout_node->title = "Callout ".$callout." on page ".$page_node->field_page_order[0]['value'];
                $callout_node->field_project[0]['nid'] = $project->nid;
                $callout_node->field_wholesaler[0]['value'] = $project->field_wholesaler[0]['value'];
                $callout_node->field_skus = array();
    
                $callout_node->status = 1;
                $callout_node->uid = 1;             
                $callout_node->revision = true;
                $callout_node = node_submit($callout_node);
                node_save($callout_node);
                $cpage_arr[] = $callout_node->nid;
            }
        $coc_e++;
        }
    
        //Now we need to assign the skus to the appropriate callout for processing
        $coc2 = count($cpage_arr);
        $coc_e2 = 0;
        while($coc_e2 < $coc2) {
            $co = $cpage_arr[$coc_e2];
            if($co !== '0') {
                $sku = $merge[$coc_e2];
                $m_arr[$co][] = $sku;
            }
        $coc_e2++;
        }
    
        //we need a way to centrally store all NID's of SKUs to the callouts they belong to
        $oc_arr = array();
        $oc = count($mcallout_nid);
        $oc_e = 0;
        while($oc_e < $oc) {
            $f_callout = $mcallout_nid[$oc_e];
            $former_callout = node_load($f_callout);
            foreach($former_callout->field_skus as $key=>$skus) {
                $oc_arr[] = $skus;
            }
            $oc_e++;
        }
    
        //Now we are processing the Pages/Callouts/SKUs to save
        $pc_e2 = 0;
        foreach($m_arr as $key=>$values) {
            $callout = node_load($key);
            foreach($values as $value) {
                $oc = count($oc_arr);
                $oc_e = 0;
                while($oc_e < $oc) {
                    $skus = $oc_arr[$oc_e];
                    if($value == $skus['nid']) {
                        $callout->field_skus[] = $skus;
                        //$nid = $oc_sku[$value];
                        $old_callout_info[] = $oc_sku[$value];
                        $oc_e = $oc;
                    }
                    else {
                        $oc_e++;
                    }
                }
            }
    
            foreach($old_callout_info as $nid) {
    /*          $nid = $oc_sku[$value]; */
                $former_callout = node_load($nid);
                foreach($former_callout->field_images as $old_image) {
                $callout->field_images[] = $old_image;
                }
                foreach($former_callout->field_line_art as $old_image) {
                    $callout->field_line_art[] = $old_image;
                }
                foreach($former_callout->field_swatches as $old_image) {
                    $callout->field_swatches[] = $old_image;
                }
                $callout->field_copy_text[0]['value'] .= $former_callout->field_copy_text[0]['value'];
            }
            $callout->field_notes[0]['value'] .= $former_callout->field_notes[0]['value'];
            $callout->field_image_notes[0]['value'] .= $former_callout->field_image_notes[0]['value'];
            $callout->field_logos = $former_callout->field_logos;
            $callout->field_affiliations = $former_callout->field_affiliations;
            $callout->field_graphics = $former_callout->field_graphics;
            $callout->revision = 1;
    
    
    
            $callout->field_status[0]['value'] = 'inprocess';
            node_save($callout);
            $pc_e2++;
        }
        }
    

    I realize this can probably be simplified in a way, but as for now, this works perfectly considering what I’m trying to do. No complaints from the client so far. Thanks for taking a look Drupal Community.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run bp_genbank2gff3.pl (bioperl package) from another perl script that gets
I'm trying to execute a python script (through a python process) under another user.
I am trying to figure out how to process XML in java script So
I'm trying to write a bash script that will process a list of files
I'm trying to process data obtained from a run of diff to an instance
I am trying to process 114,000 rows in a dataset (populated from an oracle
I am trying to process both .aspx and non-extension page requests (i.e. both contact.aspx
I am trying to do some process control in a script (bash). For this
<html> <head> <title>Group Test</title> <script type=text/javascript src=/static/javascript/jquery-1.8.2.min.js></script> </head> <body> <script type=text/javascript> var global =
I'm trying to fork a process by getting PHP to exec PHP whilst piping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.