This is a note for me to remember that this module will need to follow the exact workflow of access rules in core for 6.5+

CommentFileSizeAuthor
#11 318986.diff1.41 KBdrumm

Comments

Anonymous’s picture

Version: » 7.x-1.x-dev
Assigned: catch » Unassigned
Category: bug » task
Priority: Critical » Normal
Status: Active » Postponed

I am marking this task as postponed, as the code will be implemented as an update function, after the first official release will released.

fizk’s picture

Status: Postponed » Closed (fixed)

The difference between D6 Access rules and this module is that this module doesn't have the "Check rules" page where you can test username, email, and hostname rules.

I'll open a separate issue for this as a feature request (#1397268: Add ability to check rules).

Anonymous’s picture

Status: Closed (fixed) » Postponed

This issue is about importing the content of the database table used in Drupal 6. That is different from having a "Check rules" page, which is still present in the latest beta release.

There isn't, in the actual code, the possibility to import the settings from the Drupal 6 table. The update function for that purpose is commented out.

fizk’s picture

Title: Ensure 6.5 access rules changes are applied to user_restrictions » Create an update function to import access settings from a Drupal 6 install

Who wrote the update function that's commented out?

Anonymous’s picture

It's an update function that I found when I started to maintain the module, and that I kept updated with the code I am writing.

adammalone’s picture

Just as a note to self,

From the hook_update_N documentation when referring to the second number:

This digit should be 0 for initial porting of your module to a new Drupal core API.

The update function should therefore be 7001 7000

fizk’s picture

@typhonius, are you sure it's not 7000?

mymodule_update_7000(): This is the required update for mymodule to run with Drupal core API 7.x when upgrading from Drupal core API 6.x.

adammalone’s picture

@fiz - Yep you're right - no idea how I misread that!

code-brighton’s picture

Hi I uncommented the user_restrictions_update_7102
I threw PDO exception an error on running update.php due to faulty queries. But I fixed these and updated the code and it worked! So thanks for leaving it in there. (Note I hard coded the Access Rule type to 'mail' in the first query "SELECT COUNT(DISTINCT aid) FROM {access} WHERE type = 'mail'" as I only cared about these rule types... you could change this if you wanted. Updated code below:

function user_restrictions_update_7102(&$sandbox) {
  if (!isset($sandbox['progress']) && db_table_exists('access')) {
    $sandbox['progress'] = 0;
    $sandbox['current_aid'] = 0;
    $sandbox['max'] = db_query("SELECT COUNT(DISTINCT aid) FROM {access} WHERE type = 'mail'")->fetchField();
  }

  drupal_load('module', 'user_restrictions');

  if (!empty($sandbox['max'])) {
    $rules = db_select('access', 'access')
      ->fields('access')
      ->condition('aid', $sandbox['current_aid'], '>')
      ->orderBy('aid', 'ASC')
      ->execute();

    foreach ($rules as $rule) {
      db_merge('user_restrictions')
        ->key(array(
          'type' => $rule->type,
          'mask' => $rule->mask,
        ))
        ->fields(array('status' => $rule->status))
        ->execute();

      $sandbox['progress']++;
      $sandbox['current_aid'] = $rule->aid;
    }
  }
  $sandbox['#finished'] = (
    empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max'])
  );
}
drumm’s picture

Status: Postponed » Active
Issue tags: +Drupal.org 7.1, +affects drupal.org

There is an official release now.

drumm’s picture

Status: Active » Needs review
StatusFileSize
new1.41 KB

Here is a quick patch based on #9. I went ahead and let it have free reign on all types and included the status column.

drumm’s picture

Priority: Normal » Major
adammalone’s picture

Thanks for these, I'll review and hopefully get something in by later today.

adammalone’s picture

I've committed this locally but I'm going to make some more additions before pushing.

  • Remove hosts from the query so we only get username/mail masks (hosts are catered for in D7 core)
  • The hook_update_N function will only work for people who already have the module enabled so we also need 'import' functionality so new users are able to import from the access table after installing.
drumm’s picture

Sounds good.

tvn’s picture

Issue summary: View changes
Issue tags: -Drupal.org 7.1

Untagging. We already imported settings for D7 D.o

adammalone’s picture

Recent changes are in the most recent dev, allowing imports on both module upgrade and manually through the UI module.

adammalone’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

  • Commit f7dabe8 on 7.x-1.x, 8.x-1.x authored by drumm:
    Issue #318986 by drumm | catch: Create an update function to import...