Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -9,27 +9,27 @@
|
|||
* Implements hook_schema().
|
||||
*/
|
||||
function ban_schema() {
|
||||
$schema['ban_ip'] = array(
|
||||
$schema['ban_ip'] = [
|
||||
'description' => 'Stores banned IP addresses.',
|
||||
'fields' => array(
|
||||
'iid' => array(
|
||||
'fields' => [
|
||||
'iid' => [
|
||||
'description' => 'Primary Key: unique ID for IP addresses.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'ip' => array(
|
||||
],
|
||||
'ip' => [
|
||||
'description' => 'IP address',
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 40,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'ip' => array('ip'),
|
||||
),
|
||||
'primary key' => array('iid'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'ip' => ['ip'],
|
||||
],
|
||||
'primary key' => ['iid'],
|
||||
];
|
||||
return $schema;
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ function ban_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'help.page.ban':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Ban module allows administrators to ban visits to their site from individual IP addresses. For more information, see the <a href=":url">online documentation for the Ban module</a>.', array(':url' => 'https://www.drupal.org/documentation/modules/ban')) . '</p>';
|
||||
$output .= '<p>' . t('The Ban module allows administrators to ban visits to their site from individual IP addresses. For more information, see the <a href=":url">online documentation for the Ban module</a>.', [':url' => 'https://www.drupal.org/documentation/modules/ban']) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Banning IP addresses') . '</dt>';
|
||||
$output .= '<dd>' . t('Administrators can enter IP addresses to ban on the <a href=":bans">IP address bans</a> page.', array(':bans' => \Drupal::url('ban.admin_page'))) . '</dd>';
|
||||
$output .= '<dd>' . t('Administrators can enter IP addresses to ban on the <a href=":bans">IP address bans</a> page.', [':bans' => \Drupal::url('ban.admin_page')]) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class BanIpManager implements BanIpManagerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function isBanned($ip) {
|
||||
return (bool) $this->connection->query("SELECT * FROM {ban_ip} WHERE ip = :ip", array(':ip' => $ip))->fetchField();
|
||||
return (bool) $this->connection->query("SELECT * FROM {ban_ip} WHERE ip = :ip", [':ip' => $ip])->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,8 +45,8 @@ class BanIpManager implements BanIpManagerInterface {
|
|||
*/
|
||||
public function banIp($ip) {
|
||||
$this->connection->merge('ban_ip')
|
||||
->key(array('ip' => $ip))
|
||||
->fields(array('ip' => $ip))
|
||||
->key(['ip' => $ip])
|
||||
->fields(['ip' => $ip])
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ class BanIpManager implements BanIpManagerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function findById($ban_id) {
|
||||
return $this->connection->query("SELECT ip FROM {ban_ip} WHERE iid = :iid", array(':iid' => $ban_id))->fetchField();
|
||||
return $this->connection->query("SELECT ip FROM {ban_ip} WHERE iid = :iid", [':iid' => $ban_id])->fetchField();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,47 +52,47 @@ class BanAdmin extends FormBase {
|
|||
* address form field.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $default_ip = '') {
|
||||
$rows = array();
|
||||
$header = array($this->t('banned IP addresses'), $this->t('Operations'));
|
||||
$rows = [];
|
||||
$header = [$this->t('banned IP addresses'), $this->t('Operations')];
|
||||
$result = $this->ipManager->findAll();
|
||||
foreach ($result as $ip) {
|
||||
$row = array();
|
||||
$row = [];
|
||||
$row[] = $ip->ip;
|
||||
$links = array();
|
||||
$links['delete'] = array(
|
||||
$links = [];
|
||||
$links['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('ban.delete', ['ban_id' => $ip->iid]),
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => array(
|
||||
];
|
||||
$row[] = [
|
||||
'data' => [
|
||||
'#type' => 'operations',
|
||||
'#links' => $links,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
$form['ip'] = array(
|
||||
$form['ip'] = [
|
||||
'#title' => $this->t('IP address'),
|
||||
'#type' => 'textfield',
|
||||
'#size' => 48,
|
||||
'#maxlength' => 40,
|
||||
'#default_value' => $default_ip,
|
||||
'#description' => $this->t('Enter a valid IP address.'),
|
||||
);
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
];
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Add'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['ban_ip_banning_table'] = array(
|
||||
$form['ban_ip_banning_table'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => $this->t('No blocked IP addresses available.'),
|
||||
'#weight' => 120,
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ class BanAdmin extends FormBase {
|
|||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$ip = trim($form_state->getValue('ip'));
|
||||
$this->ipManager->banIp($ip);
|
||||
drupal_set_message($this->t('The IP address %ip has been banned.', array('%ip' => $ip)));
|
||||
drupal_set_message($this->t('The IP address %ip has been banned.', ['%ip' => $ip]));
|
||||
$form_state->setRedirect('ban.admin_page');
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class BanDelete extends ConfirmFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to unblock %ip?', array('%ip' => $this->banIp));
|
||||
return $this->t('Are you sure you want to unblock %ip?', ['%ip' => $this->banIp]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,8 +93,8 @@ class BanDelete extends ConfirmFormBase {
|
|||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->ipManager->unbanIp($this->banIp);
|
||||
$this->logger('user')->notice('Deleted %ip', array('%ip' => $this->banIp));
|
||||
drupal_set_message($this->t('The IP address %ip was deleted.', array('%ip' => $this->banIp)));
|
||||
$this->logger('user')->notice('Deleted %ip', ['%ip' => $this->banIp]);
|
||||
drupal_set_message($this->t('The IP address %ip was deleted.', ['%ip' => $this->banIp]));
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ class BlockedIP extends DestinationBase implements ContainerFactoryPluginInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
public function import(Row $row, array $old_destination_id_values = []) {
|
||||
$this->banManager->banIp($row->getDestinationProperty('ip'));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,55 +18,55 @@ class IpAddressBlockingTest extends BrowserTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('ban');
|
||||
public static $modules = ['ban'];
|
||||
|
||||
/**
|
||||
* Tests various user input to confirm correct validation and saving of data.
|
||||
*/
|
||||
function testIPAddressValidation() {
|
||||
public function testIPAddressValidation() {
|
||||
// Create user.
|
||||
$admin_user = $this->drupalCreateUser(array('ban IP addresses'));
|
||||
$admin_user = $this->drupalCreateUser(['ban IP addresses']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalGet('admin/config/people/ban');
|
||||
|
||||
// Ban a valid IP address.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['ip'] = '1.2.3.3';
|
||||
$this->drupalPostForm('admin/config/people/ban', $edit, t('Add'));
|
||||
$ip = db_query("SELECT iid from {ban_ip} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField();
|
||||
$ip = db_query("SELECT iid from {ban_ip} WHERE ip = :ip", [':ip' => $edit['ip']])->fetchField();
|
||||
$this->assertTrue($ip, 'IP address found in database.');
|
||||
$this->assertRaw(t('The IP address %ip has been banned.', array('%ip' => $edit['ip'])), 'IP address was banned.');
|
||||
$this->assertRaw(t('The IP address %ip has been banned.', ['%ip' => $edit['ip']]), 'IP address was banned.');
|
||||
|
||||
// Try to block an IP address that's already blocked.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['ip'] = '1.2.3.3';
|
||||
$this->drupalPostForm('admin/config/people/ban', $edit, t('Add'));
|
||||
$this->assertText(t('This IP address is already banned.'));
|
||||
|
||||
// Try to block a reserved IP address.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['ip'] = '255.255.255.255';
|
||||
$this->drupalPostForm('admin/config/people/ban', $edit, t('Add'));
|
||||
$this->assertText(t('Enter a valid IP address.'));
|
||||
|
||||
// Try to block a reserved IP address.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['ip'] = 'test.example.com';
|
||||
$this->drupalPostForm('admin/config/people/ban', $edit, t('Add'));
|
||||
$this->assertText(t('Enter a valid IP address.'));
|
||||
|
||||
// Submit an empty form.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['ip'] = '';
|
||||
$this->drupalPostForm('admin/config/people/ban', $edit, t('Add'));
|
||||
$this->assertText(t('Enter a valid IP address.'));
|
||||
|
||||
// Pass an IP address as a URL parameter and submit it.
|
||||
$submit_ip = '1.2.3.4';
|
||||
$this->drupalPostForm('admin/config/people/ban/' . $submit_ip, array(), t('Add'));
|
||||
$ip = db_query("SELECT iid from {ban_ip} WHERE ip = :ip", array(':ip' => $submit_ip))->fetchField();
|
||||
$this->drupalPostForm('admin/config/people/ban/' . $submit_ip, [], t('Add'));
|
||||
$ip = db_query("SELECT iid from {ban_ip} WHERE ip = :ip", [':ip' => $submit_ip])->fetchField();
|
||||
$this->assertTrue($ip, 'IP address found in database');
|
||||
$this->assertRaw(t('The IP address %ip has been banned.', array('%ip' => $submit_ip)), 'IP address was banned.');
|
||||
$this->assertRaw(t('The IP address %ip has been banned.', ['%ip' => $submit_ip]), 'IP address was banned.');
|
||||
|
||||
// Submit your own IP address. This fails, although it works when testing
|
||||
// manually.
|
||||
|
@ -85,7 +85,7 @@ class IpAddressBlockingTest extends BrowserTestBase {
|
|||
$banIp->banIp($ip);
|
||||
$banIp->banIp($ip);
|
||||
$query = db_select('ban_ip', 'bip');
|
||||
$query->fields('bip', array('iid'));
|
||||
$query->fields('bip', ['iid']);
|
||||
$query->condition('bip.ip', $ip);
|
||||
$ip_count = $query->execute()->fetchAll();
|
||||
$this->assertEqual(1, count($ip_count));
|
||||
|
@ -93,7 +93,7 @@ class IpAddressBlockingTest extends BrowserTestBase {
|
|||
$banIp->banIp($ip);
|
||||
$banIp->banIp($ip);
|
||||
$query = db_select('ban_ip', 'bip');
|
||||
$query->fields('bip', array('iid'));
|
||||
$query->fields('bip', ['iid']);
|
||||
$query->condition('bip.ip', $ip);
|
||||
$ip_count = $query->execute()->fetchAll();
|
||||
$this->assertEqual(1, count($ip_count));
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\ban\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue