/** * @see LTIToolProviderOutcomesResourceEntityControllerInterface::save */ public function save($entity) { $transaction = db_transaction(); try { $entity->is_new = empty($enity->lti_tool_provider_outcomes_resource_id); if (empty($entity->lti_tool_provider_outcomes_resource_timestamp_created)) { $entity->lti_tool_provider_outcomes_resource_timestamp_created = REQUEST_TIME; } field_attach_presave('lti_tool_provider_outcomes_resource', $entity); $primary_key = $entity->lti_tool_provider_outcomes_resource_id ? 'lti_tool_provider_outcomes_resource_id' : array(); if (empty($primary_key)) { drupal_write_record('lti_tool_provider_outcomes_resource', $entity); field_attach_insert('lti_tool_provider_outcomes_resource', $entity); $op = 'insert'; } else { drupal_write_record('lti_tool_provider_outcomes_resource', $entity, $primary_key); $op = 'update'; } $function = 'field_attach_' . $op; $function('lti_tool_provider_outcomes_resource', $entity); module_invoke_all('entity_' . $op, $entity, 'lti_tool_provider_outcomes_resource'); unset($entity->is_new); db_ignore_slave(); return $entity; } catch (Exception $e) { $transaction->rollback(); drupal_set_message(t('%e', array('%e' => $entity->{$e}))); watchdog_exception('lti_tool_provider_outcomes_resource', $e, NULL, WATCHDOG_ERROR); return FALSE; } }
public function save($entity) { $entity = (object) $entity; // Determine if we will be inserting a new entity. $entity->is_new = !(isset($entity->bid) && is_numeric($entity->bid)); $transaction = db_transaction(); // Set the timestamp fields. if (empty($entity->created)) { $entity->created = REQUEST_TIME; } $entity->changed = REQUEST_TIME; field_attach_presave('command_button', $entity); module_invoke_all('entity_presave', $entity, 'command_button'); try { if (!$entity->is_new) { drupal_write_record('command_buttons', $entity, 'bid'); field_attach_update('command_button', $entity); module_invoke_all('entity_update', $entity, 'command_button'); } else { drupal_write_record('command_buttons', $entity); field_attach_insert('command_button', $entity); module_invoke_all('entity_insert', $entity, 'command_button'); } return $entity; } catch (Exception $e) { $transaction->rollback(); watchdog_exception('command_button', $e); } return FALSE; }
public function save($entity) { $entity = (object) $entity; // Determine if we will be inserting a new entity. $entity->is_new = !(isset($entity->fpid) && is_numeric($entity->fpid)); $transaction = db_transaction(); // Set the timestamp fields. if (empty($entity->created)) { $entity->created = REQUEST_TIME; } // Only change revision timestamp if it doesn't exist. if (empty($entity->timestamp)) { $entity->timestamp = REQUEST_TIME; } $entity->changed = REQUEST_TIME; field_attach_presave('fieldable_panels_pane', $entity); module_invoke_all('entity_presave', $entity, 'fieldable_panels_pane'); // When saving a new entity revision, unset any existing $entity->vid // to ensure a new revision will actually be created and store the old // revision ID in a separate property for entity hook implementations. if (!$entity->is_new && !empty($entity->revision) && $entity->vid) { $entity->old_vid = $entity->vid; unset($entity->vid); $entity->timestamp = REQUEST_TIME; } module_invoke_all('entity_presave', $entity, 'fieldable_panels_pane'); try { if (!$entity->is_new) { // Since we already have an fpid, write the revision to ensure the // vid is the most up to date, then write the record. $this->saveRevision($entity); drupal_write_record('fieldable_panels_panes', $entity, 'fpid'); field_attach_update('fieldable_panels_pane', $entity); module_invoke_all('entity_update', $entity, 'fieldable_panels_pane'); } else { // If this is new, write the record first so we have an fpid, // then save the revision so that we have a vid. This means we // then have to write the vid again. drupal_write_record('fieldable_panels_panes', $entity); $this->saveRevision($entity); db_update('fieldable_panels_panes')->fields(array('vid' => $entity->vid))->condition('fpid', $entity->fpid)->execute(); field_attach_insert('fieldable_panels_pane', $entity); module_invoke_all('entity_insert', $entity, 'fieldable_panels_pane'); } return $entity; } catch (Exception $e) { $transaction->rollback(); watchdog_exception('fieldable_panels_pane', $e); } return FALSE; }
/** * Called to save the final product from the edit form. */ function edit_save_form($form_state) { parent::edit_save_form($form_state); // Entity bundle has been saved. $op = $form_state['form type'] == 'add' ? 'insert' : 'update'; field_attach_insert('heartbeat_activity', $form_state['item']); module_invoke_all("entity_{$op}", $form_state['item'], 'heartbeat_activity'); field_info_cache_clear(); }
public function save($entity) { $entity = (object) $entity; // Determine if we will be inserting a new entity. $entity->is_new = !(isset($entity->fpid) && is_numeric($entity->fpid)); $transaction = db_transaction(); // Load the stored entity, if any. if (!empty($entity->fpid) && !isset($entity->original)) { $entity->original = entity_load_unchanged('fieldable_panels_pane', $entity->fpid); } // Set the timestamp fields. if (empty($entity->created)) { $entity->created = REQUEST_TIME; } // Only change revision timestamp if it doesn't exist. if (empty($entity->timestamp)) { $entity->timestamp = REQUEST_TIME; } $entity->changed = REQUEST_TIME; field_attach_presave('fieldable_panels_pane', $entity); // Trigger hook_fieldable_panels_pane_presave(). module_invoke_all('fieldable_panels_pane_presave', $entity); // Trigger hook_entity_presave_update(). module_invoke_all('entity_presave', $entity, 'fieldable_panels_pane'); // When saving a new entity revision, unset any existing $entity->vid // to ensure a new revision will actually be created and store the old // revision ID in a separate property for entity hook implementations. if (!$entity->is_new && !empty($entity->revision) && $entity->vid) { $entity->old_vid = $entity->vid; unset($entity->vid); $entity->timestamp = REQUEST_TIME; } try { // Since we already have an fpid, write the revision to ensure the vid is // the most up to date, then write the record. if (!$entity->is_new) { $this->saveRevision($entity); drupal_write_record('fieldable_panels_panes', $entity, 'fpid'); field_attach_update('fieldable_panels_pane', $entity); // Trigger hook_fieldable_panels_pane_update(). module_invoke_all('fieldable_panels_pane_update', $entity); // Trigger hook_entity_update(). module_invoke_all('entity_update', $entity, 'fieldable_panels_pane'); } else { drupal_write_record('fieldable_panels_panes', $entity); $this->saveRevision($entity); db_update('fieldable_panels_panes')->fields(array('vid' => $entity->vid))->condition('fpid', $entity->fpid)->execute(); field_attach_insert('fieldable_panels_pane', $entity); // Trigger hook_fieldable_panels_pane_insert(). module_invoke_all('fieldable_panels_pane_insert', $entity); // Trigger hook_entity_insert(). module_invoke_all('entity_insert', $entity, 'fieldable_panels_pane'); } // Clear the appropriate caches for this object. entity_get_controller('fieldable_panels_pane')->resetCache(array($entity->fpid)); return $entity; } catch (Exception $e) { $transaction->rollback(); watchdog_exception('fieldable_panels_pane', $e); } return FALSE; }
public function save() { field_attach_presave('ms_products_purchase', $this); // Update or insert a new purchase. if (!is_null($this->id)) { drupal_write_record('ms_products_purchases', $this, 'id'); field_attach_update('ms_products_purchase', $this); } else { drupal_write_record('ms_products_purchases', $this); field_attach_insert('ms_products_purchase', $this); } // Next, save the options. if (!empty($this->options)) { foreach ($this->options as $option_info) { if (isset($option_info->id)) { if ($option_info == 'inactive') { db_delete('ms_products_purchase_options')->condition('id', $option_info->id)->execute(); } else { // Update the existing record. drupal_write_record('ms_products_purchase_options', $option_info, 'id'); } } elseif ($option_info->status != 'inactive') { // Create a new record. $option_info->pid = $this->id; drupal_write_record('ms_products_purchase_options', $option_info); } } } }