You are here

function prepare_field_collections_button_submit in GlobalLink Connect for Drupal 7.7

Field collections batch set.

1 string reference to 'prepare_field_collections_button_submit'
globallink_useful_tools in ./globallink_settings.inc
Globallink Useful Tools form.

File

./globallink_settings.inc, line 1055

Code

function prepare_field_collections_button_submit($form, &$form_state) {
  if (module_exists('field_collection')) {
    $batch = array(
      'operations' => array(),
      'finished' => 'globallink_settings_field_collections_batch_finished',
      'title' => t('Sets all Field Collections'),
      'init_message' => t('Sets all Field Collections is starting.'),
      'progress_message' => t('Processed @current out of @total.'),
      'error_message' => t('Update Menus has encountered an error.'),
      'file' => drupal_get_path('module', 'globallink') . '/globallink_settings.inc',
    );
    $progress = 0;
    $limit = 20;
    $resultCollection = db_query("SELECT * FROM {field_config} WHERE type = :type", array(
      ':type' => "field_collection",
    ))
      ->fetchAll();
    if (!empty($resultCollection)) {
      $result = array();
      foreach ($resultCollection as $key => $value) {
        $unserialize = unserialize($value->data);
        if (isset($unserialize['storage']['details']['sql']['FIELD_LOAD_CURRENT'])) {
          $tableNameCurrent = $unserialize['storage']['details']['sql']['FIELD_LOAD_CURRENT'];
          foreach ($tableNameCurrent as $key => $value) {
            $nameCurrent = $key;
          }
          $result[]['tableName'] = $nameCurrent;
        }
        if (isset($unserialize['storage']['details']['sql']['FIELD_LOAD_REVISION'])) {
          $tableNameRevision = $unserialize['storage']['details']['sql']['FIELD_LOAD_REVISION'];
          foreach ($tableNameRevision as $key => $value) {
            $nameRevision = $key;
          }
          $result[]['tableName'] = $nameRevision;
        }
      }
      if (!empty($result)) {
        foreach ($result as $key => $value) {
          $resultAlltabledata[$value['tableName']] = db_query("SELECT * FROM {$value['tableName']} WHERE language = :language", array(
            ':language' => "und",
          ))
            ->fetchAll();
        }
        foreach ($resultAlltabledata as $key => $value) {
          $count = count($value);
        }
        $max = $count;
        while ($progress <= $max) {
          $batch['operations'][] = array(
            'globallink_settings_field_collections_process',
            array(
              $progress,
              $limit,
              $resultAlltabledata,
            ),
          );
          $progress = $progress + $limit;
        }
        batch_set($batch);
      }
      else {
        drupal_set_message('No Recoards');
      }
    }
  }
  else {
    drupal_set_message('Please install field collection module');
  }
}