Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Issue forks
automatic_updates-3242724
Commits
4196d19e
Commit
4196d19e
authored
Jun 05, 2019
by
heddn
Committed by
heddn
Jun 05, 2019
Browse files
Issue
#3046858
by heddn, tatarbj: Add admin / config page to enable/disable PSA
parent
68a786b4
Changes
5
Hide whitespace changes
Inline
Side-by-side
AutomaticUpdatesPsa.php
View file @
4196d19e
...
...
@@ -23,6 +23,10 @@ class AutomaticUpdatesPsa {
public
static
function
getPublicServiceMessages
()
{
$messages
=
array
();
if
(
!
variable_get
(
'automatic_updates_enable_psa'
))
{
return
$messages
;
}
if
(
$cache
=
cache_get
(
'automatic_updates_psa'
))
{
$response
=
$cache
->
data
;
}
...
...
@@ -31,7 +35,7 @@ class AutomaticUpdatesPsa {
$response
=
drupal_http_request
(
$psa_endpoint
);
if
(
isset
(
$response
->
code
)
&&
(
$response
->
code
==
200
))
{
// Set response in cache for 12 hours.
cache_set
(
'automatic_updates_psa'
,
$response
,
'cache'
,
REQUEST_TIME
+
3600
*
12
);
cache_set
(
'automatic_updates_psa'
,
$response
,
'cache'
,
variable_get
(
'automatic_updates_check_frequency'
,
REQUEST_TIME
+
3600
*
12
)
)
;
}
else
{
watchdog
(
'automatic_updates'
,
'Drupal PSA endpoint %url is unreachable.'
,
array
(
'%url'
=>
$psa_endpoint
),
WATCHDOG_ERROR
);
...
...
automatic_updates.admin.inc
0 → 100644
View file @
4196d19e
<?php
/**
* @file
* Administration functions for Automatic Updates module.
*/
/**
* Form callback for administrator interface.
*/
function
automatic_updates_admin_form
(
$form
,
&
$form_state
)
{
$form
[
'description'
]
=
[
'#markup'
=>
'<p>'
.
t
(
'Public service announcements are compared against the entire code for the site, not just installed extensions.'
)
.
'</p>'
,
];
$form
[
'automatic_updates_enable_psa'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Show public service announcements on administrative pages.'
),
'#default_value'
=>
variable_get
(
'automatic_updates_enable_psa'
,
TRUE
),
];
return
system_settings_form
(
$form
);
}
automatic_updates.install
View file @
4196d19e
...
...
@@ -9,5 +9,6 @@
* Implements hook_uninstall().
*/
function
automatic_updates_uninstall
()
{
variable_del
(
'psa_endpoint_psa_endpoint'
);
variable_del
(
'automatic_updates_psa_endpoint'
);
variable_del
(
'automatic_updates_enable_psa'
);
}
automatic_updates.module
View file @
4196d19e
...
...
@@ -31,3 +31,22 @@ function automatic_updates_init() {
}
}
}
/**
* Implements hook_menu().
*/
function
automatic_updates_menu
()
{
$items
=
[];
$items
[
'admin/config/system/automatic_updates'
]
=
[
'title'
=>
'Automatic Updates'
,
'page callback'
=>
'drupal_get_form'
,
'page arguments'
=>
[
'automatic_updates_admin_form'
],
'file'
=>
'automatic_updates.admin.inc'
,
'file path'
=>
drupal_get_path
(
'module'
,
'automatic_updates'
),
'access arguments'
=>
[
'administer software updates'
],
'tab parent'
=>
'admin/config/system'
,
];
return
$items
;
}
tests/automatic_updates.test
View file @
4196d19e
...
...
@@ -27,24 +27,35 @@ class AutomaticUpdatesTestCase extends DrupalWebTestCase {
public
function
setUp
()
{
parent
::
setUp
(
array
(
'automatic_updates'
,
'automatic_updates_test'
));
// Create a user with permission to view the actions administration pages.
$user
=
$this
->
drupalCreateUser
(
array
(
'administer site configuration'
,
'access administration pages'
));
$user
=
$this
->
drupalCreateUser
(
array
(
'access administration pages'
,
'administer site configuration'
,
'administer software updates'
,
));
$this
->
drupalLogin
(
$user
);
$psa_endpoint
=
$this
->
getAbsoluteUrl
(
'automatic_updates/test-json'
);
variable_set
(
'automatic_updates_psa_endpoint'
,
$psa_endpoint
);
variable_set
(
'automatic_updates_enable_psa'
,
TRUE
);
}
/**
* Test automatic updates.
*/
public
function
testAutomaticUpdates
()
{
// Test PSAs.
$this
->
drupalGet
(
'admin'
);
$this
->
assertText
(
'Drupal Core PSA: Critical Release - PSA-2019-02-19'
);
$this
->
assertNoText
(
'Drupal Core PSA: Critical Release - PSA-Really Old'
);
$this
->
assertNoText
(
'Node - Moderately critical - Access bypass - SA-CONTRIB-2019'
);
$this
->
assertText
(
'Drupal Contrib Project PSA: Standard - Moderately critical - Access bypass - SA-CONTRIB-2019'
);
$this
->
assertText
(
'Drupal Contrib Project PSA: Seven - Moderately critical - Access bypass - SA-CONTRIB-2019'
);
// Test disabling PSAs.
variable_set
(
'automatic_updates_enable_psa'
,
FALSE
);
$this
->
drupalGet
(
'admin'
);
$this
->
assertNoText
(
'Drupal Core PSA: Critical Release - PSA-2019-02-19'
);
variable_set
(
'automatic_updates_enable_psa'
,
TRUE
);
// Test cache.
$psa_endpoint
=
$this
->
getAbsoluteUrl
(
'automatic_updates/test-json-denied'
);
variable_set
(
'automatic_updates_psa_endpoint'
,
$psa_endpoint
);
...
...
@@ -54,7 +65,7 @@ class AutomaticUpdatesTestCase extends DrupalWebTestCase {
// Test transmit errors with JSON endpoint.
drupal_flush_all_caches
();
$this
->
drupalGet
(
'admin'
);
$this
->
assertText
(
'
Drupal PSA endpoint http://localhost/
automatic_updates/test-json-denied is unreachable.'
);
$this
->
assertText
(
'automatic_updates/test-json-denied is unreachable.'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment