diff --git a/includes/FeedsSource.inc b/includes/FeedsSource.inc index 075f7b1..783751e 100644 --- a/includes/FeedsSource.inc +++ b/includes/FeedsSource.inc @@ -88,6 +88,7 @@ class FeedsState { public $updated; public $deleted; public $unpublished; + public $blocked; public $skipped; public $failed; @@ -106,6 +107,7 @@ class FeedsState { $this->updated = $this->deleted = $this->unpublished = + $this->blocked = $this->skipped = $this->failed = 0; } diff --git a/plugins/FeedsProcessor.inc b/plugins/FeedsProcessor.inc index 1c56f62..8b862b0 100755 --- a/plugins/FeedsProcessor.inc +++ b/plugins/FeedsProcessor.inc @@ -314,6 +314,16 @@ abstract class FeedsProcessor extends FeedsPlugin { ), ); } + if ($state->blocked) { + $messages[] = array( + 'message' => format_plural( + $state->blocked, + 'Blocked @number @entity.', + 'Blocked @number @entities.', + array('@number' => $state->blocked) + $tokens + ), + ); + } if ($state->deleted) { $messages[] = array( 'message' => format_plural( diff --git a/plugins/FeedsUserProcessor.inc b/plugins/FeedsUserProcessor.inc index f4d68c4..a0ec3e3 100644 --- a/plugins/FeedsUserProcessor.inc +++ b/plugins/FeedsUserProcessor.inc @@ -1,13 +1,17 @@ t('This appends _test to all imported e-mail addresses to ensure they cannot be used as recipients.'), '#default_value' => $this->config['defuse_mail'], ); - $form['update_non_existent']['#options'][FEEDS_BLOCK_NON_EXISTENT] = t('Block non existent users'); + $form['update_non_existent']['#options'][FEEDS_BLOCK_NON_EXISTENT] = t('Block non-existent users'); return $form; } @@ -241,17 +245,30 @@ class FeedsUserProcessor extends FeedsProcessor { * Block users instead of deleting them. * * @param FeedsState $state + * The FeedsState object for the given stage. */ protected function clean(FeedsState $state) { - // Delegate to parent if not unpublishing or option not set + // Delegate to parent if not blocking or option not set. if (!isset($this->config['update_non_existent']) || $this->config['update_non_existent'] != FEEDS_BLOCK_NON_EXISTENT) { return parent::clean($state); } $total = count($state->removeList); if ($total) { - user_user_operations_block($state->removeList); - $state->updated += $total; + // @see user_user_operations_block(). + // The following foreach is copied from above function but with an added + // counter to count blocked users. + $accounts = user_load_multiple($state->removeList); + foreach ($accounts as $account) { + // Skip blocking user if they are already blocked. + if ($account !== FALSE && $account->status == 1) { + // For efficiency manually save the original account before applying any + // changes. + $account->original = clone $account; + user_save($account, array('status' => 0)); + $state->blocked++; + } + } } } } diff --git a/tests/feeds/users2.csv b/tests/feeds/users2.csv new file mode 100644 index 0000000..ed10078 --- /dev/null +++ b/tests/feeds/users2.csv @@ -0,0 +1,5 @@ +name,mail,since,password +Morticia,morticia@example.com,1244347500,mort +Gomez,gomez@example.com,1228572000,gome +Wednesday,wednesdayexample.com,1228347137,wedn +Pugsley,pugsley@example,1228260225,pugs diff --git a/tests/feeds_processor_user.test b/tests/feeds_processor_user.test index 73f8d06..51cc2a3 100644 --- a/tests/feeds_processor_user.test +++ b/tests/feeds_processor_user.test @@ -118,5 +118,14 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase { $this->assertTrue($account, 'Imported user account loaded.'); $account->pass_raw = 'fest'; $this->drupalLogin($account); + + // Login as admin + $this->drupalLogin($this->admin_user); + + // Import modified CSV file, one (valid) user is missing. + $this->setSettings('user_import', 'FeedsUserProcessor', array('update_existing' => 2, 'update_non_existent' => 'block')); + $this->importFile('user_import', $this->absolutePath() . '/tests/feeds/users2.csv'); + $this->assertText('Blocked 1 user'); + $this->assertText('Failed importing 2 user'); } }