You are here

function user_restrictions_ui_import in User restrictions 7

Batch import function to import access rules from the access table

Parameters

$context:

See also

user_restrictions_ui_import_rule_form_submit()

2 string references to 'user_restrictions_ui_import'
user_restrictions_ui_import_rule_form_submit in ./user_restrictions_ui.admin.inc
Form submission function.
user_restrictions_update_7102 in ./user_restrictions.install
Imports username and e-mail masks from the {access} table.

File

./user_restrictions_ui.admin.inc, line 256
Administration pages for the user restrictions module.

Code

function user_restrictions_ui_import(&$context) {
  if (empty($context['sandbox']) && db_table_exists('access')) {
    $context['sandbox'] = array();
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['current_aid'] = 0;
    $context['sandbox']['max'] = db_query("SELECT COUNT(DISTINCT aid) FROM {access} WHERE type <> 'host'")
      ->fetchField();
  }
  $limit = 10;
  if (!empty($context['sandbox']['max'])) {
    $rules = db_select('access', 'a')
      ->fields('a')
      ->condition('aid', $context['sandbox']['current_aid'], '>')
      ->condition('type', 'host', '!=')
      ->orderBy('aid', 'ASC')
      ->range(0, $limit)
      ->execute();
    foreach ($rules as $rule) {

      // Access rules uses 'user' whilst user_restrictions uses 'name'
      $rule->type = $rule->type == 'user' ? 'name' : $rule->type;
      db_merge('user_restrictions')
        ->key(array(
        'type' => $rule->type,
        'mask' => $rule->mask,
        'status' => $rule->status,
      ))
        ->fields(array(
        'status' => $rule->status,
      ))
        ->execute();
      $context['results'][] = check_plain($rule->mask);
      $context['sandbox']['progress']++;
      $context['sandbox']['current_aid'] = $rule->aid;
    }
  }
  $context['finished'] = empty($context['sandbox']['max']) ? 1 : $context['sandbox']['progress'] / $context['sandbox']['max'];
}