You are here

function riddler_update_7000 in Captcha Riddler 7

Create new table for questions and copy variable content to it.

File

./riddler.install, line 58
Install, update and uninstall functions for the Riddler module.

Code

function riddler_update_7000() {
  drupal_install_schema('riddler');
  $query = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'riddler_question%'");
  $query
    ->execute();
  $insert = db_insert('riddler_questions')
    ->fields(array(
    'question',
    'answer',
  ));
  $numberOfQuestions = $query
    ->rowCount();
  if ($numberOfQuestions > 0) {
    for ($i = 0; $i < $numberOfQuestions; $i++) {
      $question = variable_get('riddler_question_' . $i);
      $answer = variable_get('riddler_answer_' . $i);
      if (!empty($question)) {
        $data = array(
          'question' => $question,
          'answer' => $answer,
        );
        $insert
          ->values($data)
          ->execute();
      }
    }
  }
  else {
    $data = array(
      'question' => 'Do you like SPAM?',
      'answer' => 'No',
    );
    $insert
      ->values($data)
      ->execute();
  }
}