Jump to content

Raxter

New Members
  • Posts

    7
  • Joined

  • Last visited

Raxter's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am in need of serious help. I have been working on this issue and researching for weeks. I am using entity metadata wrapper to update a time value. I am not encountering any errors. It is just not updating. I am using set() to update the value. Any ideas or input?? This is when the original value is set in the node: $node->field_event_dates[$node->language][0]['value2'] = strtotime($event->endTime); When I try to update the endtime, nothing updates: $feed_data = $json_data->dissertations; foreach ($feed_data as $event) { // make sure it doesn't already exist $event_nids = FALSE; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'event') ->propertyCondition('field_form_id', $event->{'form_id'}, '=') ->fieldCondition('field_event_dates', 'value', strtotime($event->startTime) , '=') ->range(0, 1) //($start, $length) ->addMetaData('account', user_load(1)); // Run the query as user 1. $result = $query->execute(); if (isset($result['node'])) { // existing so update $counter_existing++; //added to update event when a change $node = node_load($nid); $node_wrapper = entity_metadata_wrapper('node', $node); $node_wrapper->field_event_dates->set(array('value2'=> strtotime($event->endTime))); $node_wrapper->save(); }
  2. I apologize for the code formatting. It is from copying and pasting. It isn't like that in my module. I updated the code per your suggestion. I made a change to the title and startdate value and it did not update values. However, it will create a new event with the new values.
  3. Thanks for the info and the help! I feel like I have been looking at this for weeks! I added the code to initialize the node when it is found (per the reply from another poster). Here is the code I have: $category_matches = taxonomy_get_term_by_name('Dicate', 'events'); $category = array_pop($category_matches); if (!$category) { watchdog('rad', 'no dicate found', 'error'); return; } $feed_url = 'https://las/rad-forms/api/v1/getfeed'; $options = array('headers' => array()); $options['headers']['Authorization'] = 'Basic ' . base64_encode('rad:6WLUMwFgAjdOQPazZ7K0yxBRxklVAEWZaaaAcQuzQh4V7v7ZWP2cHl/BtCdhlj1ngacrhA=='); $response = drupal_http_request($feed_url, $options); $response_data = $response->data; $json_data = json_decode($response_data); $feed_data = $json_data->dicate; if (!count($feed_data)) { watchdog('rad_feed', 'bad feed request - ' . print_r($response, TRUE)); } foreach ($feed_data as $event) { // make sure it doesn't already exist $event_nids = FALSE; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'event') ->propertyCondition('title', $event->{'draftTitle'}, '=') ->fieldCondition('field_event_dates', 'value', strtotime($event->startTime) , '=') ->range(0, 1) //($start, $length) ->addMetaData('account', user_load(1)); // Run the query as user 1. $result = $query->execute(); if (isset($result['node'])) { // existing event found, just count it $counter_existing++; //ADDED TO UPDATE $node = new stdClass(); $node->title = $event->{'draftTitle'}; $node->field_event_category[$node->language][0]['tid'] = $category->tid; $node->field_event_dates[$node->language][0]['value'] = strtotime($event->startTime); node_save($node); } else { // event doesn't exist; create new one $counter_new++; $node = new stdClass(); $node->type = 'event'; $node->language = LANGUAGE_NONE; node_object_prepare($node); $node->status = 1; $node->promote = 0; $node->sticky = 0; $node->comment = 0; $node->uid = 1; $node->title = $event->{'draftTitle'}; $node->field_event_category[$node->language][0]['tid'] = $category->tid; $node->field_event_dates[$node->language][0]['value'] = strtotime($event->startTime); node_save($node); } } variable_set('rad_feed_last_run', $time); watchdog('rad_feed', 'ran feed update: ' . $counter_new . ' new events; found ' . $counter_existing . ' existing events'); }
  4. Thanks for the input. Obviously I am new to php and that is why I am here. If the event already exists then I am trying to just update it. If it does not exist then I need to create it. The module currently does create a new one. It wont do any updates, I will create a new one with the change.
  5. Thank you for that update. I have added the following lines of code to that if statement. Any advice is appreciated $node = new stdClass(); $node->language = LANGUAGE_NONE; node_object_prepare($node); $node->uid = 1;
  6. This if statement? if (isset($result['node'])) { // existing event found, just count it
  7. I have a custom module that is displaying events fed by a JSON feed. The problem I am having is when the JSON feed is updated (for example a title name is updated) it creates a new event instead of updating the original event. I am new to php and what I have tried is not working. Any help would be appreciated. $category_matches = taxonomy_get_term_by_name('Dicate', 'events'); $category = array_pop($category_matches); if (!$category) { watchdog('rad', 'no dicate found', 'error'); return; } $feed_url = 'https://las/rad-forms/api/v1/getfeed'; $options = array('headers' => array()); $options['headers']['Authorization'] = 'Basic ' . base64_encode('rad:6WLUMwFgAjdOQPazZ7K0yxBRxklVAEWZaaaAcQuzQh4V7v7ZWP2cHl/BtCdhlj1ngacrhA=='); $response = drupal_http_request($feed_url, $options); $response_data = $response->data; $json_data = json_decode($response_data); $feed_data = $json_data->dicate; if (!count($feed_data)) { watchdog('rad_feed', 'bad feed request - ' . print_r($response, TRUE)); } foreach ($feed_data as $event) { // make sure it doesn't already exist $event_nids = FALSE; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'event') ->propertyCondition('title', $event->{'draftTitle'}, '=') ->fieldCondition('field_event_dates', 'value', strtotime($event->startTime) , '=') ->range(0, 1) //($start, $length) ->addMetaData('account', user_load(1)); // Run the query as user 1. $result = $query->execute(); if (isset($result['node'])) { // existing event found, just count it $counter_existing++; //ADDED TO UPDATE $event->{'draftTitle'} = $node->title; $node->field_event_category[$node->language][0]['tid'] = $category->tid; $node->field_event_dates[$node->language][0]['value'] = strtotime($event->startTime); node_save($node); } else { // event doesn't exist; create new one $counter_new++; $node = new stdClass(); $node->type = 'event'; $node->language = LANGUAGE_NONE; node_object_prepare($node); $node->status = 1; $node->promote = 0; $node->sticky = 0; $node->comment = 0; $node->uid = 1; $node->title = $event->{'draftTitle'}; $node->field_event_category[$node->language][0]['tid'] = $category->tid; $node->field_event_dates[$node->language][0]['value'] = strtotime($event->startTime); node_save($node); } } variable_set('rad_feed_last_run', $time); watchdog('rad_feed', 'ran feed update: ' . $counter_new . ' new events; found ' . $counter_existing . ' existing events'); } JSON Example: "dictate":[{"form_id" : "1234", "draftTitle" : "Test123", "startTime" : "Wed, Jan 19, 2017"}]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.