Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
225
Merge Requests
225
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
65899f6b
Commit
65899f6b
authored
Feb 24, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2195417
by Sutharsan: Clean up configuration import events.
parent
228fdcbc
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
21 additions
and
40 deletions
+21
-40
core/lib/Drupal/Core/Config/BatchConfigImporter.php
core/lib/Drupal/Core/Config/BatchConfigImporter.php
+4
-4
core/lib/Drupal/Core/Config/ConfigEvents.php
core/lib/Drupal/Core/Config/ConfigEvents.php
+1
-1
core/lib/Drupal/Core/Config/ConfigImporter.php
core/lib/Drupal/Core/Config/ConfigImporter.php
+11
-29
core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php
...ib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php
+1
-1
core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php
...les/config/lib/Drupal/config/Tests/ConfigImportUITest.php
+3
-3
core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php
...dules/system/lib/Drupal/system/SystemConfigSubscriber.php
+1
-2
No files found.
core/lib/Drupal/Core/Config/BatchConfigImporter.php
View file @
65899f6b
...
...
@@ -21,9 +21,9 @@ public function initialize() {
// Ensure that the changes have been validated.
$this
->
validate
();
if
(
!
$this
->
lock
->
acquire
(
static
::
ID
))
{
if
(
!
$this
->
lock
->
acquire
(
static
::
LOCK_
ID
))
{
// Another process is synchronizing configuration.
throw
new
ConfigImporterException
(
sprintf
(
'%s is already importing'
,
static
::
ID
));
throw
new
ConfigImporterException
(
sprintf
(
'%s is already importing'
,
static
::
LOCK_
ID
));
}
$this
->
totalToProcess
=
0
;
foreach
(
array
(
'create'
,
'delete'
,
'update'
)
as
$op
)
{
...
...
@@ -48,9 +48,9 @@ public function processBatch(array &$context) {
$context
[
'finished'
]
=
1
;
}
if
(
$context
[
'finished'
]
>=
1
)
{
$this
->
notify
(
'import'
);
$this
->
eventDispatcher
->
dispatch
(
ConfigEvents
::
IMPORT
,
new
ConfigImporterEvent
(
$this
)
);
// The import is now complete.
$this
->
lock
->
release
(
static
::
ID
);
$this
->
lock
->
release
(
static
::
LOCK_
ID
);
$this
->
reset
();
}
}
...
...
core/lib/Drupal/Core/Config/ConfigEvents.php
View file @
65899f6b
...
...
@@ -47,7 +47,7 @@ final class ConfigEvents {
* @see \Drupal\Core\Config\ConfigImporter::validate().
* @see \Drupal\Core\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate().
*/
const
VALIDATE
=
'config.importer.validate'
;
const
IMPORT_
VALIDATE
=
'config.importer.validate'
;
/**
* Name of event fired when when importing configuration to target storage.
...
...
core/lib/Drupal/Core/Config/ConfigImporter.php
View file @
65899f6b
...
...
@@ -7,6 +7,7 @@
namespace
Drupal\Core\Config
;
use
Drupal\Core\Config\ConfigEvents
;
use
Drupal\Core\DependencyInjection\DependencySerialization
;
use
Drupal\Core\Lock\LockBackendInterface
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
...
...
@@ -21,7 +22,7 @@
*
* The ConfigImporter has a identifier which is used to construct event names.
* The events fired during an import are:
* - ConfigEvents::VALIDATE: Events listening can throw a
* - ConfigEvents::
IMPORT_
VALIDATE: Events listening can throw a
* \Drupal\Core\Config\ConfigImporterException to prevent an import from
* occurring.
* @see \Drupal\Core\EventSubscriber\ConfigImportSubscriber
...
...
@@ -33,9 +34,9 @@
class
ConfigImporter
extends
DependencySerialization
{
/**
* The name used to identify
events and
the lock.
* The name used to identify the lock.
*/
const
ID
=
'config.
importer'
;
const
LOCK_ID
=
'config_
importer'
;
/**
* The storage comparer used to discover configuration changes.
...
...
@@ -201,9 +202,9 @@ public function import() {
// Ensure that the changes have been validated.
$this
->
validate
();
if
(
!
$this
->
lock
->
acquire
(
static
::
ID
))
{
if
(
!
$this
->
lock
->
acquire
(
static
::
LOCK_
ID
))
{
// Another process is synchronizing configuration.
throw
new
ConfigImporterException
(
sprintf
(
'%s is already importing'
,
static
::
ID
));
throw
new
ConfigImporterException
(
sprintf
(
'%s is already importing'
,
static
::
LOCK_
ID
));
}
// First pass deleted, then new, and lastly changed configuration, in order
// to handle dependencies correctly.
...
...
@@ -215,10 +216,11 @@ public function import() {
}
}
// Allow modules to react to a import.
$this
->
notify
(
'import'
);
$this
->
eventDispatcher
->
dispatch
(
ConfigEvents
::
IMPORT
,
new
ConfigImporterEvent
(
$this
));
// The import is now complete.
$this
->
lock
->
release
(
static
::
ID
);
$this
->
lock
->
release
(
static
::
LOCK_
ID
);
$this
->
reset
();
}
return
$this
;
...
...
@@ -235,7 +237,7 @@ public function validate() {
if
(
!
$this
->
storageComparer
->
validateSiteUuid
())
{
throw
new
ConfigImporterException
(
'Site UUID in source storage does not match the target storage.'
);
}
$this
->
notify
(
'validate'
);
$this
->
eventDispatcher
->
dispatch
(
ConfigEvents
::
IMPORT_VALIDATE
,
new
ConfigImporterEvent
(
$this
)
);
$this
->
validated
=
TRUE
;
}
return
$this
;
...
...
@@ -322,16 +324,6 @@ protected function importInvokeOwner($op, $name) {
return
FALSE
;
}
/**
* Dispatches a config importer event.
*
* @param string $event_name
* The name of the config importer event to dispatch.
*/
protected
function
notify
(
$event_name
)
{
$this
->
eventDispatcher
->
dispatch
(
static
::
ID
.
'.'
.
$event_name
,
new
ConfigImporterEvent
(
$this
));
}
/**
* Determines if a import is already running.
*
...
...
@@ -339,17 +331,7 @@ protected function notify($event_name) {
* TRUE if an import is already running, FALSE if not.
*/
public
function
alreadyImporting
()
{
return
!
$this
->
lock
->
lockMayBeAvailable
(
static
::
ID
);
}
/**
* Returns the identifier for events and locks.
*
* @return string
* The identifier for events and locks.
*/
public
function
getId
()
{
return
static
::
ID
;
return
!
$this
->
lock
->
lockMayBeAvailable
(
static
::
LOCK_ID
);
}
}
core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php
View file @
65899f6b
...
...
@@ -41,7 +41,7 @@ public function onConfigImporterValidate(ConfigImporterEvent $event) {
* An array of event listener definitions.
*/
static
function
getSubscribedEvents
()
{
$events
[
ConfigEvents
::
VALIDATE
][]
=
array
(
'onConfigImporterValidate'
,
40
);
$events
[
ConfigEvents
::
IMPORT_
VALIDATE
][]
=
array
(
'onConfigImporterValidate'
,
40
);
return
$events
;
}
...
...
core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php
View file @
65899f6b
...
...
@@ -101,15 +101,15 @@ function testImportLock() {
$this
->
assertNoText
(
t
(
'There are no configuration changes.'
));
// Acquire a fake-lock on the import mechanism.
$config_importer
_lock
=
$this
->
configImporter
()
->
getId
();
$this
->
container
->
get
(
'lock'
)
->
acquire
(
$config_importer
_lock
);
$config_importer
=
$this
->
configImporter
();
$this
->
container
->
get
(
'lock'
)
->
acquire
(
$config_importer
::
LOCK_ID
);
// Attempt to import configuration and verify that an error message appears.
$this
->
drupalPostForm
(
NULL
,
array
(),
t
(
'Import all'
));
$this
->
assertText
(
t
(
'Another request may be synchronizing configuration already.'
));
// Release the lock, just to keep testing sane.
$this
->
container
->
get
(
'lock'
)
->
release
(
$config_importer
_lock
);
$this
->
container
->
get
(
'lock'
)
->
release
(
$config_importer
::
LOCK_ID
);
// Verify site name has not changed.
$this
->
assertNotEqual
(
$new_site_name
,
\
Drupal
::
config
(
'system.site'
)
->
get
(
'name'
));
...
...
core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php
View file @
65899f6b
...
...
@@ -22,7 +22,7 @@ class SystemConfigSubscriber implements EventSubscriberInterface {
* {@inheritdoc}
*/
static
function
getSubscribedEvents
()
{
$events
[
ConfigEvents
::
VALIDATE
][]
=
array
(
'onConfigImporterValidate'
,
20
);
$events
[
ConfigEvents
::
IMPORT_
VALIDATE
][]
=
array
(
'onConfigImporterValidate'
,
20
);
return
$events
;
}
...
...
@@ -42,4 +42,3 @@ public function onConfigImporterValidate(ConfigImporterEvent $event) {
}
}
}
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