Skip to content
Snippets Groups Projects
Commit 41ea72a7 authored by mikran's avatar mikran Committed by Chris Leppanen
Browse files

Issue #2092895 by mikran, MegaChriz, twistor: Block users not included in feed

parent 00f28a27
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
......@@ -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(
......
......@@ -2,13 +2,21 @@
/**
* @file
* FeedsUserProcessor class.
* Contains FeedsUserProcessor.
*/
/**
* Option to block users not found in the feed.
*
* @var string
*/
define('FEEDS_BLOCK_NON_EXISTENT', 'block');
/**
* Feeds processor plugin. Create users from feed items.
*/
class FeedsUserProcessor extends FeedsProcessor {
/**
* Define entity type.
*/
......@@ -132,6 +140,7 @@ class FeedsUserProcessor extends FeedsProcessor {
'#description' => 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');
return $form;
}
......@@ -227,4 +236,35 @@ class FeedsUserProcessor extends FeedsProcessor {
}
return 0;
}
/**
* Overrides FeedsProcessor::clean().
*
* 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 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);
}
if (!empty($state->removeList)) {
// @see user_user_operations_block().
// The following foreach is copied from above function but with an added
// counter to count blocked users.
foreach (user_load_multiple($state->removeList) as $account) {
$this->loadItemInfo($account);
$account->feeds_item->hash = $this->config['update_non_existent'];
// For efficiency manually save the original account before applying any
// changes.
$account->original = clone $account;
user_save($account, array('status' => 0));
$state->blocked++;
}
}
}
}
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
......@@ -118,5 +118,20 @@ 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');
// Import the original CSV file again.
$this->importFile('user_import', $this->absolutePath() . '/tests/feeds/users.csv');
$this->assertText('Updated 1 user');
$this->assertText('Failed importing 2 user');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment