You are here

public function BotchaFormModel::save in BOTCHA Spam Prevention 7.3

Same name and namespace in other branches
  1. 6.2 model/botcha_form.model.inc \BotchaFormModel::save()
  2. 6.3 model/form/botcha.form.model.inc \BotchaFormModel::save()
  3. 7.2 model/botcha_form.model.inc \BotchaFormModel::save()

Save form to the database.

Parameters

BotchaForm $form:

Overrides IBotchaFormModel::save

File

model/form/botcha.form.model.inc, line 52
Contains BotchaFormModel class.

Class

BotchaFormModel

Code

public function save($form) {

  // Catching of PDOException helps to avoid WSOD during update use case. The
  // reason is in that form_alter is called before performing an update.
  // @see http://drupal.org/node/1828710
  try {

    // Save form.
    $forms = db_select('botcha_form', 'bf')
      ->fields('bf')
      ->condition('id', $form->id)
      ->execute()
      ->fetchCol();
    if (!count($forms)) {
      db_insert('botcha_form')
        ->fields(array(
        'id' => $form->id,
      ))
        ->execute();
    }

    // Delete all data related to this form.
    db_delete('botcha_recipebook_form')
      ->condition('form_id', $form->id)
      ->execute();
    $rbid = $form
      ->getRecipebook();

    // @todo Remove hardcode.
    if ($rbid != 'none') {

      // Save form-recipe book relationship.
      db_merge('botcha_recipebook_form')
        ->key(array(
        'form_id' => $form->id,
      ))
        ->fields(array(
        'rbid' => $rbid,
      ))
        ->execute();
    }
  } catch (Exception $e) {
    if ($e instanceof PDOException) {
      watchdog_exception('BOTCHA', $e, 'Please perform an update via update.php or reinstall the BOTCHA module to fix the reason of this warning! %type: !message in %function (line %line of %file).', array(), WATCHDOG_WARNING);
    }
  }
}